|
| 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 | +import { ConfiguratorSection } from "../ConfiguratorSection/ConfiguratorSection"; |
| 16 | +import { useConfiguratorStatusContext } from "../ConfiguratorStatusContext"; |
| 17 | +import { ColorPickerField } from "../ColorPickerField/ColorPickerField"; |
| 18 | +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 | +} |
| 44 | + |
| 45 | +export function TokensSection() { |
| 46 | + const { theme, setTheme } = useConfiguratorStatusContext(); |
| 47 | + const { t } = useTranslation(); |
| 48 | + |
| 49 | + const tokens = theme.tokens; |
| 50 | + const setTokens = (tokens: typeof theme.tokens) => setTheme({ ...theme, tokens }); |
| 51 | + |
| 52 | + 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> |
| 124 | + </ConfiguratorSection> |
| 125 | + ); |
| 126 | +} |
0 commit comments