@naptics/vue-collection 0.2.15 → 0.3.1

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 (171) hide show
  1. package/.github/workflows/build.yml +26 -0
  2. package/.github/workflows/deploy-demo.yml +46 -0
  3. package/.github/workflows/deploy-lib.yml +59 -0
  4. package/.gitlab-ci.yml +57 -0
  5. package/.nvmrc +1 -0
  6. package/.prettierrc +8 -0
  7. package/.vscode/extensions.json +10 -0
  8. package/.vscode/launch.json +23 -0
  9. package/.vscode/settings.json +13 -0
  10. package/babel.config.json +3 -0
  11. package/components/NAlert.d.ts +1 -44
  12. package/components/NBadge.d.ts +1 -133
  13. package/components/NBreadcrub.d.ts +2 -106
  14. package/components/NBreadcrub.js +1 -1
  15. package/components/NButton.d.ts +2 -118
  16. package/components/NCheckbox.d.ts +1 -32
  17. package/components/NCheckboxLabel.d.ts +1 -45
  18. package/components/NCheckboxLabel.js +1 -1
  19. package/components/NCrudModal.d.ts +7 -251
  20. package/components/NCrudModal.js +1 -1
  21. package/components/NDialog.d.ts +1 -110
  22. package/components/NDialog.js +1 -1
  23. package/components/NDropdown.d.ts +1 -69
  24. package/components/NDropdown.js +1 -1
  25. package/components/NDropzone.d.ts +1 -115
  26. package/components/NDropzone.js +1 -1
  27. package/components/NForm.d.ts +1 -23
  28. package/components/NFormModal.d.ts +7 -151
  29. package/components/NIconButton.d.ts +3 -159
  30. package/components/NIconButton.js +1 -1
  31. package/components/NIconCircle.d.ts +1 -87
  32. package/components/NInput.d.ts +1 -164
  33. package/components/NInput.js +1 -1
  34. package/components/NInputPhone.d.ts +2 -114
  35. package/components/NInputPhone.js +1 -1
  36. package/components/NInputSelect.d.ts +2 -187
  37. package/components/NInputSelect.js +1 -1
  38. package/components/NInputSuggestion.d.ts +2 -155
  39. package/components/NInputSuggestion.js +1 -1
  40. package/components/NLink.d.ts +6 -70
  41. package/components/NLink.js +8 -1
  42. package/components/NList.d.ts +1 -43
  43. package/components/NList.js +1 -1
  44. package/components/NLoadingIndicator.d.ts +1 -49
  45. package/components/NModal.d.ts +12 -250
  46. package/components/NModal.js +15 -9
  47. package/components/NPagination.d.ts +1 -63
  48. package/components/NSearchbar.d.ts +1 -56
  49. package/components/NSearchbarList.d.ts +3 -63
  50. package/components/NSearchbarList.js +1 -1
  51. package/components/NSelect.d.ts +2 -148
  52. package/components/NSelect.js +1 -1
  53. package/components/NSuggestionList.d.ts +3 -126
  54. package/components/NSuggestionList.js +5 -2
  55. package/components/NTable.d.ts +1 -85
  56. package/components/NTable.js +12 -6
  57. package/components/NTableAction.d.ts +2 -46
  58. package/components/NTableAction.js +1 -1
  59. package/components/NTextArea.d.ts +2 -181
  60. package/components/NTextArea.js +1 -1
  61. package/components/NTooltip.d.ts +1 -105
  62. package/components/NTooltip.js +1 -1
  63. package/components/NValInput.d.ts +7 -182
  64. package/components/NValInput.js +1 -1
  65. package/env.d.ts +15 -0
  66. package/eslint.config.cjs +29 -0
  67. package/index.html +13 -0
  68. package/package.json +21 -19
  69. package/postcss.config.js +6 -0
  70. package/public/favicon.ico +0 -0
  71. package/scripts/build-lib.sh +52 -0
  72. package/scripts/sync-node-types.js +70 -0
  73. package/src/demo/App.css +9 -0
  74. package/src/demo/App.tsx +5 -0
  75. package/src/demo/components/ColorGrid.tsx +26 -0
  76. package/src/demo/components/ComponentGrid.tsx +26 -0
  77. package/src/demo/components/ComponentSection.tsx +30 -0
  78. package/src/demo/components/VariantSection.tsx +18 -0
  79. package/src/demo/i18n/de.ts +7 -0
  80. package/src/demo/i18n/en.ts +7 -0
  81. package/src/demo/i18n/index.ts +24 -0
  82. package/src/demo/main.ts +13 -0
  83. package/src/demo/router/index.ts +21 -0
  84. package/src/demo/views/HomeView.tsx +94 -0
  85. package/src/demo/views/NavigationView.tsx +43 -0
  86. package/src/demo/views/presentation/AlertView.tsx +40 -0
  87. package/src/demo/views/presentation/BadgeView.tsx +61 -0
  88. package/src/demo/views/presentation/BreadcrumbView.tsx +52 -0
  89. package/src/demo/views/presentation/ButtonView.tsx +49 -0
  90. package/src/demo/views/presentation/CheckboxView.tsx +59 -0
  91. package/src/demo/views/presentation/DropdownView.tsx +59 -0
  92. package/src/demo/views/presentation/DropzoneView.tsx +39 -0
  93. package/src/demo/views/presentation/IconButtonView.tsx +47 -0
  94. package/src/demo/views/presentation/IconCircleView.tsx +38 -0
  95. package/src/demo/views/presentation/InputView.tsx +179 -0
  96. package/src/demo/views/presentation/LinkView.tsx +60 -0
  97. package/src/demo/views/presentation/ListView.tsx +29 -0
  98. package/src/demo/views/presentation/LoadingIndicatorView.tsx +38 -0
  99. package/src/demo/views/presentation/ModalView.tsx +210 -0
  100. package/src/demo/views/presentation/PaginationView.tsx +25 -0
  101. package/src/demo/views/presentation/SearchbarView.tsx +80 -0
  102. package/src/demo/views/presentation/TableView.tsx +146 -0
  103. package/src/demo/views/presentation/TooltipView.tsx +86 -0
  104. package/src/lib/components/NAlert.tsx +85 -0
  105. package/src/lib/components/NBadge.tsx +75 -0
  106. package/src/lib/components/NBreadcrub.tsx +97 -0
  107. package/src/lib/components/NButton.tsx +80 -0
  108. package/src/lib/components/NCheckbox.tsx +55 -0
  109. package/src/lib/components/NCheckboxLabel.tsx +51 -0
  110. package/src/lib/components/NCrudModal.tsx +133 -0
  111. package/src/lib/components/NDialog.tsx +182 -0
  112. package/src/lib/components/NDropdown.tsx +167 -0
  113. package/src/lib/components/NDropzone.tsx +265 -0
  114. package/src/lib/components/NForm.tsx +32 -0
  115. package/src/lib/components/NFormModal.tsx +66 -0
  116. package/src/lib/components/NIconButton.tsx +92 -0
  117. package/src/lib/components/NIconCircle.tsx +78 -0
  118. package/src/lib/components/NInput.css +11 -0
  119. package/src/lib/components/NInput.tsx +139 -0
  120. package/src/lib/components/NInputPhone.tsx +53 -0
  121. package/src/lib/components/NInputSelect.tsx +126 -0
  122. package/src/lib/components/NInputSuggestion.tsx +80 -0
  123. package/src/lib/components/NLink.tsx +82 -0
  124. package/src/lib/components/NList.tsx +67 -0
  125. package/src/lib/components/NLoadingIndicator.css +46 -0
  126. package/src/lib/components/NLoadingIndicator.tsx +63 -0
  127. package/src/lib/components/NModal.tsx +243 -0
  128. package/src/lib/components/NPagination.css +15 -0
  129. package/src/lib/components/NPagination.tsx +131 -0
  130. package/src/lib/components/NSearchbar.tsx +78 -0
  131. package/src/lib/components/NSearchbarList.tsx +47 -0
  132. package/src/lib/components/NSelect.tsx +128 -0
  133. package/src/lib/components/NSuggestionList.tsx +216 -0
  134. package/src/lib/components/NTable.css +3 -0
  135. package/src/lib/components/NTable.tsx +247 -0
  136. package/src/lib/components/NTableAction.tsx +49 -0
  137. package/src/lib/components/NTextArea.tsx +159 -0
  138. package/src/lib/components/NTooltip.css +37 -0
  139. package/src/lib/components/NTooltip.tsx +250 -0
  140. package/src/lib/components/NValInput.tsx +163 -0
  141. package/src/lib/components/ValidatedForm.ts +71 -0
  142. package/src/lib/components/__tests__/NButton.spec.tsx +26 -0
  143. package/src/lib/components/__tests__/NCheckbox.spec.tsx +39 -0
  144. package/src/lib/i18n/de/vue-collection.json +58 -0
  145. package/src/lib/i18n/en/vue-collection.json +58 -0
  146. package/src/lib/i18n/index.ts +54 -0
  147. package/src/lib/index.ts +2 -0
  148. package/src/lib/jsx.d.ts +13 -0
  149. package/src/lib/utils/__tests__/identifiable.spec.ts +72 -0
  150. package/src/lib/utils/__tests__/validation.spec.ts +92 -0
  151. package/src/lib/utils/breakpoints.ts +47 -0
  152. package/src/lib/utils/component.tsx +131 -0
  153. package/src/lib/utils/deferred.ts +28 -0
  154. package/src/lib/utils/identifiable.ts +87 -0
  155. package/src/lib/utils/stringMaxLength.ts +25 -0
  156. package/src/lib/utils/tailwind.ts +41 -0
  157. package/src/lib/utils/utils.ts +90 -0
  158. package/src/lib/utils/vModel.ts +260 -0
  159. package/src/lib/utils/validation.ts +189 -0
  160. package/src/lib/utils/vue.ts +25 -0
  161. package/tailwind.config.js +38 -0
  162. package/tsconfig.config.json +9 -0
  163. package/tsconfig.demo.json +19 -0
  164. package/tsconfig.json +16 -0
  165. package/tsconfig.lib.json +18 -0
  166. package/tsconfig.vitest.json +8 -0
  167. package/utils/breakpoints.d.ts +1 -1
  168. package/utils/component.d.ts +3 -7
  169. package/utils/component.js +5 -2
  170. package/utils/identifiable.js +5 -1
  171. package/vite.config.ts +28 -0
