@nuxt/ui 0.4.1 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +63 -50
  3. package/dist/module.cjs +5 -0
  4. package/dist/module.d.mts +1234 -0
  5. package/dist/module.d.ts +1234 -0
  6. package/dist/module.json +8 -0
  7. package/dist/module.mjs +407 -0
  8. package/dist/runtime/app.config.d.ts +1203 -0
  9. package/dist/runtime/app.config.mjs +1057 -0
  10. package/dist/runtime/components/data/Table.vue +251 -0
  11. package/dist/runtime/components/data/Table.vue.d.ts +215 -0
  12. package/dist/runtime/components/elements/Accordion.vue +138 -0
  13. package/dist/runtime/components/elements/Accordion.vue.d.ts +80 -0
  14. package/dist/runtime/components/elements/Alert.vue +120 -0
  15. package/dist/runtime/components/elements/Alert.vue.d.ts +107 -0
  16. package/dist/runtime/components/elements/Avatar.vue +149 -0
  17. package/dist/runtime/components/elements/Avatar.vue.d.ts +115 -0
  18. package/dist/runtime/components/elements/AvatarGroup.d.ts +37 -0
  19. package/dist/runtime/components/elements/AvatarGroup.mjs +53 -0
  20. package/dist/runtime/components/elements/Badge.vue +69 -0
  21. package/dist/runtime/components/elements/Badge.vue.d.ts +63 -0
  22. package/dist/runtime/components/elements/Button.vue +182 -0
  23. package/dist/runtime/components/elements/Button.vue.d.ts +187 -0
  24. package/dist/runtime/components/elements/ButtonGroup.d.ts +39 -0
  25. package/dist/runtime/components/elements/ButtonGroup.mjs +70 -0
  26. package/dist/runtime/components/elements/Dropdown.vue +172 -0
  27. package/dist/runtime/components/elements/Dropdown.vue.d.ts +96 -0
  28. package/dist/runtime/components/elements/Icon.vue +15 -0
  29. package/dist/runtime/components/elements/Icon.vue.d.ts +12 -0
  30. package/dist/runtime/components/elements/Kbd.vue +55 -0
  31. package/dist/runtime/components/elements/Kbd.vue.d.ts +42 -0
  32. package/dist/runtime/components/elements/Link.vue +80 -0
  33. package/dist/runtime/components/elements/Link.vue.d.ts +9 -0
  34. package/dist/runtime/components/forms/Checkbox.vue +136 -0
  35. package/dist/runtime/components/forms/Checkbox.vue.d.ts +129 -0
  36. package/dist/runtime/components/forms/Form.vue +185 -0
  37. package/dist/runtime/components/forms/Form.vue.d.ts +50 -0
  38. package/dist/runtime/components/forms/FormGroup.vue +97 -0
  39. package/dist/runtime/components/forms/FormGroup.vue.d.ts +98 -0
  40. package/dist/runtime/components/forms/Input.vue +250 -0
  41. package/dist/runtime/components/forms/Input.vue.d.ts +214 -0
  42. package/dist/runtime/components/forms/Radio.vue +122 -0
  43. package/dist/runtime/components/forms/Radio.vue.d.ts +109 -0
  44. package/dist/runtime/components/forms/Range.vue +163 -0
  45. package/dist/runtime/components/forms/Range.vue.d.ts +119 -0
  46. package/dist/runtime/components/forms/Select.vue +307 -0
  47. package/dist/runtime/components/forms/Select.vue.d.ts +229 -0
  48. package/dist/runtime/components/forms/SelectMenu.vue +429 -0
  49. package/dist/runtime/components/forms/SelectMenu.vue.d.ts +330 -0
  50. package/dist/runtime/components/forms/Textarea.vue +184 -0
  51. package/dist/runtime/components/forms/Textarea.vue.d.ts +161 -0
  52. package/dist/runtime/components/forms/Toggle.vue +113 -0
  53. package/dist/runtime/components/forms/Toggle.vue.d.ts +83 -0
  54. package/dist/runtime/components/layout/Card.vue +58 -0
  55. package/dist/runtime/components/layout/Card.vue.d.ts +31 -0
  56. package/dist/runtime/components/layout/Container.vue +43 -0
  57. package/dist/runtime/components/layout/Container.vue.d.ts +31 -0
  58. package/dist/runtime/components/layout/Skeleton.vue +37 -0
  59. package/dist/runtime/components/layout/Skeleton.vue.d.ts +22 -0
  60. package/dist/runtime/components/navigation/CommandPalette.vue +304 -0
  61. package/dist/runtime/components/navigation/CommandPalette.vue.d.ts +224 -0
  62. package/dist/runtime/components/navigation/CommandPaletteGroup.vue +152 -0
  63. package/dist/runtime/components/navigation/CommandPaletteGroup.vue.d.ts +63 -0
  64. package/dist/runtime/components/navigation/Pagination.vue +197 -0
  65. package/dist/runtime/components/navigation/Pagination.vue.d.ts +125 -0
  66. package/dist/runtime/components/navigation/Tabs.vue +138 -0
  67. package/dist/runtime/components/navigation/Tabs.vue.d.ts +69 -0
  68. package/dist/runtime/components/navigation/VerticalNavigation.vue +79 -0
  69. package/dist/runtime/components/navigation/VerticalNavigation.vue.d.ts +37 -0
  70. package/dist/runtime/components/overlays/ContextMenu.vue +74 -0
  71. package/dist/runtime/components/overlays/ContextMenu.vue.d.ts +54 -0
  72. package/dist/runtime/components/overlays/Modal.vue +113 -0
  73. package/dist/runtime/components/overlays/Modal.vue.d.ts +82 -0
  74. package/dist/runtime/components/overlays/Notification.vue +197 -0
  75. package/dist/runtime/components/overlays/Notification.vue.d.ts +126 -0
  76. package/dist/runtime/components/overlays/Notifications.vue +61 -0
  77. package/dist/runtime/components/overlays/Notifications.vue.d.ts +41 -0
  78. package/dist/runtime/components/overlays/Popover.vue +139 -0
  79. package/dist/runtime/components/overlays/Popover.vue.d.ts +82 -0
  80. package/dist/runtime/components/overlays/Slideover.vue +103 -0
  81. package/dist/runtime/components/overlays/Slideover.vue.d.ts +84 -0
  82. package/dist/runtime/components/overlays/Tooltip.vue +118 -0
  83. package/dist/runtime/components/overlays/Tooltip.vue.d.ts +82 -0
  84. package/dist/runtime/composables/defineShortcuts.d.ts +13 -0
  85. package/dist/runtime/composables/defineShortcuts.mjs +108 -0
  86. package/dist/runtime/composables/useCopyToClipboard.d.ts +10 -0
  87. package/dist/runtime/composables/useCopyToClipboard.mjs +26 -0
  88. package/dist/runtime/composables/useFormGroup.d.ts +6 -0
  89. package/dist/runtime/composables/useFormGroup.mjs +30 -0
  90. package/dist/runtime/composables/usePopper.d.ts +232 -0
  91. package/dist/runtime/composables/usePopper.mjs +78 -0
  92. package/dist/runtime/composables/useShortcuts.d.ts +12 -0
  93. package/dist/runtime/composables/useShortcuts.mjs +24 -0
  94. package/dist/runtime/composables/useTimer.d.ts +8 -0
  95. package/dist/runtime/composables/useTimer.mjs +51 -0
  96. package/dist/runtime/composables/useToast.d.ts +18 -0
  97. package/dist/runtime/composables/useToast.mjs +22 -0
  98. package/dist/runtime/plugins/colors.d.ts +2 -0
  99. package/dist/runtime/plugins/colors.mjs +46 -0
  100. package/dist/runtime/types/accordion.d.ts +9 -0
  101. package/dist/runtime/types/avatar.d.ts +9 -0
  102. package/dist/runtime/types/button.d.ts +23 -0
  103. package/dist/runtime/types/clipboard.d.ts +3 -0
  104. package/dist/runtime/types/command-palette.d.ts +26 -0
  105. package/dist/runtime/types/dropdown.d.ts +13 -0
  106. package/dist/runtime/types/form.d.ts +21 -0
  107. package/dist/runtime/types/index.d.ts +12 -0
  108. package/dist/runtime/types/link.d.ts +8 -0
  109. package/dist/runtime/types/notification.d.ts +22 -0
  110. package/dist/runtime/types/popper.d.ts +14 -0
  111. package/dist/runtime/types/tabs.d.ts +6 -0
  112. package/dist/runtime/types/vertical-navigation.d.ts +11 -0
  113. package/dist/runtime/ui.css +13 -0
  114. package/dist/runtime/utils/StateEmitter.d.ts +17 -0
  115. package/dist/runtime/utils/StateEmitter.mjs +21 -0
  116. package/dist/runtime/utils/index.d.ts +11 -0
  117. package/dist/runtime/utils/index.mjs +33 -0
  118. package/dist/types.d.mts +15 -0
  119. package/dist/types.d.ts +15 -0
  120. package/package.json +56 -39
  121. package/LICENSE +0 -21
  122. package/dist/assets/styles.css +0 -14
  123. package/dist/components/NButton.vue +0 -22
  124. package/dist/components/NCard.vue +0 -5
  125. package/dist/components/NCheckbox.vue +0 -35
  126. package/dist/components/NDarkToggle.vue +0 -28
  127. package/dist/components/NDialog.vue +0 -59
  128. package/dist/components/NDropdown.vue +0 -31
  129. package/dist/components/NIcon.vue +0 -9
  130. package/dist/components/NLink.vue +0 -20
  131. package/dist/components/NRadio.vue +0 -40
  132. package/dist/components/NSwitch.vue +0 -37
  133. package/dist/components/NTextInput.vue +0 -34
  134. package/dist/components/NTip.vue +0 -16
  135. package/dist/components/NuxtContentLogo.vue +0 -7
  136. package/dist/components/NuxtExampleLayout.vue +0 -82
  137. package/dist/components/NuxtLogo.vue +0 -20
  138. package/dist/components/nuxt/NDarkToggle.vue +0 -28
  139. package/dist/nuxt.d.ts +0 -16
  140. package/dist/nuxt.mjs +0 -36
  141. package/dist/unocss.d.ts +0 -7
  142. package/dist/unocss.mjs +0 -127
  143. package/nuxt.cjs +0 -7
