@flux-ui/components 3.0.0-next.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 (261) hide show
  1. package/README.md +45 -0
  2. package/package.json +77 -0
  3. package/src/component/FluxAction.vue +27 -0
  4. package/src/component/FluxActionBar.vue +94 -0
  5. package/src/component/FluxActionPane.vue +40 -0
  6. package/src/component/FluxActions.vue +27 -0
  7. package/src/component/FluxAlert.vue +37 -0
  8. package/src/component/FluxAnimatedColors.vue +141 -0
  9. package/src/component/FluxAspectRatio.vue +21 -0
  10. package/src/component/FluxAutoGrid.vue +27 -0
  11. package/src/component/FluxAvatar.vue +119 -0
  12. package/src/component/FluxBadge.vue +84 -0
  13. package/src/component/FluxBadgeStack.vue +18 -0
  14. package/src/component/FluxBorderShine.vue +36 -0
  15. package/src/component/FluxBoxedIcon.vue +36 -0
  16. package/src/component/FluxButton.vue +110 -0
  17. package/src/component/FluxButtonGroup.vue +15 -0
  18. package/src/component/FluxButtonStack.vue +28 -0
  19. package/src/component/FluxCalendar.vue +254 -0
  20. package/src/component/FluxCalendarEvent.vue +41 -0
  21. package/src/component/FluxCheckbox.vue +60 -0
  22. package/src/component/FluxChip.vue +57 -0
  23. package/src/component/FluxClickablePane.vue +61 -0
  24. package/src/component/FluxColorPicker.vue +265 -0
  25. package/src/component/FluxColorSelect.vue +81 -0
  26. package/src/component/FluxComment.vue +71 -0
  27. package/src/component/FluxConfirm.vue +42 -0
  28. package/src/component/FluxContainer.vue +23 -0
  29. package/src/component/FluxDataTable.vue +96 -0
  30. package/src/component/FluxDatePicker.vue +353 -0
  31. package/src/component/FluxDestructiveButton.vue +28 -0
  32. package/src/component/FluxDisabled.vue +22 -0
  33. package/src/component/FluxDivider.vue +37 -0
  34. package/src/component/FluxDotPattern.vue +72 -0
  35. package/src/component/FluxDropZone.vue +202 -0
  36. package/src/component/FluxDynamicView.vue +16 -0
  37. package/src/component/FluxExpandable.vue +119 -0
  38. package/src/component/FluxExpandableGroup.vue +53 -0
  39. package/src/component/FluxFader.vue +64 -0
  40. package/src/component/FluxFaderItem.vue +15 -0
  41. package/src/component/FluxFilter.vue +133 -0
  42. package/src/component/FluxFilterDate.vue +58 -0
  43. package/src/component/FluxFilterDateRange.vue +59 -0
  44. package/src/component/FluxFilterOption.vue +49 -0
  45. package/src/component/FluxFilterOptionAsync.vue +103 -0
  46. package/src/component/FluxFilterOptions.vue +62 -0
  47. package/src/component/FluxFilterOptionsAsync.vue +113 -0
  48. package/src/component/FluxFilterRange.vue +91 -0
  49. package/src/component/FluxFlickeringGrid.vue +141 -0
  50. package/src/component/FluxFlyout.vue +205 -0
  51. package/src/component/FluxFocalPointEditor.vue +137 -0
  52. package/src/component/FluxFocalPointImage.vue +29 -0
  53. package/src/component/FluxForm.vue +35 -0
  54. package/src/component/FluxFormColumn.vue +15 -0
  55. package/src/component/FluxFormDateInput.vue +92 -0
  56. package/src/component/FluxFormDateRangeInput.vue +87 -0
  57. package/src/component/FluxFormDateTimeInput.vue +120 -0
  58. package/src/component/FluxFormField.vue +98 -0
  59. package/src/component/FluxFormFieldAddition.vue +37 -0
  60. package/src/component/FluxFormInput.vue +223 -0
  61. package/src/component/FluxFormInputAddition.vue +31 -0
  62. package/src/component/FluxFormInputGroup.vue +25 -0
  63. package/src/component/FluxFormPinInput.vue +135 -0
  64. package/src/component/FluxFormRangeSlider.vue +179 -0
  65. package/src/component/FluxFormRow.vue +15 -0
  66. package/src/component/FluxFormSection.vue +23 -0
  67. package/src/component/FluxFormSelect.vue +59 -0
  68. package/src/component/FluxFormSelectAsync.vue +118 -0
  69. package/src/component/FluxFormSlider.vue +123 -0
  70. package/src/component/FluxFormTextArea.vue +53 -0
  71. package/src/component/FluxFormTimeZonePicker.vue +713 -0
  72. package/src/component/FluxGallery.vue +99 -0
  73. package/src/component/FluxGalleryItem.vue +49 -0
  74. package/src/component/FluxGrid.vue +28 -0
  75. package/src/component/FluxGridColumn.vue +31 -0
  76. package/src/component/FluxGridPattern.vue +60 -0
  77. package/src/component/FluxIcon.vue +79 -0
  78. package/src/component/FluxInfo.vue +28 -0
  79. package/src/component/FluxInfoStack.vue +17 -0
  80. package/src/component/FluxLegend.vue +27 -0
  81. package/src/component/FluxLink.vue +35 -0
  82. package/src/component/FluxMenu.vue +31 -0
  83. package/src/component/FluxMenuGroup.vue +21 -0
  84. package/src/component/FluxMenuItem.vue +84 -0
  85. package/src/component/FluxMenuOptions.vue +38 -0
  86. package/src/component/FluxMenuSubHeader.vue +33 -0
  87. package/src/component/FluxMenuTitle.vue +17 -0
  88. package/src/component/FluxNotice.vue +79 -0
  89. package/src/component/FluxNoticeStack.vue +17 -0
  90. package/src/component/FluxOverlay.vue +31 -0
  91. package/src/component/FluxPagination.vue +148 -0
  92. package/src/component/FluxPaginationBar.vue +81 -0
  93. package/src/component/FluxPane.vue +45 -0
  94. package/src/component/FluxPaneBody.vue +15 -0
  95. package/src/component/FluxPaneDeck.vue +24 -0
  96. package/src/component/FluxPaneFooter.vue +15 -0
  97. package/src/component/FluxPaneGroup.vue +15 -0
  98. package/src/component/FluxPaneHeader.vue +44 -0
  99. package/src/component/FluxPaneIllustration.vue +68 -0
  100. package/src/component/FluxPaneMedia.vue +31 -0
  101. package/src/component/FluxPercentageBar.vue +45 -0
  102. package/src/component/FluxPersona.vue +48 -0
  103. package/src/component/FluxPlaceholder.vue +56 -0
  104. package/src/component/FluxPressable.vue +77 -0
  105. package/src/component/FluxPrimaryButton.vue +28 -0
  106. package/src/component/FluxProgressBar.vue +75 -0
  107. package/src/component/FluxPrompt.vue +77 -0
  108. package/src/component/FluxPublishButton.vue +59 -0
  109. package/src/component/FluxQuantitySelector.vue +109 -0
  110. package/src/component/FluxRemove.vue +34 -0
  111. package/src/component/FluxRoot.vue +60 -0
  112. package/src/component/FluxSecondaryButton.vue +28 -0
  113. package/src/component/FluxSegmentedControl.vue +77 -0
  114. package/src/component/FluxSegmentedView.vue +15 -0
  115. package/src/component/FluxSeparator.vue +19 -0
  116. package/src/component/FluxSlideOver.vue +25 -0
  117. package/src/component/FluxSnackbar.vue +154 -0
  118. package/src/component/FluxSnackbarProvider.vue +34 -0
  119. package/src/component/FluxSpacer.vue +9 -0
  120. package/src/component/FluxSpacing.vue +32 -0
  121. package/src/component/FluxSpinner.vue +48 -0
  122. package/src/component/FluxSplitButton.vue +61 -0
  123. package/src/component/FluxStack.vue +40 -0
  124. package/src/component/FluxStatistic.vue +68 -0
  125. package/src/component/FluxStepper.vue +69 -0
  126. package/src/component/FluxStepperStep.vue +15 -0
  127. package/src/component/FluxStepperSteps.vue +62 -0
  128. package/src/component/FluxTab.vue +23 -0
  129. package/src/component/FluxTabBar.vue +87 -0
  130. package/src/component/FluxTabBarItem.vue +104 -0
  131. package/src/component/FluxTable.vue +68 -0
  132. package/src/component/FluxTableActions.vue +16 -0
  133. package/src/component/FluxTableCell.vue +47 -0
  134. package/src/component/FluxTableHeader.vue +111 -0
  135. package/src/component/FluxTableRow.vue +15 -0
  136. package/src/component/FluxTabs.vue +91 -0
  137. package/src/component/FluxTag.vue +85 -0
  138. package/src/component/FluxTagStack.vue +18 -0
  139. package/src/component/FluxTicks.vue +44 -0
  140. package/src/component/FluxTimeline.vue +17 -0
  141. package/src/component/FluxTimelineItem.vue +73 -0
  142. package/src/component/FluxToggle.vue +64 -0
  143. package/src/component/FluxToolbar.vue +32 -0
  144. package/src/component/FluxToolbarGroup.vue +18 -0
  145. package/src/component/FluxTooltip.vue +56 -0
  146. package/src/component/FluxTooltipProvider.vue +176 -0
  147. package/src/component/FluxWindow.vue +47 -0
  148. package/src/component/index.ts +142 -0
  149. package/src/component/primitive/Anchor.vue +17 -0
  150. package/src/component/primitive/AnchorPopup.vue +194 -0
  151. package/src/component/primitive/CoordinatePicker.vue +155 -0
  152. package/src/component/primitive/CoordinatePickerThumb.vue +71 -0
  153. package/src/component/primitive/FilterItem.vue +44 -0
  154. package/src/component/primitive/FilterMenuRenderer.ts +233 -0
  155. package/src/component/primitive/FilterOptionBase.vue +67 -0
  156. package/src/component/primitive/SelectBase.vue +340 -0
  157. package/src/component/primitive/SliderBase.vue +89 -0
  158. package/src/component/primitive/SliderThumb.vue +64 -0
  159. package/src/component/primitive/SliderTrack.vue +22 -0
  160. package/src/component/primitive/VNodeRenderer.ts +11 -0
  161. package/src/component/primitive/index.ts +10 -0
  162. package/src/composable/index.ts +9 -0
  163. package/src/composable/private/index.ts +3 -0
  164. package/src/composable/private/useFormSelect.ts +66 -0
  165. package/src/composable/private/useLoaded.ts +21 -0
  166. package/src/composable/private/useTranslate.ts +35 -0
  167. package/src/composable/useBreakpoints.ts +54 -0
  168. package/src/composable/useDisabled.ts +9 -0
  169. package/src/composable/useDisabledInjection.ts +6 -0
  170. package/src/composable/useExpandableGroupInjection.ts +10 -0
  171. package/src/composable/useFilterInjection.ts +22 -0
  172. package/src/composable/useFlyoutInjection.ts +10 -0
  173. package/src/composable/useFormFieldInjection.ts +8 -0
  174. package/src/composable/useTableInjection.ts +11 -0
  175. package/src/css/base.scss +33 -0
  176. package/src/css/component/Action.module.scss +107 -0
  177. package/src/css/component/Avatar.module.scss +177 -0
  178. package/src/css/component/Badge.module.scss +189 -0
  179. package/src/css/component/Button.module.scss +293 -0
  180. package/src/css/component/Calendar.module.scss +171 -0
  181. package/src/css/component/Chip.module.scss +58 -0
  182. package/src/css/component/Color.module.scss +184 -0
  183. package/src/css/component/Comment.module.scss +123 -0
  184. package/src/css/component/DatePicker.module.scss +193 -0
  185. package/src/css/component/Divider.module.scss +79 -0
  186. package/src/css/component/DropZone.module.scss +99 -0
  187. package/src/css/component/Expandable.module.scss +112 -0
  188. package/src/css/component/Fader.module.scss +38 -0
  189. package/src/css/component/Filter.module.scss +80 -0
  190. package/src/css/component/Flyout.module.scss +63 -0
  191. package/src/css/component/FocalPoint.module.scss +84 -0
  192. package/src/css/component/Form.module.scss +812 -0
  193. package/src/css/component/Gallery.module.scss +64 -0
  194. package/src/css/component/Grid.module.scss +24 -0
  195. package/src/css/component/Icon.module.scss +104 -0
  196. package/src/css/component/Info.module.scss +15 -0
  197. package/src/css/component/Layout.module.scss +63 -0
  198. package/src/css/component/Legend.module.scss +32 -0
  199. package/src/css/component/Menu.module.scss +314 -0
  200. package/src/css/component/Notice.module.scss +279 -0
  201. package/src/css/component/Overlay.module.scss +149 -0
  202. package/src/css/component/Pagination.module.scss +59 -0
  203. package/src/css/component/Pane.module.scss +218 -0
  204. package/src/css/component/PercentageBar.module.scss +31 -0
  205. package/src/css/component/Placeholder.module.scss +72 -0
  206. package/src/css/component/Progress.module.scss +84 -0
  207. package/src/css/component/Remove.module.scss +29 -0
  208. package/src/css/component/Root.module.scss +8 -0
  209. package/src/css/component/SegmentedControl.module.scss +82 -0
  210. package/src/css/component/Snackbar.module.scss +227 -0
  211. package/src/css/component/Spinner.module.scss +36 -0
  212. package/src/css/component/Statistic.module.scss +118 -0
  213. package/src/css/component/Stepper.module.scss +103 -0
  214. package/src/css/component/Tab.module.scss +162 -0
  215. package/src/css/component/Table.module.scss +164 -0
  216. package/src/css/component/Timeline.module.scss +173 -0
  217. package/src/css/component/Toolbar.module.scss +82 -0
  218. package/src/css/component/Tooltip.module.scss +62 -0
  219. package/src/css/component/Transition.module.scss +142 -0
  220. package/src/css/component/Visual.module.scss +70 -0
  221. package/src/css/component/base/Button.module.scss +87 -0
  222. package/src/css/component/base/Effect.module.scss +139 -0
  223. package/src/css/component/base/Grid.module.scss +8 -0
  224. package/src/css/component/base/Pane.module.scss +54 -0
  225. package/src/css/component/primitive/CoordinatePicker.module.scss +24 -0
  226. package/src/css/component/primitive/Slider.module.scss +116 -0
  227. package/src/css/index.scss +5 -0
  228. package/src/css/layers.scss +1 -0
  229. package/src/css/mixin/breakpoints.scss +112 -0
  230. package/src/css/mixin/focus-ring.scss +56 -0
  231. package/src/css/mixin/hover.scss +7 -0
  232. package/src/css/mixin/index.scss +3 -0
  233. package/src/css/reset.scss +169 -0
  234. package/src/css/typography.scss +87 -0
  235. package/src/css/variables.scss +214 -0
  236. package/src/data/di.ts +42 -0
  237. package/src/data/filter.ts +9 -0
  238. package/src/data/helper.ts +9 -0
  239. package/src/data/i18n.ts +55 -0
  240. package/src/data/iconRegistry.ts +21 -0
  241. package/src/data/index.ts +8 -0
  242. package/src/data/inputMask.ts +34 -0
  243. package/src/data/store.ts +233 -0
  244. package/src/image/avatar-mask.svg +3 -0
  245. package/src/index.ts +25 -0
  246. package/src/transition/FluxAutoHeightTransition.vue +59 -0
  247. package/src/transition/FluxAutoWidthTransition.vue +59 -0
  248. package/src/transition/FluxBreakthroughTransition.vue +23 -0
  249. package/src/transition/FluxFadeTransition.vue +24 -0
  250. package/src/transition/FluxOverlayTransition.vue +22 -0
  251. package/src/transition/FluxRouteTransition.vue +23 -0
  252. package/src/transition/FluxSlideOverTransition.vue +22 -0
  253. package/src/transition/FluxTooltipTransition.vue +22 -0
  254. package/src/transition/FluxVerticalWindowTransition.vue +23 -0
  255. package/src/transition/FluxWindowTransition.vue +23 -0
  256. package/src/transition/index.ts +10 -0
  257. package/src/util/createDialogRenderer.ts +64 -0
  258. package/src/util/createLabelForDateRange.ts +61 -0
  259. package/src/util/index.ts +2 -0
  260. package/src/vite.d.ts +13 -0
  261. package/tsconfig.json +45 -0
