From e4c3a74e0eef11a4d94327ec182e7fef63473d9e Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Tue, 20 Sep 2022 11:47:52 +0200 Subject: [PATCH] chore(Notification): add preset system --- .../components/overlays/Notification.vue | 51 +++++++++++-------- src/runtime/presets/default.ts | 25 ++++++++- 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/runtime/components/overlays/Notification.vue b/src/runtime/components/overlays/Notification.vue index e169af2c..bc4d3123 100644 --- a/src/runtime/components/overlays/Notification.vue +++ b/src/runtime/components/overlays/Notification.vue @@ -9,15 +9,15 @@ leave-to-class="opacity-0" >
-
+
- +

@@ -64,6 +64,7 @@ import type { PropType } from 'vue' import Icon from '../elements/Icon.vue' import { useTimer } from '../../composables/useTimer' import { classNames } from '../../utils' +import $ui from '#build/ui' const props = defineProps({ id: { @@ -73,8 +74,8 @@ const props = defineProps({ type: { type: String, default: null, - validator (value: string | null) { - return [null, 'info', 'success', 'error', 'warning'].includes(value) + validator (value: string) { + return Object.keys($ui.notification.type).includes(value) } }, title: { @@ -85,13 +86,33 @@ const props = defineProps({ type: String, default: null }, + backgroundClass: { + type: String, + default: () => $ui.notification.background + }, + shadowClass: { + type: String, + default: () => $ui.notification.shadow + }, + ringClass: { + type: String, + default: () => $ui.notification.ring + }, + roundedClass: { + type: String, + default: () => $ui.notification.rounded + }, + customClass: { + type: String, + default: null + }, icon: { type: String, default: null }, - iconClass: { + iconBaseClass: { type: String, - default: null + default: () => $ui.notification.icon.base }, timeout: { type: Number, @@ -116,23 +137,13 @@ let timer: any = null const remaining = ref(props.timeout) const iconName = computed(() => { - return props.icon || ({ - warning: 'heroicons-outline:exclamation-circle', - info: 'heroicons-outline:information-circle', - success: 'heroicons-outline:check-circle', - error: 'heroicons-outline:x-circle' - })[props.type] + return props.icon || $ui.notification.type[props.type] }) const iconClass = computed(() => { return classNames( - ({ - warning: 'text-orange-400', - info: 'text-blue-400', - success: 'text-green-400', - error: 'text-red-400' - })[props.type] || 'u-text-gray-400', - props.iconClass + props.iconBaseClass, + $ui.notification.icon.color[props.type] || 'u-text-gray-400' ) }) diff --git a/src/runtime/presets/default.ts b/src/runtime/presets/default.ts index cd166112..099683ff 100644 --- a/src/runtime/presets/default.ts +++ b/src/runtime/presets/default.ts @@ -396,6 +396,28 @@ export default (variantColors: string[]) => { header: 'flex items-center justify-between flex-shrink-0 px-4 sm:px-6 h-16 border-b u-border-gray-200' } + const notification = { + background: 'u-bg-white', + shadow: 'shadow-lg', + rounded: 'rounded-lg', + ring: 'ring-1 u-ring-gray-200', + type: { + info: 'heroicons-outline:information-circle', + success: 'heroicons-outline:check-circle', + warning: 'heroicons-outline:exclamation-circle', + error: 'heroicons-outline:x-circle' + }, + icon: { + base: 'w-6 h-6', + color: { + warning: 'text-orange-400', + info: 'text-blue-400', + success: 'text-green-400', + error: 'text-red-400' + } + } + } + return { card, modal, @@ -417,6 +439,7 @@ export default (variantColors: string[]) => { pills, avatar, avatarGroup, - slideover + slideover, + notification } }