@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
@@ -1,19 +1,18 @@
1
1
  <template>
2
2
  <div
3
- :class="twMerge(
4
- `input--outer-wrapper
3
+ :class="twMerge(`input--outer-wrapper
5
4
  grow
6
5
  flex
7
6
  flex-wrap
8
7
  `,
9
- disabled && `
8
+ disabled && `
10
9
  text-neutral-400
11
10
  dark:text-neutral-600
12
11
  `,
13
- $.wrapperAttrs?.class
14
- )"
12
+ ($.wrapperAttrs as any)?.class,
13
+ )"
15
14
  tabindex="-1"
16
- v-bind="{ ...$.wrapperAttrs, class: void 0 }"
15
+ v-bind="{...$.wrapperAttrs, class:undefined}"
17
16
  ref="inputWrapperEl"
18
17
  >
19
18
  <slot name="label" v-bind="{ ...slotProps, label }">
@@ -38,9 +37,8 @@
38
37
  :data-disabled="disabled"
39
38
  :data-read-only="readonly"
40
39
  :data-is-open="isOpen"
41
- v-bind="{ ...$['inner-wrapperAttrs'], class: void 0 }"
42
- :class="twMerge(
43
- `input--inner-wrapper
40
+ v-bind="{...$['inner-wrapperAttrs'], class:undefined}"
41
+ :class="twMerge(`input--inner-wrapper
44
42
  relative
45
43
  flex
46
44
  flex-1
@@ -50,48 +48,48 @@
50
48
  gap-2
51
49
  px-2
52
50
  `,
53
- border && `
51
+ border && `
54
52
  bg-inherit
55
53
  border
56
54
  border-neutral-500
57
55
  outlined-within:border-accent-500
58
56
  `,
59
- isOpen && `rounded-b-none`,
60
- !valid && `
57
+ isOpen && `rounded-b-none`,
58
+ !valid && `
61
59
  border-danger-700
62
60
  outlined:!outline-danger-700
63
61
  text-danger-800
64
62
  dark:text-danger-400
65
63
  dark:border-danger-600
66
64
  `,
67
- readonly && `
65
+ readonly && `
68
66
  bg-neutral-50
69
67
  text-neutral-800
70
68
  dark:bg-neutral-950
71
69
  dark:text-neutral-200
72
70
  `,
73
- disabled && `
71
+ disabled && `
74
72
  bg-neutral-50
75
73
  text-neutral-400
76
74
  dark:border-neutral-600
77
75
  border-neutral-400
78
76
  `,
79
- $['inner-wrapperAttrs']?.class
80
- )"
77
+ ($['inner-wrapperAttrs'] as any)?.class,
78
+ )"
81
79
  >
82
80
  <slot name="left" v-bind="slotProps"/>
83
81
  <slot name="input" v-bind="{ ...inputProps, ...slotProps, suggestionsIndicatorClickHandler }">
84
82
  <lib-simple-input
85
83
  :class="twMerge(
86
- `input--input p-0`,
87
- !$slots.left && `-ml-2 pl-2`,
88
- !$slots.right && (!$values || $values.length === 0) && !suggestions && `-mr-2 -pr-2`,
89
- $.attrs?.class
90
- )"
84
+ `input--input p-0`,
85
+ !$slots.left && `-ml-2 pl-2`,
86
+ !$slots.right && (!$values || $values.length === 0) && !suggestions && `-mr-2 -pr-2`,
87
+ ($.attrs as any)?.class,
88
+ )"
91
89
  v-bind="inputProps"
92
90
  />
93
91
  </slot>
94
- <slot name="indicator" v-bind="{ isOpen, suggestionsIndicatorClickHandler }">
92
+ <slot name="indicator" v-bind="{isOpen, suggestionsIndicatorClickHandler }">
95
93
  <!-- todo, convert to button for accessibility ? -->
96
94
  <div
97
95
  v-if="suggestions"
@@ -104,31 +102,29 @@
104
102
  </slot>
105
103
  <slot
106
104
  name="values"
107
- v-bind="{ ...multivaluesProps, ...slotProps }"
105
+ v-bind="{...multivaluesProps, ...slotProps}"
108
106
  >
109
107
  <template v-if="$values && $values.length > 0">
110
108
  <lib-multi-values
111
- :class="twMerge(
112
- `
109
+ :class="twMerge(`
113
110
  input--multivalues
