|
| 1 | +import type { Meta, StoryObj } from '@storybook/react-webpack5'; |
| 2 | + |
| 3 | +import { RAGFlowAvatar } from '@/components/ragflow-avatar'; |
| 4 | + |
| 5 | +// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export |
| 6 | +const meta = { |
| 7 | + title: 'Example/RAGFlowAvatar', |
| 8 | + component: RAGFlowAvatar, |
| 9 | + parameters: { |
| 10 | + // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout |
| 11 | + layout: 'centered', |
| 12 | + docs: { |
| 13 | + description: { |
| 14 | + component: ` |
| 15 | +## RAGFlowAvatar Component |
| 16 | +
|
| 17 | +RAGFlowAvatar is a customizable avatar component that displays user avatars with intelligent fallbacks. When an image is not available, it generates colorful gradient backgrounds with user initials. |
| 18 | +
|
| 19 | +### Import Path |
| 20 | +\`\`\`typescript |
| 21 | +import { RAGFlowAvatar } from '@/components/ragflow-avatar'; |
| 22 | +\`\`\` |
| 23 | +
|
| 24 | +### Basic Usage |
| 25 | +\`\`\`tsx |
| 26 | +import { RAGFlowAvatar } from '@/components/ragflow-avatar'; |
| 27 | +
|
| 28 | +function MyComponent() { |
| 29 | + return ( |
| 30 | + <RAGFlowAvatar |
| 31 | + name="John Doe" |
| 32 | + avatar="https://example.com/avatar.jpg" |
| 33 | + isPerson={true} |
| 34 | + /> |
| 35 | + ); |
| 36 | +} |
| 37 | +\`\`\` |
| 38 | +
|
| 39 | +### Features |
| 40 | +- Displays user avatar images when available |
| 41 | +- Generates colorful gradient fallbacks with initials |
| 42 | +- Supports both person (circular) and non-person (rounded) styles |
| 43 | +- Automatic font size calculation based on container size |
| 44 | +- Color generation based on name for consistent appearance |
| 45 | +- Responsive design with resize observer |
| 46 | + `, |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | + // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs |
| 51 | + tags: ['autodocs'], |
| 52 | + // More on argTypes: https://storybook.js.org/docs/api/argtypes |
| 53 | + argTypes: { |
| 54 | + name: { |
| 55 | + description: |
| 56 | + 'The name to display initials for when no avatar is available', |
| 57 | + control: { type: 'text' }, |
| 58 | + type: { name: 'string', required: false }, |
| 59 | + }, |
| 60 | + avatar: { |
| 61 | + description: 'The URL of the avatar image', |
| 62 | + control: { type: 'text' }, |
| 63 | + type: { name: 'string', required: false }, |
| 64 | + }, |
| 65 | + isPerson: { |
| 66 | + description: 'Whether this avatar represents a person (affects styling)', |
| 67 | + control: { type: 'boolean' }, |
| 68 | + type: { name: 'boolean', required: false }, |
| 69 | + defaultValue: false, |
| 70 | + }, |
| 71 | + className: { |
| 72 | + description: 'Additional CSS classes to apply', |
| 73 | + control: { type: 'text' }, |
| 74 | + type: { name: 'string', required: false }, |
| 75 | + }, |
| 76 | + }, |
| 77 | + args: { |
| 78 | + name: 'John Doe', |
| 79 | + isPerson: false, |
| 80 | + }, |
| 81 | +} satisfies Meta<typeof RAGFlowAvatar>; |
| 82 | + |
| 83 | +export default meta; |
| 84 | +type Story = StoryObj<typeof meta>; |
| 85 | + |
| 86 | +// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args |
| 87 | +export const WithInitials: Story = { |
| 88 | + args: { |
| 89 | + name: 'John Doe', |
| 90 | + isPerson: false, |
| 91 | + }, |
| 92 | + parameters: { |
| 93 | + docs: { |
| 94 | + description: { |
| 95 | + story: ` |
| 96 | +### With Initials Only |
| 97 | +
|
| 98 | +Shows the avatar component with only a name, displaying generated initials with a gradient background. |
| 99 | +
|
| 100 | +\`\`\`tsx |
| 101 | +<RAGFlowAvatar |
| 102 | + name="John Doe" |
| 103 | + isPerson={false} |
| 104 | +/> |
| 105 | +\`\`\` |
| 106 | + `, |
| 107 | + }, |
| 108 | + }, |
| 109 | + }, |
| 110 | + tags: ['!dev'], |
| 111 | +}; |
| 112 | + |
| 113 | +export const WithAvatar: Story = { |
| 114 | + args: { |
| 115 | + name: 'Jane Smith', |
| 116 | + avatar: |
| 117 | + 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjY0IiBoZWlnaHQ9IjY0IiByeD0iMzIiIGZpbGw9IiM0RjZERUUiLz4KPGNpcmNsZSBjeD0iMzIiIGN5PSIyNCIgcj0iOCIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTQ4IDQ4QzQ4IDQxLjM3MyA0MS45NDA2IDM2IDM0LjUgMzZIMjkuNUMyMi4wNTk0IDM2IDE2IDQxLjM3MyAxNiA0OCIgZmlsbD0id2hpdGUiLz4KPC9zdmc+', |
| 118 | + isPerson: true, |
| 119 | + }, |
| 120 | + parameters: { |
| 121 | + docs: { |
| 122 | + description: { |
| 123 | + story: ` |
| 124 | +### With Avatar Image |
| 125 | +
|
| 126 | +Shows the avatar component with an actual image. When isPerson is true, the avatar will be circular. |
| 127 | +
|
| 128 | +\`\`\`tsx |
| 129 | +<RAGFlowAvatar |
| 130 | + name="Jane Smith" |
| 131 | + avatar="https://example.com/avatar.jpg" |
| 132 | + isPerson={true} |
| 133 | +/> |
| 134 | +\`\`\` |
| 135 | + `, |
| 136 | + }, |
| 137 | + }, |
| 138 | + }, |
| 139 | + tags: ['!dev'], |
| 140 | +}; |
| 141 | + |
| 142 | +export const PersonStyle: Story = { |
| 143 | + args: { |
| 144 | + name: 'Alice Johnson', |
| 145 | + isPerson: true, |
| 146 | + }, |
| 147 | + parameters: { |
| 148 | + docs: { |
| 149 | + description: { |
| 150 | + story: ` |
| 151 | +### Person Style (Circular) |
| 152 | +
|
| 153 | +Shows the avatar component with isPerson set to true, which makes it circular. |
| 154 | +
|
| 155 | +\`\`\`tsx |
| 156 | +<RAGFlowAvatar |
| 157 | + name="Alice Johnson" |
| 158 | + isPerson={true} |
| 159 | +/> |
| 160 | +\`\`\` |
| 161 | + `, |
| 162 | + }, |
| 163 | + }, |
| 164 | + }, |
| 165 | + tags: ['!dev'], |
| 166 | +}; |
| 167 | + |
| 168 | +export const NonPersonStyle: Story = { |
| 169 | + args: { |
| 170 | + name: 'Bot Assistant', |
| 171 | + isPerson: false, |
| 172 | + }, |
| 173 | + parameters: { |
| 174 | + docs: { |
| 175 | + description: { |
| 176 | + story: ` |
| 177 | +### Non-Person Style (Rounded Rectangle) |
| 178 | +
|
| 179 | +Shows the avatar component with isPerson set to false, which makes it a rounded rectangle. |
| 180 | +
|
| 181 | +\`\`\`tsx |
| 182 | +<RAGFlowAvatar |
| 183 | + name="Bot Assistant" |
| 184 | + isPerson={false} |
| 185 | +/> |
| 186 | +\`\`\` |
| 187 | + `, |
| 188 | + }, |
| 189 | + }, |
| 190 | + }, |
| 191 | + tags: ['!dev'], |
| 192 | +}; |
0 commit comments