@witchcraft/ui 0.1.1 → 0.1.3

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 (122) hide show
  1. package/dist/module.cjs +5 -0
  2. package/dist/module.d.ts +36 -0
  3. package/dist/module.json +2 -2
  4. package/dist/module.mjs +2 -1
  5. package/dist/runtime/assets/utils.css +1 -1
  6. package/dist/runtime/components/Aria/Aria.vue +9 -5
  7. package/dist/runtime/components/Focus.stories.d.ts +11 -0
  8. package/dist/runtime/components/Focus.stories.js +53 -0
  9. package/dist/runtime/components/Icon/Icon.vue +30 -10
  10. package/dist/runtime/components/LibButton/LibButton.stories.d.ts +12 -0
  11. package/dist/runtime/components/LibButton/LibButton.stories.js +94 -0
  12. package/dist/runtime/components/LibButton/LibButton.vue +72 -58
  13. package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.d.ts +14 -0
  14. package/dist/runtime/components/LibCheckbox/LibCheckbox.stories.js +29 -0
  15. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +74 -48
  16. package/dist/runtime/components/LibColorInput/LibColorInput.stories.d.ts +7 -0
  17. package/dist/runtime/components/LibColorInput/LibColorInput.stories.js +58 -0
  18. package/dist/runtime/components/LibColorInput/LibColorInput.vue +107 -63
  19. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +9 -0
  20. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +68 -0
  21. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +352 -271
  22. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.d.ts +7 -0
  23. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.js +36 -0
  24. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +56 -32
  25. package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.d.ts +11 -0
  26. package/dist/runtime/components/LibDatePicker/LibDatePicker.stories.js +98 -0
  27. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +38 -17
  28. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +82 -53
  29. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +67 -50
  30. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +8 -7
  31. package/dist/runtime/components/LibDebug/LibDebug.stories.d.ts +9 -0
  32. package/dist/runtime/components/LibDebug/LibDebug.stories.js +46 -0
  33. package/dist/runtime/components/LibDebug/LibDebug.vue +70 -42
  34. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +31 -18
  35. package/dist/runtime/components/LibFileInput/LibFileInput.stories.d.ts +10 -0
  36. package/dist/runtime/components/LibFileInput/LibFileInput.stories.js +63 -0
  37. package/dist/runtime/components/LibFileInput/LibFileInput.vue +156 -113
  38. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.d.ts +33 -0
  39. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.stories.js +384 -0
  40. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue +241 -215
  41. package/dist/runtime/components/LibLabel/LibLabel.stories.d.ts +6 -0
  42. package/dist/runtime/components/LibLabel/LibLabel.stories.js +25 -0
  43. package/dist/runtime/components/LibLabel/LibLabel.vue +46 -30
  44. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +23 -0
  45. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +61 -0
  46. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +58 -44
  47. package/dist/runtime/components/LibNotifications/LibNotification.stories.d.ts +15 -0
  48. package/dist/runtime/components/LibNotifications/LibNotification.stories.js +126 -0
  49. package/dist/runtime/components/LibNotifications/LibNotification.vue +48 -32
  50. package/dist/runtime/components/LibNotifications/LibNotifications.stories.d.ts +6 -0
  51. package/dist/runtime/components/LibNotifications/LibNotifications.stories.js +109 -0
  52. package/dist/runtime/components/LibNotifications/LibNotifications.vue +83 -63
  53. package/dist/runtime/components/LibPagination/LibPagination.stories.d.ts +6 -0
  54. package/dist/runtime/components/LibPagination/LibPagination.stories.js +40 -0
  55. package/dist/runtime/components/LibPagination/LibPagination.vue +111 -67
  56. package/dist/runtime/components/LibPalette/LibPalette.stories.d.ts +6 -0
  57. package/dist/runtime/components/LibPalette/LibPalette.stories.js +20 -0
  58. package/dist/runtime/components/LibPalette/LibPalette.vue +23 -20
  59. package/dist/runtime/components/LibPopup/LibPopup.stories.d.ts +14 -0
  60. package/dist/runtime/components/LibPopup/LibPopup.stories.js +147 -0
  61. package/dist/runtime/components/LibPopup/LibPopup.vue +351 -314
  62. package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.d.ts +10 -0
  63. package/dist/runtime/components/LibProgressBar/LibProgressBar.stories.js +81 -0
  64. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +91 -70
  65. package/dist/runtime/components/LibRecorder/LibRecorder.stories.d.ts +19 -0
  66. package/dist/runtime/components/LibRecorder/LibRecorder.stories.js +63 -0
  67. package/dist/runtime/components/LibRecorder/LibRecorder.vue +177 -133
  68. package/dist/runtime/components/LibRoot/LibRoot.vue +100 -73
  69. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.d.ts +26 -0
  70. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.js +78 -0
  71. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +77 -49
  72. package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.d.ts +27 -0
  73. package/dist/runtime/components/LibSuggestions/LibSuggestions.stories.js +112 -0
  74. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +156 -123
  75. package/dist/runtime/components/LibTable/LibTable.stories.d.ts +16 -0
  76. package/dist/runtime/components/LibTable/LibTable.stories.js +156 -0
  77. package/dist/runtime/components/LibTable/LibTable.vue +99 -63
  78. package/dist/runtime/components/Reset.stories.d.ts +5 -0
  79. package/dist/runtime/components/Reset.stories.js +19 -0
  80. package/dist/runtime/components/Scrolling.stories.d.ts +6 -0
  81. package/dist/runtime/components/Scrolling.stories.js +44 -0
  82. package/dist/runtime/components/Template/NAME.vue +36 -15
  83. package/dist/runtime/components/TestControls/TestControls.vue +9 -6
  84. package/dist/runtime/composables/useScrollNearContainerEdges.stories.d.ts +7 -0
  85. package/dist/runtime/composables/useScrollNearContainerEdges.stories.js +85 -0
  86. package/dist/types.d.mts +6 -2
  87. package/dist/types.d.ts +7 -0
  88. package/package.json +11 -5
  89. package/src/module.ts +2 -1
  90. package/src/runtime/assets/utils.css +5 -5
  91. package/src/runtime/components/LibButton/LibButton.vue +2 -6
  92. package/src/runtime/nuxt/plugins/vue-plugin.ts +1 -1
  93. package/dist/runtime/components/Aria/Aria.vue.d.ts +0 -5
  94. package/dist/runtime/components/Icon/Icon.vue.d.ts +0 -21
  95. package/dist/runtime/components/LibButton/LibButton.vue.d.ts +0 -36
  96. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue.d.ts +0 -42
  97. package/dist/runtime/components/LibColorInput/LibColorInput.vue.d.ts +0 -63
  98. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue.d.ts +0 -61
  99. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue.d.ts +0 -22
  100. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue.d.ts +0 -40
  101. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue.d.ts +0 -34
  102. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue.d.ts +0 -34
  103. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue.d.ts +0 -22
  104. package/dist/runtime/components/LibDebug/LibDebug.vue.d.ts +0 -32
  105. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue.d.ts +0 -22
  106. package/dist/runtime/components/LibFileInput/LibFileInput.vue.d.ts +0 -43
  107. package/dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue.d.ts +0 -165
  108. package/dist/runtime/components/LibLabel/LibLabel.vue.d.ts +0 -27
  109. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue.d.ts +0 -29
  110. package/dist/runtime/components/LibNotifications/LibNotification.vue.d.ts +0 -17
  111. package/dist/runtime/components/LibNotifications/LibNotifications.vue.d.ts +0 -13
  112. package/dist/runtime/components/LibPagination/LibPagination.vue.d.ts +0 -104
  113. package/dist/runtime/components/LibPalette/LibPalette.vue.d.ts +0 -14
  114. package/dist/runtime/components/LibPopup/LibPopup.vue.d.ts +0 -46
  115. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue.d.ts +0 -41
  116. package/dist/runtime/components/LibRecorder/LibRecorder.vue.d.ts +0 -77
  117. package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +0 -41
  118. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue.d.ts +0 -35
  119. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue.d.ts +0 -94
  120. package/dist/runtime/components/LibTable/LibTable.vue.d.ts +0 -45
  121. package/dist/runtime/components/Template/NAME.vue.d.ts +0 -17
  122. package/dist/runtime/components/TestControls/TestControls.vue.d.ts +0 -5
