Skip to content

Commit

Permalink
Merge pull request #48 from gsoft-inc/feature/update_tokens
Browse files Browse the repository at this point in the history
Update to the styled-system
  • Loading branch information
alexasselin008 authored Nov 13, 2023
2 parents 98ee195 + d545c01 commit f5b0097
Show file tree
Hide file tree
Showing 12 changed files with 8,947 additions and 6,394 deletions.
11 changes: 11 additions & 0 deletions .changeset/wet-windows-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@orbit-ui/transition-components": minor
---

Added:
- fontFamily is now available on all components that use the style system
- Added a list of all available semantic values for the styled-system in the tokens page

Update:
- Tokens are now updated with their latest value. No breaking changes to be expected
- Semantic elevation tokens are now working correctly
2 changes: 1 addition & 1 deletion .storybook/styles/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
}

.sbdocs.sbdocs-table .example {
color: var(--hop-primary-text);
color: var(--hop-neutral-text);
}

.sbdocs.sbdocs-table b,
Expand Down
8 changes: 4 additions & 4 deletions docs/features/style-props/PropsReferenceTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const propTypes = {
};

const ScaleLinks = {
"box-shadow-scale": <Link href="https://wl-hopper.netlify.app/tokens/semantic/shadow" target="_blank">shadows</Link>,
"color-scale": <Link href="https://wl-hopper.netlify.app/tokens/semantic/color" target="_blank">colors</Link>,
"sizing-scale": <Link href="https://wl-hopper.netlify.app/tokens/semantic/dimensions" target="_blank">dimensions</Link>,
"spacing-scale": <Link href="https://wl-hopper.netlify.app/tokens/semantic/dimensions" target="_blank">dimensions</Link>
"box-shadow-scale": <Link href="?path=/docs/tokens--page#box-shadows" target="_blank">shadows</Link>,
"color-scale": <Link href="?path=/docs/tokens--page#background-colors" target="_blank">colors</Link>,
"sizing-scale": <Link href="?path=/docs/tokens--page#sizings" target="_blank">dimensions</Link>,
"spacing-scale": <Link href="?path=/docs/tokens--page#spacings" target="_blank">dimensions</Link>
};

function toScaleLink(scale) {
Expand Down
77 changes: 59 additions & 18 deletions docs/features/tokens/TokenTable.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ThemeProvider } from "@components/styling";
import { ThemeProvider, ThemeComputedStyle } from "@components/styling";
import { arrayOf, func, shape, string } from "prop-types";

import { Div, Span } from "@components/html";
Expand All @@ -7,36 +7,40 @@ import { DocsContext } from "@storybook/addon-docs";
import { InfoCircleMajorIcon } from "@components/icons";
import { Table } from "@stories/components";
import { Text } from "@components/typography";
import { useContext } from "react";
import { useEffect, useContext, useRef, useState } from "react";

