Skip to content

Commit 6100d50

Browse files
authored
Update Skeleton.examples.stories.tsx to no longer use styled-components (#6485)
1 parent 1f531cb commit 6100d50

File tree

2 files changed

+50
-56
lines changed

2 files changed

+50
-56
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.CommentCard {
2+
border: var(--borderWidth-thin) solid var(--borderColor-default);
3+
border-radius: var(--borderRadius-medium);
4+
font-size: var(--text-body-size-medium);
5+
line-height: var(--text-body-lineHeight-large);
6+
padding: var(--base-size-16);
7+
}
8+
9+
.CommentCardHeading {
10+
display: flex;
11+
align-items: center;
12+
gap: var(--base-size-8);
13+
margin-bottom: var(--base-size-16);
14+
}
15+
16+
.CommentCardHeadingText {
17+
flex-grow: 1;
18+
}
19+
20+
.CommentCardUserMeta {
21+
display: flex;
22+
align-items: center;
23+
flex-grow: 1;
24+
gap: var(--base-size-4);
25+
}
26+
27+
.CommentCardDate {
28+
color: var(--fgColor-muted);
29+
flex-grow: 1;
30+
}
31+
32+
.CommentsSpacing > * + * {
33+
margin-block-start: var(--base-size-16);
34+
}

packages/react/src/Skeleton/Skeleton.examples.stories.tsx

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import React, {Suspense} from 'react'
22
import type {Meta} from '@storybook/react-vite'
33
import type {ComponentProps} from '../utils/types'
44
import {SkeletonText} from '../SkeletonText'
5-
import {Avatar, Box, Button, IconButton, Text} from '../'
5+
import {Avatar, Button, IconButton, Text} from '../'
66
import {SkeletonAvatar} from '../SkeletonAvatar'
77
import {VisuallyHidden} from '../VisuallyHidden'
88
import {KebabHorizontalIcon} from '@primer/octicons-react'
9+
import classes from './Skeleton.examples.stories.module.css'
910

1011
export default {
1112
title: 'Components/Skeleton/Examples',
@@ -21,37 +22,10 @@ const mockData = {
2122
avatarSrc: 'https://avatars.githubusercontent.com/u/7143434?v=4',
2223
}
2324

24-
const CommentCard = ({children}: {children: React.ReactNode}) => (
25-
<Box
26-
sx={{
27-
borderWidth: '1px',
28-
borderColor: 'border.default',
29-
borderStyle: 'solid',
30-
borderRadius: 2,
31-
fontSize: 1,
32-
lineHeight: 'default',
33-
p: 3,
34-
}}
35-
>
36-
{children}
37-
</Box>
38-
)
25+
const CommentCard = ({children}: {children: React.ReactNode}) => <div className={classes.CommentCard}>{children}</div>
3926

4027
const CommentCardHeading = ({children}: {children: React.ReactNode}) => (
41-
<Box
42-
className="CommentCardHeading"
43-
sx={{
44-
alignItems: 'center',
45-
display: 'flex',
46-
gap: 2,
47-
mb: 3,
48-
'.CommentCardHeading__text': {
49-
flexGrow: 1,
50-
},
51-
}}
52-
>
53-
{children}
54-
</Box>
28+
<div className={classes.CommentCardHeading}>{children}</div>
5529
)
5630

5731
export const CommentsLoading = () => {
@@ -69,7 +43,7 @@ export const CommentsLoading = () => {
6943
{loading ? <VisuallyHidden>Comments are loading</VisuallyHidden> : null}
7044
{/** when loading is completed, it should be announced by the screen-reader */}
7145
<VisuallyHidden aria-live="polite">{loadingFinished ? 'Comments are loaded' : null}</VisuallyHidden>
72-
<Box sx={{'> * + *': {marginBlockStart: '1rem'}}}>
46+
<div className={classes.CommentsSpacing}>
7347
<Button onClick={toggleLoadingState}>{loading ? 'Stop loading' : 'Start loading'}</Button>
7448
{Array.from({length: COMMENT_LIST_LENGTH}, (_, index) => (
7549
/* aria-busy is passed so the screenreader doesn't announce the skeleton state */
@@ -78,36 +52,29 @@ export const CommentsLoading = () => {
7852
{loading ? (
7953
<>
8054
<SkeletonAvatar size={32} />
81-
<SkeletonText maxWidth="80px" className="CommentCardHeading__text" />
55+
<SkeletonText maxWidth="80px" className={classes.CommentCardHeadingText} />
8256
</>
8357
) : (
8458
<>
8559
<Avatar src={mockData.avatarSrc} size={32} />
86-
<Box sx={{alignItems: 'center', display: 'flex', flexGrow: 1, gap: 1}}>
60+
<div className={classes.CommentCardUserMeta}>
8761
<Text>{mockData.username}</Text>
88-
<Text
89-
sx={{
90-
color: 'fg.muted',
91-
flexGrow: 1,
92-
}}
93-
>
94-
{mockData.date}
95-
</Text>
62+
<Text className={classes.CommentCardDate}>{mockData.date}</Text>
9663
{/* buttons and interactive elements should not be represented as skeleton items or shown in any way until they're ready to accept input */}
9764
<IconButton
9865
icon={KebabHorizontalIcon}
9966
size="small"
10067
aria-label="Comment actions"
10168
variant="invisible"
10269
/>
103-
</Box>
70+
</div>
10471
</>
10572
)}
10673
</CommentCardHeading>
10774
{loading ? <SkeletonText lines={2} /> : <Text>{mockData.comment}</Text>}
10875
</CommentCard>
10976
))}
110-
</Box>
77+
</div>
11178
</>
11279
)
11380
}
@@ -137,15 +104,15 @@ export const CommentsLoadingWithSuspense = () => {
137104
<VisuallyHidden aria-live="polite">{loadingStatus === 'fulfilled' ? 'Comments are loaded' : null}</VisuallyHidden>
138105

139106
{/* aria-busy is passed so the screenreader doesn't announce the skeleton state */}
140-
<Box sx={{'> * + *': {marginBlockStart: '1rem'}}} aria-busy={loadingStatus === 'pending'}>
107+
<div className={classes.CommentsSpacing} aria-busy={loadingStatus === 'pending'}>
141108
{Array.from({length: COMMENT_LIST_LENGTH}, (_, index) => (
142109
<CommentCard key={index}>
143110
<Suspense
144111
fallback={
145112
<>
146113
<CommentCardHeading>
147114
<SkeletonAvatar size={32} />
148-
<SkeletonText maxWidth="80px" className="CommentCardHeading__text" />
115+
<SkeletonText maxWidth="80px" className={classes.CommentCardHeadingText} />
149116
</CommentCardHeading>
150117
<SkeletonText lines={2} />
151118
</>
@@ -155,7 +122,7 @@ export const CommentsLoadingWithSuspense = () => {
155122
</Suspense>
156123
</CommentCard>
157124
))}
158-
</Box>
125+
</div>
159126
</>
160127
)
161128
}
@@ -167,19 +134,12 @@ const SuspendedCommentCardContent = ({promise}: {promise: Promise<typeof mockDat
167134
<>
168135
<CommentCardHeading>
169136
<Avatar src={fetchedData.avatarSrc} size={32} />
170-
<Box sx={{alignItems: 'center', display: 'flex', flexGrow: 1, gap: 1}}>
137+
<div className={classes.CommentCardUserMeta}>
171138
<Text>{fetchedData.username}</Text>
172-
<Text
173-
sx={{
174-
color: 'fg.muted',
175-
flexGrow: 1,
176-
}}
177-
>
178-
{fetchedData.date}
179-
</Text>
139+
<Text className={classes.CommentCardDate}>{fetchedData.date}</Text>
180140
{/* buttons and interactive elements should not be represented as skeleton items or shown in any way until they're ready to accept input */}
181141
<IconButton icon={KebabHorizontalIcon} size="small" aria-label="Comment actions" variant="invisible" />
182-
</Box>
142+
</div>
183143
</CommentCardHeading>
184144
<Text>{fetchedData.comment}</Text>
185145
</>

0 commit comments

Comments
 (0)