@naptics/vue-collection 0.3.2 → 1.0.0-beta.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 (129) hide show
  1. package/eslint.config.cjs +0 -2
  2. package/package.json +31 -30
  3. package/postcss.config.js +1 -4
  4. package/src/demo/App.css +47 -3
  5. package/src/demo/components/ComponentSection.tsx +1 -1
  6. package/src/demo/views/NavigationView.tsx +1 -1
  7. package/src/demo/views/presentation/TooltipView.tsx +1 -1
  8. package/src/lib/components/NAlert.tsx +3 -3
  9. package/src/lib/components/NBadge.tsx +1 -1
  10. package/src/lib/components/NButton.tsx +6 -4
  11. package/src/lib/components/NCheckbox.tsx +2 -2
  12. package/src/lib/components/NDialog.tsx +2 -2
  13. package/src/lib/components/NDropdown.tsx +11 -9
  14. package/src/lib/components/NDropzone.tsx +4 -4
  15. package/src/lib/components/NIconButton.tsx +2 -2
  16. package/src/lib/components/NInput.tsx +1 -1
  17. package/src/lib/components/NLink.tsx +1 -1
  18. package/src/lib/components/NModal.tsx +4 -4
  19. package/src/lib/components/NPagination.css +4 -2
  20. package/src/lib/components/NPagination.tsx +1 -1
  21. package/src/lib/components/NSearchbar.tsx +1 -1
  22. package/src/lib/components/NSelect.tsx +1 -1
  23. package/src/lib/components/NSuggestionList.tsx +1 -1
  24. package/src/lib/components/NTable.css +2 -0
  25. package/src/lib/components/NTableAction.tsx +1 -1
  26. package/src/lib/components/NTextArea.tsx +1 -1
  27. package/src/lib/components/NTooltip.css +2 -0
  28. package/src/lib/components/NTooltip.tsx +1 -1
  29. package/src/lib/utils/component.tsx +1 -1
  30. package/tsconfig.lib.json +1 -0
  31. package/vite.config.ts +2 -0
  32. package/components/NAlert.d.ts +0 -29
  33. package/components/NAlert.js +0 -84
  34. package/components/NBadge.d.ts +0 -73
  35. package/components/NBadge.js +0 -64
  36. package/components/NBreadcrub.d.ts +0 -69
  37. package/components/NBreadcrub.js +0 -71
  38. package/components/NButton.d.ts +0 -64
  39. package/components/NButton.js +0 -72
  40. package/components/NCheckbox.d.ts +0 -20
  41. package/components/NCheckbox.js +0 -43
  42. package/components/NCheckboxLabel.d.ts +0 -26
  43. package/components/NCheckboxLabel.js +0 -42
  44. package/components/NCrudModal.d.ts +0 -118
  45. package/components/NCrudModal.js +0 -120
  46. package/components/NDialog.d.ts +0 -81
  47. package/components/NDialog.js +0 -161
  48. package/components/NDropdown.d.ts +0 -67
  49. package/components/NDropdown.js +0 -115
  50. package/components/NDropzone.d.ts +0 -61
  51. package/components/NDropzone.js +0 -218
  52. package/components/NForm.d.ts +0 -21
  53. package/components/NForm.js +0 -29
  54. package/components/NFormModal.d.ts +0 -75
  55. package/components/NFormModal.js +0 -59
  56. package/components/NIconButton.d.ts +0 -83
  57. package/components/NIconButton.js +0 -88
  58. package/components/NIconCircle.d.ts +0 -49
  59. package/components/NIconCircle.js +0 -67
  60. package/components/NInput.css +0 -11
  61. package/components/NInput.d.ts +0 -94
  62. package/components/NInput.js +0 -110
  63. package/components/NInputPhone.d.ts +0 -58
  64. package/components/NInputPhone.js +0 -47
  65. package/components/NInputSelect.d.ts +0 -103
  66. package/components/NInputSelect.js +0 -115
  67. package/components/NInputSuggestion.d.ts +0 -79
  68. package/components/NInputSuggestion.js +0 -64
  69. package/components/NLink.d.ts +0 -47
  70. package/components/NLink.js +0 -67
  71. package/components/NList.d.ts +0 -37
  72. package/components/NList.js +0 -40
  73. package/components/NLoadingIndicator.css +0 -46
  74. package/components/NLoadingIndicator.d.ts +0 -29
  75. package/components/NLoadingIndicator.js +0 -54
  76. package/components/NModal.d.ts +0 -133
  77. package/components/NModal.js +0 -232
  78. package/components/NPagination.css +0 -15
  79. package/components/NPagination.d.ts +0 -37
  80. package/components/NPagination.js +0 -105
  81. package/components/NSearchbar.d.ts +0 -39
  82. package/components/NSearchbar.js +0 -64
  83. package/components/NSearchbarList.d.ts +0 -33
  84. package/components/NSearchbarList.js +0 -41
  85. package/components/NSelect.d.ts +0 -82
  86. package/components/NSelect.js +0 -101
  87. package/components/NSuggestionList.d.ts +0 -153
  88. package/components/NSuggestionList.js +0 -160
  89. package/components/NTable.css +0 -3
  90. package/components/NTable.d.ts +0 -97
  91. package/components/NTable.js +0 -128
  92. package/components/NTableAction.d.ts +0 -30
  93. package/components/NTableAction.js +0 -50
  94. package/components/NTextArea.d.ts +0 -96
  95. package/components/NTextArea.js +0 -133
  96. package/components/NTooltip.css +0 -37
  97. package/components/NTooltip.d.ts +0 -152
  98. package/components/NTooltip.js +0 -241
  99. package/components/NValInput.d.ts +0 -159
  100. package/components/NValInput.js +0 -113
  101. package/components/ValidatedForm.d.ts +0 -39
  102. package/components/ValidatedForm.js +0 -35
  103. package/i18n/de/vue-collection.json +0 -58
  104. package/i18n/en/vue-collection.json +0 -58
  105. package/i18n/index.d.ts +0 -40
  106. package/i18n/index.js +0 -31
  107. package/index.d.ts +0 -2
  108. package/index.js +0 -2
  109. package/tailwind.config.js +0 -38
  110. package/utils/breakpoints.d.ts +0 -18
  111. package/utils/breakpoints.js +0 -40
  112. package/utils/component.d.ts +0 -57
  113. package/utils/component.js +0 -79
  114. package/utils/deferred.d.ts +0 -13
  115. package/utils/deferred.js +0 -17
  116. package/utils/identifiable.d.ts +0 -56
  117. package/utils/identifiable.js +0 -81
  118. package/utils/stringMaxLength.d.ts +0 -14
  119. package/utils/stringMaxLength.js +0 -23
  120. package/utils/tailwind.d.ts +0 -4
  121. package/utils/tailwind.js +0 -1
  122. package/utils/utils.d.ts +0 -47
  123. package/utils/utils.js +0 -56
  124. package/utils/vModel.d.ts +0 -182
  125. package/utils/vModel.js +0 -224
  126. package/utils/validation.d.ts +0 -90
  127. package/utils/validation.js +0 -147
  128. package/utils/vue.d.ts +0 -13
  129. package/utils/vue.js +0 -21