@@ -0,0 +1,120 @@
1
+ <template>
2
+ <FluxStack
3
+ :class="$style.formDateTimeInput"
4
+ direction="horizontal"
5
+ :gap="15"
6
+ :aria-disabled="disabled ? true : undefined">
7
+ <FluxFlyout
8
+ ref="flyout"
9
+ :width="300">
10
+ <template #opener="{open}">
11
+ <FluxFormInputGroup>
12
+ <FluxFormInput
13
+ :="{autoFocus, disabled, isReadonly, modelValue, placeholder}"
14
+ :class="$style.formDateInput"
15
+ :disabled="disabled"
16
+ :model-value="localValue"
17
+ type="date"
18
+ @update:model-value="setDate"
19
+ @show-picker="open"/>
20
+
21
+ <FluxSecondaryButton
22
+ :disabled="disabled"
23
+ icon-leading="calendar"
24
+ @click.prevent="open"/>
25
+ </FluxFormInputGroup>
26
+ </template>
27
+
28
+ <FluxDatePicker
29
+ :max="max"
30
+ :min="min"
31
+ :model-value="localValue"
32
+ @update:model-value="setDate"/>
33
+ </FluxFlyout>
34
+
35
+ <FluxFormInput
36
+ :="{disabled, isReadonly, modelValue, placeholder}"
37
+ :class="$style.formTimeInput"
38
+ type="time"
39
+ :model-value="localValue"
40
+ @update:model-value="setTime"/>
41
+ </FluxStack>
42
+ </template>
43
+
44
+ <script
45
+ lang="ts"
46
+ setup>
47
+ import type { FluxAutoCompleteType } from '@flux-ui/types';
48
+ import { DateTime } from 'luxon';
49
+ import { ref, toRef, unref, useTemplateRef, watch } from 'vue';
50
+ import { useDisabled } from '$flux/composable';
51
+ import FluxDatePicker from './FluxDatePicker.vue';
52
+ import FluxFlyout from './FluxFlyout.vue';
53
+ import FluxFormInput from './FluxFormInput.vue';
54
+ import FluxFormInputGroup from './FluxFormInputGroup.vue';
55
+ import FluxSecondaryButton from './FluxSecondaryButton.vue';
56
+ import FluxStack from './FluxStack.vue';
57
+ import $style from '$flux/css/component/Form.module.scss';
58
+
59
+ const modelValue = defineModel<DateTime | null>({
60
+ required: true
61
+ });
62
+
63
+ const {
64
+ disabled: componentDisabled,
65
+ isHourOnly
66
+ } = defineProps<{
67
+ readonly autoComplete?: FluxAutoCompleteType;
68
+ readonly autoFocus?: boolean;
69
+ readonly disabled?: boolean;
70
+ readonly isHourOnly?: boolean;
71
+ readonly isReadonly?: boolean;
72
+ readonly max?: DateTime;
73
+ readonly min?: DateTime;
74
+ readonly placeholder?: string;
75
+ }>();
76
+
77
+ const disabled = useDisabled(toRef(() => componentDisabled));
78
+ const flyoutRef = useTemplateRef<{ close(): void; }>('flyout');
79
+
80
+ const localValue = ref<DateTime | null>(null);
81
+
82
+ function setDate(dateTime: DateTime | object | string | number | null): void {
83
+ if (!DateTime.isDateTime(dateTime)) {
84
+ return;
85
+ }
86
+
87
+ const value: DateTime = (localValue.value ?? DateTime.now());
88
+ localValue.value = value.set({
89
+ day: dateTime.day,
90
+ month: dateTime.month,
91
+ year: dateTime.year
92
+ });
93
+ }
94
+
95
+ function setTime(dateTime: DateTime | string | number | object | null): void {
96
+ if (!DateTime.isDateTime(dateTime)) {
97
+ return;
98
+ }
99
+
100
+ const value: DateTime = (localValue.value ?? DateTime.now());
101
+ localValue.value = value.set({
102
+ hour: dateTime.hour,
103
+ minute: unref(isHourOnly) ? 0 : dateTime.minute,
104
+ second: unref(isHourOnly) ? 0 : dateTime.second
105
+ });
106
+ }
107
+
108
+ watch(() => isHourOnly, () => isHourOnly && (localValue.value = unref(localValue)?.startOf('hour') ?? null), {immediate: true});
109
+ watch(modelValue, modelValue => localValue.value = isHourOnly ? modelValue?.startOf('hour') ?? null : modelValue, {immediate: true});
110
+
111
+ watch(localValue, localValue => {
112
+ unref(flyoutRef)?.close();
113
+
114
+ if (modelValue.value?.toISO() === localValue?.toISO()) {
115
+ return;
116
+ }
117
+
118
+ modelValue.value = localValue;
119
+ });
120
+ </script>
@@ -0,0 +1,98 @@
1
+ <template>
2
+ <div :class="$style.formField">
3
+ <label
4
+ :for="id"
5
+ :class="$style.formFieldHeader">
6
+ <span :class="$style.formFieldLabel">
7
+ {{ label }}
8
+ </span>
9
+
10
+ <span
11
+ v-if="isOptional"
12
+ :class="$style.formFieldOptional">
13
+ ({{ translate('flux.optional') }})
14
+ </span>
15
+
16
+ <span
17
+ v-if="'value' in slots"
18
+ :class="$style.formFieldValue">
19
+ <slot
20
+ name="value"
21
+ v-bind="{currentLength, error, hint, id, isOptional, label, maxLength}"/>
22
+ </span>
23
+ </label>
24
+
25
+ <slot v-bind="{id}"/>
26
+
27
+ <span
28
+ v-if="currentLength && maxLength && maxLength > 0"
29
+ :class="$style.formFieldCounter">
30
+ {{ currentLength }} / {{ maxLength }}
31
+ </span>
32
+
33
+ <FluxFormFieldAddition
34
+ v-if="error"
35
+ icon="circle-exclamation"
36
+ mode="error"
37
+ :message="error"/>
38
+
39
+ <FluxFormFieldAddition
40
+ v-if="hint"
41
+ icon="circle-info"
42
+ :message="hint"/>
43
+
44
+ <slot
45
+ name="addition"
46
+ v-bind="{currentLength, error, hint, id, isOptional, label, maxLength}"/>
47
+ </div>
48
+ </template>
49
+
50
+ <script
51
+ lang="ts"
52
+ setup>
53
+ import { provide, useId } from 'vue';
54
+ import { useTranslate } from '$flux/composable/private';
55
+ import { FluxFormFieldInjectionKey } from '$flux/data';
56
+ import FluxFormFieldAddition from './FluxFormFieldAddition.vue';
57
+ import $style from '$flux/css/component/Form.module.scss';
58
+
59
+ defineProps<{
60
+ readonly currentLength?: number;
61
+ readonly error?: string;
62
+ readonly hint?: string;
63
+ readonly isOptional?: boolean;
64
+ readonly label: string;
65
+ readonly maxLength?: number;
66
+ }>();
67
+
68
+ const slots = defineSlots<{
69
+ default(props: {
70
+ readonly id?: string;
71
+ }): any;
72
+
73
+ addition(props: {
74
+ readonly currentLength?: number;
75
+ readonly error?: string;
76
+ readonly hint?: string;
77
+ readonly isOptional?: boolean;
78
+ readonly label: string;
79
+ readonly maxLength?: number;
80
+ }): any;
81
+
82
+ value(props: {
83
+ readonly currentLength?: number;
84
+ readonly error?: string;
85
+ readonly hint?: string;
86
+ readonly isOptional?: boolean;
87
+ readonly label: string;
88
+ readonly maxLength?: number;
89
+ }): any;
90
+ }>();
91
+
92
+ const id = useId();
93
+ const translate = useTranslate();
94
+
95
+ provide(FluxFormFieldInjectionKey, {
96
+ id
97
+ });
98
+ </script>
@@ -0,0 +1,37 @@
1
+ <template>
2
+ <div
3
+ :class="clsx(
4
+ mode === 'error' && $style.formFieldAdditionError,
5
+ mode === 'hint' && $style.formFieldAdditionHint
6
+ )"
7
+ role="alert">
8
+ <FluxIcon
9
+ v-if="icon"
10
+ :class="$style.formFieldAdditionIcon"
11
+ :name="icon"
12
+ :size="16"/>
13
+
14
+ <span v-if="message">
15
+ {{ message }}
16
+ </span>
17
+
18
+ <slot/>
19
+ </div>
20
+ </template>
21
+
22
+ <script
23
+ setup
24
+ lang="ts">
25
+ import type { FluxIconName } from '@flux-ui/types';
26
+ import { clsx } from 'clsx';
27
+ import FluxIcon from './FluxIcon.vue';
28
+ import $style from '$flux/css/component/Form.module.scss';
29
+
30
+ const {
31
+ mode = 'hint'
32
+ } = defineProps<{
33
+ readonly icon?: FluxIconName;
34
+ readonly message?: string;
35
+ readonly mode?: 'error' | 'hint';
36
+ }>();
37
+ </script>
@@ -0,0 +1,223 @@
1
+ <template>
2
+ <div
3
+ :class="clsx(
4
+ disabled ? $style.formInputDisabled : $style.formInputEnabled,
5
+ isSecondary && $style.isSecondary
6
+ )"
7
+ :aria-disabled="disabled ? true : undefined">
8
+ <input
9
+ ref="input"
10
+ :class="clsx(
11
+ $style.formInputNative,
12
+ (!!iconTrailing || type === 'password') && $style.formInputNativeHasIconTrailing,
13
+ !!iconLeading && $style.formInputNativeHasIconLeading
14
+ )"
15
+ :id="id"
16
+ :autocomplete="autoComplete"
17
+ :autofocus="autoFocus"
18
+ :aria-disabled="disabled ? true : undefined"
19
+ :disabled="disabled"
20
+ :max="max"
21
+ :maxlength="maxLength"
22
+ :min="min"
23
+ :placeholder="placeholder"
24
+ :readonly="isReadonly"
25
+ :step="step"
26
+ :type="nativeType"
27
+ :value="localValue"
28
+ @blur="onBlur()"
29
+ @focus="onFocus()"
30
+ @input="onInput"
31
+ @keydown="onKeyDown">
32
+
33
+ <FluxIcon
34
+ v-if="iconLeading"
35
+ :class="$style.formInputIconLeading"
36
+ :name="iconLeading"
37
+ :size="18"/>
38
+
39
+ <FluxIcon
40
+ v-if="type === 'password'"
41
+ :class="$style.formInputIconPasswordToggle"
42
+ :name="nativeType === 'password' ? 'eye' : 'eye-slash'"
43
+ :size="18"
44
+ @click="passwordTypeToggle()"/>
45
+
46
+ <FluxIcon
47
+ v-else-if="iconTrailing"
48
+ :class="$style.formInputIconTrailing"
49
+ :name="iconTrailing"
50
+ :size="18"/>
51
+ </div>
52
+ </template>
53
+
54
+ <script
55
+ lang="ts"
56
+ setup>
57
+ import { unrefTemplateElement } from '@flux-ui/internals';
58
+ import type { FluxAutoCompleteType, FluxIconName, FluxInputMask, FluxInputType } from '@flux-ui/types';
59
+ import { clsx } from 'clsx';
60
+ import { DateTime } from 'luxon';
61
+ import { ref, toRef, unref, useTemplateRef, watch } from 'vue';
62
+ import { useDisabled, useFormFieldInjection } from '$flux/composable';
63
+ import { inputMask } from '$flux/data';
64
+ import FluxIcon from './FluxIcon.vue';
65
+ import $style from '$flux/css/component/Form.module.scss';
66
+
67
+ const emit = defineEmits<{
68
+ blur: [];
69
+ focus: [];
70
+ showPicker: [];
71
+ }>();
72
+
73
+ const modelValue = defineModel<object | string | number | null>({
74
+ default: ''
75
+ });
76
+
77
+ const {
78
+ autoFocus = false,
79
+ disabled: componentDisabled,
80
+ pattern,
81
+ type = 'text'
82
+ } = defineProps<{
83
+ readonly autoComplete?: FluxAutoCompleteType;
84
+ readonly autoFocus?: boolean;
85
+ readonly iconLeading?: FluxIconName;
86
+ readonly iconTrailing?: FluxIconName;
87
+ readonly disabled?: boolean;
88
+ readonly isReadonly?: boolean;
89
+ readonly isSecondary?: boolean;
90
+ readonly max?: string | number;
91
+ readonly maxLength?: number;
92
+ readonly min?: string | number;
93
+ readonly pattern?: FluxInputMask;
94
+ readonly placeholder?: string;
95
+ readonly step?: number;
96
+ readonly type?: FluxInputType;
97
+ }>();
98
+
99
+ const disabled = useDisabled(toRef(() => componentDisabled));
100
+ const inputRef = useTemplateRef<HTMLInputElement>('input');
101
+ const {id} = useFormFieldInjection();
102
+
103
+ const localValue = ref<string | null>(null);
104
+ const nativeType = ref(type);
105
+
106
+ function blur(): void {
107
+ unrefTemplateElement(inputRef)?.blur();
108
+ }
109
+
110
+ function focus(): void {
111
+ unrefTemplateElement(inputRef)?.focus();
112
+ }
113
+
114
+ function passwordTypeToggle(): void {
115
+ if (type !== 'password') {
116
+ return;
117
+ }
118
+
119
+ nativeType.value = unref(nativeType) === 'password' ? 'text' : 'password';
120
+ }
121
+
122
+ function onBlur(): void {
123
+ emit('blur');
124
+ }
125
+
126
+ function onFocus(): void {
127
+ emit('focus');
128
+ }
129
+
130
+ function onInput(evt: Event): void {
131
+ const value = (evt.target as HTMLInputElement).value;
132
+
133
+ switch (type) {
134
+ case 'date':
135
+ case 'datetime-local':
136
+ case 'month':
137
+ case 'time':
138
+ case 'week':
139
+ const dateTime = DateTime.fromISO(value);
140
+
141
+ if (!dateTime.isValid) {
142
+ return;
143
+ }
144
+
145
+ modelValue.value = dateTime;
146
+ break;
147
+
148
+ case 'number':
149
+ modelValue.value = Number(value);
150
+ break;
151
+
152
+ default:
153
+ modelValue.value = value;
154
+ break;
155
+ }
156
+ }
157
+
158
+ function onKeyDown(evt: KeyboardEvent): void {
159
+ if (!['date', 'datetime-local', 'month', 'week'].includes(type)) {
160
+ return;
161
+ }
162
+
163
+ if (evt.key === ' ') {
164
+ emit('showPicker');
165
+ evt.preventDefault();
166
+ }
167
+ }
168
+
169
+ watch([modelValue, () => type], ([modelValue, type]) => {
170
+ if (!modelValue && modelValue !== 0) {
171
+ localValue.value = null;
172
+ return;
173
+ }
174
+
175
+ if (DateTime.isDateTime(modelValue)) {
176
+ const iso = modelValue.toISO()!;
177
+
178
+ switch (type) {
179
+ case 'date':
180
+ localValue.value = iso.substring(0, 10);
181
+ break;
182
+
183
+ case 'datetime-local':
184
+ localValue.value = iso.substring(0, 16);
185
+ break;
186
+
187
+ case 'time':
188
+ localValue.value = iso.substring(11, 16);
189
+ break;
190
+
191
+ default:
192
+ localValue.value = iso;
193
+ break;
194
+ }
195
+
196
+ return;
197
+ }
198
+
199
+ localValue.value = modelValue.toString();
200
+ }, {immediate: true});
201
+
202
+ watch([inputRef, () => pattern, localValue], ([input, pattern, value], __, onCleanup) => {
203
+ if (!input || !pattern) {
204
+ return;
205
+ }
206
+
207
+ const mask = inputMask[pattern](input);
208
+
209
+ if (value) {
210
+ mask.value = value;
211
+ localValue.value = mask.value;
212
+ }
213
+
214
+ onCleanup(() => mask.destroy());
215
+ }, {immediate: true});
216
+
217
+ watch(() => type, type => nativeType.value = type);
218
+
219
+ defineExpose({
220
+ blur,
221
+ focus
222
+ });
223
+ </script>
@@ -0,0 +1,31 @@
1
+ <template>
2
+ <div :class="$style.formInputAddition">
3
+ <FluxIcon
4
+ v-if="icon"
5
+ :name="icon"
6
+ :size="18"/>
7
+
8
+ <span v-if="label">
9
+ {{ label }}
10
+ </span>
11
+
12
+ <slot/>
13
+ </div>
14
+ </template>
15
+
16
+ <script
17
+ lang="ts"
18
+ setup>
19
+ import type { FluxIconName } from '@flux-ui/types';
20
+ import FluxIcon from './FluxIcon.vue';
21
+ import $style from '$flux/css/component/Form.module.scss';
22
+
23
+ defineProps<{
24
+ readonly icon?: FluxIconName;
25
+ readonly label?: string;
26
+ }>();
27
+
28
+ defineSlots<{
29
+ default(): any;
30
+ }>();
31
+ </script>
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <div
3
+ :class="clsx(
4
+ $style.formInputGroup,
5
+ isSecondary && $style.isSecondary
6
+ )"
7
+ role="textbox">
8
+ <slot/>
9
+ </div>
10
+ </template>
11
+
12
+ <script
13
+ lang="ts"
14
+ setup>
15
+ import { clsx } from 'clsx';
16
+ import $style from '$flux/css/component/Form.module.scss';
17
+
18
+ defineProps<{
19
+ readonly isSecondary?: boolean;
20
+ }>();
21
+
22
+ defineSlots<{
23
+ default(): any;
24
+ }>();
25
+ </script>
@@ -0,0 +1,135 @@
1
+ <template>
2
+ <fieldset
3
+ :class="disabled ? $style.pinInputDisabled : $style.pinInputEnabled"
4
+ :id="id"
5
+ :style="{
6
+ '--max-length': maxLength
7
+ }"
8
+ :autofocus="autoFocus"
9
+ :aria-disabled="disabled ? true : undefined">
10
+ <input
11
+ v-for="field of maxLength"
12
+ :key="field"
13
+ ref="fields"
14
+ :class="$style.pinInputField"
15
+ maxlength="1"
16
+ :autocomplete="field === 1 ? autoComplete : undefined"
17
+ :autofocus="field === 1 && autoFocus"
18
+ :disabled="disabled"
19
+ :tabindex="(field - 1) === modelValue?.length ? 0 : -1"
20
+ :type="isPrivate ? 'password' : 'text'"
21
+ :value="modelValue[field - 1]"
22
+ @focus="onFocus"
23
+ @input="onInput"
24
+ @keydown="onKeyDown"
25
+ @paste="onPaste"/>
26
+ </fieldset>
27
+ </template>
28
+
29
+ <script
30
+ lang="ts"
31
+ setup>
32
+ import type { FluxAutoCompleteType } from '@flux-ui/types';
33
+ import { toRef, unref, useTemplateRef } from 'vue';
34
+ import { useDisabled, useFormFieldInjection } from '$flux/composable';
35
+ import $style from '$flux/css/component/Form.module.scss';
36
+
37
+ const modelValue = defineModel<string>({
38
+ default: ''
39
+ });
40
+
41
+ const {
42
+ autoComplete = 'one-time-code',
43
+ autoFocus = false,
44
+ disabled: componentDisabled,
45
+ maxLength = 6
46
+ } = defineProps<{
47
+ readonly autoComplete?: FluxAutoCompleteType;
48
+ readonly autoFocus?: boolean;
49
+ readonly disabled?: boolean;
50
+ readonly isPrivate?: boolean;
51
+ readonly maxLength?: number;
52
+ }>();
53
+
54
+ const disabled = useDisabled(toRef(() => componentDisabled));
55
+ const {id} = useFormFieldInjection();
56
+
57
+ const fieldRefs = useTemplateRef<HTMLInputElement[]>('fields');
58
+
59
+ function onFocus(evt: FocusEvent): void {
60
+ const input = evt.target as HTMLInputElement;
61
+ requestAnimationFrame(() => input.select());
62
+ }
63
+
64
+ function onInput(): void {
65
+ const fields = unref(fieldRefs) ?? [];
66
+ const values = fields
67
+ .map(f => f.value.trim() === '' ? NaN : Number(f.value))
68
+ .filter(v => !isNaN(v));
69
+
70
+ modelValue.value = values.join('');
71
+ }
72
+
73
+ function onKeyDown(evt: KeyboardEvent): void {
74
+ const input = evt.target as HTMLInputElement;
75
+ const value = input.value.trim();
76
+
77
+ const next = input.nextElementSibling as HTMLInputElement | null;
78
+ const previous = input.previousElementSibling as HTMLInputElement | null;
79
+
80
+ switch (evt.key) {
81
+ case 'Backspace':
82
+ value === '' && previous?.focus();
83
+ break;
84
+
85
+ case 'ArrowLeft':
86
+ case 'ArrowUp':
87
+ input.selectionStart === 0 && previous?.select();
88
+ break;
89
+
90
+ case 'ArrowDown':
91
+ case 'ArrowRight':
92
+ (input.selectionStart === 1 || value === '') && next?.select();
93
+ break;
94
+
95
+ case 'Tab':
96
+ break;
97
+
98
+ case 'v':
99
+ if (evt.ctrlKey || evt.metaKey) {
100
+ break;
101
+ }
102
+
103
+ evt.preventDefault();
104
+ break;
105
+
106
+ default:
107
+ if (isNaN(Number(evt.key))) {
108
+ evt.preventDefault();
109
+ break;
110
+ }
111
+
112
+ requestAnimationFrame(() => next?.focus());
113
+ break;
114
+ }
115
+ }
116
+
117
+ function onPaste(evt: ClipboardEvent): void {
118
+ if (!evt.clipboardData) {
119
+ return;
120
+ }
121
+
122
+ const value = evt.clipboardData.getData('text').replace(/\D/g, '');
123
+
124
+ if (value.length !== maxLength) {
125
+ return;
126
+ }
127
+
128
+ modelValue.value = value;
129
+
130
+ requestAnimationFrame(() => {
131
+ const fields = unref(fieldRefs) ?? [];
132
+ fields[maxLength - 1].focus();
133
+ });
134
+ }
135
+ </script>