vueless 0.0.781 → 0.0.783

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.781",
3
+ "version": "0.0.783",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -1,4 +1,4 @@
1
- import { Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source } from "@storybook/blocks";
1
+ import { Markdown, Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source } from "@storybook/blocks";
2
2
  import { getSource } from "../../utils/storybook.ts";
3
3
 
4
4
  import * as stories from "./stories.ts";
@@ -12,5 +12,22 @@ import defaultConfig from "../config.ts?raw"
12
12
  <Controls of={stories.Default} />
13
13
  <Stories of={stories} />
14
14
 
15
+ ## Option meta keys
16
+ Keys you may/have to provide to the component in an option object.
17
+
18
+ <Markdown>
19
+ {`
20
+ | Key name | Description | Type |
21
+ | ------------------| ----------------------------------------------- | ------------------------|
22
+ | value | Option value | String, Number, Boolean |
23
+ | label | Option label | String |
24
+ | disabled | Indicates if option is disabled | Boolean |
25
+ | icon | Icon name which appears instead of option label.| String |
26
+ | leftIcon | Option left icon name | String |
27
+ | rightIcon | Option right icon name | String |
28
+ | onClick | Option event handler | Function |
29
+ `}
30
+ </Markdown>
31
+
15
32
  ## Default config
16
33
  <Source code={getSource(defaultConfig)} language="jsx" dark />
