Skip to content

Commit 34b4daf

Browse files
authored
chore: v5 update Avatar docs (#262)
* chore: update avatar docs to be more aligned with existing convention
1 parent 2660c86 commit 34b4daf

File tree

4 files changed

+72
-99
lines changed

4 files changed

+72
-99
lines changed
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meta, Canvas, Controls } from '@storybook/blocks'
1+
import { Meta, Canvas, Controls, Description } from '@storybook/blocks'
22
import { RenderHtmlMarkup } from '../../storybook/render-html-markup'
33
import * as AvatarRectangleStories from './avatar-rectangle.stories'
44

@@ -10,30 +10,24 @@ A versatile component designed to render property image.
1010

1111
<Controls />
1212

13-
## Default Usage
14-
15-
The default usage use the residential variant and medium size, each can be set using the `data-` attribute.
13+
## Default
1614

15+
<Description of={AvatarRectangleStories.DefaultUsage} />
1716
<Canvas of={AvatarRectangleStories.DefaultUsage} />
1817
<RenderHtmlMarkup of={AvatarRectangleStories.DefaultUsage} />
1918

19+
## Avatar Rectangle Variant
20+
21+
<Canvas of={AvatarRectangleStories.AvatarRectangleVariant} />
22+
<RenderHtmlMarkup of={AvatarRectangleStories.AvatarRectangleVariant} />
23+
2024
## Using Residential Placeholder
2125

2226
<Canvas of={AvatarRectangleStories.UsingResidentialPlaceholder} />
2327
<RenderHtmlMarkup of={AvatarRectangleStories.UsingResidentialPlaceholder} />
2428

25-
## Using Commercial Variant
26-
27-
<Canvas of={AvatarRectangleStories.UsingCommercialVariant} />
28-
<RenderHtmlMarkup of={AvatarRectangleStories.UsingCommercialPlaceholder} />
2929

3030
## Using Commercial Placeholder
3131

3232
<Canvas of={AvatarRectangleStories.UsingCommercialPlaceholder} />
3333
<RenderHtmlMarkup of={AvatarRectangleStories.UsingCommercialPlaceholder} />
34-
35-
## React Usage
36-
37-
<Canvas of={AvatarRectangleStories.ReactUsage} />
38-
39-
<RenderHtmlMarkup of={AvatarRectangleStories.ReactUsage} />
Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import type { Meta, StoryObj } from '@storybook/react'
22
import { AvatarRectangle } from '.'
3-
import {
4-
ElAvatarRectangle,
5-
ElAvatarRectResidentialPlaceholder,
6-
ElAvatarRectBottomImage,
7-
ElAvatarRectCommercialPlaceholder,
8-
} from './styles'
3+
import { ElAvatarRectResidentialPlaceholder, ElAvatarRectCommercialPlaceholder } from './styles'
94