@@ -0,0 +1,78 @@
1
+ import type { HeroIcon } from '../utils/tailwind'
2
+ import { createComponent } from '../utils/component'
3
+ import type { PropType } from 'vue'
4
+
5
+ export const nIconCircleProps = {
6
+ /**
7
+ * The icon of the icon-circle.
8
+ */
9
+ icon: {
10
+ type: Function as PropType<HeroIcon>,
11
+ required: true,
12
+ },
13
+ /**
14
+ * The color of the icon-circle.
15
+ */
16
+ color: {
17
+ type: String,
18
+ default: 'primary',
19
+ },
20
+ /**
21
+ * The size of the circle in "tailwind units" (4 px).
22
+ * Tailwind classes are used for the size, so any number can be passed.
23
+ * If the `iconSize` is not set, it will be adjusted automatically.
24
+ */
25
+ circleSize: Number,
26
+ /**
27
+ * The size of the icon in "tailwind units" (4 px).
28
+ * No tailwind classes are used for the size, so any number can be passed.
29
+ * If the `circleSize` is not set, it will be adjusted automatically.
30
+ */
31
+ iconSize: Number,
32
+ /**
33
+ * The shade of the icon.
34
+ */
35
+ iconShade: {
36
+ type: Number,
37
+ default: 600,
38
+ },
39
+ /**
40
+ * The shade of the background.
41
+ */
42
+ bgShade: {
43
+ type: Number,
44
+ default: 100,
45
+ },
46
+ } as const
47
+
48
+ const DEFAULT_CIRCLE_SIZE = 16
49
+ const SCALING_FACTOR = 0.55
50
+
51
+ /**
52
+ * The `NIconCircle` is an icon with a colored circle around it.
53
+ */
54
+ const Component = createComponent('NIconCircle', nIconCircleProps, props => {
55
+ let circleSize = props.circleSize
56
+ let iconSize = props.iconSize
57
+ if (circleSize == null) {
58
+ if (iconSize == null) circleSize = DEFAULT_CIRCLE_SIZE
59
+ else circleSize = iconSize / SCALING_FACTOR
60
+ }
61
+ if (iconSize == null) iconSize = circleSize * SCALING_FACTOR
62
+
63
+ circleSize *= 4
64
+ iconSize *= 4
65
+
66
+ return () => (
67
+ <div
68
+ class={['flex items-center justify-center rounded-full', `bg-${props.color}-${props.bgShade}`]}
69
+ style={`width: ${circleSize}px; height: ${circleSize}px`}
70
+ >
71
+ <div class={`text-${props.color}-${props.iconShade}`} style={`width: ${iconSize}px; height: ${iconSize}px`}>
72
+ <props.icon />
73
+ </div>
74
+ </div>
75
+ )
76
+ })
77
+
78
+ export { Component as NIconCircle, Component as default }
@@ -0,0 +1,11 @@
1
+ /* Chrome, Safari, Edge, Opera */
2
+ input::-webkit-outer-spin-button,
3
+ input::-webkit-inner-spin-button {
4
+ -webkit-appearance: none;
5
+ margin: 0;
6
+ }
7
+
8
+ /* Firefox */
9
+ input[type='number'] {
10
+ -moz-appearance: textfield;
11
+ }
@@ -0,0 +1,139 @@
1
+ import { createComponent } from '../utils/component'
2
+ import { ref, type PropType } from 'vue'
3
+ import { ExclamationCircleIcon } from '@heroicons/vue/24/solid'
4
+ import NTooltip, { mapTooltipProps, nToolTipPropsForImplementor } from './NTooltip'
5
+ import './NInput.css'
6
+ import { vModelProps } from '../utils/vModel'
7
+
8
+ export const nInputProps = {
9
+ ...vModelProps(String),
10
+ /**
11
+ * The name of the input. Is displayed as a label above the input.
12
+ */
13
+ name: String,
14
+ /**
15
+ * The placeholder of the input.
16
+ */
17
+ placeholder: String,
18
+ /**
19
+ * The html autocomplete attribute of the input.
20
+ */
21
+ autocomplete: {
22
+ type: String,
23
+ default: 'off',
24
+ },
25
+ /**
26
+ * The html type attribute of the input.
27
+ */
28
+ type: {
29
+ type: String,
30
+ default: 'text',
31
+ },
32
+ /**
33
+ * The maximum value of the input.
34
+ */
35
+ max: String,
36
+ /**
37
+ * The minimum value of the input.
38
+ */
39
+ min: String,
40
+ /**
41
+ * If set to `true` the input is displayed with a red border.
42
+ */
43
+ error: Boolean,
44
+ /**
45
+ * If set to `true` the input is disabled and no interaction is possible.
46
+ */
47
+ disabled: Boolean,
48
+ /**
49
+ * If set to `true` the input is displayed smaller.
50
+ */
51
+ small: Boolean,
52
+ /**
53
+ * If set to `true` the input's label is hidden.
54
+ */
55
+ hideLabel: Boolean,
56
+ /**
57
+ * Adds the classes directly to the input (e.g. for shadow).
58
+ */
59
+ inputClass: String,
60
+ /**
61
+ * This is called when the input reveices focus.
62
+ */
63
+ onFocus: Function as PropType<() => void>,
64
+ /**
65
+ * This is called when the input looses focus.
66
+ */
67
+ onBlur: Function as PropType<() => void>,
68
+ ...nToolTipPropsForImplementor,
69
+ } as const
70
+
71
+ export type NInputExposed = {
72
+ /**
73
+ * Request focus on the input.
74
+ */
75
+ focus(): void
76
+ }
77
+
78
+ /**
79
+ * The base class of inputs. A styled input with a lot of configuration possibilities but no validation.
80
+ */
81
+ const Component = createComponent('NInput', nInputProps, (props, context) => {
82
+ const inputRef = ref<HTMLInputElement>()
83
+ const exposed: NInputExposed = {
84
+ focus: () => inputRef.value?.focus(),
85
+ }
86
+ context.expose(exposed)
87
+
88
+ return () => (
89
+ <div>
90
+ {props.name && !props.hideLabel && (
91
+ <label
92
+ for={props.name}
93
+ class={['block text-sm font-medium mb-1', props.disabled ? 'text-default-300' : 'text-default-700']}
94
+ >
95
+ {props.name}
96
+ </label>
97
+ )}
98
+ <NTooltip block {...mapTooltipProps(props)}>
99
+ <div class="relative">
100
+ <input
101
+ ref={inputRef}
102
+ name={props.name}
103
+ value={props.value}
104
+ onInput={event => props.onUpdateValue?.((event.target as HTMLInputElement).value)}
105
+ placeholder={props.placeholder}
106
+ autocomplete={props.autocomplete}
107
+ type={props.type}
108
+ min={props.min}
109
+ max={props.max}
110
+ disabled={props.disabled}
111
+ onFocus={() => props.onFocus?.()}
112
+ onBlur={() => props.onBlur?.()}
113
+ onInvalid={event => event.preventDefault()}
114
+ class={[
115
+ 'block w-full rounded-md border focus:outline-none focus:ring-1 ',
116
+ props.small ? 'text-xs py-0.5 px-2' : 'py-2 px-4',
117
+ props.disabled
118
+ ? 'text-default-500 placeholder-default-300 bg-default-50'
119
+ : 'text-default-900 placeholder-default-400 ',
120
+ props.error
121
+ ? 'border-red-500 focus:border-red-500 focus:ring-red-500 pr-10'
122
+ : 'border-default-300 focus:border-primary-500 focus:ring-primary-500',
123
+ props.inputClass,
124
+ ]}
125
+ />
126
+
127
+ <div
128
+ class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none"
129
+ v-show={props.error && !props.small}
130
+ >
131
+ <ExclamationCircleIcon class="h-5 w-5 text-red-700" aria-hidden="true" />
132
+ </div>
133
+ </div>
134
+ </NTooltip>
135
+ </div>
136
+ )
137
+ })
138
+
139
+ export { Component as NInput, Component as default }
@@ -0,0 +1,53 @@
1
+ import { createComponent } from '../utils/component'
2
+ import { external } from '../utils/validation'
3
+ import { computed, Suspense } from 'vue'
4
+ import NValInput, { nValInputProps } from './NValInput'
5
+ import { trsl } from '../i18n'
6
+
7
+ export const nInputPhoneProps = nValInputProps
8
+
9
+ /**
10
+ * The `NInputPhone` autoformats phone numbers and checks if they are valid.
11
+ */
12
+ const Component = createComponent('NInputPhoneSuspended', nInputPhoneProps, props => {
13
+ // Async components have to be wrapped in a suspense component.
14
+ return () => (
15
+ <Suspense>
16
+ <NPhoneInput {...props} />
17
+ </Suspense>
18
+ )
19
+ })
20
+
21
+ export { Component as NInputPhone, Component as default }
22
+
23
+ const NPhoneInput = createComponent('NInputPhone', nInputPhoneProps, async props => {
24
+ // import dynamically for better codesplitting as the library is pretty large
25
+ const { parsePhoneNumber } = await import('awesome-phonenumber')
26
+ const DEFAULT_COUNTRY_CODE = 'CH'
27
+
28
+ const formattedToPlain = (number: string) =>
29
+ parsePhoneNumber(number, { regionCode: DEFAULT_COUNTRY_CODE }).number?.e164
30
+ const plainToFormatted = (number: string) =>
31
+ parsePhoneNumber(number, { regionCode: DEFAULT_COUNTRY_CODE }).number?.international
32
+
33
+ const onUpdateValue = (newValue: string) => {
34
+ const plain = formattedToPlain(newValue)
35
+ props.onUpdateValue?.(plain || newValue)
36
+ }
37
+
38
+ const value = computed(() => {
39
+ const formatted = plainToFormatted(props.value || '')
40
+ return formatted || props.value
41
+ })
42
+
43
+ const isValid = computed(() => parsePhoneNumber(props.value || '').valid)
44
+
45
+ return () => (
46
+ <NValInput
47
+ {...{ ...props, onUpdateValue }}
48
+ value={value.value}
49
+ rules={external(isValid.value, trsl('vue-collection.validation.rules.phone'))}
50
+ type="tel"
51
+ />
52
+ )
53
+ })
@@ -0,0 +1,126 @@
1
+ import { createComponentWithSlots } from '../utils/component'
2
+ import { Id, type Identifiable } from '../utils/identifiable'
3
+ import { option } from '../utils/validation'
4
+ import { vModelForRef } from '../utils/vModel'
5
+ import { watchRef } from '../utils/vue'
6
+ import { computed, ref, watch, type PropType } from 'vue'
7
+ import { nInputProps } from './NInput'
8
+ import NSuggestionList, { nSuggestionListProps } from './NSuggestionList'
9
+ import NValInput, { nValInputProps, type NValInputExposed } from './NValInput'
10
+ import type { AnyObject } from '../utils/utils'
11
+
12
+ export const nInputSelectProps = {
13
+ ...nInputProps,
14
+ /**
15
+ * The id of the currently selected option of this input.
16
+ */
17
+ value: String,
18
+ /**
19
+ * This is called with the newly selected id when the selection has changed.
20
+ * This happens, when an item from the suggestion list is selected or the
21
+ * input matches a selection option exactly.
22
+ * If no id is selected, the empty string is passed, in order to
23
+ * match the API of all other inputs who never pass `undefined`.
24
+ */
25
+ onUpdateValue: Function as PropType<(newValue: string) => void>,
26
+ /**
27
+ * The options which are allowed and suggested for this input.
28
+ * The options are filtered based on the user input.
29
+ */
30
+ options: {
31
+ type: Array as PropType<InputSelectOption[]>,
32
+ default: () => [],
33
+ },
34
+ /**
35
+ * @see {@link nValInputProps.optional}
36
+ */
37
+ optional: nValInputProps.optional,
38
+ /**
39
+ * @see {@link nValInputProps.form}
40
+ */
41
+ form: nValInputProps.form,
42
+ /**
43
+ * @see {@link nValInputProps.error}
44
+ */
45
+ error: nValInputProps.error,
46
+ /**
47
+ * @see {@link nValInputProps.errorMessage}
48
+ */
49
+ errorMessage: nValInputProps.errorMessage,
50
+ /**
51
+ * If set to `true` the list is hidden even if there are still matching items in the list.
52
+ */
53
+ hideList: nSuggestionListProps.hideList,
54
+ /**
55
+ * @see {@link nSuggestionListProps.maxItems}
56
+ */
57
+ maxItems: nSuggestionListProps.maxItems,
58
+ /**
59
+ * @see {@link nSuggestionListProps.listItem}
60
+ */
61
+ listItem: nSuggestionListProps.listItem,
62
+ } as const
63
+
64
+ export type InputSelectOption = Identifiable & { label: string } & AnyObject
65
+
66
+ /**
67
+ * The `NInputSelect` is very similar to the {@link NSelect}, but instead of a select input it is a regular input.
68
+ * The user is forced to use a value from the specified options of the input.
69
+ * While they type, the list of options is shown to them and filtered based on their input.
70
+ */
71
+ const Component = createComponentWithSlots('NInputSelect', nInputSelectProps, ['listItem'], props => {
72
+ const inputRef = ref<NValInputExposed>()
73
+
74
+ const inputValue = ref('')
75
+ watch(
76
+ () => props.value,
77
+ newValue => {
78
+ if (newValue) {
79
+ const chosenOption = Id.find(props.options, newValue)
80
+ if (chosenOption) inputValue.value = chosenOption.label
81
+ }
82
+ },
83
+ { immediate: true }
84
+ )
85
+
86
+ const filteredOptions = computed(() =>
87
+ props.options.filter(option => option.label.includes(inputValue.value || ''))
88
+ )
89
+
90
+ const matchedOption = computed(() => {
91
+ const matches = props.options.filter(option => option.label === inputValue.value)
92
+ return matches.length > 0 ? matches[0] : null
93
+ })
94
+ watchRef(matchedOption, newOption => props.onUpdateValue?.(newOption?.id || ''))
95
+
96
+ return () => (
97
+ <NSuggestionList
98
+ items={filteredOptions.value}
99
+ onSelect={props.onUpdateValue}
100
+ inputValue={inputValue.value}
101
+ hideList={props.hideList || matchedOption.value != null || filteredOptions.value.length == 0}
102
+ maxItems={props.maxItems}
103
+ listItem={props.listItem}
104
+ input={({ onFocus, onBlur }) => (
105
+ <NValInput
106
+ ref={inputRef}
107
+ {...{ ...props, ...vModelForRef(inputValue) }}
108
+ rules={option(props.options.map(opt => opt.label))}
109
+ onFocus={() => {
110
+ onFocus()
111
+ props.onFocus?.()
112
+ }}
113
+ onBlur={onBlur}
114
+ disableBlurValidation
115
+ />
116
+ )}
117
+ onRequestInputFocus={() => inputRef.value?.focus()}
118
+ onRealBlur={() => {
119
+ props.onBlur?.()
120
+ inputRef?.value?.validate()
121
+ }}
122
+ />
123
+ )
124
+ })
125
+
126
+ export { Component as NInputSelect, Component as default }
@@ -0,0 +1,80 @@
1
+ import { createComponent } from '../utils/component'
2
+ import { Id } from '../utils/identifiable'
3
+ import { computed, ref, type PropType } from 'vue'
4
+ import NSuggestionList, { nSuggestionListProps } from './NSuggestionList'
5
+ import NValInput, { nValInputProps, type NValInputExposed } from './NValInput'
6
+
7
+ export const nInputSuggestionProps = {
8
+ ...nValInputProps,
9
+ /**
10
+ * If set to `true` the list is hidden even if there are still matching items in the list.
11
+ */
12
+ hideList: nSuggestionListProps.hideList,
13
+ /**
14
+ * @see {@link nSuggestionListProps.maxItems}
15
+ */
16
+ maxItems: nSuggestionListProps.maxItems,
17
+ /**
18
+ * The suggestions which are shown to the user for this input.
19
+ * The suggestions are filtered based on the user input.
20
+ */
21
+ suggestions: {
22
+ type: Array as PropType<string[]>,
23
+ default: () => [],
24
+ },
25
+ } as const
26
+
27
+ /**
28
+ * `NInputSuggestion` is an input, which shows a list of possible suggestions to the user
29
+ * which is filtered while typing. Contrary to {@link NInputSelect} the user is not required to choose any of the suggestions.
30
+ */
31
+ const Component = createComponent('NInputSuggestion', nInputSuggestionProps, props => {
32
+ const suggestionItems = computed(() =>
33
+ props.suggestions
34
+ .filter(suggestion => suggestion.includes(props.value || ''))
35
+ .map((value, index) => ({
36
+ id: index.toString(),
37
+ label: value,
38
+ }))
39
+ )
40
+
41
+ const select = (id: string) => props.onUpdateValue?.(Id.find(suggestionItems.value, id)?.label || '')
42
+
43
+ const hideList = computed(
44
+ () =>
45
+ props.hideList ||
46
+ suggestionItems.value.length == 0 ||
47
+ suggestionItems.value.filter(suggestion => suggestion.label !== props.value).length == 0
48
+ )
49
+
50
+ const inputRef = ref<NValInputExposed>()
51
+
52
+ return () => (
53
+ <NSuggestionList
54
+ items={suggestionItems.value}
55
+ onSelect={id => select(id)}
56
+ inputValue={props.value || ''}
57
+ hideList={hideList.value}
58
+ maxItems={props.maxItems}
59
+ input={({ onFocus, onBlur }) => (
60
+ <NValInput
61
+ ref={inputRef}
62
+ {...props}
63
+ onFocus={() => {
64
+ onFocus()
65
+ props.onFocus?.()
66
+ }}
67
+ onBlur={onBlur}
68
+ disableBlurValidation
69
+ />
70
+ )}
71
+ onRequestInputFocus={() => inputRef.value?.focus()}
72
+ onRealBlur={() => {
73
+ props.onBlur?.()
74
+ inputRef?.value?.validate()
75
+ }}
76
+ />
77
+ )
78
+ })
79
+
80
+ export { Component as NInputSuggestion, Component as default }
@@ -0,0 +1,82 @@
1
+ import { createComponent } from '../utils/component'
2
+ import type { TWTextSize } from '../utils/tailwind'
3
+ import { computed, type PropType } from 'vue'
4
+ import { RouterLink, type RouteLocationRaw } from 'vue-router'
5
+
6
+ export const nLinkProps = {
7
+ /**
8
+ * The text of the link. Can also be set in the default slot.
9
+ */
10
+ text: String,
11
+ /**
12
+ * The route of the link. If this is set,
13
+ * the link becomes a {@link RouterLink} and does not emit the `onClick` event.
14
+ */
15
+ route: [Object, String] as PropType<RouteLocationRaw>,
16
+ /**
17
+ * The color of the link.
18
+ */
19
+ color: {
20
+ type: String,
21
+ default: 'primary',
22
+ },
23
+ /**
24
+ * The text size, a standard tailwind text-size class.
25
+ */
26
+ textSize: String as PropType<TWTextSize>,
27
+ /**
28
+ * The shade of the link.
29
+ */
30
+ shade: {
31
+ type: Number,
32
+ default: 500,
33
+ },
34
+
35
+ /**
36
+ * If set to `true` the link is disabled and no interaction is possible.
37
+ * Note: If the `route` prop is set, the link will still be clickable, because it becomes a {@link RouterLink}.
38
+ */
39
+ disabled: Boolean,
40
+ /**
41
+ * This is called when the link is clicked but only, if the `route` prop is not set.
42
+ * If the `route` prop is not set, the link will act as a regular button.
43
+ */
44
+ onClick: Function as PropType<() => void>,
45
+ } as const
46
+
47
+ /**
48
+ * The `NLink` is a styled text which can be used as a {@link RouterLink} or a regular button.
49
+ */
50
+ const Component = createComponent('NLink', nLinkProps, (props, { slots }) => {
51
+ const hoverShade = computed(() => {
52
+ const shade = props.shade
53
+ if (shade <= 500) return shade + 100
54
+ else return shade - 200
55
+ })
56
+
57
+ const classes = computed(() => [
58
+ 'font-medium focus:outline-none focus-visible:ring-2 rounded-sm ring-offset-2 hover:underline text-left',
59
+ `${props.textSize} text-${props.color}-${props.shade} hover:text-${props.color}-${hoverShade.value} focus-visible:ring-${props.color}-${props.shade}`,
60
+ ])
61
+ const disabledClasses = computed(() => [
62
+ 'font-medium text-left cursor-not-allowed',
63
+ `${props.textSize} text-${props.color}-200`,
64
+ ])
65
+
66
+ return () =>
67
+ props.route ? (
68
+ <RouterLink to={props.route} class={classes.value}>
69
+ {slots.default?.() || props.text}
70
+ </RouterLink>
71
+ ) : (
72
+ <button
73
+ onClick={props.onClick}
74
+ class={props.disabled ? disabledClasses.value : classes.value}
75
+ disabled={props.disabled}
76
+ >
77
+ {slots.default?.() || props.text}
78
+ </button>
79
+ )
80
+ })
81
+
82
+ export { Component as NLink, Component as default }
@@ -0,0 +1,67 @@
1
+ import { createComponent } from '../utils/component'
2
+ import type { PropType } from 'vue'
3
+
4
+ export type ListItem = {
5
+ /**
6
+ * The title of the item. Accepts either string or a function returning a JSX element.
7
+ */
8
+ title: string | (() => JSX.Element)
9
+ /**
10
+ * The text of the item. Accepts either string or a function returning a JSX element.
11
+ */
12
+ text?: string | (() => JSX.Element)
13
+ }
14
+
15
+ export const nListProps = {
16
+ /**
17
+ * The items which are displayed in the list.
18
+ */
19
+ items: {
20
+ type: Array as PropType<ListItem[]>,
21
+ default: () => [],
22
+ },
23
+ /**
24
+ * Adds the classes to all title elements (on the left side).
25
+ */
26
+ titleClass: String,
27
+ /**
28
+ * Adds the classes to all text elements (on the right side).
29
+ */
30
+ textClass: String,
31
+ /**
32
+ * Adds the classes to each row.
33
+ */
34
+ rowClass: String,
35
+ } as const
36
+
37
+ /**
38
+ * The `NList` displays key-value data in an appealing way.
39
+ */
40
+ const Component = createComponent('NList', nListProps, props => {
41
+ return () => (
42
+ <dl>
43
+ {props.items.map((item, index) => (
44
+ <div
45
+ key={index}
46
+ class={[
47
+ 'py-5 px-4 sm:grid sm:grid-cols-3 sm:gap-4',
48
+ index % 2 === 1 ? 'bg-white' : 'bg-default-50',
49
+ props.rowClass,
50
+ ]}
51
+ >
52
+ <dt class={`text-sm font-medium text-default-500 ${props.titleClass}`}>
53
+ {buildElement(item.title)}
54
+ </dt>
55
+ <dd class={`mt-1 text-sm sm:mt-0 sm:col-span-2 ${props.textClass}`}>{buildElement(item.text)}</dd>
56
+ </div>
57
+ ))}
58
+ </dl>
59
+ )
60
+ })
61
+
62
+ export { Component as NList, Component as default }
63
+
64
+ function buildElement(element: string | undefined | (() => JSX.Element)): JSX.Element {
65
+ if (typeof element === 'function') return element()
66
+ else return <>{element}</>
67
+ }
@@ -0,0 +1,46 @@
1
+ .lds-ellipsis {
2
+ position: relative;
3
+ }
4
+
5
+ .lds-ellipsis div {
6
+ position: absolute;
7
+ border-radius: 50%;
8
+ animation-timing-function: cubic-bezier(0, 1, 1, 0);
9
+ }
10
+
11
+ .lds-ellipsis div:nth-child(1) {
12
+ animation: lds-ellipsis1 0.6s infinite;
13
+ }
14
+ .lds-ellipsis div:nth-child(2) {
15
+ animation: lds-ellipsis2 0.6s infinite;
16
+ }
17
+ .lds-ellipsis div:nth-child(3) {
18
+ animation: lds-ellipsis2 0.6s infinite;
19
+ }
20
+ .lds-ellipsis div:nth-child(4) {
21
+ animation: lds-ellipsis3 0.6s infinite;
22
+ }
23
+ @keyframes lds-ellipsis1 {
24
+ 0% {
25
+ transform: scale(0);
26
+ }
27
+ 100% {
28
+ transform: scale(1);
29
+ }
30
+ }
31
+ @keyframes lds-ellipsis3 {
32
+ 0% {
33
+ transform: scale(1);
34
+ }
35
+ 100% {
36
+ transform: scale(0);
37
+ }
38
+ }
39
+ @keyframes lds-ellipsis2 {
40
+ 0% {
41
+ transform: translate(0, 0);
42
+ }
43
+ 100% {
44
+ transform: translate(var(--n-loading-indicator-gap), 0);
45
+ }
46
+ }