From 2c192ac145e3550153821627a389f03e26f247b5 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 5 Feb 2025 13:36:46 +0100 Subject: [PATCH] feat(Alert/Toast)!: add `orientation` prop --- .../toast/ToastOrientationExample.vue | 27 ++ docs/content/3.components/alert.md | 26 +- docs/content/3.components/toast.md | 17 +- playground/app/pages/components/alert.vue | 14 +- playground/app/pages/components/toast.vue | 26 +- src/runtime/components/Alert.vue | 23 +- src/runtime/components/Toast.vue | 23 +- src/theme/alert.ts | 21 +- src/theme/toast.ts | 21 +- test/components/Alert.spec.ts | 3 + test/components/Toast.spec.ts | 3 +- .../__snapshots__/Alert-vue.spec.ts.snap | 149 +++++++---- .../__snapshots__/Alert.spec.ts.snap | 149 +++++++---- .../__snapshots__/Toast-vue.spec.ts.snap | 252 +++++++++++------- .../__snapshots__/Toast.spec.ts.snap | 252 +++++++++++------- 15 files changed, 659 insertions(+), 347 deletions(-) create mode 100644 docs/app/components/content/examples/toast/ToastOrientationExample.vue diff --git a/docs/app/components/content/examples/toast/ToastOrientationExample.vue b/docs/app/components/content/examples/toast/ToastOrientationExample.vue new file mode 100644 index 00000000..3ec85118 --- /dev/null +++ b/docs/app/components/content/examples/toast/ToastOrientationExample.vue @@ -0,0 +1,27 @@ + + + diff --git a/docs/content/3.components/alert.md b/docs/content/3.components/alert.md index c489bf74..45cc09d8 100644 --- a/docs/content/3.components/alert.md +++ b/docs/content/3.components/alert.md @@ -215,8 +215,30 @@ props: --- :: -::note -Actions renders differently when the description is not set. You can try to remove it. +### Orientation + +Use the `orientation` prop to change the orientation of the Alert. + +::component-code +--- +prettier: true +ignore: + - title + - actions + - color + - variant +props: + title: 'Heads up!' + description: 'You can change the primary color in your app config.' + color: neutral + variant: outline + orientation: horizontal + actions: + - label: Action 1 + - label: Action 2 + color: neutral + variant: subtle +--- :: ## Examples diff --git a/docs/content/3.components/toast.md b/docs/content/3.components/toast.md index c0902842..db28a0a4 100644 --- a/docs/content/3.components/toast.md +++ b/docs/content/3.components/toast.md @@ -154,8 +154,21 @@ name: 'toast-actions-example' --- :: -::note -Actions renders differently when the description is not set. You can try to remove it. +### Orientation + +Use the `orientation` prop to change the orientation of the Toast. + +::component-example +--- +options: + - name: 'orientation' + label: 'orientation' + default: 'horizontal' + items: + - horizontal + - vertical +name: 'toast-orientation-example' +--- :: ## Examples diff --git a/playground/app/pages/components/alert.vue b/playground/app/pages/components/alert.vue index 34d86bb1..f98a5ba9 100644 --- a/playground/app/pages/components/alert.vue +++ b/playground/app/pages/components/alert.vue @@ -6,7 +6,7 @@ const variants = Object.keys(theme.variants.variant) as Array [{ label: 'Action', color: color as any, - click() { + onClick() { console.log('Action clicked') } }] @@ -15,21 +15,21 @@ const multipleActions = (color: string) => [ { label: 'Action', color: color as any, - click() { + onClick() { console.log('Action clicked') } }, { label: 'Another action', color: color as any, - click() { + onClick() { console.log('Another action clicked') } }, { label: 'One more action', color: color as any, - click() { + onClick() { console.log('One more action clicked') } }, @@ -37,7 +37,7 @@ const multipleActions = (color: string) => [ label: 'And one more', color: color as any, icon: 'i-lucide-info', - click() { + onClick() { console.log('And one more clicked') } }, @@ -45,7 +45,7 @@ const multipleActions = (color: string) => [ label: 'Last one', color: color as any, icon: 'i-lucide-info', - click() { + onClick() { console.log('Last one clicked') } } @@ -65,7 +65,7 @@ const data = { - + diff --git a/playground/app/pages/components/toast.vue b/playground/app/pages/components/toast.vue index 9e356f21..afe01c60 100644 --- a/playground/app/pages/components/toast.vue +++ b/playground/app/pages/components/toast.vue @@ -20,7 +20,21 @@ const templates = (id: number) => [{ }, { title: 'Toast', description: `This is the toast ${id}`, - icon: 'i-lucide-rocket' + icon: 'i-lucide-rocket', + actions: [{ + label: 'Action 1', + color: 'neutral' as const, + onClick() { + console.log(`Toast ${id} action 1 clicked`) + } + }, { + label: 'Action 2', + color: 'neutral' as const, + variant: 'outline' as const, + onClick() { + console.log(`Toast ${id} action 2 clicked`) + } + }] }, { title: `Toast ${id}`, icon: 'i-lucide-rocket' @@ -41,34 +55,36 @@ const templates = (id: number) => [{ }, actions: [{ label: 'Action', - click() { + onClick() { console.log(`Toast ${id} action clicked`) } }] }, { title: `Toast ${id}`, icon: 'i-lucide-rocket', + orientation: 'horizontal' as const, actions: [{ label: 'Action 1', color: 'neutral' as const, - click() { + onClick() { console.log(`Toast ${id} action 1 clicked`) } }, { label: 'Action 2', color: 'neutral' as const, variant: 'outline' as const, - click() { + onClick() { console.log(`Toast ${id} action 2 clicked`) } }] }, { description: `This is the toast ${id}`, icon: 'i-lucide-rocket', + orientation: 'horizontal' as const, actions: [{ label: 'Action', variant: 'outline' as const, - click() { + onClick() { console.log(`Toast ${id} action clicked`) } }] diff --git a/src/runtime/components/Alert.vue b/src/runtime/components/Alert.vue index 4744bea7..9c5107b0 100644 --- a/src/runtime/components/Alert.vue +++ b/src/runtime/components/Alert.vue @@ -25,10 +25,11 @@ export interface AlertProps { avatar?: AvatarProps color?: AlertVariants['color'] variant?: AlertVariants['variant'] + orientation?: AlertVariants['orientation'] /** * Display a list of actions: - * - under the title and description if multiline - * - next to the close button if not multiline + * - under the title and description when orientation is `vertical` + * - next to the close button when orientation is `horizontal` * `{ size: 'xs' }`{lang="ts-type"} */ actions?: ButtonProps[] @@ -72,23 +73,25 @@ import UIcon from './Icon.vue' import UAvatar from './Avatar.vue' import UButton from './Button.vue' -const props = defineProps() +const props = withDefaults(defineProps(), { + orientation: 'vertical' +}) const emits = defineEmits() const slots = defineSlots() const { t } = useLocale() const appConfig = useAppConfig() -const multiline = computed(() => !!props.title && !!props.description) - const ui = computed(() => alert({ color: props.color, - variant: props.variant + variant: props.variant, + orientation: props.orientation, + title: !!props.title || !!slots.title }))