@@ -1,241 +0,0 @@
1
- import { createVNode as _createVNode, Fragment as _Fragment, vShow as _vShow, withDirectives as _withDirectives } from "vue";
2
- import { createComponent } from '../utils/component';
3
- import { uniqueId } from '../utils/utils';
4
- import { computed, onMounted, ref, watch, onUnmounted, Transition } from 'vue';
5
- import { createPopper } from '@popperjs/core';
6
- import { watchRef } from '../utils/vue';
7
- import './NTooltip.css';
8
- export const nTooltipProps = {
9
- /**
10
- * The text content of the tooltip.
11
- */
12
- text: String,
13
- /**
14
- * A slot to replace the content of the tooltip. This will override the `text` prop.
15
- */
16
- content: Function,
17
- /**
18
- * If set to `true` the tooltip is shown constantly.
19
- */
20
- show: Boolean,
21
- /**
22
- * If set to `true` the tooltip is hidden constantly.
23
- */
24
- hide: Boolean,
25
- /**
26
- * If set to `true` the `block` class is applied to the tooltip.
27
- * This should be set if the content in the default slot is also block.
28
- */
29
- block: Boolean,
30
- /**
31
- * The placement of the tooltip.
32
- */
33
- placement: {
34
- type: String,
35
- default: 'auto'
36
- },
37
- /**
38
- * The maximum width of the tooltip.
39
- */
40
- maxWidth: {
41
- type: String,
42
- default: 'max-w-xs'
43
- },
44
- /**
45
- * Adds the classes to the (invisible) wrapper element.
46
- */
47
- wrapperClass: String,
48
- /**
49
- * Adds the classes to the container of the tooltips content.
50
- */
51
- contentClass: String,
52
- /**
53
- * Adds the classes to the tooltip arrow. Make sure to use `before:` classes
54
- * to target the arrow (which is the before element).
55
- */
56
- arrowClass: String,
57
- /**
58
- * The delay in milliseconds before the tooltip is shown.
59
- * @default 0
60
- */
61
- delay: {
62
- type: Number,
63
- default: 0
64
- }
65
- };
66
- /**
67
- * These props are made to use on a component which implements the tooltip
68
- * and wants it to be controllable via the own props.
69
- * e.g. `text` is now called `tooltipText`.
70
- * They can be mapped to the normal tooltip props with {@link mapTooltipProps}
71
- */
72
- export const nToolTipPropsForImplementor = {
73
- /**
74
- * Adds a tooltip to the component with the specified text.
75
- * @see {@link nTooltipProps.text}
76
- */
77
- tooltipText: nTooltipProps.text,
78
- /**
79
- * A slot for the tooltip of this component.
80
- * If the slot is set, the tooltip with the specified content is added to the component.
81
- * @see {@link nTooltipProps.content}
82
- */
83
- tooltipContent: nTooltipProps.content,
84
- /**
85
- * @see {@link nTooltipProps.hide}
86
- */
87
- tooltipHide: nTooltipProps.hide,
88
- /**
89
- * @see {@link nTooltipProps.show}
90
- */
91
- tooltipShow: nTooltipProps.show,
92
- /**
93
- * @see {@link nTooltipProps.placement}
94
- */
95
- tooltipPlacement: nTooltipProps.placement,
96
- /**
97
- * @see {@link nTooltipProps.maxWidth}
98
- */
99
- tooltipMaxWidth: nTooltipProps.maxWidth,
100
- /**
101
- * @see {@link nTooltipProps.wrapperClass}
102
- */
103
- tooltipWrapperClass: nTooltipProps.wrapperClass,
104
- /**
105
- * @see {@link nTooltipProps.contentClass}
106
- */
107
- tooltipContentClass: nTooltipProps.contentClass,
108
- /**
109
- * @see {@link nTooltipProps.arrowClass}
110
- */
111
- tooltipArrowClass: nTooltipProps.arrowClass,
112
- /**
113
- * @see {@link nTooltipProps.delay}
114
- */
115
- tooltipDelay: nTooltipProps.delay
116
- };
117
- /**
118
- * Maps the {@link nToolTipPropsForImplementor} props to normal tooltip props
119
- * @returns an object containing the normal tooltip props.
120
- */
121
- export function mapTooltipProps(props) {
122
- return {
123
- text: props.tooltipText,
124
- content: props.tooltipContent,
125
- hide: props.tooltipHide,
126
- show: props.tooltipShow,
127
- placement: props.tooltipPlacement,
128
- maxWidth: props.tooltipMaxWidth,
129
- wrapperClass: props.tooltipWrapperClass,
130
- contentClass: props.tooltipContentClass,
131
- arrowClass: props.tooltipArrowClass,
132
- delay: props.tooltipDelay
133
- };
134
- }
135
- /**
136
- * The `NTooltip` is a wrapper for any component which adds a tooltip to it.
137
- * Any component can just be passed in the default slot and a tooltip will be added to it.
138
- * Note that this component disappears when neither the `text` nor the `content`
139
- * prop is passed as the tooltip would then be empty.
140
- * If this is the case, the default slot will just be rendered inside a div.
141
- * @example
142
- * <NTooltip text="Hello">
143
- * <NButton />
144
- * </NTooltip>
145
- */
146
- const Component = createComponent('NTooltip', nTooltipProps, (props, {
147
- slots
148
- }) => {
149
- return () => _createVNode("div", {
150
- "class": [props.block ? 'block' : 'inline-block', props.wrapperClass]
151
- }, [props.content || props.text ? _createVNode(NTooltipBase, props, {
152
- default: () => [slots.default?.()]
153
- }) : slots.default?.()]);
154
- });
155
- export { Component as NTooltip, Component as default };
156
- const NTooltipBase = createComponent('NTooltipBase', nTooltipProps, (props, {
157
- slots
158
- }) => {
159
- let popperInstance = null;
160
- const contentId = `content-${uniqueId()}`;
161
- const tooltipId = `tooltip-${uniqueId()}`;
162
- function createTooltip() {
163
- const content = document.getElementById(contentId);
164
- const tooltip = document.getElementById(tooltipId);
165
- if (content && tooltip) {
166
- popperInstance = createPopper(content, tooltip, {
167
- placement: props.placement,
168
- modifiers: [{
169
- name: 'offset',
170
- options: {
171
- offset: [0, 8]
172
- }
173
- }]
174
- });
175
- } else {
176
- console.error('Could not create tooltip. HTML elements for content or tooltip were not found.');
177
- }
178
- }
179
- function destroyTooltip() {
180
- popperInstance?.destroy();
181
- popperInstance = null;
182
- }
183
- onMounted(createTooltip);
184
- onUnmounted(() => {
185
- if (hoverTimeout) {
186
- clearTimeout(hoverTimeout);
187
- }
188
- destroyTooltip();
189
- });
190
- watch(() => props.placement, newPlacement => popperInstance?.setOptions({
191
- placement: newPlacement
192
- }));
193
- const isHoveringContent = ref(false);
194
- const isHoveringTooltip = ref(false);
195
- const isHovering = computed(() => isHoveringContent.value || isHoveringTooltip.value);
196
- const delayedIsHovering = ref(false);
197
- let hoverTimeout = null;
198
- const showTooltip = computed(() => props.show || !props.hide && (props.delay > 0 ? delayedIsHovering.value : isHovering.value));
199
- watch(isHovering, hovering => {
200
- if (hoverTimeout) {
201
- clearTimeout(hoverTimeout);
202
- hoverTimeout = null;
203
- }
204
- if (hovering && props.delay > 0) {
205
- hoverTimeout = setTimeout(() => {
206
- delayedIsHovering.value = true;
207
- hoverTimeout = null;
208
- }, props.delay);
209
- } else {
210
- delayedIsHovering.value = hovering;
211
- }
212
- });
213
- watchRef(showTooltip, () => popperInstance?.update());
214
- return () => _createVNode(_Fragment, null, [_createVNode("div", {
215
- "class": "p-[10px] -m-[10px]",
216
- "onMouseleave": () => setTimeout(() => isHoveringContent.value = false, 10)
217
- }, [_createVNode("div", {
218
- "id": contentId,
219
- "onMouseenter": () => isHoveringContent.value = true
220
- }, [slots.default?.()])]), _createVNode(Transition, {
221
- "enterActiveClass": "transition-opacity ease-out duration-100",
222
- "enterFromClass": "opacity-0",
223
- "enterToClass": "opacity-100",
224
- "leaveActiveClass": "transition-opacity ease-in duration-75",
225
- "leaveFromClass": "opacity-100",
226
- "leaveToClass": "opacity-0"
227
- }, {
228
- default: () => [_withDirectives(_createVNode("div", {
229
- "id": tooltipId,
230
- "role": "tooltip",
231
- "onMouseenter": () => isHoveringTooltip.value = true,
232
- "onMouseleave": () => isHoveringTooltip.value = false,
233
- "class": [isHovering.value ? 'z-20' : 'z-10', props.maxWidth, 'tooltip']
234
- }, [_createVNode("div", {
235
- "class": `bg-white rounded-md py-2 px-4 shadow-lg border-default-200 border text-sm whitespace-normal font-normal text-default-700 ${props.contentClass}`
236
- }, [props.content?.() || props.text]), _createVNode("div", {
237
- "data-popper-arrow": true,
238
- "class": `arrow ${props.arrowClass}`
239
- }, null)]), [[_vShow, showTooltip.value]])]
240
- })]);
241
- });
@@ -1,159 +0,0 @@
1
- import { type PropType } from 'vue';
2
- import { type NInputExposed } from './NInput';
3
- import { type ValidationRule, type ValidationResult } from '../utils/validation';
4
- import type { ValidatedForm } from './ValidatedForm';
5
- export declare const validationProps: {
6
- /**
7
- * If set to `true` this inputs validation will always succeed and all validation
8
- * rules are ignored. Default is `false`.
9
- */
10
- readonly disableValidation: BooleanConstructor;
11
- /**
12
- * If set to `true` this input is always valid when its value is empty.
13
- * If set to `false` the input receives the {@link required} rule. Default is `false`.
14
- */
15
- readonly optional: BooleanConstructor;
16
- /**
17
- * The rules which this input is checked with.
18
- * The rules are checked sequentially and the error of the first failed rule is displayed.
19
- * If `optional` is set to false, the rule {@link required} will be checked first.
20
- */
21
- readonly rules: {
22
- readonly type: PropType<ValidationRule[] | ValidationRule>;
23
- readonly default: () => never[];
24
- };
25
- /**
26
- * The form, which this input will be added to.
27
- * On initialization, this input will call {@link ValidatedForm.addInput} passing itself to the form.
28
- */
29
- readonly form: PropType<ValidatedForm>;
30
- /**
31
- * Overrides the internal error state. If set to true, it will always display an error.
32
- */
33
- readonly error: BooleanConstructor;
34
- /**
35
- * Overrides the internal error message. If set, this message is always displayed.
36
- */
37
- readonly errorMessage: StringConstructor;
38
- /**
39
- * If set to `true` the error message is not shown.
40
- * However, the input is still marked red if it is in an error state.
41
- */
42
- readonly hideErrorMessage: BooleanConstructor;
43
- /**
44
- * Disables the validation on blur. Should only be used in special occasions.
45
- */
46
- readonly disableBlurValidation: BooleanConstructor;
47
- };
48
- export declare const nValInputProps: {
49
- /**
50
- * A slot to replace the input.
51
- */
52
- readonly input: PropType<(props: InputSlotProps) => JSX.Element>;
53
- /**
54
- * If set to `true` this inputs validation will always succeed and all validation
55
- * rules are ignored. Default is `false`.
56
- */
57
- readonly disableValidation: BooleanConstructor;
58
- /**
59
- * If set to `true` this input is always valid when its value is empty.
60
- * If set to `false` the input receives the {@link required} rule. Default is `false`.
61
- */
62
- readonly optional: BooleanConstructor;
63
- /**
64
- * The rules which this input is checked with.
65
- * The rules are checked sequentially and the error of the first failed rule is displayed.
66
- * If `optional` is set to false, the rule {@link required} will be checked first.
67
- */
68
- readonly rules: {
69
- readonly type: PropType<ValidationRule[] | ValidationRule>;
70
- readonly default: () => never[];
71
- };
72
- /**
73
- * The form, which this input will be added to.
74
- * On initialization, this input will call {@link ValidatedForm.addInput} passing itself to the form.
75
- */
76
- readonly form: PropType<ValidatedForm>;
77
- /**
78
- * Overrides the internal error state. If set to true, it will always display an error.
79
- */
80
- readonly error: BooleanConstructor;
81
- /**
82
- * Overrides the internal error message. If set, this message is always displayed.
83
- */
84
- readonly errorMessage: StringConstructor;
85
- /**
86
- * If set to `true` the error message is not shown.
87
- * However, the input is still marked red if it is in an error state.
88
- */
89
- readonly hideErrorMessage: BooleanConstructor;
90
- /**
91
- * Disables the validation on blur. Should only be used in special occasions.
92
- */
93
- readonly disableBlurValidation: BooleanConstructor;
94
- readonly tooltipText: StringConstructor;
95
- readonly tooltipContent: PropType<() => JSX.Element /**
96
- * If set to `true` this input is always valid when its value is empty.
97
- * If set to `false` the input receives the {@link required} rule. Default is `false`.
98
- */>;
99
- readonly tooltipHide: BooleanConstructor;
100
- readonly tooltipShow: BooleanConstructor;
101
- readonly tooltipPlacement: {
102
- readonly type: PropType<import("./NTooltip").TooltipPlacement>;
103
- readonly default: "auto";
104
- };
105
- readonly tooltipMaxWidth: {
106
- readonly type: PropType<import("../utils/tailwind").TWMaxWidth>;
107
- readonly default: "max-w-xs";
108
- };
109
- readonly tooltipWrapperClass: StringConstructor;
110
- readonly tooltipContentClass: StringConstructor;
111
- readonly tooltipArrowClass: StringConstructor;
112
- readonly tooltipDelay: {
113
- readonly type: NumberConstructor;
114
- readonly default: 0;
115
- };
116
- readonly name: StringConstructor;
117
- readonly placeholder: StringConstructor;
118
- readonly autocomplete: {
119
- readonly type: StringConstructor;
120
- readonly default: "off";
121
- };
122
- readonly type: {
123
- readonly type: StringConstructor;
124
- readonly default: "text";
125
- };
126
- readonly max: StringConstructor;
127
- readonly min: StringConstructor;
128
- readonly disabled: BooleanConstructor;
129
- readonly small: BooleanConstructor;
130
- readonly hideLabel: BooleanConstructor;
131
- readonly inputClass: StringConstructor;
132
- readonly onFocus: PropType<() => void>;
133
- readonly onBlur: PropType<() => void>;
134
- readonly value: PropType<string>;
135
- readonly onUpdateValue: PropType<(newValue: string) => void>;
136
- };
137
- export type InputSlotProps = {
138
- onBlur(): void;
139
- onUpdateValue(newValue: string): void;
140
- error: boolean;
141
- };
142
- /**
143
- * The exposed functions of NValInput
144
- */
145
- export type NValInputExposed = {
146
- /**
147
- * Validates the input and returns the validation result
148
- */
149
- validate: () => ValidationResult;
150
- /**
151
- * Resets the validation state of the input.
152
- */
153
- reset: () => void;
154
- } & NInputExposed;
155
- /**
156
- * The `NValInput` is a `NInput` with custom validation.
157
- */
158
- declare const Component: import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
159
- export { Component as NValInput, Component as default };
@@ -1,113 +0,0 @@
1
- import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
2
- import { createComponentWithSlots } from '../utils/component';
3
- import { computed, onMounted, onUnmounted } from 'vue';
4
- import { ref, reactive, watch } from 'vue';
5
- import NInput, { nInputProps } from './NInput';
6
- import { validate, required, validResult } from '../utils/validation';
7
- export const validationProps = {
8
- /**
9
- * If set to `true` this inputs validation will always succeed and all validation
10
- * rules are ignored. Default is `false`.
11
- */
12
- disableValidation: Boolean,
13
- /**
14
- * If set to `true` this input is always valid when its value is empty.
15
- * If set to `false` the input receives the {@link required} rule. Default is `false`.
16
- */
17
- optional: Boolean,
18
- /**
19
- * The rules which this input is checked with.
20
- * The rules are checked sequentially and the error of the first failed rule is displayed.
21
- * If `optional` is set to false, the rule {@link required} will be checked first.
22
- */
23
- rules: {
24
- type: [Function, Array],
25
- default: () => []
26
- },
27
- /**
28
- * The form, which this input will be added to.
29
- * On initialization, this input will call {@link ValidatedForm.addInput} passing itself to the form.
30
- */
31
- form: Object,
32
- /**
33
- * Overrides the internal error state. If set to true, it will always display an error.
34
- */
35
- error: Boolean,
36
- /**
37
- * Overrides the internal error message. If set, this message is always displayed.
38
- */
39
- errorMessage: String,
40
- /**
41
- * If set to `true` the error message is not shown.
42
- * However, the input is still marked red if it is in an error state.
43
- */
44
- hideErrorMessage: Boolean,
45
- /**
46
- * Disables the validation on blur. Should only be used in special occasions.
47
- */
48
- disableBlurValidation: Boolean
49
- };
50
- export const nValInputProps = {
51
- ...nInputProps,
52
- ...validationProps,
53
- /**
54
- * A slot to replace the input.
55
- */
56
- input: Function
57
- };
58
- /**
59
- * The `NValInput` is a `NInput` with custom validation.
60
- */
61
- const Component = createComponentWithSlots('NValInput', nValInputProps, ['input'], (props, context) => {
62
- const rules = computed(() => {
63
- const otherRules = Array.isArray(props.rules) ? props.rules : [props.rules];
64
- return props.optional ? otherRules : [required, ...otherRules];
65
- });
66
- const validationResult = ref();
67
- const validateRules = input => {
68
- const result = props.disableValidation ? validResult() : validate(input, rules.value);
69
- validationResult.value = result;
70
- return result;
71
- };
72
- const showError = computed(() => props.error || validationResult.value != null && !validationResult.value.isValid);
73
- const showErrorMessage = computed(() => !props.hideErrorMessage && showError.value);
74
- const errorMessage = computed(() => props.errorMessage || validationResult.value?.errorMessage);
75
- const validateIfError = (value = props.value) => {
76
- if (showError.value) validateRules(value);
77
- };
78
- watch(() => props.value, () => validateIfError());
79
- watch(() => rules.value, () => validateIfError());
80
- watch(() => props.disableValidation, () => validateIfError());
81
- const onBlur = () => {
82
- if (!props.disableBlurValidation) validateRules(props.value);
83
- props.onBlur?.();
84
- };
85
- const onUpdateValue = newValue => {
86
- validateIfError(newValue);
87
- props.onUpdateValue?.(newValue);
88
- };
89
- const inputSlotProps = reactive({
90
- onBlur,
91
- onUpdateValue,
92
- error: showError
93
- });
94
- const inputRef = ref();
95
- const expose = {
96
- validate: () => validateRules(props.value),
97
- reset: () => validationResult.value = undefined,
98
- focus: () => inputRef.value?.focus()
99
- };
100
- context.expose(expose);
101
- let assignedId = undefined;
102
- onMounted(() => assignedId = props.form?.addInput(expose));
103
- onUnmounted(() => assignedId && props.form?.removeInput(assignedId));
104
- return () => _createVNode("div", null, [props.input?.(inputSlotProps) || _createVNode(NInput, _mergeProps({
105
- "ref": inputRef
106
- }, {
107
- ...props,
108
- ...inputSlotProps
109
- }), null), showErrorMessage.value && _createVNode("p", {
110
- "class": "text-red-500 text-xs mt-1"
111
- }, [errorMessage.value])]);
112
- });
113
- export { Component as NValInput, Component as default };
@@ -1,39 +0,0 @@
1
- import type { ValidationResult } from '../utils/validation';
2
- import type { NValInputExposed } from './NValInput';
3
- /**
4
- * A ValidatedForm groups different inputs together and provides functions, which operate on all inputs at the same time.
5
- * With a form multiple inputs can be validated together by calling the validate function.
6
- * @example
7
- * const form = createValidatedForm()
8
- * <NValInput ... form={form} />
9
- * <NValInput ... form={form} />
10
- * const onClick = () => form.validate()
11
- */
12
- export type ValidatedForm = {
13
- /**
14
- * Adds the input to the list of this form and returns the assigned `id`.
15
- * If this form is passed to a `<NValInput />` via the props, will add itself to this form.
16
- * @returns the newly assigned `id` of the added input.
17
- * @example
18
- * <NValInput ... form={form} />
19
- */
20
- addInput(input: NValInputExposed): string;
21
- /**
22
- * Removes the input with the given `id` from this form.
23
- */
24
- removeInput(id: string): void;
25
- /**
26
- * Validates all inputs of the form. If inputs are invalid they will show it visually.
27
- * The first invalid validation result is returned.
28
- */
29
- validate(): ValidationResult;
30
- /**
31
- * Resets the validation state of all inputs.
32
- */
33
- reset(): void;
34
- };
35
- /**
36
- * Creates a new ValidatedForm.
37
- * @returns the instance of the new form.
38
- */
39
- export declare function createValidatedForm(): ValidatedForm;
@@ -1,35 +0,0 @@
1
- import { Id } from '../utils/identifiable';
2
- import { uniqueId } from '../utils/utils';
3
- /**
4
- * Creates a new ValidatedForm.
5
- * @returns the instance of the new form.
6
- */
7
- export function createValidatedForm() {
8
- return new ValidatedFormImpl();
9
- }
10
- class ValidatedFormImpl {
11
- inputs = [];
12
- addInput(input) {
13
- const id = `input-${uniqueId()}`;
14
- this.inputs.push({
15
- id,
16
- ...input
17
- });
18
- return id;
19
- }
20
- removeInput(id) {
21
- Id.remove(this.inputs, id);
22
- }
23
- validate() {
24
- const results = this.inputs.map(input => input.validate());
25
- // return first invalid result
26
- for (const result of results) if (result && !result.isValid) return result;
27
- // else return valid result
28
- return {
29
- isValid: true
30
- };
31
- }
32
- reset() {
33
- this.inputs.forEach(input => input.reset());
34
- }
35
- }
@@ -1,58 +0,0 @@
1
- {
2
- "title": {},
3
- "subtitle": {},
4
- "text": {
5
- "loading-search-results": "Ergebnisse werden geladen...",
6
- "no-search-results": "Keine Ergebnisse für «{input}».",
7
- "drag-n-drop-files": "Datei auswählen oder per Drag & Drop hinzufügen. | Bis zu {n} Dateien auswählen oder per Drag & Drop hinzufügen.",
8
- "files-selected": "Keine Datei ausgewählt. | Eine Datei ausgewählt. | {n} Dateien ausgewählt."
9
- },
10
- "property": {},
11
- "term": {},
12
- "action": {
13
- "search": "Suchen",
14
- "select": "Auswählen",
15
- "remove": "Löschen",
16
- "cancel": "Abbrechen",
17
- "all-right": "Alles klar",
18
- "proceed": "Fortfahren",
19
- "save": "Speichern",
20
- "clear-files": "Auswahl löschen."
21
- },
22
- "enum": {},
23
- "error": {
24
- "file-type": "Eine Datei wurde nicht hinzugefügt, da sie im falschen Format ist. | {n} Dateien wurden nicht hinzugefügt, da sie im falschen Format sind.",
25
- "file-size": "Eine Datei wurde nicht hinzugefügt, da sie zu gross ist. | {n} Dateien wurden nicht hinzugefügt, da sie zu gross sind.",
26
- "too-many-files": "Es kann nur eine Datei hinzugefügt werden. | Es können nicht mehr als {n} Dateien hinzugefügt werden."
27
- },
28
- "validation": {
29
- "rules": {
30
- "email": "Dieses Feld muss eine gültige Email-Adresse sein.",
31
- "integer": "Dieses Feld muss eine Ganzzahl sein.",
32
- "length": {
33
- "min": "Der Text darf nicht weniger als {min} Zeichen enthalten.",
34
- "max": "Der Text darf nicht mehr als {max} Zeichen enthalten.",
35
- "min-max": "Der Text muss zwischen {min} und {max} Zeichen enthalten."
36
- },
37
- "matches": "Die Felder stimmen nicht überein.",
38
- "number-range": {
39
- "nan": "Dieses Feld muss eine Zahl sein.",
40
- "min": "Die Zahl darf nicht kleiner als {min} sein.",
41
- "max": "Die Zahl darf nicht grösser als {max} sein.",
42
- "min-max": "Die Zahl muss im Bereich von {min} bis {max} liegen."
43
- },
44
- "option": "Dieses Feld muss eine Option aus der Liste sein.",
45
- "password": {
46
- "to-short": "Das Passwort muss aus mindestens 8 Zeichen bestehen.",
47
- "no-lowercase": "Das Passwort muss einen Kleinbuchstaben enthalten.",
48
- "no-uppercase": "Das Passwort muss einen Grossbuchstaben enthalten.",
49
- "no-digits": "Das Passwort muss eine Ziffer enthalten.",
50
- "no-special-chars": "Das Passwort muss ein Sonderzeichen enthalten.",
51
- "unknown": "Dieses Feld erfüllt nicht die Anforderungen für ein Passwort."
52
- },
53
- "phone": "Dieses Feld muss eine gültige Telefonnummer sein.",
54
- "required": "Dieses Feld ist ein Pflichtfeld.",
55
- "regex": "Dieses Feld entspricht nicht dem geforderten Format."
56
- }
57
- }
58
- }