114
111
  grow-[9000]
115
112
  justify-space-between
116
113
  py-1
117
114
  `,
118
- !$slots.right && `-mr-1`,
119
- $.multivaluesAttrs?.class
120
- )"
115
+ !$slots.right && `-mr-1`,
116
+ ($.multivaluesAttrs as any)?.class,
117
+ )"
121
118
  v-bind="multivaluesProps"
122
119
  />
123
120
  </template>
124
121
  </slot>
125
122
  <slot name="right" v-bind="slotProps"/>
126
123
 
127
- <slot v-if="suggestions" name="suggestions" v-bind="{ ...suggestionProps, ...slotProps }">
124
+ <slot v-if="suggestions" name="suggestions" v-bind="{...suggestionProps, ...slotProps}">
128
125
  <!-- todo 1px needs to be abstracted to var -->
129
126
  <lib-suggestions
130
- :class="twMerge(
131
- `
127
+ :class="twMerge(`
132
128
  input--suggestions
133
129
  absolute
134
130
  -inset-x-px
@@ -138,11 +134,11 @@
138
134
  border
139
135
  top-full
140
136
  `,
141
- !border && `
137
+ !border && `
142
138
  rounded-sm
143
139
  `,
144
- $.suggestionsAttrs?.class
145
- )"
140
+ ($.suggestionsAttrs as any)?.class,
141
+ )"
146
142
  ref="suggestionsComponent"
147
143
  v-bind="suggestionProps"
148
144
  >
@@ -154,199 +150,229 @@
154
150
  </div>
155
151
  </div>
156
152
  </template>
153
+ <script setup lang="ts">
154
+ import { isBlank } from "@alanscodelog/utils/isBlank.js"
155
+ import { isObject } from "@alanscodelog/utils/isObject.js"
156
+ import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn.js"
157
+ import { computed,type HTMLAttributes,type InputHTMLAttributes, nextTick, onBeforeMount, ref, toRef, useSlots, watch } from "vue"
158
+ import type { ComponentExposed } from "vue-component-type-helpers"
159
+
160
+ import { useDivideAttrs } from "../../composables/useDivideAttrs.js"
161
+ import { useSuggestionsInputAria } from "../../composables/useSuggestions.js"
162
+ import { twMerge } from "../../utils/twMerge.js"
163
+ import Icon from "../Icon/Icon.vue"
164
+ import LibLabel from "../LibLabel/LibLabel.vue"
165
+ import LibMultiValues from "../LibMultiValues/LibMultiValues.vue"
166
+ import LibSimpleInput from "../LibSimpleInput/LibSimpleInput.vue"
167
+ import LibSuggestions from "../LibSuggestions/LibSuggestions.vue"
168
+ import { type BaseInteractiveProps, baseInteractivePropsDefaults, getFallbackId, type LabelProps, type LinkableByIdProps, type SuggestionsProps, type TailwindClassProp, type WrapperProps } from "../shared/props.js"
157
169
 