@@ -0,0 +1,37 @@
1
+ /// <reference types="lodash" />
2
+ import type { PropType } from 'vue';
3
+ import type { VerticalNavigationLink } from '../../types/vertical-navigation';
4
+ declare const _default: import("vue").DefineComponent<{
5
+ links: {
6
+ type: PropType<VerticalNavigationLink[]>;
7
+ default: () => never[];
8
+ };
9
+ ui: {
10
+ type: PropType<any>;
11
+ default: () => {};
12
+ };
13
+ }, {
14
+ attrs: import("lodash").Omit<{
15
+ [x: string]: unknown;
16
+ }, "class">;
17
+ ui: import("vue").ComputedRef<any>;
18
+ wrapperClass: import("vue").ComputedRef<string>;
19
+ omit: {
20
+ <T extends object, K extends import("lodash").PropertyName[]>(object: T | null | undefined, ...paths: K): Pick<T, Exclude<keyof T, K[number]>>;
21
+ <T_1 extends object, K_1 extends keyof T_1>(object: T_1 | null | undefined, ...paths: import("lodash").Many<K_1>[]): import("lodash").Omit<T_1, K_1>;
22
+ <T_2 extends object>(object: T_2 | null | undefined, ...paths: import("lodash").Many<import("lodash").PropertyName>[]): Partial<T_2>;
23
+ };
24
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
25
+ links: {
26
+ type: PropType<VerticalNavigationLink[]>;
27
+ default: () => never[];
28
+ };
29
+ ui: {
30
+ type: PropType<any>;
31
+ default: () => {};
32
+ };
33
+ }>>, {
34
+ ui: any;
35
+ links: VerticalNavigationLink[];
36
+ }, {}>;
37
+ export default _default;
@@ -0,0 +1,74 @@
1
+ <template>
2
+ <div v-if="isOpen" ref="container" :class="wrapperClass" v-bind="attrs">
3
+ <Transition appear v-bind="ui.transition">
4
+ <div :class="[ui.base, ui.ring, ui.rounded, ui.shadow, ui.background]">
5
+ <slot />
6
+ </div>
7
+ </Transition>
8
+ </div>
9
+ </template>
10
+
11
+ <script>
12
+ import { computed, toRef, defineComponent } from "vue";
13
+ import { defu } from "defu";
14
+ import { onClickOutside } from "@vueuse/core";
15
+ import { omit } from "lodash-es";
16
+ import { twMerge, twJoin } from "tailwind-merge";
17
+ import { usePopper } from "../../composables/usePopper";
18
+ import { defuTwMerge } from "../../utils";
19
+ import { useAppConfig } from "#imports";
20
+ export default defineComponent({
21
+ inheritAttrs: false,
22
+ props: {
23
+ modelValue: {
24
+ type: Boolean,
25
+ default: false
26
+ },
27
+ virtualElement: {
28
+ type: Object,
29
+ required: true
30
+ },
31
+ popper: {
32
+ type: Object,
33
+ default: () => ({})
34
+ },
35
+ ui: {
36
+ type: Object,
37
+ default: () => ({})
38
+ }
39
+ },
40
+ emits: ["update:modelValue", "close"],
41
+ setup(props, { attrs, emit }) {
42
+ const appConfig2 = useAppConfig();
43
+ const ui = computed(() => defuTwMerge({}, props.ui, appConfig2.ui.contextMenu));
44
+ const popper = computed(() => defu({}, props.popper, ui.value.popper));
45
+ const isOpen = computed({
46
+ get() {
47
+ return props.modelValue;
48
+ },
49
+ set(value) {
50
+ emit("update:modelValue", value);
51
+ }
52
+ });
53
+ const virtualElement = toRef(props, "virtualElement");
54
+ const [, container] = usePopper(popper.value, virtualElement);
55
+ const wrapperClass = computed(() => {
56
+ return twMerge(twJoin(
57
+ ui.value.container,
58
+ ui.value.width
59
+ ), attrs.class);
60
+ });
61
+ onClickOutside(container, () => {
62
+ isOpen.value = false;
63
+ });
64
+ return {
65
+ attrs: omit(attrs, ["class"]),
66
+ // eslint-disable-next-line vue/no-dupe-keys
67
+ ui,
68
+ isOpen,
69
+ wrapperClass,
70
+ container
71
+ };
72
+ }
73
+ });
74
+ </script>
@@ -0,0 +1,54 @@
1
+ /// <reference types="lodash" />
2
+ import type { PropType, Ref } from 'vue';
3
+ import type { PopperOptions } from '../../types/popper';
4
+ declare const _default: import("vue").DefineComponent<{
5
+ modelValue: {
6
+ type: BooleanConstructor;
7
+ default: boolean;
8
+ };
9
+ virtualElement: {
10
+ type: ObjectConstructor;
11
+ required: true;
12
+ };
13
+ popper: {
14
+ type: PropType<PopperOptions>;
15
+ default: () => {};
16
+ };
17
+ ui: {
18
+ type: PropType<any>;
19
+ default: () => {};
20
+ };
21
+ }, {
22
+ attrs: import("lodash").Omit<{
23
+ [x: string]: unknown;
24
+ }, "class">;
25
+ ui: import("vue").ComputedRef<any>;
26
+ isOpen: import("vue").WritableComputedRef<boolean>;
27
+ wrapperClass: import("vue").ComputedRef<string>;
28
+ container: Ref<import("@vueuse/core").MaybeElement>;
29
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("close" | "update:modelValue")[], "close" | "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
30
+ modelValue: {
31
+ type: BooleanConstructor;
32
+ default: boolean;
33
+ };
34
+ virtualElement: {
35
+ type: ObjectConstructor;
36
+ required: true;
37
+ };
38
+ popper: {
39
+ type: PropType<PopperOptions>;
40
+ default: () => {};
41
+ };
42
+ ui: {
43
+ type: PropType<any>;
44
+ default: () => {};
45
+ };
46
+ }>> & {
47
+ onClose?: ((...args: any[]) => any) | undefined;
48
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
49
+ }, {
50
+ ui: any;
51
+ popper: PopperOptions;
52
+ modelValue: boolean;
53
+ }, {}>;
54
+ export default _default;
@@ -0,0 +1,113 @@
1
+ <template>
2
+ <TransitionRoot :appear="appear" :show="isOpen" as="template">
3
+ <HDialog :class="wrapperClass" v-bind="attrs" @close="(e) => !preventClose && close(e)">
4
+ <TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition">
5
+ <div :class="[ui.overlay.base, ui.overlay.background]" />
6
+ </TransitionChild>
7
+
8
+ <div :class="ui.inner">
9
+ <div :class="[ui.container, ui.padding]">
10
+ <TransitionChild as="template" :appear="appear" v-bind="transitionClass">
11
+ <HDialogPanel
12
+ :class="[
13
+ ui.base,
14
+ ui.background,
15
+ ui.ring,
16
+ ui.shadow,
17
+ fullscreen ? 'w-screen' : ui.width,
18
+ fullscreen ? 'h-screen' : ui.height,
19
+ fullscreen ? 'rounded-none' : ui.rounded,
20
+ fullscreen ? 'm-0' : ui.margin
21
+ ]"
22
+ >
23
+ <slot />
24
+ </HDialogPanel>
25
+ </TransitionChild>
26
+ </div>
27
+ </div>
28
+ </HDialog>
29
+ </TransitionRoot>
30
+ </template>
31
+
32
+ <script>
33
+ import { computed, defineComponent } from "vue";
34
+ import { omit } from "lodash-es";
35
+ import { twMerge } from "tailwind-merge";
36
+ import { Dialog as HDialog, DialogPanel as HDialogPanel, TransitionRoot, TransitionChild } from "@headlessui/vue";
37
+ import { defuTwMerge } from "../../utils";
38
+ import { useAppConfig } from "#imports";
39
+ export default defineComponent({
40
+ components: {
41
+ HDialog,
42
+ HDialogPanel,
43
+ TransitionRoot,
44
+ TransitionChild
45
+ },
46
+ inheritAttrs: false,
47
+ props: {
48
+ modelValue: {
49
+ type: Boolean,
50
+ default: false
51
+ },
52
+ appear: {
53
+ type: Boolean,
54
+ default: false
55
+ },
56
+ overlay: {
57
+ type: Boolean,
58
+ default: true
59
+ },
60
+ transition: {
61
+ type: Boolean,
62
+ default: true
63
+ },
64
+ preventClose: {
65
+ type: Boolean,
66
+ default: false
67
+ },
68
+ fullscreen: {
69
+ type: Boolean,
70
+ default: false
71
+ },
72
+ ui: {
73
+ type: Object,
74
+ default: () => ({})
75
+ }
76
+ },
77
+ emits: ["update:modelValue", "close"],
78
+ setup(props, { attrs, emit }) {
79
+ const appConfig2 = useAppConfig();
80
+ const ui = computed(() => defuTwMerge({}, props.ui, appConfig2.ui.modal));
81
+ const isOpen = computed({
82
+ get() {
83
+ return props.modelValue;
84
+ },
85
+ set(value) {
86
+ emit("update:modelValue", value);
87
+ }
88
+ });
89
+ const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class));
90
+ const transitionClass = computed(() => {
91
+ if (!props.transition) {
92
+ return {};
93
+ }
94
+ return {
95
+ ...ui.value.transition
96
+ };
97
+ });
98
+ function close(value) {
99
+ isOpen.value = value;
100
+ emit("close");
101
+ }
102
+ return {
103
+ attrs: omit(attrs, ["class"]),
104
+ // eslint-disable-next-line vue/no-dupe-keys
105
+ ui,
106
+ isOpen,
107
+ wrapperClass,
108
+ transitionClass,
109
+ close
110
+ };
111
+ }
112
+ });
113
+ </script>
@@ -0,0 +1,82 @@
1
+ /// <reference types="lodash" />
2
+ import type { PropType } from 'vue';
3
+ declare const _default: import("vue").DefineComponent<{
4
+ modelValue: {
5
+ type: BooleanConstructor;
6
+ default: boolean;
7
+ };
8
+ appear: {
9
+ type: BooleanConstructor;
10
+ default: boolean;
11
+ };
12
+ overlay: {
13
+ type: BooleanConstructor;
14
+ default: boolean;
15
+ };
16
+ transition: {
17
+ type: BooleanConstructor;
18
+ default: boolean;
19
+ };
20
+ preventClose: {
21
+ type: BooleanConstructor;
22
+ default: boolean;
23
+ };
24
+ fullscreen: {
25
+ type: BooleanConstructor;
26
+ default: boolean;
27
+ };
28
+ ui: {
29
+ type: PropType<any>;
30
+ default: () => {};
31
+ };
32
+ }, {
33
+ attrs: import("lodash").Omit<{
34
+ [x: string]: unknown;
35
+ }, "class">;
36
+ ui: import("vue").ComputedRef<any>;
37
+ isOpen: import("vue").WritableComputedRef<boolean>;
38
+ wrapperClass: import("vue").ComputedRef<string>;
39
+ transitionClass: import("vue").ComputedRef<any>;
40
+ close: (value: boolean) => void;
41
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("close" | "update:modelValue")[], "close" | "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
42
+ modelValue: {
43
+ type: BooleanConstructor;
44
+ default: boolean;
45
+ };
46
+ appear: {
47
+ type: BooleanConstructor;
48
+ default: boolean;
49
+ };
50
+ overlay: {
51
+ type: BooleanConstructor;
52
+ default: boolean;
53
+ };
54
+ transition: {
55
+ type: BooleanConstructor;
56
+ default: boolean;
57
+ };
58
+ preventClose: {
59
+ type: BooleanConstructor;
60
+ default: boolean;
61
+ };
62
+ fullscreen: {
63
+ type: BooleanConstructor;
64
+ default: boolean;
65
+ };
66
+ ui: {
67
+ type: PropType<any>;
68
+ default: () => {};
69
+ };
70
+ }>> & {
71
+ onClose?: ((...args: any[]) => any) | undefined;
72
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
73
+ }, {
74
+ ui: any;
75
+ modelValue: boolean;
76
+ appear: boolean;
77
+ overlay: boolean;
78
+ transition: boolean;
79
+ preventClose: boolean;
80
+ fullscreen: boolean;
81
+ }, {}>;
82
+ export default _default;
@@ -0,0 +1,197 @@
1
+ <template>
2
+ <Transition appear v-bind="ui.transition">
3
+ <div :class="wrapperClass" v-bind="attrs" @mouseover="onMouseover" @mouseleave="onMouseleave">
4
+ <div :class="[ui.container, ui.rounded, ui.ring]">
5
+ <div :class="ui.padding">
6
+ <div class="flex gap-3" :class="{ 'items-start': description || $slots.description, 'items-center': !description && !$slots.description }">
7
+ <UIcon v-if="icon" :name="icon" :class="iconClass" />
8
+ <UAvatar v-if="avatar" v-bind="{ size: ui.avatar.size, ...avatar }" :class="ui.avatar.base" />
9
+
10
+ <div class="w-0 flex-1">
11
+ <p :class="ui.title">
12
+ <slot name="title" :title="title">
13
+ {{ title }}
14
+ </slot>
15
+ </p>
16
+ <p v-if="(description || $slots.description)" :class="ui.description">
17
+ <slot name="description" :description="description">
18
+ {{ description }}
19
+ </slot>
20
+ </p>
21
+
22
+ <div v-if="(description || $slots.description) && actions.length" class="mt-3 flex items-center gap-2">
23
+ <UButton v-for="(action, index) of actions" :key="index" v-bind="{ ...ui.default.actionButton, ...action }" @click.stop="onAction(action)" />
24
+ </div>
25
+ </div>
26
+ <div class="flex-shrink-0 flex items-center gap-3">
27
+ <div v-if="!description && !$slots.description && actions.length" class="flex items-center gap-2">
28
+ <UButton v-for="(action, index) of actions" :key="index" v-bind="{ ...ui.default.actionButton, ...action }" @click.stop="onAction(action)" />
29
+ </div>
30
+
31
+ <UButton v-if="closeButton" v-bind="{ ...ui.default.closeButton, ...closeButton }" @click.stop="onClose" />
32
+ </div>
33
+ </div>
34
+ </div>
35
+ <div v-if="timeout" :class="progressClass" :style="progressStyle" />
36
+ </div>
37
+ </div>
38
+ </Transition>
39
+ </template>
40
+
41
+ <script>
42
+ import { ref, computed, onMounted, onUnmounted, watchEffect, defineComponent } from "vue";
43
+ import { omit } from "lodash-es";
44
+ import { twMerge, twJoin } from "tailwind-merge";
45
+ import UIcon from "../elements/Icon.vue";
46
+ import UAvatar from "../elements/Avatar.vue";
47
+ import UButton from "../elements/Button.vue";
48
+ import { useTimer } from "../../composables/useTimer";
49
+ import { defuTwMerge } from "../../utils";
50
+ import { useAppConfig } from "#imports";
51
+ import appConfig from "#build/app.config";
52
+ export default defineComponent({
53
+ components: {
54
+ UIcon,
55
+ UAvatar,
56
+ UButton
57
+ },
58
+ inheritAttrs: false,
59
+ props: {
60
+ id: {
61
+ type: [String, Number],
62
+ required: true
63
+ },
64
+ title: {
65
+ type: String,
66
+ required: true
67
+ },
68
+ description: {
69
+ type: String,
70
+ default: null
71
+ },
72
+ icon: {
73
+ type: String,
74
+ default: () => appConfig.ui.notification.default.icon
75
+ },
76
+ avatar: {
77
+ type: Object,
78
+ default: null
79
+ },
80
+ closeButton: {
81
+ type: Object,
82
+ default: () => appConfig.ui.notification.default.closeButton
83
+ },
84
+ timeout: {
85
+ type: Number,
86
+ default: 5e3
87
+ },
88
+ actions: {
89
+ type: Array,
90
+ default: () => []
91
+ },
92
+ callback: {
93
+ type: Function,
94
+ default: null
95
+ },
96
+ color: {
97
+ type: String,
98
+ default: () => appConfig.ui.notification.default.color,
99
+ validator(value) {
100
+ return ["gray", ...appConfig.ui.colors].includes(value);
101
+ }
102
+ },
103
+ ui: {
104
+ type: Object,
105
+ default: () => ({})
106
+ }
107
+ },
108
+ emits: ["close"],
109
+ setup(props, { attrs, emit }) {
110
+ const appConfig2 = useAppConfig();
111
+ const ui = computed(() => defuTwMerge({}, props.ui, appConfig2.ui.notification));
112
+ let timer = null;
113
+ const remaining = ref(props.timeout);
114
+ const wrapperClass = computed(() => {
115
+ return twMerge(twJoin(
116
+ ui.value.wrapper,
117
+ ui.value.background,
118
+ ui.value.rounded,
119
+ ui.value.shadow
120
+ ), attrs.class);
121
+ });
122
+ const progressClass = computed(() => {
123
+ return twJoin(
124
+ ui.value.progress.base,
125
+ ui.value.progress.background?.replaceAll("{color}", props.color)
126
+ );
127
+ });
128
+ const progressStyle = computed(() => {
129
+ const remainingPercent = remaining.value / props.timeout * 100;
130
+ return { width: `${remainingPercent || 0}%` };
131
+ });
132
+ const iconClass = computed(() => {
133
+ return twJoin(
134
+ ui.value.icon.base,
135
+ ui.value.icon.color?.replaceAll("{color}", props.color)
136
+ );
137
+ });
138
+ function onMouseover() {
139
+ if (timer) {
140
+ timer.pause();
141
+ }
142
+ }
143
+ function onMouseleave() {
144
+ if (timer) {
145
+ timer.resume();
146
+ }
147
+ }
148
+ function onClose() {
149
+ if (timer) {
150
+ timer.stop();
151
+ }
152
+ if (props.callback) {
153
+ props.callback();
154
+ }
155
+ emit("close");
156
+ }
157
+ function onAction(action) {
158
+ if (timer) {
159
+ timer.stop();
160
+ }
161
+ if (action.click) {
162
+ action.click();
163
+ }
164
+ emit("close");
165
+ }
166
+ onMounted(() => {
167
+ if (!props.timeout) {
168
+ return;
169
+ }
170
+ timer = useTimer(() => {
171
+ onClose();
172
+ }, props.timeout);
173
+ watchEffect(() => {
174
+ remaining.value = timer.remaining.value;
175
+ });
176
+ });
177
+ onUnmounted(() => {
178
+ if (timer) {
179
+ timer.stop();
180
+ }
181
+ });
182
+ return {
183
+ attrs: omit(attrs, ["class"]),
184
+ // eslint-disable-next-line vue/no-dupe-keys
185
+ ui,
186
+ wrapperClass,
187
+ progressClass,
188
+ progressStyle,
189
+ iconClass,
190
+ onMouseover,
191
+ onMouseleave,
192
+ onClose,
193
+ onAction
194
+ };
195
+ }
196
+ });
197
+ </script>
@@ -0,0 +1,126 @@
1
+ /// <reference types="lodash" />
2
+ import type { PropType } from 'vue';
3
+ import type { NotificationAction } from '../../types/notification';
4
+ import type { Avatar } from '../../types/avatar';
5
+ import type { Button } from '../../types/button';
6
+ declare const _default: import("vue").DefineComponent<{
7
+ id: {
8
+ type: (StringConstructor | NumberConstructor)[];
9
+ required: true;
10
+ };
11
+ title: {
12
+ type: StringConstructor;
13
+ required: true;
14
+ };
15
+ description: {
16
+ type: StringConstructor;
17
+ default: null;
18
+ };
19
+ icon: {
20
+ type: StringConstructor;
21
+ default: () => any;
22
+ };
23
+ avatar: {
24
+ type: PropType<Avatar>;
25
+ default: null;
26
+ };
27
+ closeButton: {
28
+ type: PropType<Button>;
29
+ default: () => any;
30
+ };
31
+ timeout: {
32
+ type: NumberConstructor;
33
+ default: number;
34
+ };
35
+ actions: {
36
+ type: PropType<NotificationAction[]>;
37
+ default: () => never[];
38
+ };
39
+ callback: {
40
+ type: FunctionConstructor;
41
+ default: null;
42
+ };
43
+ color: {
44
+ type: StringConstructor;
45
+ default: () => any;
46
+ validator(value: string): boolean;
47
+ };
48
+ ui: {
49
+ type: PropType<any>;
50
+ default: () => {};
51
+ };
52
+ }, {
53
+ attrs: import("lodash").Omit<{
54
+ [x: string]: unknown;
55
+ }, "class">;
56
+ ui: import("vue").ComputedRef<any>;
57
+ wrapperClass: import("vue").ComputedRef<string>;
58
+ progressClass: import("vue").ComputedRef<string>;
59
+ progressStyle: import("vue").ComputedRef<{
60
+ width: string;
61
+ }>;
62
+ iconClass: import("vue").ComputedRef<string>;
63
+ onMouseover: () => void;
64
+ onMouseleave: () => void;
65
+ onClose: () => void;
66
+ onAction: (action: NotificationAction) => void;
67
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "close"[], "close", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
68
+ id: {
69
+ type: (StringConstructor | NumberConstructor)[];
70
+ required: true;
71
+ };
72
+ title: {
73
+ type: StringConstructor;
74
+ required: true;
75
+ };
76
+ description: {
77
+ type: StringConstructor;
78
+ default: null;
79
+ };
80
+ icon: {
81
+ type: StringConstructor;
82
+ default: () => any;
83
+ };
84
+ avatar: {
85
+ type: PropType<Avatar>;
86
+ default: null;
87
+ };
88
+ closeButton: {
89
+ type: PropType<Button>;
90
+ default: () => any;
91
+ };
92
+ timeout: {
93
+ type: NumberConstructor;
94
+ default: number;
95
+ };
96
+ actions: {
97
+ type: PropType<NotificationAction[]>;
98
+ default: () => never[];
99
+ };
100
+ callback: {
101
+ type: FunctionConstructor;
102
+ default: null;
103
+ };
104
+ color: {
105
+ type: StringConstructor;
106
+ default: () => any;
107
+ validator(value: string): boolean;
108
+ };
109
+ ui: {
110
+ type: PropType<any>;
111
+ default: () => {};
112
+ };
113
+ }>> & {
114
+ onClose?: ((...args: any[]) => any) | undefined;
115
+ }, {
116
+ description: string;
117
+ icon: string;
118
+ avatar: Avatar;
119
+ closeButton: Button;
120
+ timeout: number;
121
+ actions: NotificationAction[];
122
+ callback: Function;
123
+ color: string;
124
+ ui: any;
125
+ }, {}>;
126
+ export default _default;