@@ -2,49 +2,65 @@
2
2
  <!-- we use data-disabled because labels have no disabled property technically -->
3
3
  <label
4
4
  :id="`label-${id ?? fallbackId}`"
5
- :class="!$attrs.unstyle && twMerge(
6
- `
5
+ :class="!($attrs as any).unstyle && twMerge(`
7
6
  pr-0
8
7
  text-sm
9
8
  `,
10
- !valid && `text-danger-700`,
11
- $attrs?.class
12
- )"
9
+ !valid && `text-danger-700`,
10
+ ($attrs as any)?.class
11
+ )"
13
12
  :data-disabled="disabled"
14
13
  :data-invalid="!valid"
15
14
  :for="id"
16
- v-bind="{ ...$attrs, class: void 0 }"
15
+ v-bind="{...$attrs, class:undefined}"
17
16
  >
18
17
  <slot/>
19
18
  </label>
20
19
  </template>
21
20
 
22
- <script setup>
23
- import { toRef, useAttrs } from "vue";
24
- import { twMerge } from "../../utils/twMerge.js";
25
- import { baseInteractivePropsDefaults, getFallbackId } from "../shared/props.js";
21
+ <script setup lang="ts">
22
+ import type { MakeRequired } from "@alanscodelog/utils/types"
23
+ import { type LabelHTMLAttributes,toRef,useAttrs } from "vue"
24
+
25
+ import { twMerge } from "../../utils/twMerge.js"
26
+ import { type BaseInteractiveProps, baseInteractivePropsDefaults, getFallbackId, type LabelProps, type LinkableByIdProps, type TailwindClassProp } from "../shared/props.js"
27
+
28
+
26
29
  defineOptions({
27
- name: "lib-label"
28
- });
29
- const fallbackId = getFallbackId();
30
- defineProps(/* @__PURE__ */ _mergeDefaults({
31
- id: { type: String, required: false },
32
- label: { type: String, required: false },
33
- disabled: { type: Boolean, required: false },
34
- readonly: { type: Boolean, required: false },
35
- border: { type: Boolean, required: false },
36
- unstyle: { type: Boolean, required: false },
37
- unstyled: { type: Boolean, required: false },
38
- valid: { type: Boolean, required: false }
39
- }, {
40
- id: "",
41
- unstyled: void 0,
42
- valid: true,
43
- ...baseInteractivePropsDefaults
44
- }));
45
- const $attrs = useAttrs();
30
+ name: "lib-label",
31
+ })
32
+
33
+ const fallbackId = getFallbackId()
34
+
35
+ // eslint-disable-next-line no-undef
36
+ withDefaults(defineProps<Props>(), {
37
+ id: "",
38
+ unstyled: undefined,
39
+ valid: true,
40
+ ...baseInteractivePropsDefaults,
41
+ })
42
+
43
+ const $attrs = useAttrs()
44
+ </script>
45
+
46
+ <script lang="ts">
47
+ type RealProps =
48
+ & LinkableByIdProps
49
+ & LabelProps
50
+ & BaseInteractiveProps
51
+ & {
52
+ unstyled?: boolean
53
+ valid?: boolean
54
+ }
55
+
56
+ interface Props
57
+ extends
58
+ /** @vue-ignore */
59
+ Partial<Omit<LabelHTMLAttributes,"class"> & TailwindClassProp>,
60
+ RealProps
61
+ { }
46
62
  </script>
47
63
 
48
- <script>
64
+ <script lang="ts">
49
65
 
50
66
  </script>
@@ -0,0 +1,23 @@
1
+ import type { StoryObj } from "@storybook/vue3";
2
+ import LibMultiValues from "./LibMultiValues.vue.js";
3
+ declare const meta: {
4
+ component: any;
5
+ title: string;
6
+ args: {
7
+ modelValue: string[];
8
+ border: boolean;
9
+ };
10
+ tags: string[];
11
+ };
12
+ export default meta;
13
+ type Story = StoryObj<typeof LibMultiValues>;
14
+ /**
15
+ * The multi-value component is just the values part beneath the input.
16
+ *
17
+ * This is a simple example of how it can be combined with the simple-input component to create an input with multiple values.
18
+ *
19
+ * Note that setting the `disabled` or `readonly` props won't prevent the component from accepting an updated `values` prop. Disabling adding must be done separately from whatever is controlling the component (e.g. the input in this case).
20
+ */
21
+ export declare const Primary: Story;
22
+ export declare const Disabled: any;
23
+ export declare const Readonly: any;
@@ -0,0 +1,61 @@
1
+ import { ref } from "vue";
2
+ import LibMultiValues from "./LibMultiValues.vue";
3
+ import * as components from "../index.js";
4
+ const meta = {
5
+ component: LibMultiValues,
6
+ title: "Components/MultiValues",
7
+ args: {
8
+ modelValue: ["A", "B", "C"],
9
+ border: true
10
+ },
11
+ tags: ["!test"]
12
+ };
13
+ export default meta;
14
+ export const Primary = {
15
+ render: (args) => ({
16
+ components: { ...components, LibMultiValues },
17
+ setup: () => {
18
+ const inputValue = ref("B");
19
+ const multiValueEl = ref(null);
20
+ const onKeydownEnter = (e) => {
21
+ if (e.key === "Enter") args.modelValue.push(inputValue.value);
22
+ };
23
+ return {
24
+ args,
25
+ inputValue,
26
+ multiValueEl,
27
+ onKeydownEnter
28
+ };
29
+ },
30
+ template: `
31
+ <p>Simple Input connected to multi-value.</p>
32
+ <p>Note: You will be able to add values, including duplicates, even to the disabled/readonly version in this test, see the Input component for a properly connected approach.</p>
33
+ <p> Press enter to add value :</p>
34
+ <lib-simple-input
35
+ v-model="inputValue"
36
+ @keydown="onKeydownEnter"
37
+ >
38
+ </lib-simple-input>
39
+ <p>Multi-value component: </p>
40
+ <div class="flex justify-start">
41
+ <lib-multi-values
42
+ ref="multiValueEl"
43
+ v-bind="args"
44
+ v-model="args.modelValue"
45
+ />
46
+ </div>
47
+ `
48
+ })
49
+ };
50
+ export const Disabled = {
51
+ ...Primary,
52
+ args: {
53
+ disabled: true
54
+ }
55
+ };
56
+ export const Readonly = {
57
+ ...Primary,
58
+ args: {
59
+ readonly: true
60
+ }
61
+ };
@@ -1,9 +1,7 @@
1
1
  <template>
2
2
  <div
3
3
  v-if="$modelValue && $modelValue?.length > 0"
4
- :class="
5
- twMerge(
6
- `
4
+ :class="twMerge(`
7
5
  multivalues