158
- <script setup>
159
- import { isBlank } from "@alanscodelog/utils/isBlank.js";
160
- import { isObject } from "@alanscodelog/utils/isObject.js";
161
- import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn.js";
162
- import { computed, nextTick, onBeforeMount, ref, toRef, useSlots, watch } from "vue";
163
- import { useDivideAttrs } from "../../composables/useDivideAttrs.js";
164
- import { useSuggestionsInputAria } from "../../composables/useSuggestions.js";
165
- import { twMerge } from "../../utils/twMerge.js";
166
- import Icon from "../Icon/Icon.vue";
167
- import LibLabel from "../LibLabel/LibLabel.vue";
168
- import LibMultiValues from "../LibMultiValues/LibMultiValues.vue";
169
- import LibSimpleInput from "../LibSimpleInput/LibSimpleInput.vue";
170
- import LibSuggestions from "../LibSuggestions/LibSuggestions.vue";
171
- import { baseInteractivePropsDefaults, getFallbackId } from "../shared/props.js";
170
+
171
+ /* #region base */
172
172
  defineOptions({
173
- name: "lib-simple-input-deprecated",
174
- inheritAttrs: false
175
- });
176
- const $slots = useSlots();
177
- const emit = defineEmits(["input", "submit", "keydown", "blur", "focus", "indicatorClick"]);
178
- const fallbackId = getFallbackId();
179
- const props = defineProps(/* @__PURE__ */ _mergeDefaults({
180
- suggestions: { type: Array, required: false },
181
- suggestionLabel: { type: Function, required: false },
182
- restrictToSuggestions: { type: Boolean, required: false },
183
- updateOnlyOnSubmit: { type: Boolean, required: false },
184
- suggestionsFilter: { type: Function, required: false },
185
- allowOpenEmpty: { type: Boolean, required: false },
186
- canOpen: { type: Boolean, required: false },
187
- canClose: { type: Boolean, required: false },
188
- isValid: { type: Boolean, required: false },
189
- suggestionSelector: { type: Function, required: false },
190
- showSelectedValues: { type: Boolean, required: false },
191
- id: { type: String, required: false },
192
- label: { type: String, required: false },
193
- disabled: { type: Boolean, required: false },
194
- readonly: { type: Boolean, required: false },
195
- border: { type: Boolean, required: false },
196
- unstyle: { type: Boolean, required: false },
197
- valid: { type: Boolean, required: false }
198
- }, {
199
- valid: true,
200
- suggestions: void 0,
201
- updateOnlyOnSubmit: false,
202
- ...baseInteractivePropsDefaults
203
- }));
204
- const $ = useDivideAttrs(["wrapper", "inner-wrapper", "suggestions", "multivalues"]);
205
- const $values = defineModel("values", { type: null, ...{ default: void 0 } });
206
- const $modelValue = defineModel({ type: String, ...{ required: true } });
207
- const fullId = computed(() => props.id ?? fallbackId);
208
- const $inputValue = defineModel("inputValue", { type: String, ...{ default: "" } });
209
- $inputValue.value = $modelValue.value ?? "";
210
- const canEdit = computed(() => !props.disabled && !props.readonly);
211
- const suggestionsComponent = ref(null);
212
- const activeSuggestion = ref(0);
173
+ name: "lib-simple-input-deprecated",
174
+ inheritAttrs: false,
175
+ })
176
+ const $slots = useSlots()
177
+ const emit = defineEmits<{
178
+ (e: "input", val: InputEvent): void
179
+ (e: "submit", val: string, suggestion?: any): void
180
+ (e: "keydown", val: KeyboardEvent): void
181
+ (e: "blur", val: FocusEvent): void
182
+ (e: "focus", val: FocusEvent): void
183
+ (e: "indicatorClick", val: MouseEvent): void
184
+ }>()
185
+
186
+ const fallbackId = getFallbackId()
187
+
188
+ const props = withDefaults(defineProps<Props>(), {
189
+ valid: true,
190
+ suggestions: undefined,
191
+ updateOnlyOnSubmit: false,
192
+ ...baseInteractivePropsDefaults,
193
+ })
194
+
195
+ const $ = useDivideAttrs(["wrapper", "inner-wrapper", "suggestions", "multivalues"] as const)
196
+
197
+ const $values = defineModel<string[] | undefined>("values", { default: undefined })
198
+ const $modelValue = defineModel<string>({ required: true })
199
+
200
+ const fullId = computed(() => props.id ?? fallbackId)
201
+
202
+ const $inputValue = defineModel<string>("inputValue", { default: "" })
203
+ $inputValue.value = $modelValue.value ?? ""
204
+
205
+ const canEdit = computed(() => !props.disabled && !props.readonly)
206
+ const suggestionsComponent = ref<ComponentExposed<typeof LibSuggestions> | null>(null)
207
+ const activeSuggestion = ref(0)
213
208
  watch($modelValue, () => {
214
- $inputValue.value = $modelValue.value;
215
- });
216
- const inputWrapperEl = ref(null);
217
- const isOpen = ref(false);
218
- const suggestionsIndicatorClickHandler = (e) => {
219
- nextTick(() => {
220
- if (props.suggestions) {
221
- suggestionsComponent.value?.suggestions.toggle();
222
- }
223
- });
224
- emit("indicatorClick", e);
225
- };
226
- const handleKeydown = (e) => {
227
- if (props.suggestions) {
228
- if (e.key === "Enter" && activeSuggestion.value === -1 && $values.value) {
229
- pushIfNotIn($values.value, [$inputValue.value]);
230
- $inputValue.value = "";
231
- $modelValue.value = "";
232
- } else {
233
- suggestionsComponent.value?.inputKeydownHandler?.(e);
234
- if ($values.value) {
235
- $modelValue.value = "";
236
- }
237
- }
238
- }
239
- emit("keydown", e);
240
- };
241
- const handleBlur = (e) => {
242
- if (props.suggestions) {
243
- suggestionsComponent.value?.inputBlurHandler?.(e);
244
- }
245
- emit("blur", e);
246
- };
247
- const handleFocus = (e) => {
248
- if (props.suggestions) {
249
- suggestionsComponent.value?.inputFocusHandler?.(e);
250
- }
251
- emit("focus", e);
252
- };
253
- function addValue(val) {
254
- if ($values.value === void 0) return;
255
- if (isBlank(val)) return;
256
- pushIfNotIn($values.value, [val]);
257
- $inputValue.value = "";
258
- $modelValue.value = "";
209
+ $inputValue.value = $modelValue.value
210
+ })
211
+ const inputWrapperEl = ref<HTMLElement | null>(null)
212
+ const isOpen = ref(false)
213
+
214
+ const suggestionsIndicatorClickHandler = (e: MouseEvent) => {
215
+ nextTick(() => {
216
+ if (props.suggestions) {
217
+ (suggestionsComponent.value as any)?.suggestions.toggle()
218
+ }
219
+ })
220
+ emit("indicatorClick", e)
221
+ }
222
+
223
+
224
+ const handleKeydown = (e: KeyboardEvent) => {
225
+ if (props.suggestions) {
226
+ if (e.key === "Enter" && activeSuggestion.value === -1 && $values.value) {
227
+ pushIfNotIn($values.value, [$inputValue.value])
228
+ $inputValue.value = ""
229
+ $modelValue.value = ""
230
+ } else {
231
+ (suggestionsComponent.value as any)?.inputKeydownHandler?.(e)
232
+ if ($values.value) {
233
+ $modelValue.value = ""
234
+ }
235
+ }
236
+ }
237
+ emit("keydown", e)
259
238
  }
