Skip to content

Commit 940110c

Browse files
feat: convert accordion to radix primitive (#1721)
Co-authored-by: Jamie Howard <[email protected]>
1 parent 7c81e86 commit 940110c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1669
-736
lines changed

.changeset/tidy-games-divide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@strapi/design-system': major
3+
---
4+
5+
feat!: refactor Accordion to use radix primitive
6+
7+
The Accordion API has changed significently whilst retaining it's functionality, we recommend your review the documentation to understand the changes and how to migrate your code.

docs/.storybook/main.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { dirname, join, resolve } from 'path';
2+
import { mergeConfig } from 'vite';
3+
import turbosnap from 'vite-plugin-turbosnap';
24
import type { StorybookConfig } from '@storybook/react-vite';
35

46
const config: StorybookConfig = {
@@ -21,8 +23,8 @@ const config: StorybookConfig = {
2123
},
2224
},
2325
},
24-
viteFinal: (config) => {
25-
if (config.mode !== 'production') {
26+
viteFinal: (config, { configType }) => {
27+
if (configType !== 'PRODUCTION') {
2628
config.optimizeDeps = {
2729
...config.optimizeDeps,
2830
include: [
@@ -59,9 +61,18 @@ const config: StorybookConfig = {
5961
'@strapi/icons': resolve(__dirname, '..', '..', 'packages', 'icons', 'src'),
6062
'styled-components': resolve(__dirname, '..', '..', 'node_modules', 'styled-components'),
6163
};
62-
}
6364

64-
return config;
65+
return config;
66+
} else {
67+
return mergeConfig(config, {
68+
plugins: [
69+
turbosnap({
70+
// This should be the base path of your storybook. In monorepos, you may only need process.cwd().
71+
rootDir: config.root ?? process.cwd(),
72+
}),
73+
],
74+
});
75+
}
6576
},
6677

6778
framework: {

docs/components/Markdown.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { styled, css } from 'styled-components';
55
import { DeprecationNotice } from './DeprecationNotice';
66
import { Image } from './Image';
77
import { H1, H2, H3, H4, Li, P } from './Typography';
8+
import { ViewSource } from './ViewSource';
89

910
/* -------------------------------------------------------------------------------------------------
1011
* List
@@ -101,6 +102,7 @@ const Markdown = (props) => {
101102

102103
const MARKDOWN_OVERRIDES = {
103104
...BASE_MARKDOWN_OVERRIDES,
105+
ViewSource,
104106
DeprecationNotice,
105107
Markdown,
106108
};

docs/components/ViewSource.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Link } from '@strapi/design-system';
2+
3+
interface ViewSourceProps {
4+
pkg?: 'design-system' | 'icons' | 'primitives';
5+
path: string;
6+
}
7+
8+
const ViewSource = ({ pkg = 'design-system', path }: ViewSourceProps) => {
9+
if (!path) {
10+
console.warn('ViewSource requires a path prop to be passed.');
11+
12+
return null;
13+
}
14+
15+
return (
16+
<Link
17+
marginTop={4}
18+
isExternal
19+
href={`https://github.com/strapi/design-system/tree/releases/2.0.0/packages/${pkg}/${pkg === 'icons' ? 'assets' : 'src'}/${path}`}
20+
target="_blank"
21+
rel="noopener noreferrer"
22+
>
23+
View source
24+
</Link>
25+
);
26+
};
27+
28+
export { ViewSource };
29+
export type { ViewSourceProps };

docs/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@storybook/addon-actions": "^7.6.17",
88
"@storybook/addon-essentials": "^7.6.17",
99
"@storybook/react": "^7.6.17",
10+
"@storybook/test": "8.0.10",
1011
"@strapi/design-system": "workspace:*",
1112
"@strapi/icons": "workspace:*",
1213
"@strapi/ui-primitives": "workspace:*",
@@ -28,7 +29,8 @@
2829
"outdent": "0.8.0",
2930
"storybook": "^7.6.17",
3031
"typescript": "5.4.5",
31-
"vite": "^5.0.2"
32+
"vite": "^5.0.2",
33+
"vite-plugin-turbosnap": "1.0.3"
3234
},
3335
"scripts": {
3436
"build": "storybook build",

docs/stories/Accordion.mdx

Lines changed: 0 additions & 49 deletions
This file was deleted.

docs/stories/Accordion.stories.tsx

Lines changed: 0 additions & 120 deletions
This file was deleted.

docs/stories/BaseRadio.stories.tsx

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22

33
import { Meta, StoryObj } from '@storybook/react';
4-
import { BaseRadio, RadioGroup, Typography, useTheme } from '@strapi/design-system';
4+
import { BaseRadio, RadioGroup, Typography } from '@strapi/design-system';
55

66
const meta: Meta<typeof BaseRadio> = {
77
title: 'Design System/Technical Components/BaseRadio',
@@ -14,10 +14,6 @@ type Story = StoryObj<typeof BaseRadio>;
1414

1515
export const Base = {
1616
render: () => {
17-
const {
18-
colors: { neutral800 },
19-
} = useTheme();
20-
2117
const [selected, setSelected] = React.useState<string>();
2218

2319
return (
@@ -32,25 +28,11 @@ export const Base = {
3228
name="prefered-meal"
3329
>
3430
<div>
35-
<label
36-
style={{
37-
color: neutral800,
38-
}}
39-
htmlFor="pizza"
40-
>
41-
Pizza
42-
</label>
31+
<label htmlFor="pizza">Pizza</label>
4332
<BaseRadio value="pizza" id="pizza" />
4433
</div>
4534
<div>
46-
<label
47-
style={{
48-
color: neutral800,
49-
}}
50-
htmlFor="bagel"
51-
>
52-
Bagel
53-
</label>
35+
<label htmlFor="bagel">Bagel</label>
5436
<BaseRadio value="bagel" id="bagel" />
5537
</div>
5638
</RadioGroup>
@@ -63,10 +45,6 @@ export const Base = {
6345

6446
export const Disabled = {
6547
render: () => {
66-
const {
67-
colors: { neutral800 },
68-
} = useTheme();
69-
7048
const [selected, setSelected] = React.useState<string>();
7149

7250
return (
@@ -81,36 +59,15 @@ export const Disabled = {
8159
name="prefered-meal"
8260
>
8361
<div>
84-
<label
85-
style={{
86-
color: neutral800,
87-
}}
88-
htmlFor="first"
89-
>
90-
Mario
91-
</label>
62+
<label htmlFor="first">Mario</label>
9263
<BaseRadio value="first" id="first" />
9364
</div>
9465
<div>
95-
<label
96-
style={{
97-
color: neutral800,
98-
}}
99-
htmlFor="second"
100-
>
101-
Luigi
102-
</label>
66+
<label htmlFor="second">Luigi</label>
10367
<BaseRadio value="second" id="second" disabled />
10468
</div>
10569
<div>
106-
<label
107-
style={{
108-
color: neutral800,
109-
}}
110-
htmlFor="third"
111-
>
112-
Wario
113-
</label>
70+
<label htmlFor="third">Wario</label>
11471
<BaseRadio value="third" id="third" />
11572
</div>
11673
</RadioGroup>

0 commit comments

Comments
 (0)