|
1 |
| -import { |
2 |
| - AreaLoader, |
3 |
| - BentoThemeProvider, |
4 |
| - Body, |
5 |
| - Box, |
6 |
| - Column, |
7 |
| - Columns, |
8 |
| - DecorativeDivider, |
9 |
| - LocalizedString, |
10 |
| - SliderField, |
11 |
| - Stack, |
12 |
| - Title, |
13 |
| - unsafeLocalizedString, |
14 |
| -} from "@buildo/bento-design-system"; |
15 | 1 | import { ConfiguratorSection } from "../ConfiguratorSection/ConfiguratorSection";
|
16 | 2 | import { useConfiguratorStatusContext } from "../ConfiguratorStatusContext";
|
17 |
| -import { ColorPickerField } from "../ColorPickerField/ColorPickerField"; |
18 | 3 | import { useTranslation } from "react-i18next";
|
19 |
| - |
20 |
| -function ColorTokenField(props: { |
21 |
| - label: LocalizedString; |
22 |
| - value: string; |
23 |
| - onChange: (value: string) => void; |
24 |
| -}) { |
25 |
| - const { theme } = useConfiguratorStatusContext(); |
26 |
| - const { t } = useTranslation(); |
27 |
| - return ( |
28 |
| - <Columns space={24} alignY="stretch"> |
29 |
| - <Column width="content"> |
30 |
| - <Box borderRadius={16} height="full" style={{ background: props.value, width: 64 }} /> |
31 |
| - </Column> |
32 |
| - <Stack space={8}> |
33 |
| - <Title size="medium">{props.label}</Title> |
34 |
| - <ColorPickerField |
35 |
| - colors={theme.colors} |
36 |
| - label={t("Tokens.Color.label")} |
37 |
| - value={props.value} |
38 |
| - onChange={props.onChange} |
39 |
| - /> |
40 |
| - </Stack> |
41 |
| - </Columns> |
42 |
| - ); |
43 |
| -} |
| 4 | +import { useState } from "react"; |
| 5 | +import { BrandTokens } from "./BrandTokens"; |
| 6 | +import { match } from "ts-pattern"; |
44 | 7 |
|
45 | 8 | export function TokensSection() {
|
46 | 9 | const { theme, setTheme } = useConfiguratorStatusContext();
|
47 | 10 | const { t } = useTranslation();
|
48 | 11 |
|
49 |
| - const tokens = theme.tokens; |
50 |
| - const setTokens = (tokens: typeof theme.tokens) => setTheme({ ...theme, tokens }); |
| 12 | + const steps = ["brand" as const]; |
| 13 | + const [currentStep] = useState<(typeof steps)[0]>("brand"); |
| 14 | + const currentStepIndex = steps.indexOf(currentStep); |
51 | 15 |
|
52 | 16 | return (
|
53 |
| - <ConfiguratorSection title={t("Tokens.title")} steps={[]} currentStep={0}> |
54 |
| - <Columns space={40} alignY="stretch"> |
55 |
| - <Column width="1/4"> |
56 |
| - <Stack space={16}> |
57 |
| - <ColorTokenField |
58 |
| - label={t("Tokens.Color.primary")} |
59 |
| - value={tokens.brandColor.brandPrimary} |
60 |
| - onChange={(value) => |
61 |
| - setTokens({ ...tokens, brandColor: { ...tokens.brandColor, brandPrimary: value } }) |
62 |
| - } |
63 |
| - /> |
64 |
| - <ColorTokenField |
65 |
| - label={t("Tokens.Color.secondary")} |
66 |
| - value={tokens.brandColor.brandSecondary} |
67 |
| - onChange={(value) => |
68 |
| - setTokens({ |
69 |
| - ...tokens, |
70 |
| - brandColor: { ...tokens.brandColor, brandSecondary: value }, |
71 |
| - }) |
72 |
| - } |
73 |
| - /> |
74 |
| - <ColorTokenField |
75 |
| - label={t("Tokens.Color.tertiary")} |
76 |
| - value={tokens.brandColor.brandTertiary} |
77 |
| - onChange={(value) => |
78 |
| - setTokens({ ...tokens, brandColor: { ...tokens.brandColor, brandTertiary: value } }) |
79 |
| - } |
80 |
| - /> |
81 |
| - </Stack> |
82 |
| - </Column> |
83 |
| - <Box |
84 |
| - borderRadius={24} |
85 |
| - padding={40} |
86 |
| - background="backgroundSecondary" |
87 |
| - display="flex" |
88 |
| - flexDirection="column" |
89 |
| - flexGrow={1} |
90 |
| - > |
91 |
| - <BentoThemeProvider theme={tokens}> |
92 |
| - <Stack space={40}> |
93 |
| - <Stack space={12}> |
94 |
| - <Body size="medium" color="secondary"> |
95 |
| - {t("Component.decorativeDivider")} |
96 |
| - </Body> |
97 |
| - <DecorativeDivider /> |
98 |
| - </Stack> |
99 |
| - <Stack space={12}> |
100 |
| - <Body size="medium" color="secondary"> |
101 |
| - {t("Component.areaLoader")} |
102 |
| - </Body> |
103 |
| - <Box position="relative" style={{ height: 240 }}> |
104 |
| - <AreaLoader /> |
105 |
| - </Box> |
106 |
| - </Stack> |
107 |
| - <Stack space={12}> |
108 |
| - <Body size="medium" color="secondary"> |
109 |
| - {t("Component.sliderField")} |
110 |
| - </Body> |
111 |
| - <SliderField |
112 |
| - type="single" |
113 |
| - label={unsafeLocalizedString("")} |
114 |
| - value={50} |
115 |
| - minValue={0} |
116 |
| - maxValue={100} |
117 |
| - onChange={() => {}} |
118 |
| - /> |
119 |
| - </Stack> |
120 |
| - </Stack> |
121 |
| - </BentoThemeProvider> |
122 |
| - </Box> |
123 |
| - </Columns> |
| 17 | + <ConfiguratorSection |
| 18 | + title={t("Tokens.title")} |
| 19 | + steps={steps.map((step) => ({ label: t(`TokensSection.Step.${step}`) }))} |
| 20 | + currentStep={currentStepIndex} |
| 21 | + > |
| 22 | + {match(currentStep) |
| 23 | + .with("brand", () => ( |
| 24 | + <BrandTokens |
| 25 | + tokens={theme.tokens} |
| 26 | + onChange={(brandTokens) => |
| 27 | + setTheme({ ...theme, tokens: { ...theme.tokens, brandColor: brandTokens } }) |
| 28 | + } |
| 29 | + /> |
| 30 | + )) |
| 31 | + .exhaustive()} |
124 | 32 | </ConfiguratorSection>
|
125 | 33 | );
|
126 | 34 | }
|
0 commit comments