@nuxt/ui 2.8.1 → 2.10.0

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 (120) hide show
  1. package/README.md +1 -0
  2. package/dist/module.d.mts +1411 -1092
  3. package/dist/module.d.ts +1411 -1092
  4. package/dist/module.json +1 -1
  5. package/dist/module.mjs +55 -11
  6. package/dist/runtime/components/data/Table.vue +47 -32
  7. package/dist/runtime/components/data/Table.vue.d.ts +22 -14
  8. package/dist/runtime/components/elements/Accordion.vue +33 -28
  9. package/dist/runtime/components/elements/Accordion.vue.d.ts +25 -18
  10. package/dist/runtime/components/elements/Alert.vue +22 -18
  11. package/dist/runtime/components/elements/Alert.vue.d.ts +26 -19
  12. package/dist/runtime/components/elements/Avatar.vue +22 -16
  13. package/dist/runtime/components/elements/Avatar.vue.d.ts +28 -19
  14. package/dist/runtime/components/elements/AvatarGroup.d.ts +17 -8
  15. package/dist/runtime/components/elements/AvatarGroup.mjs +18 -13
  16. package/dist/runtime/components/elements/Badge.vue +21 -17
  17. package/dist/runtime/components/elements/Badge.vue.d.ts +28 -19
  18. package/dist/runtime/components/elements/Button.vue +22 -18
  19. package/dist/runtime/components/elements/Button.vue.d.ts +28 -19
  20. package/dist/runtime/components/elements/ButtonGroup.d.ts +17 -8
  21. package/dist/runtime/components/elements/ButtonGroup.mjs +22 -15
  22. package/dist/runtime/components/elements/Dropdown.vue +45 -37
  23. package/dist/runtime/components/elements/Dropdown.vue.d.ts +22 -17
  24. package/dist/runtime/components/elements/Kbd.vue +16 -12
  25. package/dist/runtime/components/elements/Kbd.vue.d.ts +20 -12
  26. package/dist/runtime/components/elements/Link.vue +18 -5
  27. package/dist/runtime/components/elements/Meter.vue +166 -0
  28. package/dist/runtime/components/elements/Meter.vue.d.ts +123 -0
  29. package/dist/runtime/components/elements/MeterGroup.d.ts +78 -0
  30. package/dist/runtime/components/elements/MeterGroup.mjs +172 -0
  31. package/dist/runtime/components/elements/Progress.vue +284 -0
  32. package/dist/runtime/components/elements/Progress.vue.d.ts +2 -0
  33. package/dist/runtime/components/forms/Checkbox.vue +27 -17
  34. package/dist/runtime/components/forms/Checkbox.vue.d.ts +33 -15
  35. package/dist/runtime/components/forms/Form.vue +34 -9
  36. package/dist/runtime/components/forms/Form.vue.d.ts +2 -1
  37. package/dist/runtime/components/forms/FormGroup.vue +51 -27
  38. package/dist/runtime/components/forms/FormGroup.vue.d.ts +23 -15
  39. package/dist/runtime/components/forms/Input.vue +41 -29
  40. package/dist/runtime/components/forms/Input.vue.d.ts +51 -24
  41. package/dist/runtime/components/forms/Radio.vue +32 -21
  42. package/dist/runtime/components/forms/Radio.vue.d.ts +36 -18
  43. package/dist/runtime/components/forms/RadioGroup.vue +136 -0
  44. package/dist/runtime/components/forms/RadioGroup.vue.d.ts +118 -0
  45. package/dist/runtime/components/forms/Range.vue +26 -16
  46. package/dist/runtime/components/forms/Range.vue.d.ts +37 -18
  47. package/dist/runtime/components/forms/Select.vue +34 -26
  48. package/dist/runtime/components/forms/Select.vue.d.ts +42 -24
  49. package/dist/runtime/components/forms/SelectMenu.vue +104 -89
  50. package/dist/runtime/components/forms/SelectMenu.vue.d.ts +53 -33
  51. package/dist/runtime/components/forms/Textarea.vue +43 -31
  52. package/dist/runtime/components/forms/Textarea.vue.d.ts +50 -23
  53. package/dist/runtime/components/forms/Toggle.vue +26 -15
  54. package/dist/runtime/components/forms/Toggle.vue.d.ts +31 -12
  55. package/dist/runtime/components/layout/Card.vue +15 -10
  56. package/dist/runtime/components/layout/Card.vue.d.ts +17 -9
  57. package/dist/runtime/components/layout/Container.vue +15 -10
  58. package/dist/runtime/components/layout/Container.vue.d.ts +17 -9
  59. package/dist/runtime/components/layout/Divider.vue +107 -0
  60. package/dist/runtime/components/layout/Divider.vue.d.ts +82 -0
  61. package/dist/runtime/components/layout/Skeleton.vue +15 -10
  62. package/dist/runtime/components/layout/Skeleton.vue.d.ts +17 -9
  63. package/dist/runtime/components/navigation/CommandPalette.vue +57 -38
  64. package/dist/runtime/components/navigation/CommandPalette.vue.d.ts +24 -23
  65. package/dist/runtime/components/navigation/CommandPaletteGroup.vue +1 -1
  66. package/dist/runtime/components/navigation/CommandPaletteGroup.vue.d.ts +3 -4
  67. package/dist/runtime/components/navigation/Pagination.vue +129 -64
  68. package/dist/runtime/components/navigation/Pagination.vue.d.ts +70 -25
  69. package/dist/runtime/components/navigation/Tabs.vue +17 -14
  70. package/dist/runtime/components/navigation/Tabs.vue.d.ts +18 -11
  71. package/dist/runtime/components/navigation/VerticalNavigation.vue +15 -13
  72. package/dist/runtime/components/navigation/VerticalNavigation.vue.d.ts +20 -16
  73. package/dist/runtime/components/overlays/ContextMenu.vue +21 -11
  74. package/dist/runtime/components/overlays/ContextMenu.vue.d.ts +20 -11
  75. package/dist/runtime/components/overlays/Modal.vue +16 -14
  76. package/dist/runtime/components/overlays/Modal.vue.d.ts +18 -11
  77. package/dist/runtime/components/overlays/Notification.vue +25 -15
  78. package/dist/runtime/components/overlays/Notification.vue.d.ts +25 -19
  79. package/dist/runtime/components/overlays/Notifications.vue +19 -13
  80. package/dist/runtime/components/overlays/Notifications.vue.d.ts +22 -14
  81. package/dist/runtime/components/overlays/Popover.vue +39 -22
  82. package/dist/runtime/components/overlays/Popover.vue.d.ts +32 -11
  83. package/dist/runtime/components/overlays/Slideover.vue +15 -13
  84. package/dist/runtime/components/overlays/Slideover.vue.d.ts +18 -11
  85. package/dist/runtime/components/overlays/Tooltip.vue +31 -23
  86. package/dist/runtime/components/overlays/Tooltip.vue.d.ts +19 -11
  87. package/dist/runtime/composables/useFormGroup.d.ts +12 -2
  88. package/dist/runtime/composables/useFormGroup.mjs +21 -4
  89. package/dist/runtime/composables/usePopper.d.ts +3 -3
  90. package/dist/runtime/composables/usePopper.mjs +47 -31
  91. package/dist/runtime/composables/useToast.d.ts +3 -3
  92. package/dist/runtime/composables/useUI.d.ts +10 -0
  93. package/dist/runtime/composables/useUI.mjs +24 -0
  94. package/dist/runtime/types/avatar.d.ts +10 -4
  95. package/dist/runtime/types/badge.d.ts +14 -0
  96. package/dist/runtime/types/button.d.ts +10 -3
  97. package/dist/runtime/types/command-palette.d.ts +3 -1
  98. package/dist/runtime/types/form.d.ts +18 -4
  99. package/dist/runtime/types/index.d.ts +4 -0
  100. package/dist/runtime/types/link.d.ts +1 -0
  101. package/dist/runtime/types/meter.d.ts +5 -0
  102. package/dist/runtime/types/notification.d.ts +5 -3
  103. package/dist/runtime/types/popper.d.ts +1 -0
  104. package/dist/runtime/types/progress.d.ts +4 -0
  105. package/dist/runtime/types/tabs.d.ts +1 -0
  106. package/dist/runtime/types/utils.d.ts +11 -0
  107. package/dist/runtime/ui.config.d.ts +1470 -0
  108. package/dist/runtime/{app.config.mjs → ui.config.mjs} +313 -97
  109. package/dist/runtime/utils/index.d.ts +5 -11
  110. package/dist/runtime/utils/index.mjs +21 -9
  111. package/dist/runtime/utils/lodash.d.ts +2 -0
  112. package/dist/runtime/utils/lodash.mjs +23 -0
  113. package/dist/runtime/utils/uid.d.ts +1 -0
  114. package/dist/runtime/utils/uid.mjs +4 -0
  115. package/dist/types.d.mts +1 -1
  116. package/dist/types.d.ts +1 -1
  117. package/package.json +27 -29
  118. package/dist/runtime/app.config.d.ts +0 -1203
  119. package/dist/runtime/utils/StateEmitter.d.ts +0 -17
  120. package/dist/runtime/utils/StateEmitter.mjs +0 -21
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/ui",
3
- "version": "2.8.1",
3
+ "version": "2.10.0",
4
4
  "configKey": "ui",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.0.0-rc.8"
