Add storybook story for iconSVG including export the icon names needed

This commit is contained in:
Wolfgang Huß 2024-03-22 14:03:18 +01:00
parent 52b813d4ab
commit ae7f800cbd
2 changed files with 39 additions and 0 deletions

View File

@ -7,11 +7,14 @@ type Module = {
default: object default: object
} }
const icons: Record<string, Module> = {} const icons: Record<string, Module> = {}
const iconNames: string[] = []
Object.entries(iconsModule).forEach(([key, module]) => { Object.entries(iconsModule).forEach(([key, module]) => {
const iconName: string = key.split('/').slice(-1)[0].replace('.vue', '') const iconName: string = key.split('/').slice(-1)[0].replace('.vue', '')
// eslint-disable-next-line security/detect-object-injection // eslint-disable-next-line security/detect-object-injection
icons[iconName] = module as Module icons[iconName] = module as Module
iconNames.push('$' + iconName) // because it's used this way
}) })
export default icons export default icons
export { iconNames }

View File

@ -0,0 +1,36 @@
import { iconNames } from '#assets/icons'
import { SBComp } from '#types/SBComp'
import IconSVG from './IconSVG.vue'
import type { Meta, StoryObj } from '@storybook/vue3'
// More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction
const meta = {
title: 'Icons/IconSVG',
component: IconSVG as SBComp,
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
tags: ['autodocs'],
argTypes: {
icon: { control: 'select', options: iconNames },
size: { control: 'select', options: ['x-small', 'small', 'default', 'large', 'x-large'] },
color: {
control: {
type: 'color',
presetColors: ['#000000', '#ff0000', '#00ff00', '#0000ff'],
},
},
},
args: { size: 'default', icon: '$heart', color: '' }, // default value
} satisfies Meta<typeof IconSVG>
export default meta
type Story = StoryObj<typeof meta>
/*
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
* See https://storybook.js.org/docs/vue/api/csf
* to learn how to use render functions.
*/
export const Primary: Story = {
args: {},
}