Skip to content

Commit

Permalink
Export boxShadows for outlineColors + fix export
Browse files Browse the repository at this point in the history
  • Loading branch information
veej committed Dec 7, 2023
1 parent 8ef27cc commit 0c9ce78
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions packages/configuration-builder/src/utils/useConfigGeneratorTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ function elevationToVarName(elevation: "small" | "medium" | "large"): string {
export function useConfigGeneratorTS(): () => string {
const { tokens, colors, elevations } = useConfiguratorStatusContext().theme;
const colorTokenToValue = _colorTokenToValue(colors);

function elevationToValue(elevation: ElevationConfig): string {
return `${elevation.x}px ${elevation.y}px ${elevation.blur}px ${colorTokenToValue(
return `${elevation.x}px ${elevation.y}px ${elevation.blur}px \${${colorTokenToVarName(
elevation.color
)}`;
)}}`;
}

return () => {
const prelude = `import { BentoTheme } from "@buildo/bento-design-system";`;

Expand All @@ -40,6 +42,12 @@ export function useConfigGeneratorTS(): () => string {
}
});
});
Object.entries(elevations).forEach(([_, elevation]) => {
const rgba = colorTokenToValue(elevation.color);
if (rgba) {
usedColors[colorTokenToVarName(elevation.color)] = rgba;
}
});

const colorConsts = Object.entries(usedColors)
.reduce((acc, [colorKey, color]) => {
Expand All @@ -56,10 +64,22 @@ export function useConfigGeneratorTS(): () => string {
themeCode += "},";
});
themeCode += `boxShadow: {`;
Object.entries(tokens.outlineColor).forEach(([key, colorToken]) => {
themeCode += `${key}: \`inset 0px 0px 0px 1px \${${colorTokenToVarName(colorToken)}}\`,`;
});
themeCode += `outlineInteractiveBottom: \`inset 0px 0px -1px 0px \${${colorTokenToVarName(
tokens.outlineColor.outlineInteractive
)}}\`,`;
themeCode += `outlineDecorativeBottom: \`inset 0px 0px -1px 0px \${${colorTokenToVarName(
tokens.outlineColor.outlineDecorative
)}}\`,`;
themeCode += `outlineNegativeStrong: \`inset 0px 0px 0px 2px \${${colorTokenToVarName(
tokens.outlineColor.outlineNegative
)}}\`,`;
Object.entries(elevations).forEach(([key, value]) => {
themeCode += `${elevationToVarName(key as "small" | "medium" | "large")}: "${elevationToValue(
value
)}",`;
themeCode += `${elevationToVarName(
key as "small" | "medium" | "large"
)}: \`${elevationToValue(value)}\`,`;
});
themeCode += `}};`;

Expand Down

0 comments on commit 0c9ce78

Please sign in to comment.