@@ -140,16 +140,16 @@ export const OptionSlot = DefaultTemplate.bind({});
140
140
  OptionSlot.args = {
141
141
  name: "optionSlot",
142
142
  options: [
143
- { value: "1", label: "Download", rightIcon: "download", color: "green" },
144
- { value: "2", label: "Edit", rightIcon: "edit_note", color: "orange" },
145
- { value: "3", label: "Delete", rightIcon: "delete", color: "red" },
143
+ { value: "1", label: "Download", iconName: "download", color: "green" },
144
+ { value: "2", label: "Edit", iconName: "edit_note", color: "orange" },
145
+ { value: "3", label: "Delete", iconName: "delete", color: "red" },
146
146
  ],
147
147
  slotTemplate: `
148
148
  <template #option="{ label, index }">
149
149
  <UBadge
150
150
  :label="label"
151
151
  :color="args.options[index].color"
152
- :right-icon="args.options[index].rightIcon"
152
+ :right-icon="args.options[index].iconName"
153
153
  />
154
154
  </template>
155
155
  `,
@@ -16,7 +16,7 @@ import defaultConfig from "../config.ts?raw"
16
16
  Each character in the table below can be used in `dateFormat` and `userDateFormat` / `userDateTimeFormat` options to achieve the format you need.
17
17
 
18
18
  ## Row meta keys
19
- Keys you have/may to provide to component in row object.
19
+ Keys you have/may to provide to the component in row object.
20
20
 
21
21
  <Markdown>
22
22
  {`
@@ -13,7 +13,7 @@ import defaultConfig from "../config.ts?raw"
13
13
  <Stories of={stories} />
14
14
 
15
15
  ## Option meta keys
16
- Keys you may/have to provide to component in an option object.
16
+ Keys you may/have to provide to the component in an option object.
17
17
 
18
18
  <Markdown>
19
19
  {`
@@ -13,7 +13,7 @@ import defaultConfig from "../config.ts?raw"
13
13
  <Stories of={stories} />
14
14
 
15
15
  ## Option meta keys
16
- Keys you may/have to provide to component in an option object.
16
+ Keys you may/have to provide to the component in an option object.
17
17
 
18
18
  <Markdown>
19
19
  {`
@@ -13,7 +13,7 @@ import defaultConfig from "../config.ts?raw"
13
13
  <Stories of={stories} />
14
14
 
15
15
  ## Option meta keys
16
- Full list of keys you may/have to provide to component in an option object can be found here: [UCheckbox docs](https://ui.vueless.com/?path=/docs/3100--docs).
16
+ Full list of keys you may/have to provide to the component in an option object can be found here: <a href="https://ui.vueless.com/?path=/docs/3100--docs" target="_blank">UCheckbox docs</a>.
17
17
 
18
18
  ## Default config
19
19
  <Source code={getSource(defaultConfig)} language="jsx" dark />
@@ -36,10 +36,10 @@ const emit = defineEmits([
36
36
  "update:modelValue",
37
37
 
38
38
  /**
39
- * Triggers when the input has not passed validation.
39
+ * Triggers error changes.
40
40
  * @property {string} value
41
41
  */
42
- "update:error",
42
+ "error",
43
43
  ]);
44
44
 
45
45
  const { tm } = useLocale();
@@ -47,6 +47,8 @@ const { tm } = useLocale();
47
47
  const dropZoneRef = ref<HTMLDivElement | null>(null);
48
48
  const fileInputRef = ref<HTMLInputElement | null>(null);
49
49
 
50
+ const localError = ref("");
51
+
50
52
  const elementId = props.id || useId();
51
53
 
52
54
  const i18nGlobal = tm(COMPONENT_NAME);
@@ -61,10 +63,7 @@ const currentFiles = computed<File | File[] | null>({
61
63
  },
62
64
  });
63
65
 
64
- const currentError = computed({
65
- get: () => props.error,
66
- set: (newValue) => emit("update:error", newValue),
67
- });
66
+ const currentError = computed(() => localError.value || props.error);
68
67
 
69
68
  const extensionNames = computed(() => {
70
69
  return props.allowedFileTypes.map((type) => type.replace(".", ""));
@@ -105,6 +104,7 @@ onBeforeUnmount(() => {
105
104
  });
106
105
 
107
106
  watch(() => props.multiple, normalizeFilesForMultipleMode);
107
+ watch(currentError, () => emit("error", currentError.value));
108
108
 
109
109
  function normalizeFilesForMultipleMode() {
110
110
  if (!props.multiple) return;
@@ -131,13 +131,19 @@ function validate(file: File) {
131
131
 
132
132
  const isValidSize = Number(targetFileSize) <= props.maxFileSize;
133
133
 
134
- if (!isValidSize && props.maxFileSize) {
135
- currentError.value = currentLocale.value.sizeError;
134
+ if (!isValidType) {
135
+ localError.value = currentLocale.value.formatError;
136
+
137
+ return;
136
138
  }
137
139
 
138
- if (!isValidType) {
139
- currentError.value = currentLocale.value.formatError;
140
+ if (!isValidSize && props.maxFileSize) {
141
+ localError.value = currentLocale.value.sizeError;
142
+
143
+ return;
140
144
  }
145
+
146
+ localError.value = "";
141
147
  }
142
148
 
143
149
  function onChangeFile(event: Event) {
@@ -242,10 +248,18 @@ function onClickRemoveItem(id: string | number) {
242
248
  * Applies: `class`, `config`, redefined default `props` and dev `vl-...` attributes.
243
249
  */
244
250
  const mutatedProps = computed(() => ({
245
- error: Boolean(props.error),
251
+ error: Boolean(currentError.value),
246
252
  label: Boolean(props.label),
247
253
  }));
248
254
 
255
+ defineExpose({
256
+ /**
257
+ * An error.
258
+ * @property {boolean}
259
+ */
260
+ error: currentError,
261
+ });
262
+
249
263
  const {
250
264
  getDataTest,
251
265
  config,
@@ -260,6 +274,8 @@ const {
260
274
  inputAttrs,
261
275
  fileListAttrs,
262
276
  buttonsAttrs,
277
+ chooseFileButtonErrorAttrs,
278
+ clearButtonErrorAttrs,
263
279
  } = useUI<Config>(defaultConfig, mutatedProps);
264
280
  </script>
265
281
 
@@ -268,7 +284,7 @@ const {
268
284
  :for="elementId"
269
285
  :size="size"
270
286
  :label="label"
271
- :error="error"
287
+ :error="currentError"
272
288
  :align="labelAlign"
273
289
  :disabled="disabled"
274
290
  :description="description"
@@ -316,11 +332,10 @@ const {
316
332
  :for="elementId"
317
333
  tag="label"
318
334
  variant="thirdary"
319
- :color="error ? 'red' : 'brand'"
320
335
  :right-icon="config.defaults.chooseFileIcon"
321
336
  :label="currentLocale.uploadFile"
322
337
  :disabled="disabled"
323
- v-bind="chooseFileButtonAttrs"
338
+ v-bind="currentError ? chooseFileButtonErrorAttrs : chooseFileButtonAttrs"
324
339
  :data-test="getDataTest('upload')"
325
340
  />
326
341
 
@@ -343,9 +358,8 @@ const {
343
358
  filled
344
359
  variant="thirdary"
345
360
  :disabled="disabled"
346
- :color="error ? 'red' : 'brand'"
347
361
  :left-icon="config.defaults.clearIcon"
348
- v-bind="clearButtonAttrs"
362
+ v-bind="currentError ? clearButtonErrorAttrs : clearButtonAttrs"
349
363
  :data-test="getDataTest('clear')"
350
364
  @click="onClickResetFiles"
351
365
  />
@@ -65,6 +65,12 @@ export default /*tw*/ {
65
65
  },
66
66
  },
67
67
  },
68
+ chooseFileButtonError: {
69
+ base: "{>chooseFileButton}",
70
+ defaults: {
71
+ color: "red",
72
+ },
73
+ },
68
74
  clearButton: {
69
75
  base: "{UButton}",
70
76
  defaults: {
@@ -75,6 +81,12 @@ export default /*tw*/ {
75
81
  },
76
82
  },
77
83
  },
84
+ clearButtonError: {
85
+ base: "{>clearButton}",
86
+ defaults: {
87
+ color: "red",
88
+ },
89
+ },
78
90
  input: "sr-only",
79
91
  i18n: {
80
92
  sizeError: "File size is too big.",
@@ -13,7 +13,7 @@ import defaultConfig from "../config.ts?raw"
13
13
  <Stories of={stories} />
14
14
 
15
15
  ## Option meta keys
16
- Full list of keys you may/have to provide to component in an option object can be found here: [UDropdownList docs](https://ui.vueless.com/?path=/docs/2050--docs).
16
+ Full list of keys you may/have to provide to the component in an option object can be found here: <a href="https://ui.vueless.com/?path=/docs/2050--docs" target="_blank">UDropdownList docs</a>.
17
17
 
18
18
  ## Default config
19
19
  <Source code={getSource(defaultConfig)} language="jsx" dark />