105
export default {
116
title: 'Components/Avatar Rectangle',
127
component: AvatarRectangle,
138
args: {
149
variant: 'residential',
1510
size: 'medium',
11+
src: 'https://picsum.photos/id/206/100/100',
1612
},
1713
argTypes: {
1814
variant: {
@@ -26,36 +22,23 @@ export default {
2622
},
2723
} as Meta<typeof AvatarRectangle>
2824

29-
const exampleImageUrl = 'https://picsum.photos/id/206/100/100'
25+
type Story = StoryObj<typeof AvatarRectangle>
3026

31-
export const DefaultUsage = {
32-
render: ({}) => (
33-
<ElAvatarRectangle>
34-
<img src={exampleImageUrl} alt="example" />
35-
</ElAvatarRectangle>
36-
),
37-
}
27+
/**
28+
* The default usage use the residential variant and medium size, each can be set using the `data-` attribute.
29+
*/
30+
export const DefaultUsage: Story = {}
3831

39-
export const UsingResidentialPlaceholder = {
40-
render: ({}) => <ElAvatarRectResidentialPlaceholder aria-label="Image placeholder" />,
32+
export const AvatarRectangleVariant: Story = {
33+
args: {
34+
variant: 'commercial',
35+
},
4136
}
4237

43-
export const UsingCommercialVariant = {
44-
render: ({}) => (
45-
<ElAvatarRectangle data-variant="commercial">
46-
<img src={exampleImageUrl} alt="example" />
47-
<ElAvatarRectBottomImage aria-hidden="true" />
48-
</ElAvatarRectangle>
49-
),
38+
export const UsingResidentialPlaceholder = {
39+
render: () => <ElAvatarRectResidentialPlaceholder aria-label="Image placeholder" />,
5040
}
5141

5242
export const UsingCommercialPlaceholder = {
53-
render: ({}) => <ElAvatarRectCommercialPlaceholder aria-label="Image placeholder" />,
54-
}
55-
56-
export const ReactUsage: StoryObj<typeof AvatarRectangle> = {
57-
args: {
58-
src: exampleImageUrl,
59-
},
60-
render: (props) => <AvatarRectangle {...props}></AvatarRectangle>,
43+
render: () => <ElAvatarRectCommercialPlaceholder aria-label="Image placeholder" />,
6144
}

src/components/avatar/avatar.mdx

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
1-
import { Meta, Story, Canvas, Controls } from '@storybook/blocks'
1+
import { Meta, Story, Canvas, Controls, Description
2+
} from '@storybook/blocks'
23
import { RenderHtmlMarkup } from '../../storybook/render-html-markup'
34
import * as AvatarStories from './avatar.stories'
45

56
<Meta of={AvatarStories} />
67

78
# Avatar
89

9-
An avatar component to be used typically with a `Card` or `Nav` component. The default variant renders a circle with children.
10+
<Description of={AvatarStories.Default} />
1011

11-
There are multiple variants that can be used by utilizing the data props, such as size, colour, and shape (see the HTML version of React usage). In addition to text, it also accepts an Icon as a child.
12-
13-
## Style Only Usage
14-
15-
<Canvas of={AvatarStories.StyleOnlyUsage} />
12+
<Controls />
1613

17-
<RenderHtmlMarkup of={AvatarStories.StyleOnlyUsage} />
14+
## Default
1815

19-
<Canvas of={AvatarStories.WithIconUsage} />
16+
<Canvas of={AvatarStories.Default} />
2017

21-
<RenderHtmlMarkup of={AvatarStories.WithIconUsage} />
18+
<RenderHtmlMarkup of={AvatarStories.Default} />
2219

23-
## With Colour
20+
## Avatar with Icon
2421

25-
<Canvas of={AvatarStories.WithColour} />
22+
<Canvas of={AvatarStories.AvatarWithIcon} />
2623

27-
<RenderHtmlMarkup of={AvatarStories.WithColour} />
24+
<RenderHtmlMarkup of={AvatarStories.AvatarWithIcon} />
2825

29-
## With Square Shape
3026

31-
<Canvas of={AvatarStories.WithSquareShape} />
27+
## Avatar Colour
3228

33-
<RenderHtmlMarkup of={AvatarStories.WithSquareShape} />
29+
<Canvas of={AvatarStories.AvatarColour} />
3430

35-
## With Small Size
31+
<RenderHtmlMarkup of={AvatarStories.AvatarColour} />
3632

37-
<Canvas of={AvatarStories.WithSmallSize} />
33+
## Avatar Shape
3834

39-
<RenderHtmlMarkup of={AvatarStories.WithSmallSize} />
35+
<Canvas of={AvatarStories.AvatarShape} />
4036

41-
## React Usage
37+
<RenderHtmlMarkup of={AvatarStories.AvatarShape} />
4238

43-
<Controls />
39+
## Avatar Size
4440

45-
<Canvas of={AvatarStories.ReactUsage} />
41+
<Canvas of={AvatarStories.AvatarSize} />
4642

47-
<RenderHtmlMarkup of={AvatarStories.ReactUsage} />WithColourWithColour
43+
<RenderHtmlMarkup of={AvatarStories.AvatarSize} />
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
import type { StoryObj } from '@storybook/react'
2-
import { Avatar, ElAvatar } from '.'
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import { Avatar } from '.'
33
import { Icon } from '../icon'
44

55
export default {
66
title: 'Components/Avatar',
77
component: Avatar,
8-
}
8+
args: {
9+
children: 'AD',
10+
},
11+
} as Meta<typeof Avatar>
912

10-
export const StyleOnlyUsage = {
11-
render: ({}) => <ElAvatar>AD</ElAvatar>,
12-
}
13+
type Story = StoryObj<typeof Avatar>
14+
15+
/**
16+
* An avatar component to be used typically with a `Card` or `Nav` component.
17+
* The default variant renders a circle with children.
18+
*
19+
* There are multiple variants that can be used by utilizing the `data-` props
20+
* such as `size`, `colour`, and `shape` (see the HTML version of each version).
21+
* In addition to text, it also accepts an Icon as a child.
22+
*/
23+
export const Default: Story = {}
1324

14-
export const WithIconUsage = {
15-
render: ({}) => (
16-
<ElAvatar>
25+
export const AvatarWithIcon: Story = {
26+
render: (props) => (
27+
<Avatar {...props}>
1728
<Icon icon="contact" />
18-
</ElAvatar>
29+
</Avatar>
1930
),
2031
}
2132

22-
export const WithColour = {
23-
render: ({}) => <ElAvatar data-colour="purple">AD</ElAvatar>,
24-
name: 'Colour: Purple',
25-
}
26-
27-
export const WithSquareShape = {
28-
render: ({}) => <ElAvatar data-shape="square">AD</ElAvatar>,
29-
name: 'Shape: Square',
33+
export const AvatarColour: Story = {
34+
args: {
35+
colour: 'purple',
36+
},
3037
}
3138

32-
export const WithSmallSize = {
33-
render: ({}) => (
34-
<ElAvatar data-size="small">
35-
<Icon icon="contact" />
36-
</ElAvatar>
37-
),
38-
name: 'Size: Small',
39+
export const AvatarShape: Story = {
40+
args: {
41+
shape: 'square',
42+
},
3943
}
4044

41-
export const ReactUsage: StoryObj<typeof Avatar> = {
45+
export const AvatarSize: Story = {
4246
args: {
43-
shape: 'circle',
44-
size: 'medium',
45-
colour: 'default',
46-
children: 'AD',
47+
size: 'small',
4748
},
48-
render: (props) => <Avatar {...props}>{props.children}</Avatar>,
4949
}

0 commit comments

Comments
 (0)