Skip to content

Commit bdb66a5

Browse files
feat(tokens): add spacing Storybook story with size variable mapping (#1821)
* feat(tokens): add spacing stories Co-Authored-By: Naomi Hironaka <[email protected]> * chore: add empty changeset for spacing stories Co-Authored-By: Naomi Hironaka <[email protected]> * feat(tokens): add size variable mapping to spacing stories Co-Authored-By: Naomi Hironaka <[email protected]> * fix(tokens): remove unused @ts-expect-error comment Co-Authored-By: Naomi Hironaka <[email protected]> * fix: add description to story --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 95f1f76 commit bdb66a5

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

.changeset/thin-readers-doubt.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
docs(tokens): add spacing Storybook story (no release)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { default as Tokens } from '../dist';
2+
3+
import { vars } from '@launchpad-ui/vars';
4+
import { Fragment } from 'react';
5+
6+
import { Button } from '../../components/src/Button';
7+
import { ToastRegion, toastQueue } from '../../components/src/Toast';
8+
import { Tooltip, TooltipTrigger } from '../../components/src/Tooltip';
9+
// @ts-expect-error ts not detecting d.ts for es file
10+
import tokens from '../dist/index.es.js';
11+
import spacingJson from '../tokens/spacing.json';
12+
13+
export default {
14+
title: 'Tokens/Spacing',
15+
};
16+
17+
const spacing: typeof Tokens.spacing = tokens.spacing;
18+
19+
const spacingToSize = Object.fromEntries(
20+
Object.entries(spacingJson.spacing)
21+
.filter(([k]) => !k.startsWith('$'))
22+
.map(([k, v]: [string, any]) => {
23+
const m = typeof v.$value === 'string' ? v.$value.match(/\{size\.(\d+)\}/) : null;
24+
return [k, m ? m[1] : ''];
25+
}),
26+
);
27+
28+
export const Spacing = {
29+
render: () => (
30+
<>
31+
<div style={{ marginBottom: 'var(--lp-spacing-500)', font: vars.text.body[1].regular }}>
32+
Use <code style={{ font: vars.text.code[1].regular }}>var(--space-*)</code> for margin,
33+
padding, and gap. Need a negative offset? Wrap in{' '}
34+
<code style={{ font: vars.text.code[1].regular }}>calc()</code>
35+
</div>
36+
<div
37+
style={{
38+
display: 'grid',
39+
gridTemplateColumns: 'max-content max-content min-content auto',
40+
alignItems: 'center',
41+
gap: 'var(--lp-spacing-700)',
42+
}}
43+
>
44+
{Object.entries(spacing).map(([key, value]) => (
45+
<Fragment key={key}>
46+
<TooltipTrigger>
47+
<Button
48+
onPress={() => {
49+
navigator.clipboard.writeText(`--lp-spacing-${key}`);
50+
toastQueue.add({ title: 'Copied!', status: 'success' });
51+
}}
52+
style={{ font: 'var(--lp-text-code-1-regular)' }}
53+
variant="minimal"
54+
>
55+
{`--lp-spacing-${key}`}
56+
</Button>
57+
<Tooltip placement="bottom">Copy to clipboard</Tooltip>
58+
</TooltipTrigger>
59+
<div style={{ font: 'var(--lp-text-code-1-regular)' }}>
60+
{spacingToSize[key] ? `--lp-size-${spacingToSize[key]}` : ''}
61+
</div>
62+
<div>{value}</div>
63+
<div
64+
style={{
65+
backgroundColor: 'var(--lp-color-green-500)',
66+
width: value,
67+
height: 'var(--lp-spacing-500)',
68+
}}
69+
/>
70+
</Fragment>
71+
))}
72+
</div>
73+
<ToastRegion />
74+
</>
75+
),
76+
};

0 commit comments

Comments
 (0)