From 6c60a6c244d7e09e85c820e5dda4763b238842cf Mon Sep 17 00:00:00 2001 From: System Administrator Date: Tue, 12 Sep 2023 16:46:10 +0300 Subject: [PATCH 1/2] chore: release v1.0.1-beta.1 --- packages/nuxt-ui-vue/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxt-ui-vue/package.json b/packages/nuxt-ui-vue/package.json index ae1353f..3ff4106 100755 --- a/packages/nuxt-ui-vue/package.json +++ b/packages/nuxt-ui-vue/package.json @@ -1,6 +1,6 @@ { "name": "nuxt-ui-vue", - "version": "1.0.1-beta.0", + "version": "1.0.1-beta.1", "private": false, "exports": { ".": { From 87d9238579be10a12facf2dc095a6e8ab522b82c Mon Sep 17 00:00:00 2001 From: System Administrator Date: Wed, 13 Sep 2023 14:46:50 +0300 Subject: [PATCH 2/2] feat (Notifications): add Notifications component --- .../src/Types/componentsTypes/components.ts | 7 ++ .../nuxt-ui-vue/src/Types/enums/Components.ts | 1 + packages/nuxt-ui-vue/src/Types/variant.ts | 3 +- packages/nuxt-ui-vue/src/components/index.ts | 1 + .../overlays/Notification/UNotifications.vue | 77 +++++++++++++++++++ .../src/composables/useCopyToClipboard.ts | 4 +- .../nuxt-ui-vue/src/composables/useToast.ts | 28 +++++-- packages/nuxt-ui-vue/src/index.ts | 2 +- .../nuxt-ui-vue/src/theme/nuxtLabsTheme.ts | 27 ++++++- 9 files changed, 139 insertions(+), 11 deletions(-) create mode 100644 packages/nuxt-ui-vue/src/components/overlays/Notification/UNotifications.vue diff --git a/packages/nuxt-ui-vue/src/Types/componentsTypes/components.ts b/packages/nuxt-ui-vue/src/Types/componentsTypes/components.ts index faf079d..58390e1 100755 --- a/packages/nuxt-ui-vue/src/Types/componentsTypes/components.ts +++ b/packages/nuxt-ui-vue/src/Types/componentsTypes/components.ts @@ -349,6 +349,12 @@ export interface UNotification extends UComponentRoot { default?: objectProp } +export interface UNotifications extends UComponentRoot { + position?: string + width?: string + container?: string +} + export interface UPagination extends UComponentRoot { paginationBase?: string rounded?: string @@ -637,6 +643,7 @@ export type UTabsVariants = WithVariantProps export type UTextareaVariants = WithVariantProps export type UModalVariants = WithVariantProps export type UNotificationVariants = WithVariantProps +export type UNotificationsVariants = WithVariantProps export type UKbdVariants = WithVariantProps export type UPaginationVariants = WithVariantProps export type UPopoverVariants = WithVariantProps diff --git a/packages/nuxt-ui-vue/src/Types/enums/Components.ts b/packages/nuxt-ui-vue/src/Types/enums/Components.ts index ab99bd7..d690abc 100755 --- a/packages/nuxt-ui-vue/src/Types/enums/Components.ts +++ b/packages/nuxt-ui-vue/src/Types/enums/Components.ts @@ -20,6 +20,7 @@ export enum Components { UKbd = 'UKbd', UModal = 'UModal', UNotification = 'UNotification', + UNotifications = 'UNotifications', UPagination = 'UPagination', UPopover = 'UPopover', URadio = 'URadio', diff --git a/packages/nuxt-ui-vue/src/Types/variant.ts b/packages/nuxt-ui-vue/src/Types/variant.ts index 0d71859..2e262a5 100755 --- a/packages/nuxt-ui-vue/src/Types/variant.ts +++ b/packages/nuxt-ui-vue/src/Types/variant.ts @@ -1,5 +1,5 @@ import type { Components } from './enums/Components' -import type { UAccordionVariants, UAlertVariants, UAvatarVariants, UBadgeVariants, UButtonGroupVariants, UButtonVariants, UCardVariants, UCheckboxVariants, UCommandPaletteVariants, UContainerVariants, UContextMenuVariants, UDropdownVariants, UFormGroupVariants, UIconVariants, UInputVariants, UKbdVariants, UModalVariants, UNotificationVariants, UPaginationVariants, URadioVariants, URangeVariants, USelectMenuVariants, USelectVariants, USkeletonVariants, USlideoverVariants, UTabsVariants, UTextareaVariants, UToggleVariants, UTooltipVariants, UVerticalNavigationVariants } from './componentsTypes/components' +import type { UAccordionVariants, UAlertVariants, UAvatarVariants, UBadgeVariants, UButtonGroupVariants, UButtonVariants, UCardVariants, UCheckboxVariants, UCommandPaletteVariants, UContainerVariants, UContextMenuVariants, UDropdownVariants, UFormGroupVariants, UIconVariants, UInputVariants, UKbdVariants, UModalVariants, UNotificationVariants, UNotificationsVariants, UPaginationVariants, URadioVariants, URangeVariants, USelectMenuVariants, USelectVariants, USkeletonVariants, USlideoverVariants, UTabsVariants, UTextareaVariants, UToggleVariants, UTooltipVariants, UVerticalNavigationVariants } from './componentsTypes/components' export declare interface CSSClassKeyValuePair { [key: string]: any @@ -48,6 +48,7 @@ export interface NuxtLabsUIConfiguration { [Components.UKbd]?: UKbdVariants [Components.UModal]?: UModalVariants [Components.UNotification]?: UNotificationVariants + [Components.UNotifications]?: UNotificationsVariants [Components.UTextarea]?: UTextareaVariants [Components.UPagination]?: UPaginationVariants [Components.URadio]?: URadioVariants diff --git a/packages/nuxt-ui-vue/src/components/index.ts b/packages/nuxt-ui-vue/src/components/index.ts index f495eb9..73964d3 100755 --- a/packages/nuxt-ui-vue/src/components/index.ts +++ b/packages/nuxt-ui-vue/src/components/index.ts @@ -17,6 +17,7 @@ export { default as UIcon } from './elements/Icon/UIcon.vue' export { default as UKbd } from './elements/Kbd/UKbd.vue' export { default as UModal } from './overlays/Modal/UModal.vue' export { default as UNotification } from './overlays/Notification/UNotification.vue' +export { default as UNotifications } from './overlays/Notification/UNotifications.vue' export { default as UInput } from './forms/Input/UInput.vue' export { default as ULink } from './elements/Link/ULink.vue' export { default as UPagination } from './navigation/Pagination/UPagination.vue' diff --git a/packages/nuxt-ui-vue/src/components/overlays/Notification/UNotifications.vue b/packages/nuxt-ui-vue/src/components/overlays/Notification/UNotifications.vue new file mode 100644 index 0000000..eed5328 --- /dev/null +++ b/packages/nuxt-ui-vue/src/components/overlays/Notification/UNotifications.vue @@ -0,0 +1,77 @@ + + + + + + diff --git a/packages/nuxt-ui-vue/src/composables/useCopyToClipboard.ts b/packages/nuxt-ui-vue/src/composables/useCopyToClipboard.ts index 39e2624..8f65574 100755 --- a/packages/nuxt-ui-vue/src/composables/useCopyToClipboard.ts +++ b/packages/nuxt-ui-vue/src/composables/useCopyToClipboard.ts @@ -1,10 +1,10 @@ import { useClipboard } from '@vueuse/core' -import useToast from './useToast' +import { injectToast } from './useToast' import type { Notification } from '@/Types/components/notification' export function useCopyToClipboard(options: Partial = {}) { const { copy: copyToClipboard, isSupported } = useClipboard() - const toast = useToast() + const toast = injectToast() function copy(text: string, success: { title?: string; description?: string } = {}, failure: { title?: string; description?: string } = {}) { if (!isSupported) diff --git a/packages/nuxt-ui-vue/src/composables/useToast.ts b/packages/nuxt-ui-vue/src/composables/useToast.ts index d546b6e..7da525d 100755 --- a/packages/nuxt-ui-vue/src/composables/useToast.ts +++ b/packages/nuxt-ui-vue/src/composables/useToast.ts @@ -1,8 +1,17 @@ -import { ref } from 'vue' +/* eslint-disable symbol-description */ +import type { InjectionKey } from 'vue' +import { inject, provide, ref } from 'vue' import type { Notification } from '@/Types/components/notification' -function useToast() { - const notifications = ref([]) +interface ToastProvider { + add: (notification: Partial) => void + remove: (id: string) => void +} + +const toastSymbol: InjectionKey = Symbol() + +export function injectToast() { + const notifications = ref([]) function add(notification: Partial) { const body = { @@ -12,8 +21,6 @@ function useToast() { const index = notifications.value.findIndex((n: Notification) => n.id === body.id) if (index === -1) - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error notifications.value.push(body as Notification) return body @@ -23,10 +30,19 @@ function useToast() { notifications.value = notifications.value.filter((n: Notification) => n.id !== id) } + provide(toastSymbol, { + notifications, + add, + remove, + }) + return { + notifications, add, remove, } } -export default useToast +export function useToast() { + return inject(toastSymbol) +} diff --git a/packages/nuxt-ui-vue/src/index.ts b/packages/nuxt-ui-vue/src/index.ts index ce90396..0baf7bf 100755 --- a/packages/nuxt-ui-vue/src/index.ts +++ b/packages/nuxt-ui-vue/src/index.ts @@ -8,7 +8,7 @@ export { useCopyToClipboard } from '@/composables/useCopyToClipboard' export { useShortcuts } from '@/composables/useShortcuts' -export { default as useToast } from '@/composables/useToast' +export { useToast, injectToast } from '@/composables/useToast' export { NuxtUIVueComponentResolver } from '@/componentResolver' diff --git a/packages/nuxt-ui-vue/src/theme/nuxtLabsTheme.ts b/packages/nuxt-ui-vue/src/theme/nuxtLabsTheme.ts index 026af50..e1a929f 100755 --- a/packages/nuxt-ui-vue/src/theme/nuxtLabsTheme.ts +++ b/packages/nuxt-ui-vue/src/theme/nuxtLabsTheme.ts @@ -842,7 +842,7 @@ export default { closeButton: { icon: 'heroicons:x-mark-20-solid', color: 'gray', - variant: 'link', + intent: 'link', padded: false, }, actionButton: { @@ -863,6 +863,31 @@ export default { }, }, + UNotifications: { + base: { + root: 'fixed flex flex-col justify-end z-[55]', + position: { + 'top-right': 'top-0 right-0', + 'bottom-right': 'bottom-0 right-0', + 'top-left': 'top-0 left-0', + 'bottom-left': 'bottom-0 left-0', + }, + width: 'w-full sm:w-96', + container: 'px-4 sm:px-6 py-6 space-y-3 overflow-y-auto', + }, + + variants: { + default: { + position: { + 'top-right': 'top-0 right-0', + 'bottom-right': 'bottom-0 right-0', + 'top-left': 'top-0 left-0', + 'bottom-left': 'bottom-0 left-0', + }, + }, + }, + }, + UPagination: { base: { root: 'flex items-center -space-x-px',