Skip to content

Commit 665ba22

Browse files
authored
Add docs for S2 illustrations (#6882)
1 parent 6932a9f commit 665ba22

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

.storybook-s2/docs/Illustrations.jsx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import linearIllustrations from '@react-spectrum/s2/spectrum-illustrations/linear/*.tsx';
2+
import gradientIllustrations from '@react-spectrum/s2/spectrum-illustrations/gradient/*.svg';
3+
import Paste from '@react-spectrum/s2/s2wf-icons/S2_Icon_Paste_20_N.svg';
4+
import { style } from '../../packages/@react-spectrum/s2/style/spectrum-theme' with {type: 'macro'};
5+
import {ActionButton, Text} from '@react-spectrum/s2';
6+
import {H2, P, Code, Pre} from './typography';
7+
import {highlight} from './highlight' with {type: 'macro'};
8+
import { Radio, RadioGroup } from '../../packages/@react-spectrum/s2/src';
9+
import { useState } from 'react';
10+
11+
export function Illustrations() {
12+
let [gradientStyle, setStyle] = useState('generic1');
13+
return (
14+
<div className={style({maxWidth: 'lg', marginX: 'auto'})}>
15+
<div className={style({marginX: 48})}>
16+
<h1 className={style({font: 'heading-2xl', marginBottom: 48})}>
17+
Illustrations
18+
</h1>
19+
<P>Spectrum 2 offers a collection of illustrations in two styles: gradient and linear. These illustrations can be imported from <Code>@react-spectrum/s2/illustrations</Code>. See below for a full list of available illustrations. Click the clipboard icon to copy the import statement.</P>
20+
<H2>Gradient illustrations</H2>
21+
<P>Gradient illustrations are available in two styles: Generic 1 and Generic 2. These should be consistently applied within products. They can be imported using the corresponding sub-path, for example:</P>
22+
<Pre>{highlight("import Cloud from '@react-spectrum/s2/illustrations/gradient/generic1/Cloud';")}</Pre>
23+
<RadioGroup label="Style" value={gradientStyle} onChange={setStyle} orientation="horizontal" styles={style({marginTop: 32})}>
24+
<Radio value="generic1">Generic 1</Radio>
25+
<Radio value="generic2">Generic 2</Radio>
26+
</RadioGroup>
27+
<div className={style({display: 'grid', gridTemplateColumns: 'repeat(auto-fit, 164px)', gap: 20, justifyContent: 'space-between', marginTop: 32})}>
28+
{Object.keys(gradientIllustrations).filter(name => name.includes(gradientStyle)).map(icon => {
29+
let Illustration = gradientIllustrations[icon].default;
30+
let name = icon.replace(/^S2_(fill|lin)_(.+)_(generic\d)_(\d+)$/, (m, type, name) => {
31+
return name[0].toUpperCase() + name.slice(1).replace(/_/g, '');
32+
});
33+
let importPath = icon.replace(/^S2_(fill|lin)_(.+)_(generic\d)_(\d+)$/, (m, type, name, style) => {
34+
name = name[0].toUpperCase() + name.slice(1).replace(/_/g, '');
35+
return 'gradient/' + style + '/' + name;
36+
});
37+
return (
38+
<div className={style({display: 'flex', flexDirection: 'column', rowGap: 8, alignItems: 'center', padding: 16, borderRadius: 'lg', boxShadow: 'elevated'})}>
39+
<Illustration UNSAFE_style={{width: 96, height: 96}} />
40+
<span className={style({font: 'ui', display: 'flex', gap: 8, alignItems: 'center', maxWidth: 'full'})}>
41+
<span className={style({truncate: true})}>{name}</span>
42+
<ActionButton
43+
size="XS"
44+
isQuiet
45+
aria-label="Copy"
46+
onPress={() => navigator.clipboard.writeText(`import ${name} from '@react-spectrum/s2/illustrations/${importPath}';`)}>
47+
<Paste />
48+
</ActionButton>
49+
</span>
50+
</div>
51+
);
52+
})}
53+
</div>
54+
<H2>Linear illustrations</H2>
55+
<P>Linear illustrations can be imported as shown below:</P>
56+
<Pre>{highlight("import Cloud from '@react-spectrum/s2/illustrations/linear/Cloud';")}</Pre>
57+
<div className={style({display: 'grid', gridTemplateColumns: 'repeat(auto-fit, 164px)', gap: 20, justifyContent: 'space-between', marginTop: 48})}>
58+
{Object.keys(linearIllustrations).map(icon => {
59+
let Illustration = linearIllustrations[icon].default;
60+
return (
61+
<div className={style({display: 'flex', flexDirection: 'column', rowGap: 8, alignItems: 'center', padding: 16, borderRadius: 'lg', boxShadow: 'elevated'})}>
62+
<Illustration />
63+
<span className={style({font: 'ui', display: 'flex', gap: 8, alignItems: 'center', maxWidth: 'full'})}>
64+
<span className={style({truncate: true})}>{icon}</span>
65+
<ActionButton
66+
size="XS"
67+
isQuiet
68+
aria-label="Copy"
69+
onPress={() => navigator.clipboard.writeText(`import ${icon} from '@react-spectrum/s2/illustrations/linear/${icon}';`)}>
70+
<Paste />
71+
</ActionButton>
72+
</span>
73+
</div>
74+
);
75+
})}
76+
</div>
77+
</div>
78+
</div>
79+
);
80+
}

.storybook-s2/docs/Illustrations.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {Illustrations} from './Illustrations.jsx';
2+
3+
<Illustrations />

.storybook-s2/preview.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ const preview = {
6262
brandTitle: 'React Spectrum - Spectrum 2 Preview',
6363
brandImage: new URL('raw:logo-dark.svg', import.meta.url).toString()
6464
}
65+
},
66+
options: {
67+
storySort: {
68+
order: ['Intro', 'Style Macro', 'Workflow Icons', 'Illustrations', 'Release Notes'],
69+
method: 'alphabetical'
70+
}
6571
}
6672
},
6773
argTypes: {

packages/dev/parcel-transformer-icon/IconTransformer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ const {Transformer} = require('@parcel/plugin');
1414
const {transform} = require('@svgr/core');
1515
const path = require('path');
1616
const tokens = require('@adobe/spectrum-tokens/dist/json/variables.json');
17+
const crypto = require('crypto');
1718

1819
module.exports = new Transformer({
1920
async transform({asset}) {
2021
let contents = await asset.getCode();
2122
let iconName = path.basename(asset.filePath, '.svg');
23+
let hash = crypto.createHash('md5');
24+
hash.update(iconName);
25+
let prefix = hash.digest('hex').slice(-6);
2226
let optimized = (await transform(
2327
contents,
2428
{
@@ -33,6 +37,12 @@ module.exports = new Transformer({
3337
inlineStyles: {
3438
onlyMatchedOnce: false,
3539
removeMatchedSelectors: true
40+
},
41+
cleanupIDs: {
42+
prefix
43+
},
44+
convertPathData: {
45+
makeArcs: false
3646
}
3747
}
3848
},

0 commit comments

Comments
 (0)