From 665ba229bf50200a744b131b6ee2f3248643e0a8 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Thu, 15 Aug 2024 08:08:02 -0700 Subject: [PATCH] Add docs for S2 illustrations (#6882) --- .storybook-s2/docs/Illustrations.jsx | 80 +++++++++++++++++++ .storybook-s2/docs/Illustrations.mdx | 3 + .storybook-s2/preview.tsx | 6 ++ .../IconTransformer.js | 10 +++ 4 files changed, 99 insertions(+) create mode 100644 .storybook-s2/docs/Illustrations.jsx create mode 100644 .storybook-s2/docs/Illustrations.mdx diff --git a/.storybook-s2/docs/Illustrations.jsx b/.storybook-s2/docs/Illustrations.jsx new file mode 100644 index 00000000000..df9836b1945 --- /dev/null +++ b/.storybook-s2/docs/Illustrations.jsx @@ -0,0 +1,80 @@ +import linearIllustrations from '@react-spectrum/s2/spectrum-illustrations/linear/*.tsx'; +import gradientIllustrations from '@react-spectrum/s2/spectrum-illustrations/gradient/*.svg'; +import Paste from '@react-spectrum/s2/s2wf-icons/S2_Icon_Paste_20_N.svg'; +import { style } from '../../packages/@react-spectrum/s2/style/spectrum-theme' with {type: 'macro'}; +import {ActionButton, Text} from '@react-spectrum/s2'; +import {H2, P, Code, Pre} from './typography'; +import {highlight} from './highlight' with {type: 'macro'}; +import { Radio, RadioGroup } from '../../packages/@react-spectrum/s2/src'; +import { useState } from 'react'; + +export function Illustrations() { + let [gradientStyle, setStyle] = useState('generic1'); + return ( +
+
+

+ Illustrations +

+

Spectrum 2 offers a collection of illustrations in two styles: gradient and linear. These illustrations can be imported from @react-spectrum/s2/illustrations. See below for a full list of available illustrations. Click the clipboard icon to copy the import statement.

+

Gradient illustrations

+

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:

+
{highlight("import Cloud from '@react-spectrum/s2/illustrations/gradient/generic1/Cloud';")}
+ + Generic 1 + Generic 2 + +
+ {Object.keys(gradientIllustrations).filter(name => name.includes(gradientStyle)).map(icon => { + let Illustration = gradientIllustrations[icon].default; + let name = icon.replace(/^S2_(fill|lin)_(.+)_(generic\d)_(\d+)$/, (m, type, name) => { + return name[0].toUpperCase() + name.slice(1).replace(/_/g, ''); + }); + let importPath = icon.replace(/^S2_(fill|lin)_(.+)_(generic\d)_(\d+)$/, (m, type, name, style) => { + name = name[0].toUpperCase() + name.slice(1).replace(/_/g, ''); + return 'gradient/' + style + '/' + name; + }); + return ( +
+ + + {name} + navigator.clipboard.writeText(`import ${name} from '@react-spectrum/s2/illustrations/${importPath}';`)}> + + + +
+ ); + })} +
+

Linear illustrations

+

Linear illustrations can be imported as shown below:

+
{highlight("import Cloud from '@react-spectrum/s2/illustrations/linear/Cloud';")}
+
+ {Object.keys(linearIllustrations).map(icon => { + let Illustration = linearIllustrations[icon].default; + return ( +
+ + + {icon} + navigator.clipboard.writeText(`import ${icon} from '@react-spectrum/s2/illustrations/linear/${icon}';`)}> + + + +
+ ); + })} +
+
+
+ ); +} diff --git a/.storybook-s2/docs/Illustrations.mdx b/.storybook-s2/docs/Illustrations.mdx new file mode 100644 index 00000000000..e280472a105 --- /dev/null +++ b/.storybook-s2/docs/Illustrations.mdx @@ -0,0 +1,3 @@ +import {Illustrations} from './Illustrations.jsx'; + + diff --git a/.storybook-s2/preview.tsx b/.storybook-s2/preview.tsx index 09ca460420b..00b0108dcfe 100644 --- a/.storybook-s2/preview.tsx +++ b/.storybook-s2/preview.tsx @@ -62,6 +62,12 @@ const preview = { brandTitle: 'React Spectrum - Spectrum 2 Preview', brandImage: new URL('raw:logo-dark.svg', import.meta.url).toString() } + }, + options: { + storySort: { + order: ['Intro', 'Style Macro', 'Workflow Icons', 'Illustrations', 'Release Notes'], + method: 'alphabetical' + } } }, argTypes: { diff --git a/packages/dev/parcel-transformer-icon/IconTransformer.js b/packages/dev/parcel-transformer-icon/IconTransformer.js index 2d2de032f25..275835e7552 100644 --- a/packages/dev/parcel-transformer-icon/IconTransformer.js +++ b/packages/dev/parcel-transformer-icon/IconTransformer.js @@ -14,11 +14,15 @@ const {Transformer} = require('@parcel/plugin'); const {transform} = require('@svgr/core'); const path = require('path'); const tokens = require('@adobe/spectrum-tokens/dist/json/variables.json'); +const crypto = require('crypto'); module.exports = new Transformer({ async transform({asset}) { let contents = await asset.getCode(); let iconName = path.basename(asset.filePath, '.svg'); + let hash = crypto.createHash('md5'); + hash.update(iconName); + let prefix = hash.digest('hex').slice(-6); let optimized = (await transform( contents, { @@ -33,6 +37,12 @@ module.exports = new Transformer({ inlineStyles: { onlyMatchedOnce: false, removeMatchedSelectors: true + }, + cleanupIDs: { + prefix + }, + convertPathData: { + makeArcs: false } } },