Skip to content

Commit c6c1450

Browse files
committed
refactors, exposed vars.transition to styles
1 parent 5f01f43 commit c6c1450

6 files changed

Lines changed: 106 additions & 63 deletions

File tree

.changeset/red-drinks-float.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'braid-design-system': minor
3+
---
4+
5+
---
6+
updated:
7+
- vars
8+
---
9+
10+
**vars:** Exposed `vars.transition`. Transition CSS variables are available in stylesheets and runtime styles.
11+
12+
**EXAMPLE USAGE:**
13+
```ts
14+
export const myStyle = style({
15+
transition: vars.transition.fast,
16+
});

packages/braid-design-system/src/css.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
borderRadius,
2525
borderWidth,
2626
shadow,
27+
transition,
2728
} = internalVars;
2829

2930
const vars = {
@@ -38,6 +39,7 @@ const vars = {
3839
borderRadius,
3940
borderWidth,
4041
shadow,
42+
transition,
4143
};
4244

4345
function atoms(props: Omit<Atoms, 'background'>) {

packages/braid-design-system/src/lib/css/vars.docs.tsx

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Row = ({
3232
hideCanvas?: boolean;
3333
darkCanvas?: boolean;
3434
}) => (
35-
<Columns space="large" alignY="center">
35+
<Columns space="large" alignY="center" collapseBelow="tablet">
3636
<Column>
3737
<Text>
3838
<Hidden below="tablet">vars{group ? `.${group}` : null}.</Hidden>
@@ -49,16 +49,22 @@ const Row = ({
4949
</Columns>
5050
);
5151

52-
const ContentWidthValue = ({ var: varName }: { var: string }) => {
53-
const [size, setSize] = useState(0);
52+
const CssVarValue = ({
53+
var: varName,
54+
property,
55+
}: {
56+
var: string;
57+
property: 'width' | 'transition';
58+
}) => {
59+
const [value, setValue] = useState('');
5460
const { themeKey } = useThemeSettings();
5561
const ref = useRef<HTMLDivElement | null>(null);
5662

5763
useEffect(() => {
5864
if (ref.current && themeKey) {
59-
setSize(ref.current.offsetWidth);
65+
setValue(getComputedStyle(ref.current)[property]);
6066
}
61-
}, [themeKey]);
67+
}, [themeKey, property]);
6268

6369
return (
6470
<>
@@ -68,9 +74,9 @@ const ContentWidthValue = ({ var: varName }: { var: string }) => {
6874
pointerEvents="none"
6975
opacity={0}
7076
ref={ref}
71-
style={{ width: varName }}
77+
style={{ [property]: varName } as any}
7278
/>
73-
{size > 0 ? `${size}px` : '&nbsp;'}
79+
{value || '\u00a0'}
7480
</>
7581
);
7682
};
@@ -106,7 +112,7 @@ const varDocs: Record<keyof typeof vars, ReactNodeNoStrings> = {
106112
{index > 0 ? <Divider /> : null}
107113
<Row key={widthName} group="contentWidth" name={widthName} hideCanvas>
108114
<Text>
109-
<ContentWidthValue var={widthVar} />
115+
<CssVarValue var={widthVar} property="width" />
110116
</Text>
111117
</Row>
112118
</Fragment>
@@ -283,6 +289,27 @@ const varDocs: Record<keyof typeof vars, ReactNodeNoStrings> = {
283289
))}
284290
</Stack>
285291
),
292+
transition: (
293+
<Stack space="large">
294+
{Object.entries(vars.transition).map(
295+
([transitionName, transitionVar], index) => (
296+
<Fragment key={transitionName}>
297+
{index > 0 ? <Divider /> : null}
298+
<Row
299+
key={transitionName}
300+
group="transition"
301+
name={transitionName}
302+
hideCanvas
303+
>
304+
<Text>
305+
<CssVarValue var={transitionVar} property="transition" />
306+
</Text>
307+
</Row>
308+
</Fragment>
309+
),
310+
)}
311+
</Stack>
312+
),
286313
} as const;
287314

288315
const docs: CssDoc = {

packages/docs-ui/src/components/TitleLink/TitleLink.css.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ export const titleLink = style([
1515
},
1616
]);
1717

18-
export const showOnHover = style({
18+
export const isCopying = style({});
19+
20+
export const showIcon = style({
1921
selectors: {
20-
[`${titleLink}:hover &, ${titleLink}:focus-visible &`]: {
22+
[`${titleLink}:hover &, ${titleLink}:focus-visible &, ${isCopying}&`]: {
2123
opacity: 1,
2224
},
25+
[`${titleLink}:hover &`]: {
26+
transition: vars.transition.fast,
27+
},
2328
},
2429
});

packages/docs-ui/src/components/TitleLink/TitleLink.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ const TitleLinkAnchor = ({
4343
href={`#${slug}`}
4444
className={styles.titleLink}
4545
onClick={onClick}
46-
aria-label={triggerProps ? 'Copy link to clipboard' : undefined}
4746
{...triggerProps}
4847
>
4948
{children}
5049
<Box
5150
component="span"
52-
transition="fast"
53-
opacity={!copying ? 0 : undefined}
54-
className={!copying && styles.showOnHover}
51+
opacity={0}
52+
className={[styles.showIcon, copying && styles.isCopying]}
5553
>
5654
{copying ? <IconPositive tone="positive" /> : <IconLink />}
5755
</Box>
Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { TitleLink } from '@braid-design-system/docs-ui';
2-
import { Stack, Badge, Heading, Bleed } from 'braid-src/lib/components';
2+
import {
3+
Stack,
4+
Badge,
5+
Heading,
6+
Bleed,
7+
HiddenVisually,
8+
} from 'braid-src/lib/components';
39
import type { ResponsiveSpace } from 'braid-src/lib/css/atoms/atoms';
410
import { PlayroomStateProvider } from 'braid-src/lib/playroom/playroomState';
511