8
6
  group
9
7
  flex
@@ -14,19 +12,17 @@
14
12
  overflow-x-scroll
15
13
  scrollbar-hidden
16
14
  `,
17
- $.attrs?.class
18
- )
19
- "
15
+ ($.attrs as any)?.class)
16
+ "
20
17
  :data-disabled="disabled"
21
18
  :data-read-only="readonly"
22
19
  :aria-label="`Values for ${label}`"
23
20
  :tabindex="disabled ? -1 : 0"
24
- v-bind="{ ...$.attrs, class: void 0 }"
21
+ v-bind="{...$.attrs, class:undefined}"
25
22
  >
26
23
  <div
27
24
  :data-border="border"
28
- :class="twMerge(
29
- `
25
+ :class="twMerge(`
30
26
  multivalues--item
31
27
  flex-basis-0
32
28
  min-w-2
@@ -39,24 +35,24 @@
39
35
  px-1
40
36
  text-xs
41
37
  leading-none`,
42
- !(disabled || readonly) && `
38
+ !(disabled || readonly) && `
43
39
  group-focus:text-accent-500
44
40
  focus:text-accent-500`,
45
- border && `
41
+ border && `
46
42
  rounded-sm
47
43
  border-neutral-400
48
44
  border
49
45
  focus:border-accent-400