const propTypes = {
colors: arrayOf(shape({
valueLight: string.isRequired,
valueDark: string.isRequired,
tokens: arrayOf(shape({
token: string.isRequired,
variable: string.isRequired,
itemRenderer: func.isRequired
})).isRequired
};

function toRowValues({ token, variable, valueLight, valueDark, itemRenderer }, docsContext) {
const scheme = docsContext.globals.colorScheme;
const value = scheme === "light" ? valueLight : valueDark;
function toRowValues({ token, variable, itemRenderer }, docsContext, themeComputedStyle) {
const valueTest = themeComputedStyle ? themeComputedStyle.getPropertyValue(variable) : "N/A";

return [
token,
variable,
value,
valueTest,
itemRenderer(token)
];
}

export function TokenTable({ colors }) {
export function TokenTable({ tokens }) {
const docsContext = useContext(DocsContext);
const [rows, setRows] = useState([]);
const ref = useRef(null);

useEffect(() => {
// we need to delay this until the ref is set
setRows(tokens.map(x => toRowValues(x, docsContext, new ThemeComputedStyle(ref))));
}, [tokens, docsContext, ref]);

return (
// eslint-disable-next-line react/destructuring-assignment
<ThemeProvider colorScheme={docsContext.globals.colorScheme}>
<ThemeProvider ref={ref} colorScheme={docsContext.globals.colorScheme}>
<Table
className="token-table"
columns={[
Expand All @@ -45,7 +49,7 @@ export function TokenTable({ colors }) {
{ title: "Value", headerStyle: { width: "225px" }, rowClassName: "code" },
{ title: "Example", headerStyle: { width: "275px" }, rowClassName: "example", rowStyle: { backgroundColor: "var(--hop-neutral-surface)" } }
]}
rows={colors.map(x => toRowValues(x, docsContext))}
rows={rows}
/>
</ThemeProvider>
);
Expand Down Expand Up @@ -75,6 +79,10 @@ export function fontSizeRenderer(token) {
return <Div height={960} display="flex" alignItems="center" justifyContent="start"><Text fontSize={token} lineHeight={1}>Ag</Text></Div>;
}

export function fontFamilyRenderer(token) {
return <Div height={960} display="flex" alignItems="center" justifyContent="start"><Text fontFamily={token} lineHeight={1}>Ag</Text></Div>;
}

export function fontWeightRenderer(token) {
return <Flex height={320} alignItems="center"><Text fontWeight={token} fontSize="1.375rem" lineHeight={1}>Ag</Text></Flex>;
}
Expand All @@ -93,18 +101,51 @@ export function lineHeightRenderer(token) {

export function radiiRenderer(token) {
if (token === "circular") {
return <Div height={240} width={240} borderRadius={token} border="primary"></Div>;
return <Div height={240} width={240} borderRadius={token} border="neutral"></Div>;
} else {
return <Div height={240} width="3.5rem" borderRadius={token} border="primary"></Div>;
return <Div height={240} width="3.5rem" borderRadius={token} border="neutral"></Div>;
}
}

export function sizingRenderer() {
return <Div></Div>;
export function sizingRenderer(token) {
return <Div width={token} height="24px" backgroundColor="primary"></Div>;
}

export function spacingRenderer(token) {
return <Div height={240} width={token} backgroundColor="primary" borderRadius="rounded-md"></Div>;
export function paddingRenderer(token) {
return (
<Div display="flex" justifyContent="center" padding={1}>
<Div padding={token} display="inline-block" backgroundColor="primary">
<Div backgroundColor="neutral" height={400} width={400}></Div>
</Div>
</Div>
);
}

export function marginRenderer(token) {
const isStack = token.includes("stack");


if (!isStack) {
return marginInlineRenderer(token);
}

return (
<Div display="flex" alignItems="center" padding={1}>
<Div display="flex" backgroundColor="primary" border="neutral" height="40px" width="24px">
<Div backgroundColor="neutral" marginTop={token} width="24px"></Div>
</Div>
</Div>
);
}

export function marginInlineRenderer(token) {
return (
<Div display="flex" alignItems="center" padding={1}>
<Div display="inline-block" backgroundColor="primary" border="neutral" width="48px">
<Div backgroundColor="neutral" height={240} marginLeft={token}></Div>
</Div>
</Div>
);
}

export function textRenderer(token) {
Expand Down
102 changes: 102 additions & 0 deletions docs/features/tokens/Tokens.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {
boxShadowRenderer,
backgroundRenderer,
borderRenderer,
textRenderer,
iconRenderer,
fontSizeRenderer,
fontWeightRenderer,
lineHeightRenderer,
radiiRenderer,
fontFamilyRenderer,
paddingRenderer,
marginRenderer,
sizingRenderer
} from "./TokenTable";
import {
BackgroundColorMapping,
TextColorMapping,
IconColorMapping,
BoxShadowMapping,
BorderMapping,
BorderWidthAndStyle,
BoxShadowAliases,
IconColorAliases,
TextColorAliases,
BorderColorAliases,
BackgroundColorAliases,
FontSizeMapping,
FontSizeAliases,
FontWeightMapping,
FontWeightAliases,
LineHeightMapping,
LineHeightAliases,
BorderRadiusMapping,
BorderRadiusAliases,
FontFamilyMapping,
FontFamilyAliases,
SimplePaddingMapping,
ComplexPaddingMapping,
SemanticSimplePaddingSpace,
SemanticComplexPaddingSpace,
SemanticSimpleMarginSpace,
SimpleMarginMapping,
ComplexMarginMapping,
SemanticComplexMarginSpace,
SizingMapping
} from "@components/styling";

function toTokenValue(key, value) {
return {
token: key,
variable: value.replace("var(", "").replace(")", "")
};
}

function coreAndSemanticTokenSplitter(allMappings, semanticKeys, renderer, additionalTokenTransformationMethod = null) {
return Object.entries(allMappings).reduce((acc, [key, value]) => {
let collectionRef = acc.Semantic;
if (!semanticKeys.includes(key)) {
collectionRef = acc.Core;
}

let token = {
...toTokenValue(key, value),
itemRenderer: renderer
};

if (additionalTokenTransformationMethod) {
token = additionalTokenTransformationMethod(token);
}

collectionRef.push(token);

return acc;
}, { Core: [], Semantic: [] });
}

export const BackgroundColors = coreAndSemanticTokenSplitter(BackgroundColorMapping, Object.keys(BackgroundColorAliases), backgroundRenderer);
export const BorderColors = coreAndSemanticTokenSplitter(BorderMapping, Object.keys(BorderColorAliases), borderRenderer, token => {
return {
...token,
variable: token.variable.replace(BorderWidthAndStyle, "").trim()
};
});

export const TextColors = coreAndSemanticTokenSplitter(TextColorMapping, Object.keys(TextColorAliases), textRenderer);
export const IconColors = coreAndSemanticTokenSplitter(IconColorMapping, Object.keys(IconColorAliases), iconRenderer);

export const Shadows = coreAndSemanticTokenSplitter(BoxShadowMapping, BoxShadowAliases, boxShadowRenderer);

export const FontFamily = coreAndSemanticTokenSplitter(FontFamilyMapping, FontFamilyAliases, fontFamilyRenderer);
export const FontSizes = coreAndSemanticTokenSplitter(FontSizeMapping, FontSizeAliases, fontSizeRenderer);
export const FontWeight = coreAndSemanticTokenSplitter(FontWeightMapping, FontWeightAliases, fontWeightRenderer);
export const LineHeight = coreAndSemanticTokenSplitter(LineHeightMapping, LineHeightAliases, lineHeightRenderer);

export const Radii = coreAndSemanticTokenSplitter(BorderRadiusMapping, BorderRadiusAliases, radiiRenderer);

export const Sizing = coreAndSemanticTokenSplitter(SizingMapping, [], sizingRenderer);
export const SimplePadding = coreAndSemanticTokenSplitter(SimplePaddingMapping, SemanticSimplePaddingSpace, paddingRenderer);
export const ComplexPadding = coreAndSemanticTokenSplitter(ComplexPaddingMapping, SemanticComplexPaddingSpace, paddingRenderer);
export const SimpleMargin = coreAndSemanticTokenSplitter(SimpleMarginMapping, SemanticSimpleMarginSpace, marginRenderer);
export const ComplexMargin = coreAndSemanticTokenSplitter(ComplexMarginMapping, SemanticComplexMarginSpace, marginRenderer);
Loading

0 comments on commit f5b0097

Please sign in to comment.