package/dist/module.mjs CHANGED
@@ -1,8 +1,9 @@
1
- import { defineNuxtModule, createResolver, resolvePath, installModule, addPlugin, addComponentsDir, addImportsDir } from '@nuxt/kit';
1
+ import { addTemplate, useNuxt, defineNuxtModule, createResolver, installModule, addPlugin, addComponentsDir, addImportsDir } from '@nuxt/kit';
2
2
  import defaultColors from 'tailwindcss/colors.js';
3
3
  import { defaultExtractor as defaultExtractor$1 } from 'tailwindcss/lib/lib/defaultExtractor.js';
4
4
  import { iconsPlugin, getIconCollections } from '@egoist/tailwindcss-icons';
5
- import { omit, kebabCase, upperFirst, camelCase } from 'lodash-es';
5
+ import { kebabCase, upperFirst, camelCase } from 'scule';
6
+ import { dirname } from 'pathe';
6
7
 
7
8
 
8
9
 
@@ -14,7 +15,15 @@ const __filename = __cjs_url__.fileURLToPath(import.meta.url);
14
15
  const __dirname = __cjs_path__.dirname(__filename);
15
16
  const require = __cjs_mod__.createRequire(import.meta.url);
16
17
  const name = "@nuxt/ui";
17
- const version = "2.8.1";
18
+ const version = "2.10.0";
19
+
20
+ function omit(object, keysToOmit) {
21
+ const result = { ...object };
22
+ for (const key of keysToOmit) {
23
+ delete result[key];
24
+ }
25
+ return result;
26
+ }
18
27
 