50
46
  `,
51
- border && (disabled || readonly) && `
47
+ border && (disabled || readonly) && `
52
48
  border-neutral-200
53
49
  focus:border-neutral-200
54
50
  dark:border-neutral-800
55
51
  dark:focus:border-neutral-800
56
52
  `,
57
- $.itemAttrs?.class
58
- )"
59
- :tabindex="canEdit ? 0 : void 0"
53
+ ($.itemAttrs as any)?.class
54
+ )"
55
+ :tabindex="canEdit ? 0 : undefined"
60
56
  v-for="(value) of $modelValue"
61
57
  :key="value"
62
58
  @keydown.ctrl.c.prevent="copy(value.toString())"
@@ -75,37 +71,55 @@
75
71
  </div>
76
72
  </template>
77
73
 
78
- <script setup>
79
- import { removeIfIn } from "@alanscodelog/utils/removeIfIn.js";
80
- import { computed } from "vue";
81
- import { useDivideAttrs } from "../../composables/useDivideAttrs.js";
82
- import { copy } from "../../helpers/copy.js";
83
- import { twMerge } from "../../utils/twMerge.js";
84
- import Icon from "../Icon/Icon.vue";
85
- import LibButton from "../LibButton/LibButton.vue";
86
- import { baseInteractivePropsDefaults } from "../shared/props.js";
74
+ <script setup lang="ts" generic="T extends string | number">
75
+ import { removeIfIn } from "@alanscodelog/utils/removeIfIn.js"
76
+ import { computed, type HTMLAttributes } from "vue"
77
+
78
+ import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
79
+ import { copy } from "../../helpers/copy.js"
80
+ import { twMerge } from "../../utils/twMerge.js"
81
+ import Icon from "../Icon/Icon.vue"
82
+ import LibButton from "../LibButton/LibButton.vue"
83
+ import { type BaseInteractiveProps, baseInteractivePropsDefaults,type LabelProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
84
+
85
+
87
86
  defineOptions({
88
- name: "lib-multi-values",
89
- inheritAttrs: false
90
- });
91
- const $ = useDivideAttrs(["item"]);
92
- const props = defineProps(/* @__PURE__ */ _mergeDefaults({
93
- label: { type: String, required: false },
94
- disabled: { type: Boolean, required: false },
95
- readonly: { type: Boolean, required: false },
96
- border: { type: Boolean, required: false },
97
- unstyle: { type: Boolean, required: false }
98
- }, {
99
- ...baseInteractivePropsDefaults
100
- }));
101
- const canEdit = computed(() => !props.disabled && !props.readonly);
102
- const $modelValue = defineModel({ type: Array, ...{ default: () => [] } });
103
- const removeVal = (value) => {
104
- if (!canEdit.value) return;
105
- removeIfIn($modelValue.value, value);
106
- };
87
+ name: "lib-multi-values",
88
+ inheritAttrs: false,
89
+ })
90
+
91
+ const $ = useDivideAttrs(["item"] as const)
92
+ const props = withDefaults(defineProps<Props>(), {
93
+ ...baseInteractivePropsDefaults
94
+ })
95
+
96
+
97
+ const canEdit = computed(() => !props.disabled && !props.readonly)
98
+ const $modelValue = defineModel<T[]>({ default: () => []})
99
+
100
+ const removeVal = (value: T) => {
101
+ if (!canEdit.value) return
102
+ removeIfIn($modelValue.value, value)
103
+ }
107
104
  </script>