260
- const suggestions = toRef(props, "suggestions");
239
+ const handleBlur = (e: FocusEvent) => {
240
+ if (props.suggestions) {
241
+ (suggestionsComponent.value as any)?.inputBlurHandler?.(e)
242
+ }
243
+ emit("blur", e)
244
+ }
245
+ const handleFocus = (e: FocusEvent) => {
246
+ if (props.suggestions) {
247
+ (suggestionsComponent.value as any)?.inputFocusHandler?.(e)
248
+ }
249
+ emit("focus", e)
250
+ }
251
+
252
+ function addValue(val: string) {
253
+ if ($values.value === undefined) return
254
+ if (isBlank(val)) return
255
+ pushIfNotIn($values.value, [val])
256
+ $inputValue.value = ""
257
+ $modelValue.value = ""
258
+ }
259
+ const suggestions = toRef(props, "suggestions")
261
260
  const inputAriaProps = useSuggestionsInputAria(
262
- fullId,
263
- isOpen,
264
- activeSuggestion,
265
- suggestions
266
- );
261
+ fullId,
262
+ isOpen,
263
+ activeSuggestion,
264
+ suggestions,
265
+ )
267
266
  const inputProps = computed(() => ({
268
- id: fullId.value,
269
- border: false,
270
- disabled: props.disabled,
271
- readonly: props.readonly,
272
- isValid: props.valid,
273
- onKeydown: handleKeydown,
274
- onBlur: handleBlur,
275
- onFocus: handleFocus,
276
- modelValue: $inputValue.value,
277
- "onUpdate:modelValue": (e) => {
278
- $inputValue.value = e;
279
- if (!props.suggestions && !props.updateOnlyOnSubmit && !props.restrictToSuggestions) {
280
- $modelValue.value = e;
281
- }
282
- },
283
- onSubmit: (e) => {
284
- if (!props.suggestions) {
285
- $modelValue.value = $values.value ? "" : e;
286
- emit("submit", e);
287
- if ($values.value) {
288
- addValue(e);
289
- }
290
- }
291
- },
292
- ...inputAriaProps.value,
293
- canEdit: canEdit.value,
294
- ...$.value.attrs,
295
- class: void 0
296
- }));
297
- function slotSubmit(val, _wasRemoved) {
298
- emit("submit", val);
267
+ id: fullId.value,
268
+ border: false,
269
+ disabled: props.disabled,
270
+ readonly: props.readonly,
271
+ isValid: props.valid,
272
+ onKeydown: handleKeydown,
273
+ onBlur: handleBlur,
274
+ onFocus: handleFocus,
275
+ modelValue: $inputValue.value,
276
+ "onUpdate:modelValue": (e: string) => {
277
+ $inputValue.value = e
278
+ if (!props.suggestions && !props.updateOnlyOnSubmit && !props.restrictToSuggestions) {
279
+ $modelValue.value = e
280
+ }
281
+ },
282
+ onSubmit: (e: string) => {
283
+ if (!props.suggestions) {
284
+ $modelValue.value = $values.value ? "" : e
285
+ emit("submit", e)
286
+ if ($values.value) {
287
+ addValue(e)
288
+ }
289
+ }
290
+ },
291
+ ...inputAriaProps.value,
292
+ canEdit: canEdit.value,
293
+ ...$.value.attrs,
294
+ class: undefined,
295
+ }))
296
+
297
+ function slotSubmit(val: any, _wasRemoved: boolean): void {
298
+ emit("submit", val)
299
299
  }