19
28
  const colorsToExclude = [
20
29
  "inherit",
@@ -185,6 +194,23 @@ const safelistByComponent = {
185
194
  pattern: new RegExp(`ring-(${colorsAsRegex2})-500`),
186
195
  variants: ["focus-visible"]
187
196
  }],
197
+ progress: (colorsAsRegex2) => [{
198
+ pattern: new RegExp(`text-(${colorsAsRegex2})-400`),
199
+ variants: ["dark"]
200
+ }, {
201
+ pattern: new RegExp(`text-(${colorsAsRegex2})-500`)
202
+ }],
203
+ meter: (colorsAsRegex2) => [{
204
+ pattern: new RegExp(`bg-(${colorsAsRegex2})-400`),
205
+ variants: ["dark"]
206
+ }, {
207
+ pattern: new RegExp(`bg-(${colorsAsRegex2})-500`)
208
+ }, {
209
+ pattern: new RegExp(`text-(${colorsAsRegex2})-400`),
210
+ variants: ["dark"]
211
+ }, {
212
+ pattern: new RegExp(`text-(${colorsAsRegex2})-500`)
213
+ }],
188
214
  notification: (colorsAsRegex2) => [{
189
215
  pattern: new RegExp(`bg-(${colorsAsRegex2})-400`),
190
216
  variants: ["dark"]
@@ -200,7 +226,9 @@ const safelistByComponent = {
200
226
  const safelistComponentAliasesMap = {
201
227
  "USelect": "UInput",
202
228
  "USelectMenu": "UInput",
203
- "UTextarea": "UInput"
229
+ "UTextarea": "UInput",
230
+ "URadioGroup": "URadio",
231
+ "UMeterGroup": "UMeter"
204
232
  };
205
233
  const colorsAsRegex = (colors) => colors.join("|");
206
234
  const excludeColors = (colors) => {
@@ -251,6 +279,23 @@ const customSafelistExtractor = (prefix, content, colors, safelistColors) => {
251
279
  return classes;
252
280
  };
253
281
 
282
+ function createTemplates(nuxt = useNuxt()) {
283
+ const template = addTemplate({
284
+ filename: "ui.colors.mjs",
285
+ getContents: () => `export default ${JSON.stringify(nuxt.options.appConfig.ui.colors)};`,
286
+ write: true
287
+ });
288
+ const typesTemplate = addTemplate({
289
+ filename: "ui.colors.d.ts",
290
+ getContents: () => `declare module '#ui-colors' { const defaultExport: ${JSON.stringify(nuxt.options.appConfig.ui.colors)}; export default defaultExport; }`,
291
+ write: true
292
+ });
293
+ nuxt.options.alias["#ui-colors"] = dirname(template.dst);
294
+ nuxt.hook("prepare:types", (opts) => {
295
+ opts.references.push({ path: typesTemplate.dst });
296
+ });
297
+ }
298
+
254
299
  const defaultExtractor = defaultExtractor$1({ tailwindConfig: { separator: ":" } });
255
300
  delete defaultColors.lightBlue;
256
301
  delete defaultColors.warmGray;
@@ -276,11 +321,8 @@ const module = defineNuxtModule({
276
321
  const runtimeDir = resolve("./runtime");
277
322
  nuxt.options.build.transpile.push(runtimeDir);
278
323
  nuxt.options.build.transpile.push("@popperjs/core", "@headlessui/vue");
324
+ nuxt.options.alias["#ui"] = runtimeDir;
279
325
  nuxt.options.css.push(resolve(runtimeDir, "ui.css"));
280
- const appConfigFile = await resolvePath(resolve(runtimeDir, "app.config"));
281
- nuxt.hook("app:resolve", (app) => {
282
- app.configs.push(appConfigFile);
283
- });
284
326
  nuxt.hook("tailwindcss:config", function(tailwindConfig) {
285
327
  const globalColors = {
286
328
  ...tailwindConfig.theme.colors || defaultColors,
@@ -319,16 +361,17 @@ const module = defineNuxtModule({
319
361
  };
320
362
  const colors = excludeColors(globalColors);
321
363
  nuxt.options.appConfig.ui = {
322
- ...nuxt.options.appConfig.ui,
323
364
  primary: "green",
324
365
  gray: "cool",
325
- colors
366
+ colors,
367
+ strategy: "merge"
326
368
  };
327
369
  tailwindConfig.safelist = tailwindConfig.safelist || [];
328
370
  tailwindConfig.safelist.push(...generateSafelist(options.safelistColors, colors));
329
371
  tailwindConfig.plugins = tailwindConfig.plugins || [];
330
372
  tailwindConfig.plugins.push(iconsPlugin({ collections: getIconCollections(options.icons) }));
331
373
  });
374
+ createTemplates(nuxt);
332
375
  await installModule("@nuxtjs/color-mode", { classSuffix: "" });
333
376
  await installModule("@nuxtjs/tailwindcss", {
334
377
  exposeConfig: true,
@@ -338,7 +381,8 @@ const module = defineNuxtModule({
338
381
  require("@tailwindcss/forms")({ strategy: "class" }),
339
382
  require("@tailwindcss/aspect-ratio"),
340
383
  require("@tailwindcss/typography"),
341
- require("@tailwindcss/container-queries")
384
+ require("@tailwindcss/container-queries"),
385
+ require("@headlessui/tailwindcss")
342
386
  ],
343
387
  content: {
344
388
  files: [
@@ -1,10 +1,10 @@
1
1
  <template>
2
- <div :class="wrapperClass" v-bind="attrs">
2
+ <div :class="ui.wrapper" v-bind="attrs">
3
3
  <table :class="[ui.base, ui.divide]">
4
4
  <thead :class="ui.thead">
5
5
  <tr :class="ui.tr.base">
6
- <th v-if="modelValue" scope="col" class="ps-4">
7
- <UCheckbox :checked="indeterminate || selected.length === rows.length" :indeterminate="indeterminate" @change="onChange" />
6
+ <th v-if="modelValue" scope="col" :class="ui.checkbox.padding">
7
+ <UCheckbox :checked="indeterminate || selected.length === rows.length" :indeterminate="indeterminate" aria-label="Select all" @change="onChange" />
8
8
  </th>
9
9
 
10
10
  <th v-for="(column, index) in columns" :key="index" scope="col" :class="[ui.th.base, ui.th.padding, ui.th.color, ui.th.font, ui.th.size, column.class]">
@@ -49,12 +49,12 @@
49
49
  </tr>
50
50
 
51
51
  <template v-else>
52
- <tr v-for="(row, index) in rows" :key="index" :class="[ui.tr.base, isSelected(row) && ui.tr.selected, $attrs.onSelect && ui.tr.active]" @click="() => onSelect(row)">
53
- <td v-if="modelValue" class="ps-4">
54
- <UCheckbox v-model="selected" :value="row" @click.stop />
52
+ <tr v-for="(row, index) in rows" :key="index" :class="[ui.tr.base, isSelected(row) && ui.tr.selected, $attrs.onSelect && ui.tr.active, row?.class]" @click="() => onSelect(row)">
53
+ <td v-if="modelValue" :class="ui.checkbox.padding">
54
+ <UCheckbox v-model="selected" :value="row" aria-label="Select row" @click.stop />
55
55
  </td>
56
56
 
57
- <td v-for="(column, subIndex) in columns" :key="subIndex" :class="[ui.td.base, ui.td.padding, ui.td.color, ui.td.font, ui.td.size]">
57
+ <td v-for="(column, subIndex) in columns" :key="subIndex" :class="[ui.td.base, ui.td.padding, ui.td.color, ui.td.font, ui.td.size, row[column.key]?.class]">
58
58
  <slot :name="`${column.key}-data`" :column="column" :row="row" :index="index" :get-row-data="(defaultValue) => getRowData(row, column.key, defaultValue)">
59
59
  {{ getRowData(row, column.key) }}
60
60
  </slot>
@@ -67,16 +67,17 @@
67
67
  </template>
68
68
 
69
69
  <script>
70
- import { ref, computed, defineComponent, toRaw } from "vue";
71
- import { omit, capitalize, orderBy, get } from "lodash-es";
70
+ import { ref, computed, defineComponent, toRaw, toRef } from "vue";
71
+ import { upperFirst } from "scule";
72
72
  import { defu } from "defu";
73
- import { twMerge } from "tailwind-merge";
74
- import { defuTwMerge } from "../../utils";
75
73
  import UButton from "../elements/Button.vue";
76
74
  import UIcon from "../elements/Icon.vue";
77
75
  import UCheckbox from "../forms/Checkbox.vue";
78
- import { useAppConfig } from "#imports";
76
+ import { useUI } from "../../composables/useUI";
77
+ import { mergeConfig, omit, get } from "../../utils";
79
78
  import appConfig from "#build/app.config";
79
+ import { table } from "#ui/ui.config";
80
+ const config = mergeConfig(appConfig.ui.strategy, appConfig.ui.table, table);
80
81
  function defaultComparator(a, z) {
81
82
  return a === z;
82
83
  }
@@ -114,15 +115,15 @@ export default defineComponent({
114
115
  },
115
116
  sortButton: {
116
117
  type: Object,
117
- default: () => appConfig.ui.table.default.sortButton
118
+ default: () => config.default.sortButton
118
119
  },
119
120
  sortAscIcon: {
120
121
  type: String,
121
- default: () => appConfig.ui.table.default.sortAscIcon
122
+ default: () => config.default.sortAscIcon
122
123
  },
123
124
  sortDescIcon: {
124
125
  type: String,
125
- default: () => appConfig.ui.table.default.sortDescIcon
126
+ default: () => config.default.sortDescIcon
126
127
  },
127
128
  loading: {
128
129
  type: Boolean,
@@ -130,30 +131,44 @@ export default defineComponent({
130
131
  },
131
132
  loadingState: {
132
133
  type: Object,
133
- default: () => appConfig.ui.table.default.loadingState
134
+ default: () => config.default.loadingState
134
135
  },
135
136
  emptyState: {
136
137
  type: Object,
137
- default: () => appConfig.ui.table.default.emptyState
138
+ default: () => config.default.emptyState
139
+ },
140
+ class: {
141
+ type: [String, Object, Array],
142
+ default: void 0
138
143
  },
139
144
  ui: {
140
145
  type: Object,
141
- default: () => ({})
146
+ default: void 0
142
147
  }
143
148
  },
144
- emits: ["update:modelValue"],
145
- setup(props, { emit, attrs }) {
146
- const appConfig2 = useAppConfig();
147
- const ui = computed(() => defuTwMerge({}, props.ui, appConfig2.ui.table));
148
- const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class));
149
- const columns = computed(() => props.columns ?? Object.keys(omit(props.rows[0] ?? {}, ["click"])).map((key) => ({ key, label: capitalize(key), sortable: false })));
149
+ emits: ["update:modelValue", "update:sort"],
150
+ setup(props, { emit, attrs: $attrs }) {
151
+ const { ui, attrs } = useUI("table", toRef(props, "ui"), config, toRef(props, "class"));
152
+ const columns = computed(() => props.columns ?? Object.keys(omit(props.rows[0] ?? {}, ["click"])).map((key) => ({ key, label: upperFirst(key), sortable: false })));
150
153
  const sort = ref(defu({}, props.sort, { column: null, direction: "asc" }));
154
+ const defaultSort = { column: sort.value.column, direction: null };
151
155
  const rows = computed(() => {
152
156
  if (!sort.value?.column) {
153
157
  return props.rows;
154
158
  }
155
159
  const { column, direction } = sort.value;
156
- return orderBy(props.rows, column, direction);
160
+ return props.rows.slice().sort((a, b) => {
161
+ const aValue = get(a, column);
162
+ const bValue = get(b, column);
163
+ if (aValue === bValue) {
164
+ return 0;
165
+ }
166
+ if (direction === "asc") {
167
+ return aValue < bValue ? -1 : 1;
168
+ } else {
169
+ return aValue > bValue ? -1 : 1;
170
+ }
171
+ });
157
172
  });
158
173
  const selected = computed({
159
174
  get() {
@@ -191,26 +206,27 @@ export default defineComponent({
191
206
  if (sort.value.column === column.key) {
192
207
  const direction = !column.direction || column.direction === "asc" ? "desc" : "asc";
193
208
  if (sort.value.direction === direction) {
194
- sort.value = defu({}, props.sort, { column: null, direction: "asc" });
209
+ sort.value = defu({}, defaultSort, { column: null, direction: "asc" });
195
210
  } else {
196
211
  sort.value.direction = sort.value.direction === "asc" ? "desc" : "asc";
197
212
  }
198
213
  } else {
199
214
  sort.value = { column: column.key, direction: column.direction || "asc" };
200
215
  }
216
+ emit("update:sort", sort.value);
201
217
  }
202
218
  function onSelect(row) {
203
- if (!attrs.onSelect) {
219
+ if (!$attrs.onSelect) {
204
220
  return;
205
221
  }
206
- attrs.onSelect(row);
222
+ $attrs.onSelect(row);
207
223
  }
208
224
  function selectAllRows() {
209
225
  props.rows.forEach((row) => {
210
- if (selected.value.some((item) => compare(toRaw(item), toRaw(row)))) {
226
+ if (isSelected(row)) {
211
227
  return;
212
228
  }
213
- onSelect(row);
229
+ selected.value.push(row);
214
230
  });
215
231
  }
216
232
  function onChange(event) {
@@ -224,10 +240,9 @@ export default defineComponent({
224
240
  return get(row, rowKey, defaultValue);
225
241
  }
226
242
  return {
227
- attrs: omit(attrs, ["class"]),
228
243
  // eslint-disable-next-line vue/no-dupe-keys
229
244
  ui,
230
- wrapperClass,
245
+ attrs,
231
246
  // eslint-disable-next-line vue/no-dupe-keys
232
247
  sort,
233
248
  // eslint-disable-next-line vue/no-dupe-keys
@@ -1,6 +1,5 @@
1
- /// <reference types="lodash" />
2
1
  import type { PropType } from 'vue';
3
- import type { Button } from '../../types/button';
2
+ import type { Button } from '../../types';
4
3
  declare function defaultComparator<T>(a: T, z: T): boolean;
5
4
  declare const _default: import("vue").DefineComponent<{
6
5
  modelValue: {
@@ -41,7 +40,7 @@ declare const _default: import("vue").DefineComponent<{
41
40
  };
42
41
  sortButton: {
43
42
  type: PropType<Button>;
44
- default: () => any;
43
+ default: () => Button;
45
44
  };
46
45
  sortAscIcon: {
47
46
  type: StringConstructor;
@@ -69,16 +68,19 @@ declare const _default: import("vue").DefineComponent<{
69
68
  }>;
70
69
  default: () => any;
71
70
  };
72
- ui: {
71
+ class: {
73
72
  type: PropType<any>;
74
- default: () => {};
73
+ default: undefined;
74
+ };
75
+ ui: {
76
+ type: PropType<Partial<any>>;
77
+ default: undefined;
75
78
  };
76
79
  }, {
77
- attrs: import("lodash").Omit<{
78
- [x: string]: unknown;
79
- }, "class">;
80
80
  ui: import("vue").ComputedRef<any>;
81
- wrapperClass: import("vue").ComputedRef<string>;
81
+ attrs: import("vue").ComputedRef<Pick<{
82
+ [x: string]: unknown;
83
+ }, string>>;
82
84
  sort: import("vue").Ref<{
83
85
  direction: string;
84
86
  column: string;
@@ -106,7 +108,7 @@ declare const _default: import("vue").DefineComponent<{
106
108
  onSelect: (row: any) => void;
107
109
  onChange: (event: any) => void;
108
110
  getRowData: (row: Object, rowKey: string | string[], defaultValue?: any) => any;
109
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update:modelValue"[], "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
111
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("update:modelValue" | "update:sort")[], "update:modelValue" | "update:sort", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
110
112
  modelValue: {
111
113
  type: ArrayConstructor;
112
114
  default: null;
@@ -145,7 +147,7 @@ declare const _default: import("vue").DefineComponent<{
145
147
  };
146
148
  sortButton: {
147
149
  type: PropType<Button>;
148
- default: () => any;
150
+ default: () => Button;
149
151
  };
150
152
  sortAscIcon: {
151
153
  type: StringConstructor;
@@ -173,18 +175,24 @@ declare const _default: import("vue").DefineComponent<{
173
175
  }>;
174
176
  default: () => any;
175
177
  };
176
- ui: {
178
+ class: {
177
179
  type: PropType<any>;
178
- default: () => {};
180
+ default: undefined;
181
+ };
182
+ ui: {
183
+ type: PropType<Partial<any>>;
184
+ default: undefined;
179
185
  };
180
186
  }>> & {
181
187
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
188
+ "onUpdate:sort"?: ((...args: any[]) => any) | undefined;
182
189
  }, {
183
190
  sort: {
184
191
  column: string;
185
192
  direction: 'asc' | 'desc';
186
193
  };
187
- ui: any;
194
+ ui: Partial<any>;
195
+ class: any;
188
196
  modelValue: unknown[];
189
197
  by: string | Function;
190
198
  rows: {
@@ -1,7 +1,14 @@
1
1
  <template>
2
- <div :class="wrapperClass">
2
+ <div :class="ui.wrapper">
3
3
  <HDisclosure v-for="(item, index) in items" v-slot="{ open, close }" :key="index" :default-open="defaultOpen || item.defaultOpen">
4
- <HDisclosureButton :ref="() => buttonRefs[index] = close" as="template" :disabled="item.disabled">
4
+ <HDisclosureButton
5
+ :ref="() => buttonRefs[index] = { open, close }"
6
+ as="template"
7
+ :disabled="item.disabled"
8
+ @click="closeOthers(index, $event)"
9
+ @keydown.enter="closeOthers(index, $event)"
10
+ @keydown.space="closeOthers(index, $event)"
11
+ >
5
12
  <slot :item="item" :index="index" :open="open" :close="close">
6
13
  <UButton v-bind="{ ...omit(ui.default, ['openIcon', 'closeIcon']), ...attrs, ...omit(item, ['slot', 'disabled', 'content', 'defaultOpen']) }">
7
14
  <template #trailing>
@@ -18,8 +25,6 @@
18
25
  </slot>
19
26
  </HDisclosureButton>
20
27
 
21
- <StateEmitter :open="open" @open="closeOthers(index)" />
22
-
23
28
  <Transition
24
29
  v-bind="ui.transition"
25
30
  @enter="onEnter"
@@ -40,24 +45,23 @@
40
45
  </template>
41
46
 
42
47
  <script>
43
- import { ref, computed, defineComponent } from "vue";
48
+ import { ref, computed, toRef, defineComponent } from "vue";
44
49
  import { Disclosure as HDisclosure, DisclosureButton as HDisclosureButton, DisclosurePanel as HDisclosurePanel } from "@headlessui/vue";
45
- import { omit } from "lodash-es";
46
- import { twMerge } from "tailwind-merge";
47
50
  import UIcon from "../elements/Icon.vue";
48
51
  import UButton from "../elements/Button.vue";
49
- import { defuTwMerge } from "../../utils";
50
- import StateEmitter from "../../utils/StateEmitter";
51
- import { useAppConfig } from "#imports";
52
+ import { useUI } from "../../composables/useUI";
53
+ import { mergeConfig, omit } from "../../utils";
52
54
  import appConfig from "#build/app.config";
55
+ import { accordion, button } from "#ui/ui.config";
56
+ const config = mergeConfig(appConfig.ui.strategy, appConfig.ui.accordion, accordion);
57
+ const configButton = mergeConfig(appConfig.ui.strategy, appConfig.ui.button, button);
53
58
  export default defineComponent({
54
59
  components: {
55
60
  HDisclosure,
56
61
  HDisclosureButton,
57
62
  HDisclosurePanel,
58
63
  UIcon,
59
- UButton,
60
- StateEmitter
64
+ UButton
61
65
  },
62
66
  inheritAttrs: false,
63
67
  props: {
@@ -71,35 +75,37 @@ export default defineComponent({
71
75
  },
72
76
  openIcon: {
73
77
  type: String,
74
- default: () => appConfig.ui.accordion.default.openIcon
78
+ default: () => config.default.openIcon
75
79
  },
76
80
  closeIcon: {
77
81
  type: String,
78
- default: () => appConfig.ui.accordion.default.closeIcon
82
+ default: () => config.default.closeIcon
79
83
  },
80
84
  multiple: {
81
85
  type: Boolean,
82
86
  default: false
83
87
  },
88
+ class: {
89
+ type: [String, Object, Array],
90
+ default: void 0
91
+ },
84
92
  ui: {
85
93
  type: Object,
86
- default: () => ({})
94
+ default: void 0
87
95
  }
88
96
  },
89
- setup(props, { attrs }) {
90
- const appConfig2 = useAppConfig();
91
- const ui = computed(() => defuTwMerge({}, props.ui, appConfig2.ui.accordion));
92
- const uiButton = computed(() => appConfig2.ui.button);
93
- const wrapperClass = computed(() => twMerge(ui.value.wrapper, attrs.class));
97
+ setup(props) {
98
+ const { ui, attrs } = useUI("accordion", toRef(props, "ui"), config, toRef(props, "class"));
99
+ const uiButton = computed(() => configButton);
94
100
  const buttonRefs = ref([]);
95
- function closeOthers(itemIndex) {
96
- if (!props.items[itemIndex].closeOthers && props.multiple) {
101
+ function closeOthers(currentIndex, e) {
102
+ if (!props.items[currentIndex].closeOthers && props.multiple) {
97
103
  return;
98
104
  }
99
- buttonRefs.value.forEach((close, index) => {
100
- if (index === itemIndex)
101
- return;
102
- close();
105
+ buttonRefs.value.forEach((button2) => {
106
+ if (button2.open) {
107
+ button2.close(e.target);
108
+ }
103
109
  });
104
110
  }
105
111
  function onEnter(el, done) {
@@ -120,11 +126,10 @@ export default defineComponent({
120
126
  el.addEventListener("transitionend", done, { once: true });
121
127
  }
122
128
  return {
123
- attrs: omit(attrs, ["class"]),
124
129
  // eslint-disable-next-line vue/no-dupe-keys
125
130
  ui,
126
131
  uiButton,
127
- wrapperClass,
132
+ attrs,
128
133
  buttonRefs,
129
134
  closeOthers,
130
135
  omit,
@@ -1,6 +1,6 @@
1
- /// <reference types="lodash" />
2
1
  import type { PropType } from 'vue';
3
- import type { AccordionItem } from '../../types/accordion';
2
+ import { omit } from '../../utils';
3
+ import type { AccordionItem } from '../../types';
4
4
  declare const _default: import("vue").DefineComponent<{
5
5
  items: {
6
6
  type: PropType<AccordionItem[]>;
@@ -22,24 +22,26 @@ declare const _default: import("vue").DefineComponent<{
22
22
  type: BooleanConstructor;
23
23
  default: boolean;
24
24
  };
25
- ui: {
25
+ class: {
26
26
  type: PropType<any>;
27
- default: () => {};
27
+ default: undefined;
28
+ };
29
+ ui: {
30
+ type: PropType<Partial<any>>;
31
+ default: undefined;
28
32
  };
29
33
  }, {
30
- attrs: import("lodash").Omit<{
31
- [x: string]: unknown;
32
- }, "class">;
33
34
  ui: import("vue").ComputedRef<any>;
34
35
  uiButton: import("vue").ComputedRef<any>;
35
- wrapperClass: import("vue").ComputedRef<string>;
36
- buttonRefs: import("vue").Ref<Function[]>;
37
- closeOthers: (itemIndex: number) => void;
38
- omit: {
39
- <T extends object, K extends import("lodash").PropertyName[]>(object: T | null | undefined, ...paths: K): Pick<T, Exclude<keyof T, K[number]>>;
40
- <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>;
41
- <T_2 extends object>(object: T_2 | null | undefined, ...paths: import("lodash").Many<import("lodash").PropertyName>[]): Partial<T_2>;
42
- };
36
+ attrs: import("vue").ComputedRef<Pick<{
37
+ [x: string]: unknown;
38
+ }, string>>;
39
+ buttonRefs: import("vue").Ref<{
40
+ open: boolean;
41
+ close: (e: EventTarget) => {};
42
+ }[]>;
43
+ closeOthers: (currentIndex: number, e: Event) => void;
44
+ omit: typeof omit;
43
45
  onEnter: (el: HTMLElement, done: any) => void;
44
46
  onBeforeLeave: (el: HTMLElement) => void;
45
47
  onAfterEnter: (el: HTMLElement) => void;
@@ -65,12 +67,17 @@ declare const _default: import("vue").DefineComponent<{
65
67
  type: BooleanConstructor;
66
68
  default: boolean;
67
69
  };
68
- ui: {
70
+ class: {
69
71
  type: PropType<any>;
70
- default: () => {};
72
+ default: undefined;
73
+ };
74
+ ui: {
75
+ type: PropType<Partial<any>>;
76
+ default: undefined;
71
77
  };
72
78
  }>>, {
73
- ui: any;
79
+ ui: Partial<any>;
80
+ class: any;
74
81
  defaultOpen: boolean;
75
82
  items: AccordionItem[];
76
83
  openIcon: string;