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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
| import React, { useState } from 'react'; import { Meta, StoryObj } from '@storybook/react'; import { Tag } from '@hardyhu-ui/core';
const meta: Meta<typeof Tag> = { title: 'Components/Tag', component: Tag, argTypes: { variant: { control: { type: 'select' }, options: ['solid', 'outline', 'soft'], description: 'Tag style variant', table: { type: { summary: 'string' }, defaultValue: { summary: 'solid' }, }, }, size: { control: { type: 'select' }, options: ['small', 'medium', 'large'], description: 'Tag size', table: { type: { summary: 'string' }, defaultValue: { summary: 'medium' }, }, }, color: { control: { type: 'select' }, options: ['primary', 'secondary', 'accent', 'success', 'info', 'warning', 'error', 'grey'], description: 'Tag color', table: { type: { summary: 'string' }, defaultValue: { summary: 'primary' }, }, }, shape: { control: { type: 'select' }, options: ['default', 'rounded', 'pill'], description: 'Tag border radius style', table: { type: { summary: 'string' }, defaultValue: { summary: 'default' }, }, }, closable: { control: 'boolean', description: 'Whether tag is closable', table: { type: { summary: 'boolean' }, defaultValue: { summary: 'false' }, }, }, clickable: { control: 'boolean', description: 'Whether tag is clickable', table: { type: { summary: 'boolean' }, defaultValue: { summary: 'false' }, }, }, onClose: { action: 'closed' }, onClick: { action: 'clicked' }, }, parameters: { docs: { description: { component: 'A versatile tag component for categorization and filtering.', }, }, }, };
export default meta; type Story = StoryObj<typeof Tag>;
export const Default: Story = { args: { children: 'Default Tag', }, };
export const Variants: Story = { render: (args) => ( <div style={{ display: 'flex', gap: '0.75rem', flexWrap: 'wrap' }}> <Tag {...args} variant="solid">Solid</Tag> <Tag {...args} variant="outline">Outline</Tag> <Tag {...args} variant="soft">Soft</Tag> </div> ), };
export const Colors: Story = { render: (args) => ( <div style={{ display: 'flex', gap: '0.75rem', flexWrap: 'wrap' }}> <Tag {...args} color="primary">Primary</Tag> <Tag {...args} color="secondary">Secondary</Tag> <Tag {...args} color="accent">Accent</Tag> <Tag {...args} color="success">Success</Tag> <Tag {...args} color="info">Info</Tag> <Tag {...args} color="warning">Warning</Tag> <Tag {...args} color="error">Error</Tag> <Tag {...args} color="grey">Grey</Tag> </div> ), };
export const Sizes: Story = { render: (args) => ( <div style={{ display: 'flex', gap: '0.75rem', alignItems: 'center' }}> <Tag {...args} size="small">Small</Tag> <Tag {...args} size="medium">Medium</Tag> <Tag {...args} size="large">Large</Tag> </div> ), };
export const Shapes: Story = { render: (args) => ( <div style={{ display: 'flex', gap: '0.75rem' }}> <Tag {...args} shape="default">Default</Tag> <Tag {...args} shape="rounded">Rounded</Tag> <Tag {...args} shape="pill">Pill</Tag> </div> ), };
export const WithIcons: Story = { render: (args) => ( <div style={{ display: 'flex', gap: '0.75rem', flexWrap: 'wrap' }}> <Tag {...args} leftIcon={<span style={{ fontSize: '1em' }}>🔍</span>} > Search </Tag> <Tag {...args} rightIcon={<span style={{ fontSize: '1em' }}>✓</span>} > Verified </Tag> <Tag {...args} leftIcon={<span style={{ fontSize: '1em' }}>⚠️</span>} > Warning </Tag> <Tag {...args} leftIcon={<span style={{ fontSize: '1em' }}>👤</span>} > User </Tag> </div> ), };
export const Closable: Story = { render: (args) => { const [tags, setTags] = useState(['React', 'TypeScript', 'CSS', 'Storybook']); const handleClose = (index: number) => { setTags(tags.filter((_, i) => i !== index)); }; return ( <div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}> {tags.map((tag, index) => ( <Tag key={index} closable onClose={() => handleClose(index)} color={['primary', 'secondary', 'info', 'success'][index % 4] as any} > {tag} </Tag> ))} {tags.length === 0 && ( <div>All tags have been removed. Refresh to reset.</div> )} </div> ); }, };
export const Clickable: Story = { args: { children: 'Clickable Tag', clickable: true, onClick: () => alert('Tag clicked!'), }, };
export const TagsGroup: Story = { render: () => { const [selected, setSelected] = useState('medium'); const sizes = ['small', 'medium', 'large', 'xl', 'custom']; return ( <div> <div style={{ marginBottom: '0.5rem', fontWeight: 'bold' }}>Select Size:</div> <div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}> {sizes.map((size) => ( <Tag key={size} variant={selected === size ? 'solid' : 'outline'} color="primary" clickable onClick={() => setSelected(size)} > {size} </Tag> ))} </div> <div style={{ marginTop: '1rem' }}> Selected size: <strong>{selected}</strong> </div> </div> ); }, };
export const StatusTags: Story = { render: () => ( <div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}> <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}> <span style={{ width: '100px' }}>Order:</span> <Tag variant="soft" color="info" shape="pill" size="small">Processing</Tag> </div> <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}> <span style={{ width: '100px' }}>Payment:</span> <Tag variant="soft" color="success" shape="pill" size="small">Completed</Tag> </div> <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}> <span style={{ width: '100px' }}>Shipping:</span> <Tag variant="soft" color="warning" shape="pill" size="small">Pending</Tag> </div> <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}> <span style={{ width: '100px' }}>Return:</span> <Tag variant="soft" color="error" shape="pill" size="small">Rejected</Tag> </div> </div> ), };
export const TagsVariantCombinations: Story = { render: () => ( <div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}> <div> <h3 style={{ margin: '0 0 0.5rem 0' }}>Solid Variant</h3> <div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}> <Tag variant="solid" color="primary">Primary</Tag> <Tag variant="solid" color="secondary">Secondary</Tag> <Tag variant="solid" color="success">Success</Tag> <Tag variant="solid" color="warning">Warning</Tag> <Tag variant="solid" color="error">Error</Tag> </div> </div> <div> <h3 style={{ margin: '0 0 0.5rem 0' }}>Outline Variant</h3> <div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}> <Tag variant="outline" color="primary">Primary</Tag> <Tag variant="outline" color="secondary">Secondary</Tag> <Tag variant="outline" color="success">Success</Tag> <Tag variant="outline" color="warning">Warning</Tag> <Tag variant="outline" color="error">Error</Tag> </div> </div> <div> <h3 style={{ margin: '0 0 0.5rem 0' }}>Soft Variant</h3> <div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}> <Tag variant="soft" color="primary">Primary</Tag> <Tag variant="soft" color="secondary">Secondary</Tag> <Tag variant="soft" color="success">Success</Tag> <Tag variant="soft" color="warning">Warning</Tag> <Tag variant="soft" color="error">Error</Tag> </div> </div> </div> ), };
|