Skip to content

Commit

Permalink
Extract brand tokens step
Browse files Browse the repository at this point in the history
  • Loading branch information
veej committed Sep 26, 2023
1 parent 505d4c4 commit de50474
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 114 deletions.
104 changes: 104 additions & 0 deletions packages/configuration-builder/src/TokensSection/BrandTokens.tsx
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>
);
}
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 packages/configuration-builder/src/TokensSection/TokensSection.tsx
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>
);
}
3 changes: 2 additions & 1 deletion packages/configuration-builder/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"Tokens.Color.label": "Color",
"Component.decorativeDivider": "Decorative Divider",
"Component.areaLoader": "Area Loader",
"Component.sliderField": "Slider Field"
"Component.sliderField": "Slider Field",
"TokensSection.Step.brand": "Brand"
}
}

0 comments on commit de50474

Please sign in to comment.