Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Convert VButton story to mdx and add all variants (#1346)

Olga Bulat638760e5c529
diff --git a/src/components/VButton.vue b/src/components/VButton.vue
index b553c2a10..5b8c66e04 100644
--- a/src/components/VButton.vue
+++ b/src/components/VButton.vue
@@ -39,11 +39,11 @@ import type { ProperlyExtractPropTypes } from '~/types/prop-extraction'
import VLink from '~/components/VLink.vue'
-const buttonForms = ['VLink', 'button'] as const
+export const buttonForms = ['VLink', 'button'] as const
type ButtonForm = typeof buttonForms[number]
-const buttonVariants = [
+export const buttonVariants = [
'primary',
'secondary',
'tertiary',
@@ -57,7 +57,7 @@ const buttonVariants = [
type ButtonVariant = typeof buttonVariants[number]
-const buttonSizes = ['large', 'medium', 'small', 'disabled'] as const
+export const buttonSizes = ['large', 'medium', 'small', 'disabled'] as const
type ButtonSize = typeof buttonSizes[number]
@@ -114,7 +114,6 @@ const VButton = defineComponent({
variant: {
type: String as PropType<ButtonVariant>,
default: 'primary',
- validate: (v: ButtonVariant) => buttonVariants.includes(v),
},
/**
* Allows for programmatically setting the pressed state of a button,
@@ -135,7 +134,6 @@ const VButton = defineComponent({
size: {
type: String as PropType<ButtonSize>,
default: 'medium',
- validate: (val: ButtonSize) => buttonSizes.includes(val),
},
/**
* Whether the button is disabled. Used alone this will only
@@ -169,7 +167,6 @@ const VButton = defineComponent({
type: {
type: String as PropType<ButtonType>,
default: 'button',
- validate: (v: ButtonType) => buttonTypes.includes(v),
},
},
setup(props, { attrs }) {
@@ -294,7 +291,7 @@ a.button {
}
.action-menu {
- @apply bg-white text-dark-charcoal border border-tx hover:border-dark-charcoal-20;
+ @apply bg-tx text-dark-charcoal border border-tx hover:border-dark-charcoal-20;
}
.action-menu-secondary {
diff --git a/src/components/meta/VButton.stories.js b/src/components/meta/VButton.stories.js
deleted file mode 100644
index efec69621..000000000
--- a/src/components/meta/VButton.stories.js
+++ /dev/null
@@ -1,43 +0,0 @@
-import VButton from '~/components/VButton.vue'
-
-export default {
- title: 'Components/VButton',
- component: VButton,
- argTypes: {
- variant: {
- options: [
- 'primary',
- 'secondary',
- 'tertiary',
- 'action-menu',
- 'action-menu-muted',
- ],
- control: { type: 'radio' },
- },
- as: {
- options: ['button', 'a'],
- control: { type: 'radio' },
- },
- pressed: 'boolean',
- size: {
- options: ['large', 'medium', 'small'],
- control: { type: 'radio' },
- },
- disabled: 'boolean',
- focusableWhenDisabled: 'boolean',
- },
-}
-
-const VButtonStory = (args, { argTypes }) => ({
- template: `<VButton v-bind="$props" @click="onClick">Code is Poetry</VButton>`,
- components: { VButton },
- props: Object.keys(argTypes),
- methods: {
- onClick() {
- window.alert('hello!')
- },
- },
-})
-
-export const Default = VButtonStory.bind({})
-Default.args = {}
diff --git a/src/components/meta/VButton.stories.mdx b/src/components/meta/VButton.stories.mdx
new file mode 100644
index 000000000..2e0720213
--- /dev/null
+++ b/src/components/meta/VButton.stories.mdx
@@ -0,0 +1,111 @@
+import {
+ ArgsTable,
+ Canvas,
+ Description,
+ Meta,
+ Story,
+} from '@storybook/addon-docs'
+
+import VButton, {
+ buttonForms,
+ buttonSizes,
+ buttonVariants,
+} from '~/components/VButton.vue'
+import { capital } from 'case'
+
+<Meta title="Components/VButton" components={VButton} />
+
+export const Template = (args) => ({
+ template: `
+ <VButton v-bind="args" @click="onClick" href="/">
+ Code is Poetry
+ </VButton>
+ `,
+ components: { VButton },
+ methods: {
+ onClick() {
+ window.alert('hello!')
+ },
+ },
+ setup() {
+ return { args }
+ },
+})
+
+# VButton
+
+<Description of={VButton} />
+
+<ArgsTable of={VButton} />
+
+<Canvas>
+ <Story
+ name="VButton"
+ args={{}}
+ argTypes={{
+ as: {
+ options: buttonForms,
+ control: { type: 'radio' },
+ },
+ variant: {
+ options: buttonVariants,
+ control: { type: 'select' },
+ },
+ pressed: { control: 'boolean' },
+ size: {
+ options: buttonSizes,
+ control: { type: 'radio' },
+ },
+ disabled: { control: 'boolean' },
+ focusableWhenDisabled: { control: 'boolean' },
+ type: { control: 'text' },
+ }}
+ >
+ {Template.bind({})}
+ </Story>
+</Canvas>
+
+## Button variants
+
+export const variants = buttonVariants
+
+export const VariantsTemplate = (args) => ({
+ template: `
+<div class="flex gap-4 flex-wrap">
+<VButton v-for="variant in buttonVariants"
+ :variant="variant"
+ :key="variant"
+ :v-bind="args">
+ {{ capitalize(variant) }}
+ </VButton>
+ </div>`,
+ components: { VButton },
+ data: () => ({
+ buttonVariants,
+ }),
+ methods: {
+ capitalize(str) {
+ return capital(str)
+ },
+ },
+ setup() {
+ return { args }
+ },
+})
+
+<Canvas>
+ <Story
+ name="VButton Variants"
+ args={{}}
+ argTypes={{
+ pressed: { control: 'boolean' },
+ size: {
+ options: buttonSizes,
+ control: { type: 'radio' },
+ },
+ disabled: { control: 'boolean' },
+ }}
+ >
+ {VariantsTemplate.bind({})}
+ </Story>
+</Canvas>