300
300
  const slotProps = computed(() => ({
301
- id: fullId.value,
302
- isOpen: isOpen.value,
303
- valid: props.valid,
304
- disabled: props.disabled,
305
- readonly: props.readonly,
306
- emitSubmit: slotSubmit
307
- }));
301
+ id: fullId.value,
302
+ isOpen: isOpen.value,
303
+ valid: props.valid,
304
+ disabled: props.disabled,
305
+ readonly: props.readonly,
306
+ emitSubmit: slotSubmit
307
+ }))
308
+
309
+
308
310
  const suggestionProps = computed(() => ({
309
- id: fullId.value,
310
- suggestions: props.suggestions,
311
- allowOpenEmpty: props.allowOpenEmpty,
312
- restrictToSuggestions: props.restrictToSuggestions,
313
- suggestionLabel: props.suggestionLabel,
314
- suggestionsFilter: props.suggestionsFilter,
315
- modelValue: $values.value ?? $modelValue.value.toString(),
316
- inputValue: $inputValue.value,
317
- isValid: props.isValid,
318
- "onUpdate:inputValue": (e) => $inputValue.value = e,
319
- onSubmit: (e, suggestion, wasRemoved) => {
320
- $modelValue.value = wasRemoved ? "" : e;
321
- emit("submit", e, suggestion);
322
- },
323
- "onUpdate:modelValue": (e) => {
324
- $values.value &&= e;
325
- },
326
- "onUpdate:isOpen": (e) => {
327
- isOpen.value = e;
328
- },
329
- "onUpdate:activeSuggestion": (e) => activeSuggestion.value = e,
330
- ...$.value.suggestionsAttrs,
331
- class: void 0
332
- }));
311
+ id: fullId.value,
312
+ suggestions: props.suggestions,
313
+ allowOpenEmpty: props.allowOpenEmpty,
314
+ restrictToSuggestions: props.restrictToSuggestions,
315
+ suggestionLabel: props.suggestionLabel,
316
+ suggestionsFilter: props.suggestionsFilter,
317
+ modelValue: $values.value ?? $modelValue.value.toString(),
318
+ inputValue: $inputValue.value,
319
+ isValid: props.isValid,
320
+ "onUpdate:inputValue": (e: string) => $inputValue.value = e,
321
+ onSubmit: (e: string, suggestion?: any, wasRemoved?: boolean) => {
322
+ $modelValue.value = wasRemoved ? "" : e
323
+ emit("submit", e, suggestion)
324
+ },
325
+ "onUpdate:modelValue": (e: string | string[]) => {
326
+ $values.value &&= e as string[]
327
+ },
328
+ "onUpdate:isOpen": (e: boolean) => { isOpen.value = e },
329
+ "onUpdate:activeSuggestion": (e: number) => activeSuggestion.value = e,
330
+ ...$.value.suggestionsAttrs,
331
+ class: undefined,
332
+ }))
333
+
333
334
  const multivaluesProps = computed(() => ({
334
- hasSlotRight: !$slots.right,
335
- label: props.label,
336
- border: props.border,
337
- disabled: props.disabled,
338
- readonly: props.readonly,
339
- modelValue: $values.value,
340
- "onUpdate:modelValue": (e) => $values.value = e,
341
- ...$.value.multivaluesAttrs,
342
- class: void 0
343
- }));
335
+ hasSlotRight: !$slots.right,
336
+ label: props.label,
337
+ border: props.border,
338
+ disabled: props.disabled,
339
+ readonly: props.readonly,
340
+ modelValue: $values.value,
341
+ "onUpdate:modelValue": (e: string[]) => $values.value = e,
342
+ ...$.value.multivaluesAttrs,
343
+ class: undefined,
344
+ }))
345
+
346
+
344
347
  defineExpose({
345
- suggestionsComponent,
346
- el: inputWrapperEl
347
- });
348
+ suggestionsComponent,
349
+ el: inputWrapperEl,
350
+ })
351
+
348
352
  </script>
353
+ <script lang="ts">
349
354
 
350
- <script>
355
+ type WrapperTypes =
356
+ & WrapperProps<"suggestions",HTMLAttributes >
357
+ & WrapperProps<"wrapper", HTMLAttributes >
358
+ & WrapperProps<"inner-wrapper",HTMLAttributes>
351
359
 
360
+ type RealProps =
361
+ SuggestionsProps
362
+ & LinkableByIdProps
363
+ & LabelProps
364
+ & BaseInteractiveProps
365
+ & {
366
+ suggestions?: SuggestionsProps["suggestions"]
367
+ valid?: boolean
368
+ }
369
+
370
+ interface Props
371
+ extends
372
+ /** @vue-ignore */
373
+ Partial<Omit<InputHTMLAttributes,"class" | "readonly" | "disabled" | "onSubmit"> & TailwindClassProp>,
374
+ /** @vue-ignore */
375
+ Partial<WrapperTypes>,
376
+ RealProps { }
352
377
  </script>
378
+
@@ -0,0 +1,6 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3";
2
+ import Label from "./LibLabel.vue.js";
3
+ declare const meta: Meta<typeof Label>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof Label>;
6
+ export declare const Primary: Story;
@@ -0,0 +1,25 @@
1
+ import Label from "./LibLabel.vue";
2
+ import * as components from "../index.js";
3
+ const meta = {
4
+ component: Label,
5
+ title: "Components/Label",
6
+ args: {
7
+ slot: "label"
8
+ }
9
+ };
10
+ export default meta;
11
+ export const Primary = {
12
+ render: (args) => ({
13
+ components,
14
+ setup: () => ({ args }),
15
+ template: `
16
+ <lib-label v-bind="args">{{args.slot}}</lib-label>
17
+ <br/>
18
+ In flex col with input:
19
+ <div class="flex flex-col">
20
+ <lib-label v-bind="args">{{args.slot}}</lib-label>
21
+ <lib-simple-input modelValue="some input"></lib-simple-input>
22
+ </div>
23
+ `
24
+ })
25
+ };