-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
156 additions
and
114 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
packages/configuration-builder/src/TokensSection/BrandTokens.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { | ||
AreaLoader, | ||
BentoThemeProvider, | ||
BentoTokens, | ||
Body, | ||
Box, | ||
Column, | ||
Columns, | ||
SliderField, | ||
Stack, | ||
unsafeLocalizedString, | ||
DecorativeDivider, | ||
Headline, | ||
} from "@buildo/bento-design-system"; | ||
import { ColorTokenField } from "./ColorTokenField"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
type Props = { | ||
tokens: BentoTokens; | ||
onChange: (value: BentoTokens["brandColor"]) => void; | ||
}; | ||
|
||
export function BrandTokens(props: Props) { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Stack space={40}> | ||
<Headline size="small">{t("TokensSection.Step.brand")}</Headline> | ||
<Columns space={40} alignY="stretch"> | ||
<Column width="1/4"> | ||
<Stack space={16}> | ||
<ColorTokenField | ||
label={t("Tokens.Color.primary")} | ||
value={props.tokens.brandColor.brandPrimary} | ||
onChange={(value) => | ||
props.onChange({ ...props.tokens.brandColor, brandPrimary: value }) | ||
} | ||
/> | ||
<ColorTokenField | ||
label={t("Tokens.Color.secondary")} | ||
value={props.tokens.brandColor.brandSecondary} | ||
onChange={(value) => | ||
props.onChange({ | ||
...props.tokens.brandColor, | ||
brandSecondary: value, | ||
}) | ||
} | ||
/> | ||
<ColorTokenField | ||
label={t("Tokens.Color.tertiary")} | ||
value={props.tokens.brandColor.brandTertiary} | ||
onChange={(value) => | ||
props.onChange({ | ||
...props.tokens.brandColor, | ||
brandTertiary: value, | ||
}) | ||
} | ||
/> | ||
</Stack> | ||
</Column> | ||
<Box | ||
borderRadius={24} | ||
padding={40} | ||
background="backgroundSecondary" | ||
display="flex" | ||
flexDirection="column" | ||
flexGrow={1} | ||
> | ||
<BentoThemeProvider theme={props.tokens}> | ||
<Stack space={40}> | ||
<Stack space={12}> | ||
<Body size="medium" color="secondary"> | ||
{t("Component.decorativeDivider")} | ||
</Body> | ||
<DecorativeDivider /> | ||
</Stack> | ||
<Stack space={12}> | ||
<Body size="medium" color="secondary"> | ||
{t("Component.areaLoader")} | ||
</Body> | ||
<Box position="relative" style={{ height: 240 }}> | ||
<AreaLoader /> | ||
</Box> | ||
</Stack> | ||
<Stack space={12}> | ||
<Body size="medium" color="secondary"> | ||
{t("Component.sliderField")} | ||
</Body> | ||
<SliderField | ||
type="single" | ||
label={unsafeLocalizedString("")} | ||
value={50} | ||
minValue={0} | ||
maxValue={100} | ||
onChange={() => {}} | ||
/> | ||
</Stack> | ||
</Stack> | ||
</BentoThemeProvider> | ||
</Box> | ||
</Columns> | ||
</Stack> | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/configuration-builder/src/TokensSection/ColorTokenField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Box, Column, Columns, LocalizedString, Stack, Title } from "@buildo/bento-design-system"; | ||
import { useConfiguratorStatusContext } from "../ConfiguratorStatusContext"; | ||
import { useTranslation } from "react-i18next"; | ||
import { ColorPickerField } from "../ColorPickerField/ColorPickerField"; | ||
|
||
export function ColorTokenField(props: { | ||
label: LocalizedString; | ||
value: string; | ||
onChange: (value: string) => void; | ||
}) { | ||
const { theme } = useConfiguratorStatusContext(); | ||
const { t } = useTranslation(); | ||
return ( | ||
<Columns space={24} alignY="stretch"> | ||
<Column width="content"> | ||
<Box borderRadius={16} height="full" style={{ background: props.value, width: 64 }} /> | ||
</Column> | ||
<Stack space={8}> | ||
<Title size="medium">{props.label}</Title> | ||
<ColorPickerField | ||
colors={theme.colors} | ||
label={t("Tokens.Color.label")} | ||
value={props.value} | ||
onChange={props.onChange} | ||
/> | ||
</Stack> | ||
</Columns> | ||
); | ||
} |
134 changes: 21 additions & 113 deletions
134
packages/configuration-builder/src/TokensSection/TokensSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,34 @@ | ||
import { | ||
AreaLoader, | ||
BentoThemeProvider, | ||
Body, | ||
Box, | ||
Column, | ||
Columns, | ||
DecorativeDivider, | ||
LocalizedString, | ||
SliderField, | ||
Stack, | ||
Title, | ||
unsafeLocalizedString, | ||
} from "@buildo/bento-design-system"; | ||
import { ConfiguratorSection } from "../ConfiguratorSection/ConfiguratorSection"; | ||
import { useConfiguratorStatusContext } from "../ConfiguratorStatusContext"; | ||
import { ColorPickerField } from "../ColorPickerField/ColorPickerField"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
function ColorTokenField(props: { | ||
label: LocalizedString; | ||
value: string; | ||
onChange: (value: string) => void; | ||
}) { | ||
const { theme } = useConfiguratorStatusContext(); | ||
const { t } = useTranslation(); | ||
return ( | ||
<Columns space={24} alignY="stretch"> | ||
<Column width="content"> | ||
<Box borderRadius={16} height="full" style={{ background: props.value, width: 64 }} /> | ||
</Column> | ||
<Stack space={8}> | ||
<Title size="medium">{props.label}</Title> | ||
<ColorPickerField | ||
colors={theme.colors} | ||
label={t("Tokens.Color.label")} | ||
value={props.value} | ||
onChange={props.onChange} | ||
/> | ||
</Stack> | ||
</Columns> | ||
); | ||
} | ||
import { useState } from "react"; | ||
import { BrandTokens } from "./BrandTokens"; | ||
import { match } from "ts-pattern"; | ||
|
||
export function TokensSection() { | ||
const { theme, setTheme } = useConfiguratorStatusContext(); | ||
const { t } = useTranslation(); | ||
|
||
const tokens = theme.tokens; | ||
const setTokens = (tokens: typeof theme.tokens) => setTheme({ ...theme, tokens }); | ||
const steps = ["brand" as const]; | ||
const [currentStep] = useState<(typeof steps)[0]>("brand"); | ||
const currentStepIndex = steps.indexOf(currentStep); | ||
|
||
return ( | ||
<ConfiguratorSection title={t("Tokens.title")} steps={[]} currentStep={0}> | ||
<Columns space={40} alignY="stretch"> | ||
<Column width="1/4"> | ||
<Stack space={16}> | ||
<ColorTokenField | ||
label={t("Tokens.Color.primary")} | ||
value={tokens.brandColor.brandPrimary} | ||
onChange={(value) => | ||
setTokens({ ...tokens, brandColor: { ...tokens.brandColor, brandPrimary: value } }) | ||
} | ||
/> | ||
<ColorTokenField | ||
label={t("Tokens.Color.secondary")} | ||
value={tokens.brandColor.brandSecondary} | ||
onChange={(value) => | ||
setTokens({ | ||
...tokens, | ||
brandColor: { ...tokens.brandColor, brandSecondary: value }, | ||
}) | ||
} | ||
/> | ||
<ColorTokenField | ||
label={t("Tokens.Color.tertiary")} | ||
value={tokens.brandColor.brandTertiary} | ||
onChange={(value) => | ||
setTokens({ ...tokens, brandColor: { ...tokens.brandColor, brandTertiary: value } }) | ||
} | ||
/> | ||
</Stack> | ||
</Column> | ||
<Box | ||
borderRadius={24} | ||
padding={40} | ||
background="backgroundSecondary" | ||
display="flex" | ||
flexDirection="column" | ||
flexGrow={1} | ||
> | ||
<BentoThemeProvider theme={tokens}> | ||
<Stack space={40}> | ||
<Stack space={12}> | ||
<Body size="medium" color="secondary"> | ||
{t("Component.decorativeDivider")} | ||
</Body> | ||
<DecorativeDivider /> | ||
</Stack> | ||
<Stack space={12}> | ||
<Body size="medium" color="secondary"> | ||
{t("Component.areaLoader")} | ||
</Body> | ||
<Box position="relative" style={{ height: 240 }}> | ||
<AreaLoader /> | ||
</Box> | ||
</Stack> | ||
<Stack space={12}> | ||
<Body size="medium" color="secondary"> | ||
{t("Component.sliderField")} | ||
</Body> | ||
<SliderField | ||
type="single" | ||
label={unsafeLocalizedString("")} | ||
value={50} | ||
minValue={0} | ||
maxValue={100} | ||
onChange={() => {}} | ||
/> | ||
</Stack> | ||
</Stack> | ||
</BentoThemeProvider> | ||
</Box> | ||
</Columns> | ||
<ConfiguratorSection | ||
title={t("Tokens.title")} | ||
steps={steps.map((step) => ({ label: t(`TokensSection.Step.${step}`) }))} | ||
currentStep={currentStepIndex} | ||
> | ||
{match(currentStep) | ||
.with("brand", () => ( | ||
<BrandTokens | ||
tokens={theme.tokens} | ||
onChange={(brandTokens) => | ||
setTheme({ ...theme, tokens: { ...theme.tokens, brandColor: brandTokens } }) | ||
} | ||
/> | ||
)) | ||
.exhaustive()} | ||
</ConfiguratorSection> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters