-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathlink.stories.tsx
More file actions
180 lines (169 loc) · 4.17 KB
/
Copy pathlink.stories.tsx
File metadata and controls
180 lines (169 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import type { Meta, StoryObj } from '@storybook/react-vite';
import { BrowserRouter } from 'react-router';
import { expect, within } from 'storybook/test';
import { Heading, Link, List, ListLink } from '~/src/index';
const meta: Meta<typeof Link> = {
title: 'Components (Verified)/Links',
tags: ['autodocs'],
component: Link,
argTypes: {
href: { control: 'text' },
label: { control: 'text' },
isButton: { control: 'boolean' },
isJump: { control: 'boolean' },
isRouterLink: { control: 'boolean' },
appearance: {
control: 'select',
options: ['primary', 'secondary', 'warning', 'destructive'],
},
iconLeft: { control: 'text' },
iconRight: { control: 'text' },
children: { control: 'text' },
},
};
export default meta;
type Story = StoryObj<typeof meta>;
const DefaultArguments = {
args: {
href: '/#',
label: 'Link Text',
isButton: false,
isJump: false,
isRouterLink: false,
appearance: 'primary',
iconLeft: undefined,
iconRight: undefined,
children: undefined,
},
};
export const Configurable: Story = {
args: {
...DefaultArguments.args,
},
render: (arguments_) =>
arguments_.isRouterLink ? (
<BrowserRouter>
<Link {...arguments_} />
</BrowserRouter>
) : (
<Link {...arguments_} />
),
play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement);
const link = canvas.getByRole('link');
await expect(link).toHaveAttribute('href', args.href);
},
};
export const Inline: Story = {
render: () => (
<p>
Here's the default <Link href='/#' label='inline link' /> style.
</p>
),
};
export const Standalone: Story = {
render: (arguments_) => (
<Link {...arguments_} href='/#' isJump label='Standalone link' />
),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const link = canvas.getByRole('link', { name: /standalone link/i });
await expect(link).toHaveAttribute('href', '/#');
},
};
export const WithIcon: Story = {
name: 'With icon',
args: {
...DefaultArguments.args,
},
render: () => (
<>
<Heading type='4'>Inline</Heading>
<p>
The document icon should emphasize a link that contains a{' '}
<Link
href={DefaultArguments.args.href}
label='file or document'
iconRight='download'
/>
. The external link icon is used to emphasize a link to a{' '}
<Link
href={DefaultArguments.args.href}
label='non-CFPB webpage'
iconRight='external-link'
/>
.
</p>
<Heading type='4'>Standalone</Heading>
<p>
<Link
isJump
href='https://www.example.com'
iconLeft='left'
label='Go back'
/>
</p>
<p>
<Link
isJump
href='https://www.example.com'
label='Continue'
iconRight='right'
/>
</p>
<p>
<Link
isJump
href='https://www.example.com'
label='External link'
iconRight='external-link'
/>
</p>
<p>
<Link
isJump
href='https://www.example.com'
label='Document or file'
iconRight='document'
/>
</p>
</>
),
};
export const Listlink: Story = {
name: 'List',
args: {
...DefaultArguments.args,
},
render: () => (
<List isLinks>
<ListLink href='/#' label='List item 1' />
<ListLink href='/#' label='List item 2' />
<ListLink href='/#' label='List item 3' />
</List>
),
};
export const Destructive: Story = {
args: {
...DefaultArguments.args,
},
render: () => (
<Link href='/#' appearance='warning' label='Destructive link' />
),
};
export const LinkWithReactRouterLink: Story = {
name: 'Link using React Router Link',
parameters: {
docs: {
description: {
story:
'See [React Router Link docs](https://reactrouter.com/api/components/Link) for usage information',
},
},
},
render: () => (
<BrowserRouter>
<Link href='/#' label='Link using React Router Link' isRouterLink />
</BrowserRouter>
),
};