108
105
 
109
- <script>
106
+ <script lang="ts">
107
+ type WrapperTypes = Partial<WrapperProps<"item",HTMLAttributes>>
108
+
109
+ type RealProps =
110
+ & LabelProps
111
+ & BaseInteractiveProps
112
+ & {
113
+ border?: boolean
114
+ }
115
+ interface Props
116
+ extends
117
+ /** @vue-ignore */
118
+ Partial<Omit<HTMLAttributes,"class"> & TailwindClassProp>,
119
+ /** @vue-ignore */
120
+ WrapperTypes,
121
+ RealProps
122
+ {}
110
123
 
111
124
  </script>
125
+
@@ -0,0 +1,15 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3";
2
+ import LibNotification from "./LibNotification.vue.js";
3
+ declare const meta: Meta<typeof LibNotification>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof LibNotification>;
6
+ export declare const Primary: Story;
7
+ export declare const WithoutTitle: Story;
8
+ export declare const WithCode: Story;
9
+ export declare const RequiresAction: Story;
10
+ /** Should not have cancel cross in top corner. */
11
+ export declare const Uncancellable: Story;
12
+ export declare const CustomOptions: Story;
13
+ export declare const CustomDefaultOption: Story;
14
+ export declare const CustomDangerousOption: Story;
15
+ export declare const CustomDefaultAndDangerousOption: Story;
@@ -0,0 +1,126 @@
1
+ import LibNotification from "./LibNotification.vue";
2
+ import { NotificationHandler } from "../../helpers/NotificationHandler.js";
3
+ import * as components from "../index.js";
4
+ const handler = new NotificationHandler();
5
+ const meta = {
6
+ component: LibNotification,
7
+ title: "Components/Notification",
8
+ args: {}
9
+ };
10
+ export default meta;
11
+ export const Primary = {
12
+ render: (args) => ({
13
+ components: { ...components, LibNotification },
14
+ setup() {
15
+ return { args };
16
+ },
17
+ backgrounds: { disable: true },
18
+ template: `
19
+ <lib-notification v-bind="args"/>
20
+ `
21
+ }),
22
+ args: {
23
+ // @ts-expect-error calling protected method
24
+ notification: {
25
+ ...handler._createEntry({
26
+ title: `Notification`,
27
+ message: `This is a notification. Pick an option:`
28
+ }),
29
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
30
+ resolve: () => {
31
+ }
32
+ }
33
+ }
34
+ };
35
+ export const WithoutTitle = {
36
+ ...Primary,
37
+ args: {
38
+ ...Primary.args,
39
+ // @ts-expect-error calling protected method
40
+ notification: handler._createEntry({
41
+ ...Primary.args.notification,
42
+ title: void 0
43
+ })
44
+ }
45
+ };
46
+ export const WithCode = {
47
+ ...Primary,
48
+ args: {
49
+ ...Primary.args,
50
+ // @ts-expect-error calling protected method
51
+ notification: handler._createEntry({
52
+ ...Primary.args.notification,
53
+ code: "0001"
54
+ })
55
+ }
56
+ };
57
+ export const RequiresAction = {
58
+ ...Primary,
59
+ args: {
60
+ ...Primary.args,
61
+ // @ts-expect-error calling protected method
62
+ notification: handler._createEntry({
63
+ ...Primary.args.notification,
64
+ requiresAction: true
65
+ })
66
+ }
67
+ };
68
+ export const Uncancellable = {
69
+ ...Primary,
70
+ args: {
71
+ ...Primary.args,
72
+ // @ts-expect-error calling protected method
73
+ notification: handler._createEntry({
74
+ ...Primary.args.notification,
75
+ options: ["Ok"],
76
+ cancellable: false
77
+ })
78
+ }
79
+ };
80
+ export const CustomOptions = {
81
+ ...Primary,
82
+ args: {
83
+ ...Primary.args,
84
+ // @ts-expect-error calling protected method
85
+ notification: handler._createEntry({
86
+ ...Primary.args.notification,
87
+ options: ["Ok", "Default Answer", "Cancel"]
88
+ })
89
+ }
90
+ };
91
+ export const CustomDefaultOption = {
92
+ ...Primary,
93
+ args: {
94
+ ...Primary.args,
95
+ // @ts-expect-error calling protected method
96
+ notification: handler._createEntry({
97
+ ...CustomOptions.args.notification,
98
+ default: "Default Answer"
99
+ })
100
+ }
101
+ };
102
+ export const CustomDangerousOption = {
103
+ ...Primary,
104
+ args: {
105
+ ...Primary.args,
106
+ // @ts-expect-error calling protected method
107
+ notification: handler._createEntry({
108
+ ...CustomOptions.args.notification,
109
+ options: ["Ok", "Dangerous Option", "Cancel"],
110
+ dangerous: ["Dangerous Option"]
111
+ })
112
+ }
113
+ };
114
+ export const CustomDefaultAndDangerousOption = {
115
+ ...Primary,
116
+ args: {
117
+ ...Primary.args,
118
+ // @ts-expect-error calling protected method
119
+ notification: handler._createEntry({
120
+ ...CustomOptions.args.notification,
121
+ options: ["Ok", "Default Answer", "Dangerous Option", "Cancel"],
122
+ default: "Default Answer",
123
+ dangerous: ["Dangerous Option"]
124
+ })
125
+ }
126
+ };
@@ -1,6 +1,5 @@
1
1
  <template>
