vueless 0.0.488 → 0.0.490

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.488",
3
+ "version": "0.0.490",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
package/plugin-vite.js CHANGED
@@ -36,7 +36,7 @@ export const Vueless = function (options = {}) {
36
36
  /* if server stopped by developer (Ctrl+C) */
37
37
  process.on("SIGINT", async () => {
38
38
  /* remove dynamically copied icons */
39
- await removeIcons({ debug, isNuxt });
39
+ await removeIcons({ debug });
40
40
 
41
41
  /* clear tailwind safelist */
42
42
  clearTailwindSafelist(debug);
@@ -63,22 +63,22 @@ export const Vueless = function (options = {}) {
63
63
  }
64
64
 
65
65
  if (config.command === "build") {
66
- await removeIcons({ debug, isNuxt });
66
+ await removeIcons({ debug });
67
67
 
68
68
  /* dynamically copy used icons before build */
69
69
  await copyIcons({ mode: "vuelessIcons", env, debug, targetFiles });
70
- await copyIcons({ mode, env, debug, targetFiles, isNuxt });
70
+ await copyIcons({ mode, env, debug, targetFiles });
71
71
  }
72
72
 
73
73
  if (config.command === "dev" || config.command === "serve") {
74
74
  /* remove dynamically copied icons on dev server start */
75
- await removeIcons({ debug, isNuxt });
75
+ await removeIcons({ debug });
76
76
  }
77
77
  },
78
78
 
79
79
  /* remove dynamically copied icons after build */
80
80
  buildEnd: async () => {
81
- await removeIcons({ debug, isNuxt });
81
+ await removeIcons({ debug });
82
82
  },
83
83
 
84
84
  /* load SVG images as a Vue components */
package/types.ts CHANGED
@@ -5,6 +5,7 @@ import UTextDefaultConfig from "./ui.text-block/config.ts";
5
5
  import UButtonDefaultConfig from "./ui.button/config.ts";
6
6
  import UBadgeDefaultConfig from "./ui.text-badge/config.ts";
7
7
  import UCalendarDefaultConfig from "./ui.form-calendar/config.ts";
8
+ import UDatePickerConfig from "./ui.form-date-picker/config.ts";
8
9
 
9
10
  import type { ComputedRef, MaybeRef, Ref } from "vue";
10
11
  import type { Props } from "tippy.js";
@@ -115,6 +116,7 @@ export interface Components {
115
116
  UButton?: Partial<typeof UButtonDefaultConfig>;
116
117
  UBadge?: Partial<typeof UBadgeDefaultConfig>;
117
118
  UCalendar?: Partial<typeof UCalendarDefaultConfig>;
119
+ UDatePicker?: Partial<typeof UDatePickerConfig>;
118
120
  }
119
121
 
120
122
  export interface Directives {
@@ -110,7 +110,7 @@ const {
110
110
  timepickerSubmitButtonAttrs,
111
111
  } = useAttrs(props);
112
112
 
113
- const wrapperRef = useTemplateRef<HTMLInputElement>("wrapper");
113
+ const wrapperRef = useTemplateRef<HTMLDivElement>("wrapper");
114
114
  const hoursRef = useTemplateRef<HTMLInputElement>("hours-input");
115
115
  const minutesRef = useTemplateRef<HTMLInputElement>("minutes-input");
116
116
  const secondsRef = useTemplateRef<HTMLInputElement>("seconds-input");
@@ -55,12 +55,6 @@ export const LOCALE_TYPE = {
55
55
  month: "month",
56
56
  };
57
57
 
58
- export const VIEW = {
59
- day: "day",
60
- month: "month",
61
- year: "year",
62
- };
63
-
64
58
  export const ARROW_KEYS: string[] = [
65
59
  KeyCode.ArrowLeft,
66
60
  KeyCode.ArrowUp,
@@ -1,90 +1,16 @@
1
- <template>
2
- <div v-bind="wrapperAttrs" ref="wrapperRef">
3
- <UInput
4
- :id="elementId"
5
- :key="isShownCalendar"
6
- v-model="userFormatDate"
7
- :label-align="labelAlign"
8
- :label="label"
9
- :placeholder="placeholder"
10
- :error="error"
11
- :description="description"
12
- readonly
13
- :disabled="disabled"
14
- :size="size"
15
- :left-icon="leftIcon"
16
- :right-icon="rightIcon"
17
- v-bind="isShownCalendar ? activeInputAttrs : inputAttrs"
18
- @focus="activate"
19
- >
20
- <template #left>
21
- <!-- @slot Use it add something before the date. -->
22
- <slot name="left" />
23
- </template>
24
-
25
- <template #left-icon="{ iconName, iconSize }">
26
- <!--
27
- @slot Use it add an icon before the date.
28
- @binding {string} icon-name
29
- @binding {string} icon-nize
30
- -->
31
- <slot name="left-icon" :icon-name="iconName" :icon-size="iconSize" />
32
- </template>
33
-
34
- <template #right-icon="{ iconName, iconSize }">
35
- <!--
36
- @slot Use it add an icon after the date.
37
- @binding {string} icon-name
38
- @binding {string} icon-size
39
- -->
40
- <slot name="right-icon" :icon-name="iconName" :icon-size="iconSize">
41
- <UIcon :name="iconName" :size="iconSize" color="gray" />
42
- </slot>
43
- </template>
44
-
45
- <template #right>
46
- <!-- @slot Use it add something after the date. -->
47
- <slot name="right" />
48
- </template>
49
- </UInput>
50
-
51
- <Transition v-bind="config.calendarTransition">
52
- <UCalendar
53
- v-show="isShownCalendar"
54
- ref="calendarRef"
55
- v-model="localValue"
56
- v-model:view="customView"
57
- tabindex="-1"
58
- :timepicker="timepicker"
59
- :date-format="dateFormat"
60
- :date-time-format="dateTimeFormat"
61
- :user-date-format="userDateFormat"
62
- :user-date-time-format="userDateTimeFormat"
63
- :max-date="maxDate"
64
- :min-date="minDate"
65
- v-bind="calendarAttrs"
66
- @keydown.esc="deactivate"
67
- @user-date-change="onUserFormatDateChange"
68
- @input="onInput"
69
- @blur="onBlur"
70
- @submit="onSubmit"
71
- />
72
- </Transition>
73
- </div>
74
- </template>
75
-
76
- <script setup>
77
- import { computed, nextTick, ref, useId } from "vue";
1
+ <script setup lang="ts">
2
+ import { computed, nextTick, ref, useId, useTemplateRef } from "vue";
78
3
  import { merge } from "lodash-es";
79
4
 
80
5
  import UIcon from "../ui.image-icon/UIcon.vue";
81
6
  import UInput from "../ui.form-input/UInput.vue";
82
7
  import UCalendar from "../ui.form-calendar/UCalendar.vue";
83
- import { VIEW, STANDARD_USER_FORMAT } from "../ui.form-calendar/constants.ts";
8
+ import { View, STANDARD_USER_FORMAT } from "../ui.form-calendar/constants.js";
84
9
 
85
10
  import { getDefault } from "../utils/ui.ts";
86
11
 
87
- import { addDays, isSameDay } from "../ui.form-calendar/utilDate.ts";
12
+ import { addDays, isSameDay } from "../ui.form-calendar/utilDate.js";
13
+ import { parseDate } from "../ui.form-calendar/utilCalendar.ts";
88
14
 
89
15
  import useAttrs from "./useAttrs.js";
90
16
  import { useLocale } from "../composables/useLocale.ts";
@@ -93,188 +19,25 @@ import { useAutoPosition } from "../composables/useAutoPosition.ts";
93
19
  import defaultConfig from "./config.js";
94
20
  import { UDatePicker } from "./constants.js";
95
21
 
96
- defineOptions({ inheritAttrs: false });
97
-
98
- const props = defineProps({
99
- /**
100
- * Datepicker value (JavaScript Date object or string formatted in given `dateFormat`).
101
- */
102
- modelValue: {
103
- type: [Date, String],
104
- default: null,
105
- },
106
-
107
- /**
108
- * Datepicker label.
109
- */
110
- label: {
111
- type: String,
112
- default: "",
113
- },
114
-
115
- /**
116
- * Datepicker label placement.
117
- * @values top, topInside, topWithDesc, left, right
118
- */
119
- labelAlign: {
120
- type: String,
121
- default: getDefault(defaultConfig, UDatePicker).labelAlign,
122
- },
123
-
124
- /**
125
- * Datepicker placeholder.
126
- */
127
- placeholder: {
128
- type: String,
129
- default: "",
130
- },
131
-
132
- /**
133
- * Datepicker description.
134
- */
135
- description: {
136
- type: String,
137
- default: "",
138
- },
139
-
140
- /**
141
- * Datepicker error message.
142
- */
143
- error: {
144
- type: String,
145
- default: "",
146
- },
147
-
148
- /**
149
- * Datepicker size.
150
- * @values sm, md, lg
151
- */
152
- size: {
153
- type: String,
154
- default: getDefault(defaultConfig, UDatePicker).size,
155
- },
156
-
157
- /**
158
- * Datepicker open direction on x-axis.
159
- * @values auto, left, right
160
- */
161
- openDirectionX: {
162
- type: String,
163
- default: getDefault(defaultConfig, UDatePicker).openDirectionX,
164
- },
165
-
166
- /**
167
- * Datepicker open direction on y-axis.
168
- * @values auto, top, bottom
169
- */
170
- openDirectionY: {
171
- type: String,
172
- default: getDefault(defaultConfig, UDatePicker).openDirectionY,
173
- },
174
-
175
- /**
176
- * Min date (JavaScript Date object or string formatted in given `dateFormat`).
177
- */
178
- minDate: {
179
- type: [Date, String],
180
- default: getDefault(defaultConfig, UDatePicker).minDate,
181
- },
182
-
183
- /**
184
- * Max date (JavaScript Date object or string formatted in given `dateFormat`).
185
- */
186
- maxDate: {
187
- type: [Date, String],
188
- default: getDefault(defaultConfig, UDatePicker).maxDate,
189
- },
190
-
191
- /**
192
- * Date string format.
193
- */
194
- dateFormat: {
195
- type: String,
196
- default: getDefault(defaultConfig, UDatePicker).dateFormat,
197
- },
198
-
199
- /**
200
- * Same as date format, but used when timepicker is enabled.
201
- */
202
- dateTimeFormat: {
203
- type: String,
204
- default: getDefault(defaultConfig, UDatePicker).dateTimeFormat,
205
- },
206
-
207
- /**
208
- * User-friendly date format (it will be shown in UI).
209
- */
210
- userDateFormat: {
211
- type: String,
212
- default: getDefault(defaultConfig, UDatePicker).userDateFormat,
213
- },
22
+ import type { UDatePickerProps } from "./types.ts";
214
23
 
215
- /**
216
- * Same as user format, but used when timepicker is enabled.
217
- */
218
- userDateTimeFormat: {
219
- type: String,
220
- default: getDefault(defaultConfig, UDatePicker).userDateTimeFormat,
221
- },
222
-
223
- /**
224
- * Left icon name.
225
- */
226
- leftIcon: {
227
- type: String,
228
- default: "",
229
- },
230
-
231
- /**
232
- * Right icon name.
233
- */
234
- rightIcon: {
235
- type: String,
236
- default: getDefault(defaultConfig, UDatePicker).rightIcon,
237
- },
238
-
239
- /**
240
- * Make datepicker disabled.
241
- */
242
- disabled: {
243
- type: Boolean,
244
- default: getDefault(defaultConfig, UDatePicker).disabled,
245
- },
246
-
247
- /**
248
- * Show timepicker.
249
- */
250
- timepicker: {
251
- type: Boolean,
252
- default: getDefault(defaultConfig, UDatePicker).timepicker,
253
- },
254
-
255
- /**
256
- * Unique element id.
257
- */
258
- id: {
259
- type: String,
260
- default: "",
261
- },
262
-
263
- /**
264
- * Component config object.
265
- */
266
- config: {
267
- type: Object,
268
- default: () => ({}),
269
- },
24
+ defineOptions({ inheritAttrs: false });
270
25
 
271
- /**
272
- * Data-test attribute for automated testing.
273
- */
274
- dataTest: {
275
- type: String,
276
- default: "",
277
- },
26
+ const props = withDefaults(defineProps<UDatePickerProps>(), {
27
+ labelAlign: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).labelAlign,
28
+ size: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).size,
29
+ openDirectionX: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).openDirectionX,
30
+ openDirectionY: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).openDirectionY,
31
+ timepicker: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).timepicker,
32
+ dateFormat: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).dateFormat,
33
+ dateTimeFormat: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).dateTimeFormat,
34
+ userDateFormat: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).userDateFormat,
35
+ userDateTimeFormat: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).userDateTimeFormat,
36
+ leftIcon: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).leftIcon,
37
+ rightIcon: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).rightIcon,
38
+ disabled: getDefault<UDatePickerProps>(defaultConfig, UDatePicker).disabled,
39
+ dataTest: "",
40
+ config: () => ({}),
278
41
  });
