|
| 1 | +import type {Meta, StoryObj} from '@storybook/vue3'; |
| 2 | +import {Text} from '@ui'; |
| 3 | +import {computed} from 'vue'; |
| 4 | + |
| 5 | +const meta = { |
| 6 | + title: 'Components/Text', |
| 7 | + component: Text, |
| 8 | + argTypes: { |
| 9 | + size: { |
| 10 | + control: 'select', |
| 11 | + options: ['xs', 'sm', 'base', 'lg'], |
| 12 | + }, |
| 13 | + variant: { |
| 14 | + control: 'select', |
| 15 | + options: ['default', 'strong', 'subtle', 'code', 'danger', 'success', 'warning'], |
| 16 | + }, |
| 17 | + as: { |
| 18 | + control: 'select', |
| 19 | + options: ['span', 'p', 'div'], |
| 20 | + }, |
| 21 | + }, |
| 22 | +} satisfies Meta<typeof Text>; |
| 23 | + |
| 24 | +export default meta; |
| 25 | +type Story = StoryObj<typeof meta>; |
| 26 | + |
| 27 | +export const Default: Story = { |
| 28 | + args: { |
| 29 | + text: 'The quick brown fox jumps over the lazy dog.', |
| 30 | + }, |
| 31 | +}; |
| 32 | + |
| 33 | +const introCode = ` |
| 34 | +<div class="flex flex-wrap gap-3 items-center"> |
| 35 | + <Text text="Default" /> |
| 36 | + <Text variant="strong" text="Strong" /> |
| 37 | + <Text variant="subtle" text="Subtle" /> |
| 38 | + <Text variant="code" text="code_example" /> |
| 39 | +</div> |
| 40 | +`; |
| 41 | + |
| 42 | +export const _DocsIntro: Story = { |
| 43 | + tags: ['!dev'], |
| 44 | + parameters: { |
| 45 | + docs: { |
| 46 | + source: { code: introCode }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + render: () => ({ |
| 50 | + components: { Text }, |
| 51 | + template: introCode, |
| 52 | + }), |
| 53 | +}; |
| 54 | + |
| 55 | +export const Variants: Story = { |
| 56 | + argTypes: { |
| 57 | + variant: { control: { disable: true } }, |
| 58 | + text: { control: { disable: true } }, |
| 59 | + }, |
| 60 | + parameters: { |
| 61 | + docs: { |
| 62 | + source: { |
| 63 | + code: ` |
| 64 | + <Text variant="default" text="Default" /> |
| 65 | + <Text variant="strong" text="Strong" /> |
| 66 | + <Text variant="subtle" text="Subtle" /> |
| 67 | + <Text variant="code" text="code_example" /> |
| 68 | + <Text variant="danger" text="Danger" /> |
| 69 | + <Text variant="success" text="Success" /> |
| 70 | + <Text variant="warning" text="Warning" /> |
| 71 | + `, |
| 72 | + }, |
| 73 | + }, |
| 74 | + }, |
| 75 | + render: (args) => ({ |
| 76 | + components: { Text }, |
| 77 | + setup() { |
| 78 | + const sharedProps = computed(() => { |
| 79 | + const { variant, text, ...rest } = args; |
| 80 | + return rest; |
| 81 | + }); |
| 82 | + return { sharedProps }; |
| 83 | + }, |
| 84 | + template: ` |
| 85 | + <div class="flex flex-wrap gap-3 items-center"> |
| 86 | + <Text variant="default" text="Default" v-bind="sharedProps" /> |
| 87 | + <Text variant="strong" text="Strong" v-bind="sharedProps" /> |
| 88 | + <Text variant="subtle" text="Subtle" v-bind="sharedProps" /> |
| 89 | + <Text variant="code" text="code_example" v-bind="sharedProps" /> |
| 90 | + <Text variant="danger" text="Danger" v-bind="sharedProps" /> |
| 91 | + <Text variant="success" text="Success" v-bind="sharedProps" /> |
| 92 | + <Text variant="warning" text="Warning" v-bind="sharedProps" /> |
| 93 | + </div> |
| 94 | + `, |
| 95 | + }), |
| 96 | +}; |
| 97 | + |
| 98 | +export const Sizes: Story = { |
| 99 | + argTypes: { |
| 100 | + size: { control: { disable: true } }, |
| 101 | + text: { control: { disable: true } }, |
| 102 | + }, |
| 103 | + parameters: { |
| 104 | + docs: { |
| 105 | + source: { |
| 106 | + code: ` |
| 107 | + <Text size="lg" text="Large" /> |
| 108 | + <Text size="base" text="Base" /> |
| 109 | + <Text size="sm" text="Small" /> |
| 110 | + `, |
| 111 | + }, |
| 112 | + }, |
| 113 | + }, |
| 114 | + render: (args) => ({ |
| 115 | + components: { Text }, |
| 116 | + setup() { |
| 117 | + const sharedProps = computed(() => { |
| 118 | + const { size, text, ...rest } = args; |
| 119 | + return rest; |
| 120 | + }); |
| 121 | + return { sharedProps }; |
| 122 | + }, |
| 123 | + template: ` |
| 124 | + <div class="flex flex-wrap gap-3 items-center"> |
| 125 | + <Text size="lg" text="Large" v-bind="sharedProps" /> |
| 126 | + <Text size="base" text="Base" v-bind="sharedProps" /> |
| 127 | + <Text size="sm" text="Small" v-bind="sharedProps" /> |
| 128 | + </div> |
| 129 | + `, |
| 130 | + }), |
| 131 | +}; |
| 132 | + |
| 133 | +const inlineCode = ` |
| 134 | +<Text>Default with <Text variant="strong">strong</Text> and <Text variant="subtle">subtle</Text> inline</Text> |
| 135 | +`; |
| 136 | + |
| 137 | +export const _InlineDocs: Story = { |
| 138 | + tags: ['!dev'], |
| 139 | + parameters: { |
| 140 | + docs: { |
| 141 | + source: { code: inlineCode }, |
| 142 | + }, |
| 143 | + }, |
| 144 | + render: () => ({ |
| 145 | + components: { Text }, |
| 146 | + template: inlineCode, |
| 147 | + }), |
| 148 | +}; |
| 149 | + |
| 150 | +const paragraphCode = ` |
| 151 | +<div class="space-y-2"> |
| 152 | + <Text as="p">This is a paragraph of default text that could appear inside a widget or table description.</Text> |
| 153 | + <Text as="p" variant="subtle">This is a subtle paragraph, useful for secondary information or metadata.</Text> |
| 154 | +</div> |
| 155 | +`; |
| 156 | + |
| 157 | +export const _AsParagraph: Story = { |
| 158 | + tags: ['!dev'], |
| 159 | + parameters: { |
| 160 | + docs: { |
| 161 | + source: { code: paragraphCode }, |
| 162 | + }, |
| 163 | + }, |
| 164 | + render: () => ({ |
| 165 | + components: { Text }, |
| 166 | + template: paragraphCode, |
| 167 | + }), |
| 168 | +}; |
0 commit comments