2
- <div :class="twMerge(
3
- `notification
2
+ <div :class="twMerge(`notification
4
3
  max-w-700px
5
4
  bg-neutral-50
6
5
  dark:bg-neutral-900
@@ -14,9 +13,8 @@
14
13
  gap-2
15
14
  p-2 m-2
16
15
  `,
17
- $attrs.class
18
- )"
19
- v-bind="{ ...$attrs, class: void 0 }"
16
+ ($attrs as any).class)"
17
+ v-bind="{ ...$attrs, class: undefined }"
20
18
  tabindex="0"
21
19
  ref="notificationEl"
22
20
  @keydown.enter.self="NotificationHandler.resolveToDefault(notification)"
@@ -65,12 +63,11 @@
65
63
  "
66
64
  >
67
65
  <lib-button :label="option"
68
- :class="twMerge(
69
- `
66
+ :class="twMerge(`
70
67
  notification--option-button
71
68
  `,
72
- buttonColors[i] == 'secondary' && 'p-0'
73
- )"
69
+ buttonColors[i] == 'secondary' && 'p-0'
70
+ )"
74
71
  :border="buttonColors[i] !== 'secondary'"
75
72
  :color="buttonColors[i]"
76
73
  v-for="option, i in notification.options"
@@ -81,33 +78,52 @@
81
78
  </div>
82
79
  </div>
83
80
  </template>
81
+ <script setup lang="ts">
82
+ import { computed, type HTMLAttributes,ref, useAttrs } from "vue"
83
+
84
+ import { copy } from "../../helpers/copy.js"
85
+ import { type NotificationEntry, NotificationHandler } from "../../helpers/NotificationHandler.js"
86
+ import { twMerge } from "../../utils/twMerge.js"
87
+ import Icon from "../Icon/Icon.vue"
88
+ import LibButton from "../LibButton/LibButton.vue"
89
+ import type { TailwindClassProp } from "../shared/props.js"
90
+
84
91
 
85
- <script setup>
86
- import { computed, ref, useAttrs } from "vue";
87
- import { copy } from "../../helpers/copy.js";
88
- import { NotificationHandler } from "../../helpers/NotificationHandler.js";
89
- import { twMerge } from "../../utils/twMerge.js";
90
- import Icon from "../Icon/Icon.vue";
91
- import LibButton from "../LibButton/LibButton.vue";
92
92
  defineOptions({
93
- name: "lib-notification",
94
- inheritAttrs: false
95
- });
96
- const $attrs = useAttrs();
97
- const props = defineProps({
98
- notification: { type: null, required: true },
99
- handler: { type: Object, required: false, default: void 0 }
100
- });
101
- const getColor = (notification, option) => notification.default === option ? "primary" : notification.dangerous.includes(option) ? "danger" : "secondary";
102
- const buttonColors = computed(() => props.notification.options.map((option) => getColor(props.notification, option)));
103
- const notificationEl = ref(null);
93
+ name: "lib-notification",
94
+ inheritAttrs: false,
95
+ })
96
+ const $attrs = useAttrs()
97
+
98
+ const props = withDefaults(defineProps<Props>(), {
99
+ handler: undefined,
100
+ })
101
+
102
+ const getColor = (notification: NotificationEntry, option: string): "ok" | "primary" | "danger" | "secondary" => notification.default === option ? "primary" : notification.dangerous.includes(option) ? "danger" : "secondary"
103
+
104
+ /* Todo make this more flexible? */
105
+ // eslint-disable-next-line @stylistic/space-in-parens
106
+ const buttonColors = computed(() => props.notification.options.map((option: any /* what ??? */) => getColor(props.notification, option)))
107
+
108
+ const notificationEl = ref<null | HTMLElement>(null)
104
109
  defineExpose({
105
- focus: () => {
106
- notificationEl.value?.focus();
107
- }
108
- });
110
+ focus: () => {
111
+ notificationEl.value?.focus()
112
+ },
113
+ })
114
+
109
115
  </script>
110
116
 
111
- <script>
117
+ <script lang="ts">
118
+ type RealProps = {
119
+ notification: NotificationEntry
120
+ handler?: NotificationHandler
121
+ }
112
122
 
123
+ interface Props
124
+ extends
125
+ /** @vue-ignore */
126
+ Partial<Omit<HTMLAttributes,"class"> & TailwindClassProp>,
127
+ RealProps
128
+ {}
113
129
  </script>
@@ -0,0 +1,6 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3";
2
+ import LibNotifications from "./LibNotifications.vue.js";
3
+ declare const meta: Meta<typeof LibNotifications>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof LibNotifications>;
6
+ export declare const Primary: Story;