279
42
 
280
43
  const emit = defineEmits([
@@ -298,12 +61,12 @@ const i18nGlobal = tm(UDatePicker);
298
61
  const isShownCalendar = ref(false);
299
62
  const userFormatDate = ref("");
300
63
  const formattedDate = ref("");
301
- const customView = ref(VIEW.day);
64
+ const customView = ref(View.Day);
302
65
 
303
- const wrapperRef = ref(null);
304
- const calendarRef = ref(null);
66
+ const wrapperRef = useTemplateRef<HTMLDivElement>("wrapper");
67
+ const calendarRef = useTemplateRef<InstanceType<typeof UCalendar>>("calendar");
305
68
 
306
- const calendarWrapperRef = computed(() => calendarRef?.value?.wrapperRef);
69
+ const calendarWrapperRef = computed(() => calendarRef?.value?.wrapperRef || null);
307
70
 
308
71
  const { isTop, isRight, adjustPositionY, adjustPositionX } = useAutoPosition(
309
72
  wrapperRef,
@@ -322,7 +85,6 @@ const currentLocale = computed(() => merge(defaultConfig.i18n, i18nGlobal, props
322
85
  const elementId = props.id || useId();
323
86
 
324
87
  const { config, inputAttrs, activeInputAttrs, calendarAttrs, wrapperAttrs } = useAttrs(props, {
325
- isShownCalendar,
326
88
  isTop,
327
89
  isRight,
328
90
  });
@@ -334,17 +96,17 @@ function activate() {
334
96
  adjustPositionY();
335
97
  adjustPositionX();
336
98
 
337
- calendarRef.value.wrapperRef.focus();
99
+ calendarRef.value?.wrapperRef?.focus();
338
100
  });
339
101
  }
340
102
 
341
103
  function deactivate() {
342
104
  isShownCalendar.value = false;
343
105
 
344
- customView.value = VIEW.day;
106
+ customView.value = View.Day;
345
107
  }
346
108
 
347
- function onUserFormatDateChange(value) {
109
+ function onUserFormatDateChange(value: string) {
348
110
  userFormatDate.value = formatUserDate(value) || "";
349
111
  }
350
112
 
@@ -352,13 +114,13 @@ function onSubmit() {
352
114
  deactivate();
353
115
  }
354
116
 
355
- function onBlur(event) {
117
+ function onBlur(event: FocusEvent) {
356
118
  const { relatedTarget } = event;
357
119
 
358
- if (!calendarRef?.value?.wrapperRef?.contains(relatedTarget)) deactivate();
120
+ if (!calendarRef?.value?.wrapperRef?.contains(relatedTarget as HTMLElement)) deactivate();
359
121
  }
360
122
 
361
- function formatUserDate(data) {
123
+ function formatUserDate(data: string) {
362
124
  if (props.userDateFormat !== STANDARD_USER_FORMAT || props.timepicker) return data;
363
125
 
364
126
  let prefix = "";
@@ -367,9 +129,10 @@ function formatUserDate(data) {
367
129
 
368
130
  const today = new Date();
369
131
 
370
- const isToday = isSameDay(today, localValue.value);
371
- const isYesterday = isSameDay(addDays(today, -1), localValue.value);
372
- const isTomorrow = isSameDay(addDays(today, 1), localValue.value);
132
+ const parsedLocalDate = parseDate(localValue.value, props.dateFormat, currentLocale.value);
133
+ const isToday = parsedLocalDate && isSameDay(today, parsedLocalDate);
134
+ const isYesterday = parsedLocalDate && isSameDay(addDays(today, -1), parsedLocalDate);
135
+ const isTomorrow = parsedLocalDate && isSameDay(addDays(today, 1), parsedLocalDate);
373
136
 
374
137
  if (isToday) {
375
138
  prefix = currentLocale.value.today;
@@ -413,3 +176,78 @@ defineExpose({
413
176
  formattedDate,
414
177
  });
415
178
  </script>
179
+
180
+ <template>
181
+ <div v-bind="wrapperAttrs" ref="wrapper">
182
+ <UInput
183
+ :id="elementId"
184
+ :key="String(isShownCalendar)"
185
+ v-model="userFormatDate"
186
+ :label-align="labelAlign"
187
+ :label="label"
188
+ :placeholder="placeholder"
189
+ :error="error"
190
+ :description="description"
191
+ readonly
192
+ :disabled="disabled"
193
+ :size="size"
194
+ :left-icon="leftIcon"
195
+ :right-icon="rightIcon"
196
+ v-bind="isShownCalendar ? activeInputAttrs : inputAttrs"
197
+ @focus="activate"
198
+ >
199
+ <template #left>
200
+ <!-- @slot Use it add something before the date. -->
201
+ <slot name="left" />
202
+ </template>
203
+
204
+ <template #left-icon="{ iconName, iconSize }">
205
+ <!--
206
+ @slot Use it add an icon before the date.
207
+ @binding {string} icon-name
208
+ @binding {string} icon-nize
209
+ -->
210
+ <slot name="left-icon" :icon-name="iconName" :icon-size="iconSize" />
211
+ </template>
212
+
213
+ <template #right-icon="{ iconName, iconSize }">
214
+ <!--
215
+ @slot Use it add an icon after the date.
216
+ @binding {string} icon-name
217
+ @binding {string} icon-size
218
+ -->
219
+ <slot name="right-icon" :icon-name="iconName" :icon-size="iconSize">
220
+ <UIcon :name="iconName" :size="iconSize" color="gray" />
221
+ </slot>
222
+ </template>
223
+
224
+ <template #right>
225
+ <!-- @slot Use it add something after the date. -->
226
+ <slot name="right" />
227
+ </template>
228
+ </UInput>
229
+
230
+ <Transition v-bind="config.calendarTransition">
231
+ <UCalendar
232
+ v-show="isShownCalendar"
233
+ ref="calendarRef"
234
+ v-model="localValue"
235
+ v-model:view="customView"
236
+ tabindex="-1"
237
+ :timepicker="timepicker"
238
+ :date-format="dateFormat"
239
+ :date-time-format="dateTimeFormat"
240
+ :user-date-format="userDateFormat"
241
+ :user-date-time-format="userDateTimeFormat"
242
+ :max-date="maxDate"
243
+ :min-date="minDate"
244
+ v-bind="calendarAttrs"
245
+ @keydown.esc="deactivate"
246
+ @user-date-change="onUserFormatDateChange"
247
+ @input="onInput"
248
+ @blur="onBlur"
249
+ @submit="onSubmit"
250
+ />
251
+ </Transition>
252
+ </div>
253
+ </template>
@@ -0,0 +1,53 @@
1
+ import { Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source, Markdown } from "@storybook/blocks";
2
+ import { getSource } from "../../utils/storybook.ts";
3
+
4
+ import * as stories from "./stories.ts";
5
+ import defaultConfig from "../config.ts?raw"
6
+
7
+ <Meta of={stories} />
8
+ <Title of={stories} />
9
+ <Subtitle of={stories} />
10
+ <Description of={stories} />
11
+ <Primary of={stories} />
12
+ <Controls of={stories.Default} />
13
+ <Stories of={stories} />
14
+
15
+ ## Default config
16
+ <Source code={getSource(defaultConfig)} language="jsx" dark />
17
+
18
+ ## Formatting tokens
19
+ Each character in the table below can be used in `dateFormat` / `dateTimeFormat` and `userDateFormat` / `userDateTimeFormat` options
20
+ to achieve the format you need.
21
+
22
+ <Markdown>
23
+ {`
24
+ | Token | Description | Example |
25
+ | ----- | --------------------------------------------------------- | ------------------------------------------------------------- |
26
+ | d | Day of the month, 2 digits with leading zeros | 01 to 31 |
27
+ | D | A textual representation of a day | Mon through Sun |
28
+ | l | A full textual representation of the day of the week | Sunday through Saturday |
29
+ | j | Day of the month without leading zeros | 1 to 31 |
30
+ | J | Day of the month without leading zeros and ordinal suffix | 1st, 2nd, to 31st |
31
+ | w | Numeric representation of the day of the week | 0 (for Sunday) through 6 (for Saturday) |
32
+ | W | Numeric representation of the week | 0 (first week of the year) through 52 (last week of the year) |
33
+ | F | A full textual representation of a month | January through December |
34
+ | m | Numeric representation of a month, with leading zero | 01 through 12 |
35
+ | n | Numeric representation of a month, without leading zeros | 1 through 12 |
36
+ | M | A short textual representation of a month | Jan through Dec |
37
+ | U | A short textual representation of a month | 1413704993 |
38
+ | y | A two-digit representation of a year | 99 or 03 |
39
+ | Y | A full numeric representation of a year, 4 digits | 1999 or 2003 |
40
+ | Z | ISO Date format | 2017-03-04T01:23:43.000Z |
41
+ | H | Hours (24 hours) | 00 to 23 |
42
+ | h | Hours | 1 to 12 |
43
+ | G | Hours, 2 digits with leading zeros | 1 to 12 |
44
+ | i | Minutes | 00 to 59 |
45
+ | S | Seconds, 2 digits | 00 to 59 |
46
+ | s | Seconds | 0, 1 to 59 |
47
+ `}
48
+ </Markdown>
49
+
50
+ ## Escaping Formatting Tokens
51
+ You may escape formatting tokens using `\\`.
52
+
53
+ <Source code={`dateFormat: "Y-m-d\\Z", // Displays: 2017-01-22Z`} language="jsx" dark />