@@ -13,53 +19,42 @@ export const DocSection = ({
1319
}: {
1420
section: ComponentExample;
1521
headingSpacing?: ResponsiveSpace;
16-
}) => (
17-
<Stack space="small">
18-
{section.deprecated ? (
19-
<Bleed left="xsmall">
20-
<Badge
21-
tone="caution"
22-
id={section.label ? `deprecated-${section.label}` : undefined}
23-
aria-hidden
24-
>
25-
Deprecated
26-
</Badge>
27-
</Bleed>
28-
) : undefined}
29-
<Stack space={headingSpacing}>
30-
{section.label ? (
31-
<Heading
32-
level="3"
33-
aria-describedby={
34-
section.deprecated ? `deprecated-${section.label}` : undefined
35-
}
36-
>
37-
<TitleLink label={section.label} copyable>
38-
<span
39-
aria-describedby={
40-
section.deprecated ? `deprecated-${section.label}` : undefined
41-
}
42-
>
22+
}) => {
23+
const { deprecated } = section;
24+
return (
25+
<Stack space="small">
26+
{deprecated ? (
27+
<Bleed left="xsmall">
28+
<Badge tone="caution">Deprecated</Badge>
29+
</Bleed>
30+
) : undefined}
31+
<Stack space={headingSpacing}>
32+
{section.label ? (
33+
<Heading level="3">
34+
<TitleLink label={section.label} copyable>
4335
{section.label}
44-
</span>
45-
</TitleLink>
46-
</Heading>
47-
) : null}
48-
{section.description ?? null}
49-
{section.code || section.Example ? (
50-
<PlayroomStateProvider>
51-
<DocExample
52-
code={section.code}
53-
Example={section.Example}
54-
Container={section.Container}
55-
background={section.background}
56-
showCodeByDefault={
57-
section.showCodeByDefault || section.Example === undefined
58-
}
59-
playroom={section.playroom}
60-
/>
61-
</PlayroomStateProvider>
62-
) : null}
36+
{deprecated ? (
37+
<HiddenVisually>, deprecated</HiddenVisually>
38+
) : null}
39+
</TitleLink>
40+
</Heading>
41+
) : null}
42+
{section.description ?? null}
43+
{section.code || section.Example ? (
44+
<PlayroomStateProvider>
45+
<DocExample
46+
code={section.code}
47+
Example={section.Example}
48+
Container={section.Container}
49+
background={section.background}
50+
showCodeByDefault={
51+
section.showCodeByDefault || section.Example === undefined
52+
}
53+
playroom={section.playroom}
54+
/>
55+
</PlayroomStateProvider>
56+
) : null}
57+
</Stack>
6358
</Stack>
64-
</Stack>
65-
);
59+
);
60+
};

0 commit comments

Comments
 (0)