|
| 1 | +import { createTemplateFromVueFile, getIconNames } from '@/common/storybook_utils'; |
| 2 | +import DtAvatar from './Avatar.vue'; |
| 3 | +import { AVATAR_SIZE_MODIFIERS, AVATAR_PRESENCE_STATES } from './AvatarConstants'; |
| 4 | +import DtAvatarDefaultTemplate from './AvatarDefault.story.vue'; |
| 5 | +import DtAvatarVariantsTemplate from './AvatarVariants.story.vue'; |
| 6 | +import { action } from 'storybook/actions'; |
| 7 | + |
| 8 | +import defaultImage from '@/common/assets/avatar2.png'; |
| 9 | + |
| 10 | +const ICONS_LIST = getIconNames(); |
| 11 | + |
| 12 | +export const argsData = { |
| 13 | + onClick: action('click'), |
| 14 | + size: 300, |
| 15 | + presence: null, |
| 16 | + fullName: 'Jaqueline Nackos', |
| 17 | + imageAlt: 'profile image', |
| 18 | + imageSrc: defaultImage, |
| 19 | + seed: '', |
| 20 | + iconName: 'accessibility', |
| 21 | + iconSize: '500', |
| 22 | +}; |
| 23 | + |
| 24 | +export const argTypesData = { |
| 25 | + // Props |
| 26 | + avatarClass: { |
| 27 | + description: 'Pass through classes. Used to customize the avatar container', |
| 28 | + }, |
| 29 | + color: { |
| 30 | + control: { |
| 31 | + type: 'text', |
| 32 | + }, |
| 33 | + description: 'Legacy color prop. Use seed instead for auto-generated colors.', |
| 34 | + }, |
| 35 | + iconName: { |
| 36 | + options: ICONS_LIST, |
| 37 | + control: { |
| 38 | + type: 'select', |
| 39 | + labels: { |
| 40 | + undefined: '(empty)', |
| 41 | + }, |
| 42 | + }, |
| 43 | + }, |
| 44 | + iconSize: { |
| 45 | + defaultValue: null, |
| 46 | + }, |
| 47 | + id: { |
| 48 | + table: { |
| 49 | + defaultValue: { |
| 50 | + summary: 'generated unique ID', |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + overlayClass: { |
| 55 | + description: 'Pass through classes. Used to customize the avatar overlay', |
| 56 | + }, |
| 57 | + overlayIcon: { |
| 58 | + options: ICONS_LIST, |
| 59 | + control: { |
| 60 | + type: 'select', |
| 61 | + labels: { |
| 62 | + undefined: '(empty)', |
| 63 | + }, |
| 64 | + }, |
| 65 | + }, |
| 66 | + overlayText: { |
| 67 | + description: 'The text that overlays the avatar', |
| 68 | + }, |
| 69 | + presence: { |
| 70 | + defaultValue: null, |
| 71 | + control: { |
| 72 | + type: 'select', |
| 73 | + }, |
| 74 | + options: Object.values(AVATAR_PRESENCE_STATES), |
| 75 | + table: { |
| 76 | + defaultValue: { |
| 77 | + summary: 'null', |
| 78 | + }, |
| 79 | + }, |
| 80 | + }, |
| 81 | + presenceProps: { |
| 82 | + description: 'Pass through props. Used to customize the presence component', |
| 83 | + }, |
| 84 | + size: { |
| 85 | + control: { |
| 86 | + type: 'select', |
| 87 | + }, |
| 88 | + options: Object.keys(AVATAR_SIZE_MODIFIERS), |
| 89 | + }, |
| 90 | + |
| 91 | + // Action Event Handlers |
| 92 | + onClick: { |
| 93 | + table: { |
| 94 | + disable: true, |
| 95 | + }, |
| 96 | + }, |
| 97 | +}; |
| 98 | + |
| 99 | +// Story Collection |
| 100 | +export default { |
| 101 | + title: 'Components/Avatar', |
| 102 | + component: DtAvatar, |
| 103 | + args: argsData, |
| 104 | + argTypes: argTypesData, |
| 105 | + excludeStories: /.*Data$/, |
| 106 | +}; |
| 107 | + |
| 108 | +// Templates |
| 109 | +const DefaultTemplate = (args, { argTypes }) => |
| 110 | + createTemplateFromVueFile(args, argTypes, DtAvatarDefaultTemplate); |
| 111 | + |
| 112 | +const VariantsTemplate = (args, { argTypes }) => |
| 113 | + createTemplateFromVueFile(args, argTypes, DtAvatarVariantsTemplate); |
| 114 | + |
| 115 | +// Stories |
| 116 | +export const Default = { |
| 117 | + render: DefaultTemplate, |
| 118 | + decorators: [ |
| 119 | + () => ({ |
| 120 | + template: `<dt-stack direction="row"><story /></dt-stack>`, |
| 121 | + }), |
| 122 | + ], |
| 123 | +}; |
| 124 | + |
| 125 | +export const Variants = { |
| 126 | + render: VariantsTemplate, |
| 127 | + parameters: { |
| 128 | + percy: { |
| 129 | + args: { |
| 130 | + seed: 'seed', |
| 131 | + }, |
| 132 | + }, |
| 133 | + options: { showPanel: false }, |
| 134 | + controls: { disable: true }, |
| 135 | + }, |
| 136 | +}; |
0 commit comments