From 521d308a6c6777a45c94183751f3305ce23bdad3 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 18 Jan 2024 14:35:25 +0200 Subject: [PATCH] themes 3 initial work --- src/components/button.style.js | 18 +++++ src/components/icon.style.js | 3 + src/components/panel.style.js | 8 +++ src/components/text.style.js | 9 +++ src/components/underlay.style.js | 6 ++ .../theme_data/theme_data_3.service.js | 66 +++++++++++++++++++ 6 files changed, 110 insertions(+) create mode 100644 src/components/button.style.js create mode 100644 src/components/icon.style.js create mode 100644 src/components/panel.style.js create mode 100644 src/components/text.style.js create mode 100644 src/components/underlay.style.js create mode 100644 src/services/theme_data/theme_data_3.service.js diff --git a/src/components/button.style.js b/src/components/button.style.js new file mode 100644 index 0000000000..8f2e8f8294 --- /dev/null +++ b/src/components/button.style.js @@ -0,0 +1,18 @@ +export default { + name: 'Button', + states: { + hover: ':hover', + disabled: ':disabled', + pressed: ':active', + toggled: '.toggled' + }, + variants: { + danger: '.danger', + unstyled: '.unstyled', + sublime: '.sublime' + }, + validInnerComponents: [ + 'Text', + 'Icon' + ] +} diff --git a/src/components/icon.style.js b/src/components/icon.style.js new file mode 100644 index 0000000000..1e2781d6ca --- /dev/null +++ b/src/components/icon.style.js @@ -0,0 +1,3 @@ +export default { + name: 'Icon' +} diff --git a/src/components/panel.style.js b/src/components/panel.style.js new file mode 100644 index 0000000000..1666d92316 --- /dev/null +++ b/src/components/panel.style.js @@ -0,0 +1,8 @@ +export default { + name: 'Panel', + validInnerComponents: [ + 'Text', + 'Icon', + 'Button' + ] +} diff --git a/src/components/text.style.js b/src/components/text.style.js new file mode 100644 index 0000000000..f87268bbfa --- /dev/null +++ b/src/components/text.style.js @@ -0,0 +1,9 @@ +export default { + name: 'Text', + states: { + faint: '.faint' + }, + variants: { + green: '/.greentext' + } +} diff --git a/src/components/underlay.style.js b/src/components/underlay.style.js new file mode 100644 index 0000000000..bae9fc0b35 --- /dev/null +++ b/src/components/underlay.style.js @@ -0,0 +1,6 @@ +export default { + name: 'Panel', + validInnerComponents: [ + 'Panel' + ] +} diff --git a/src/services/theme_data/theme_data_3.service.js b/src/services/theme_data/theme_data_3.service.js new file mode 100644 index 0000000000..3a6fd55266 --- /dev/null +++ b/src/services/theme_data/theme_data_3.service.js @@ -0,0 +1,66 @@ +import Underlay from 'src/components/underlay.style.js' +import Panel from 'src/components/panel.style.js' +import Button from 'src/components/button.style.js' +import Text from 'src/components/text.style.js' +import Icon from 'src/components/icon.style.js' + +const root = Underlay +const components = { + Underlay, + Panel, + Button, + Text, + Icon +} + +// This gives you an array of arrays of all possible unique (i.e. order-insensitive) combinations +const getAllPossibleCombinations = (array) => { + const combos = [array.map(x => [x])] + for (let comboSize = 2; comboSize <= array.length; comboSize++) { + const previous = combos[combos.length - 1] + const selfSet = new Set() + const newCombos = previous.map(self => { + self.forEach(x => selfSet.add(x)) + const nonSelf = array.filter(x => !selfSet.has(x)) + return nonSelf.map(x => [...self, x]) + }) + const flatCombos = newCombos.reduce((acc, x) => [...acc, ...x], []) + combos.push(flatCombos) + } + return combos.reduce((acc, x) => [...acc, ...x], []) +} + +export const init = () => { + const rootName = root.name + const rules = [] + + const processInnerComponent = (component, parent) => { + const { + validInnerComponents, + states: originalStates = {}, + variants: originalVariants = {} + } = component + + const states = { normal: '', ...originalStates } + const variants = { normal: '', ...originalVariants } + const innerComponents = validInnerComponents.map(name => components[name]) + + const stateCombinations = getAllPossibleCombinations(Object.keys(states)) + const stateVariantCombination = Object.keys(variants).map(variant => { + return stateCombinations.map(state => ({ variant, state })) + }).reduce((acc, x) => [...acc, ...x], []) + + stateVariantCombination.forEach(combination => { + rules.push(({ + parent, + component: component.name, + state: combination.state, + variant: combination.variant + })) + + innerComponents.forEach(innerComponent => processInnerComponent(innerComponent, combination)) + }) + } + + processInnerComponent(components[rootName]) +}