-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
11 changed files
with
492 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
import { | ||
getArgTypes, | ||
getSlotNames, | ||
getSlotsFragment, | ||
getDocsDescription, | ||
} from "../../utils/storybook.ts"; | ||
|
||
import { ref } from "vue"; | ||
|
||
import UButton from "../../ui.button/UButton.vue"; | ||
import UIcon from "../../ui.image-icon/UIcon.vue"; | ||
import URow from "../../ui.container-row/URow.vue"; | ||
import UCol from "../../ui.container-col/UCol.vue"; | ||
|
||
import { useDarkMode } from "../../composables/useDarkMode.ts"; | ||
|
||
import type { Meta, StoryFn } from "@storybook/vue3"; | ||
import type { Props } from "../types.ts"; | ||
|
||
interface UButtonArgs extends Props { | ||
slotTemplate?: string; | ||
enum: "variant" | "size"; | ||
} | ||
|
||
interface StoryArgType { | ||
options?: string[]; | ||
} | ||
|
||
export default { | ||
id: "1010", | ||
title: "Buttons & Links / Button", | ||
component: UButton, | ||
args: { | ||
label: "Button", | ||
}, | ||
argTypes: { | ||
...getArgTypes(UButton.__name), | ||
}, | ||
parameters: { | ||
docs: { | ||
...getDocsDescription(UButton.__name), | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
const DefaultTemplate: StoryFn<UButtonArgs> = (args: UButtonArgs) => ({ | ||
components: { UButton, UIcon }, | ||
setup() { | ||
const slots = getSlotNames(UButton.__name); | ||
|
||
return { args, slots }; | ||
}, | ||
template: ` | ||
<UButton v-bind="args"> | ||
${args.slotTemplate || getSlotsFragment("")} | ||
</UButton> | ||
`, | ||
}); | ||
|
||
const EnumVariantTemplate: StoryFn<UButtonArgs> = (args: UButtonArgs, { argTypes }) => ({ | ||
components: { UButton, URow, UCol }, | ||
setup() { | ||
return { args, options: argTypes?.[args.enum]?.options }; | ||
}, | ||
template: ` | ||
<UCol> | ||
<URow no-mobile> | ||
<UButton | ||
v-for="(option, index) in options" | ||
:key="index" | ||
v-bind="args" | ||
:[args.enum]="option" | ||
:label="option" | ||
/> | ||
</URow> | ||
</UCol> | ||
`, | ||
}); | ||
|
||
const ColorTemplate: StoryFn<UButtonArgs> = (args: UButtonArgs, { argTypes }) => ({ | ||
components: { UButton, URow, UCol }, | ||
setup() { | ||
const variantOptions = (argTypes.variant as StoryArgType)?.options ?? []; | ||
const variants = [...Array.from(variantOptions), "thirdary"]; | ||
|
||
return { | ||
args, | ||
variants, | ||
colors: argTypes?.color?.options, | ||
shouldBeFilled: (variant: string, index: number) => { | ||
return variant === "thirdary" && index === variants.length - 2; | ||
}, | ||
}; | ||
}, | ||
template: ` | ||
<UCol> | ||
<URow v-for="(variant, variantIndex) in variants" :key="variantIndex" no-mobile> | ||
<UButton | ||
v-for="(color, colorIndex) in colors" | ||
v-bind="args" | ||
:variant="variant" | ||
:color="color" | ||
:label="color" | ||
:key="colorIndex" | ||
:filled="shouldBeFilled(variant, variantIndex)" | ||
/> | ||
</URow> | ||
</UCol> | ||
`, | ||
}); | ||
|
||
export const Default = DefaultTemplate.bind({}); | ||
Default.args = {}; | ||
|
||
export const Variants = EnumVariantTemplate.bind({}); | ||
Variants.args = { enum: "variant" }; | ||
|
||
export const Sizes = EnumVariantTemplate.bind({}); | ||
Sizes.args = { enum: "size" }; | ||
|
||
export const Round = EnumVariantTemplate.bind({}); | ||
Round.args = { enum: "variant", round: true }; | ||
|
||
export const Loading: StoryFn<UButtonArgs> = (args) => ({ | ||
components: { UButton, URow }, | ||
setup() { | ||
const loading = ref(false); | ||
|
||
function toggleLoading() { | ||
loading.value = !loading.value; | ||
} | ||
|
||
return { args, toggleLoading, loading }; | ||
}, | ||
template: ` | ||
<URow no-mobile> | ||
<UButton | ||
label="Loader demo" | ||
:loading="loading" | ||
/> | ||
<UButton | ||
label="Toggle loading" | ||
variant="secondary" | ||
color="green" | ||
leftIcon="play_arrow" | ||
@click="toggleLoading" | ||
/> | ||
</URow> | ||
`, | ||
}); | ||
|
||
export const Block = DefaultTemplate.bind({}); | ||
Block.args = { block: true }; | ||
|
||
export const Disabled = EnumVariantTemplate.bind({}); | ||
Disabled.args = { enum: "variant", disabled: true }; | ||
|
||
export const Colors = ColorTemplate.bind({}); | ||
Colors.args = {}; | ||
|
||
export const Square = DefaultTemplate.bind({}); | ||
Square.args = { square: true, icon: "filter_list" }; | ||
|
||
export const IconProps: StoryFn<UButtonArgs> = (args) => ({ | ||
components: { UButton, URow }, | ||
setup() { | ||
return { args }; | ||
}, | ||
template: ` | ||
<URow no-mobile> | ||
<UButton | ||
v-bind="args" | ||
left-icon="download" | ||
label="Download" | ||
/> | ||
<UButton | ||
v-bind="args" | ||
right-icon="menu" | ||
label="Menu" | ||
/> | ||
</URow> | ||
`, | ||
}); | ||
|
||
export const Slots: StoryFn<UButtonArgs> = (args) => ({ | ||
components: { UButton, UIcon, URow }, | ||
setup() { | ||
const { isDarkMode } = useDarkMode(); | ||
|
||
return { args, isDarkMode }; | ||
}, | ||
template: ` | ||
<URow no-mobile> | ||
<UButton v-bind="args" label="Add to favorite"> | ||
<template #left> | ||
<UIcon | ||
name="heart_plus" | ||
size="sm" | ||
color="inherit" | ||
:variant="isDarkMode ? 'dark' : 'default'" | ||
/> | ||
</template> | ||
</UButton> | ||
<UButton v-bind="args" square> | ||
<template #default> | ||
<UIcon | ||
name="settings" | ||
size="sm" | ||
color="inherit" | ||
:variant="isDarkMode ? 'dark' : 'default'" | ||
/> | ||
</template> | ||
</UButton> | ||
<UButton v-bind="args" label="Delete"> | ||
<template #right> | ||
<UIcon | ||
name="delete" | ||
size="sm" | ||
color="inherit" | ||
:variant="isDarkMode ? 'dark' : 'default'" | ||
/> | ||
</template> | ||
</UButton> | ||
</URow> | ||
`, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copy existing component | ||
|
||
If Vueless customization options are not enough for your needs, you can fully copy and modify any Vueless component. | ||
|
||
{% hint style="warning" %} | ||
However, use this approach only when absolutely necessary, as you will need to manually update the component after each new Vueless release. | ||
|
||
**Note:** We do not provide free support for custom components. | ||
{% endhint %} | ||
|
||
{% tabs %} | ||
{% tab title="npm" %} | ||
```bash | ||
npx vueless copy <src> <target> | ||
|
||
# example: | ||
# npx vueless copy UButton CustomButton | ||
``` | ||
{% endtab %} | ||
|
||
{% tab title="yarn" %} | ||
```bash | ||
yarn vueless copy <src> <target> | ||
|
||
# example: | ||
# yarn vueless copy UButton CustomButton | ||
``` | ||
{% endtab %} | ||
|
||
{% tab title="pnpm" %} | ||
```bash | ||
pnpm exec vueless copy <src> <target> | ||
|
||
# example: | ||
# pnpm exec vueless copy UButton CustomButton | ||
``` | ||
{% endtab %} | ||
|
||
{% tab title="bun" %} | ||
```bash | ||
bunx vueless copy <src> <target> | ||
|
||
# example: | ||
# bunx vueless copy UButton CustomButton | ||
``` | ||
{% endtab %} | ||
{% endtabs %} | ||
|
||
The component will be created in the project's `/components` folder: | ||
|
||
* `/src/components/<componentName>` – for Vue | ||
* `/components/<componentName>` – for Nuxt |
Oops, something went wrong.