@naptics/vue-collection 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -15
- package/components/NAlert.js +81 -0
- package/components/NBadge.js +57 -0
- package/components/NBreadcrub.js +66 -0
- package/components/NButton.js +65 -0
- package/components/NCheckbox.js +42 -0
- package/components/NCheckboxLabel.js +39 -0
- package/components/NCrudModal.js +105 -0
- package/components/NDialog.js +160 -0
- package/components/NDropdown.js +108 -0
- package/components/NDropzone.js +210 -0
- package/components/NForm.js +28 -0
- package/components/NFormModal.js +54 -0
- package/components/NIconButton.js +81 -0
- package/components/NIconCircle.js +66 -0
- package/components/NInput.js +105 -0
- package/components/NInputPhone.d.ts +1 -1
- package/components/NInputPhone.js +46 -0
- package/components/NInputPhone.jsx +2 -1
- package/components/NInputSelect.js +114 -0
- package/components/NInputSuggestion.d.ts +1 -1
- package/components/NInputSuggestion.js +63 -0
- package/components/NLink.js +59 -0
- package/components/NList.js +24 -0
- package/components/NLoadingIndicator.js +53 -0
- package/components/NModal.js +210 -0
- package/components/NPagination.js +108 -0
- package/components/NSearchbar.js +66 -0
- package/components/NSearchbarList.js +36 -0
- package/components/NSelect.js +84 -0
- package/components/NSuggestionList.js +156 -0
- package/components/NTable.js +126 -0
- package/components/NTableAction.js +49 -0
- package/components/NTextArea.d.ts +1 -1
- package/components/NTextArea.js +128 -0
- package/components/NTooltip.js +178 -0
- package/components/NValInput.d.ts +1 -1
- package/components/NValInput.js +104 -0
- package/components/ValidatedForm.js +18 -18
- package/i18n/index.d.ts +24 -1
- package/i18n/index.js +13 -16
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +11 -4
- package/utils/breakpoints.js +21 -21
- package/utils/component.js +17 -9
- package/utils/deferred.js +12 -12
- package/utils/identifiable.js +27 -29
- package/utils/stringMaxLength.js +8 -13
- package/utils/tailwind.js +1 -1
- package/utils/utils.js +5 -5
- package/utils/vModel.js +82 -73
- package/utils/validation.d.ts +9 -3
- package/utils/validation.js +67 -83
- package/utils/vue.js +7 -5
- package/i18n/de/template.json +0 -10
- package/i18n/de.d.ts +0 -61
- package/i18n/de.js +0 -5
- package/i18n/en/template.json +0 -10
- package/i18n/en.d.ts +0 -61
- package/i18n/en.js +0 -5
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createVNode as _createVNode } from "vue";
|
|
2
|
+
import { createComponent, createProps } from '../utils/component';
|
|
3
|
+
export const nIconCircleProps = createProps({
|
|
4
|
+
/**
|
|
5
|
+
* The icon of the icon-circle.
|
|
6
|
+
*/
|
|
7
|
+
icon: {
|
|
8
|
+
type: Function,
|
|
9
|
+
required: true
|
|
10
|
+
},
|
|
11
|
+
/**
|
|
12
|
+
* The color of the icon-circle.
|
|
13
|
+
*/
|
|
14
|
+
color: {
|
|
15
|
+
type: String,
|
|
16
|
+
default: 'primary'
|
|
17
|
+
},
|
|
18
|
+
/**
|
|
19
|
+
* The size of the circle in "tailwind units" (4 px).
|
|
20
|
+
* Tailwind classes are used for the size, so any number can be passed.
|
|
21
|
+
* If the `iconSize` is not set, it will be adjusted automatically.
|
|
22
|
+
*/
|
|
23
|
+
circleSize: Number,
|
|
24
|
+
/**
|
|
25
|
+
* The size of the icon in "tailwind units" (4 px).
|
|
26
|
+
* No tailwind classes are used for the size, so any number can be passed.
|
|
27
|
+
* If the `circleSize` is not set, it will be adjusted automatically.
|
|
28
|
+
*/
|
|
29
|
+
iconSize: Number,
|
|
30
|
+
/**
|
|
31
|
+
* The shade of the icon.
|
|
32
|
+
*/
|
|
33
|
+
iconShade: {
|
|
34
|
+
type: Number,
|
|
35
|
+
default: 600
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* The shade of the background.
|
|
39
|
+
*/
|
|
40
|
+
bgShade: {
|
|
41
|
+
type: Number,
|
|
42
|
+
default: 100
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const DEFAULT_CIRCLE_SIZE = 16;
|
|
46
|
+
const SCALING_FACTOR = 0.55;
|
|
47
|
+
/**
|
|
48
|
+
* The `NIconCircle` is an icon with a colored circle around it.
|
|
49
|
+
*/
|
|
50
|
+
export default createComponent('NIconCircle', nIconCircleProps, props => {
|
|
51
|
+
let circleSize = props.circleSize;
|
|
52
|
+
let iconSize = props.iconSize;
|
|
53
|
+
if (circleSize == null) {
|
|
54
|
+
if (iconSize == null) circleSize = DEFAULT_CIRCLE_SIZE;else circleSize = iconSize / SCALING_FACTOR;
|
|
55
|
+
}
|
|
56
|
+
if (iconSize == null) iconSize = circleSize * SCALING_FACTOR;
|
|
57
|
+
circleSize *= 4;
|
|
58
|
+
iconSize *= 4;
|
|
59
|
+
return () => _createVNode("div", {
|
|
60
|
+
"class": ['flex items-center justify-center rounded-full', `bg-${props.color}-${props.bgShade}`],
|
|
61
|
+
"style": `width: ${circleSize}px; height: ${circleSize}px`
|
|
62
|
+
}, [_createVNode("div", {
|
|
63
|
+
"class": `text-${props.color}-${props.iconShade}`,
|
|
64
|
+
"style": `width: ${iconSize}px; height: ${iconSize}px`
|
|
65
|
+
}, [_createVNode(props.icon, null, null)])]);
|
|
66
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { mergeProps as _mergeProps, withDirectives as _withDirectives, vShow as _vShow, createVNode as _createVNode } from "vue";
|
|
2
|
+
import { createComponent, createProps } from '../utils/component';
|
|
3
|
+
import { ref } from 'vue';
|
|
4
|
+
import { ExclamationCircleIcon } from '@heroicons/vue/24/solid';
|
|
5
|
+
import NTooltip, { mapTooltipProps, nToolTipPropsForImplementor } from './NTooltip';
|
|
6
|
+
import './NInput.css';
|
|
7
|
+
import { vModelProps } from '../utils/vModel';
|
|
8
|
+
export const nInputProps = createProps({
|
|
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
|
+
* This is called when the input reveices focus.
|
|
58
|
+
*/
|
|
59
|
+
onFocus: Function,
|
|
60
|
+
/**
|
|
61
|
+
* This is called when the input looses focus.
|
|
62
|
+
*/
|
|
63
|
+
onBlur: Function,
|
|
64
|
+
...nToolTipPropsForImplementor
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* The base class of inputs. A styled input with a lot of configuration possibilities but no validation.
|
|
68
|
+
*/
|
|
69
|
+
export default createComponent('NInput', nInputProps, (props, context) => {
|
|
70
|
+
const inputRef = ref();
|
|
71
|
+
const exposed = {
|
|
72
|
+
focus: () => inputRef.value?.focus()
|
|
73
|
+
};
|
|
74
|
+
context.expose(exposed);
|
|
75
|
+
return () => _createVNode("div", null, [props.name && !props.hideLabel && _createVNode("label", {
|
|
76
|
+
"for": props.name,
|
|
77
|
+
"class": ['block text-sm font-medium mb-1', props.disabled ? 'text-default-300' : 'text-default-700']
|
|
78
|
+
}, [props.name]), _createVNode(NTooltip, _mergeProps({
|
|
79
|
+
"block": true
|
|
80
|
+
}, mapTooltipProps(props)), {
|
|
81
|
+
default: () => [_createVNode("div", {
|
|
82
|
+
"class": "relative"
|
|
83
|
+
}, [_createVNode("input", {
|
|
84
|
+
"ref": inputRef,
|
|
85
|
+
"name": props.name,
|
|
86
|
+
"value": props.value,
|
|
87
|
+
"onInput": event => props.onUpdateValue?.(event.target.value),
|
|
88
|
+
"placeholder": props.placeholder,
|
|
89
|
+
"autocomplete": props.autocomplete,
|
|
90
|
+
"type": props.type,
|
|
91
|
+
"min": props.min,
|
|
92
|
+
"max": props.max,
|
|
93
|
+
"disabled": props.disabled,
|
|
94
|
+
"onFocus": () => props.onFocus?.(),
|
|
95
|
+
"onBlur": () => props.onBlur?.(),
|
|
96
|
+
"onInvalid": event => event.preventDefault(),
|
|
97
|
+
"class": ['block w-full rounded-md border focus:outline-none focus:ring-1 ', props.small ? 'text-xs py-0.5 px-2' : 'py-2 px-4', props.disabled ? 'text-default-500 placeholder-default-300 bg-default-50' : 'text-default-900 placeholder-default-400 ', props.error ? 'border-red-500 focus:border-red-500 focus:ring-red-500 pr-10' : 'border-default-300 focus:border-primary-500 focus:ring-primary-500']
|
|
98
|
+
}, null), _withDirectives(_createVNode("div", {
|
|
99
|
+
"class": "absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none"
|
|
100
|
+
}, [_createVNode(ExclamationCircleIcon, {
|
|
101
|
+
"class": "h-5 w-5 text-red-700",
|
|
102
|
+
"aria-hidden": "true"
|
|
103
|
+
}, null)]), [[_vShow, props.error && !props.small]])])]
|
|
104
|
+
})]);
|
|
105
|
+
});
|
|
@@ -140,10 +140,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
140
140
|
tooltipMaxWidth: import("../utils/tailwind").TWMaxWidth;
|
|
141
141
|
disabled: boolean;
|
|
142
142
|
error: boolean;
|
|
143
|
-
rules: import("../utils/validation").ValidationRule | import("../utils/validation").ValidationRule[];
|
|
144
143
|
autocomplete: string;
|
|
145
144
|
hideLabel: boolean;
|
|
146
145
|
optional: boolean;
|
|
146
|
+
rules: import("../utils/validation").ValidationRule | import("../utils/validation").ValidationRule[];
|
|
147
147
|
hideErrorMessage: boolean;
|
|
148
148
|
disableBlurValidation: boolean;
|
|
149
149
|
}>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
|
|
2
|
+
import { createComponent, createProps } from '../utils/component';
|
|
3
|
+
import { external } from '../utils/validation';
|
|
4
|
+
import { computed, Suspense } from 'vue';
|
|
5
|
+
import NValInput, { nValInputProps } from './NValInput';
|
|
6
|
+
import { trsl } from '../i18n';
|
|
7
|
+
export const nInputPhoneProps = createProps(nValInputProps);
|
|
8
|
+
/**
|
|
9
|
+
* The `NInputPhone` autoformats phone numbers and checks if they are valid.
|
|
10
|
+
*/
|
|
11
|
+
export default createComponent('NInputPhoneSuspended', nInputPhoneProps, props => {
|
|
12
|
+
// Async components have to be wrapped in a suspense component.
|
|
13
|
+
return () => _createVNode(Suspense, null, {
|
|
14
|
+
default: () => [_createVNode(NPhoneInput, props, null)]
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
const NPhoneInput = createComponent('NInputPhone', nInputPhoneProps, async props => {
|
|
18
|
+
// import dynamically for better codesplitting as the library is pretty large
|
|
19
|
+
const {
|
|
20
|
+
parsePhoneNumber
|
|
21
|
+
} = await import('awesome-phonenumber');
|
|
22
|
+
const DEFAULT_COUNTRY_CODE = 'CH';
|
|
23
|
+
const formattedToPlain = number => parsePhoneNumber(number, {
|
|
24
|
+
regionCode: DEFAULT_COUNTRY_CODE
|
|
25
|
+
}).number?.e164;
|
|
26
|
+
const plainToFormatted = number => parsePhoneNumber(number, {
|
|
27
|
+
regionCode: DEFAULT_COUNTRY_CODE
|
|
28
|
+
}).number?.international;
|
|
29
|
+
const onUpdateValue = newValue => {
|
|
30
|
+
const plain = formattedToPlain(newValue);
|
|
31
|
+
props.onUpdateValue?.(plain || newValue);
|
|
32
|
+
};
|
|
33
|
+
const value = computed(() => {
|
|
34
|
+
const formatted = plainToFormatted(props.value || '');
|
|
35
|
+
return formatted || props.value;
|
|
36
|
+
});
|
|
37
|
+
const isValid = computed(() => parsePhoneNumber(props.value || '').valid);
|
|
38
|
+
return () => _createVNode(NValInput, _mergeProps({
|
|
39
|
+
...props,
|
|
40
|
+
onUpdateValue
|
|
41
|
+
}, {
|
|
42
|
+
"value": value.value,
|
|
43
|
+
"rules": external(isValid.value, trsl('vue-collection.validation.rules.phone')),
|
|
44
|
+
"type": "tel"
|
|
45
|
+
}), null);
|
|
46
|
+
});
|
|
@@ -2,6 +2,7 @@ import { createComponent, createProps } from '../utils/component';
|
|
|
2
2
|
import { external } from '../utils/validation';
|
|
3
3
|
import { computed, Suspense } from 'vue';
|
|
4
4
|
import NValInput, { nValInputProps } from './NValInput';
|
|
5
|
+
import { trsl } from '../i18n';
|
|
5
6
|
export const nInputPhoneProps = createProps(nValInputProps);
|
|
6
7
|
/**
|
|
7
8
|
* The `NInputPhone` autoformats phone numbers and checks if they are valid.
|
|
@@ -27,5 +28,5 @@ const NPhoneInput = createComponent('NInputPhone', nInputPhoneProps, async (prop
|
|
|
27
28
|
return formatted || props.value;
|
|
28
29
|
});
|
|
29
30
|
const isValid = computed(() => parsePhoneNumber(props.value || '').valid);
|
|
30
|
-
return () => (<NValInput {...{ ...props, onUpdateValue }} value={value.value} rules={external(isValid.value, 'phone')} type="tel"/>);
|
|
31
|
+
return () => (<NValInput {...{ ...props, onUpdateValue }} value={value.value} rules={external(isValid.value, trsl('vue-collection.validation.rules.phone'))} type="tel"/>);
|
|
31
32
|
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createVNode as _createVNode, mergeProps as _mergeProps } from "vue";
|
|
2
|
+
import { createComponent, createProps } from '../utils/component';
|
|
3
|
+
import { Id } from '../utils/identifiable';
|
|
4
|
+
import { option } from '../utils/validation';
|
|
5
|
+
import { vModelForRef } from '../utils/vModel';
|
|
6
|
+
import { watchRef } from '../utils/vue';
|
|
7
|
+
import { computed, ref, watch } from 'vue';
|
|
8
|
+
import { nInputProps } from './NInput';
|
|
9
|
+
import NSuggestionList, { nSuggestionListProps } from './NSuggestionList';
|
|
10
|
+
import NValInput, { nValInputProps } from './NValInput';
|
|
11
|
+
export const nInputSelectProps = createProps({
|
|
12
|
+
...nInputProps,
|
|
13
|
+
/**
|
|
14
|
+
* The id of the currently selected option of this input.
|
|
15
|
+
*/
|
|
16
|
+
value: String,
|
|
17
|
+
/**
|
|
18
|
+
* This is called with the newly selected id when the selection has changed.
|
|
19
|
+
* This happens, when an item from the suggestion list is selected or the
|
|
20
|
+
* input matches a selection option exactly.
|
|
21
|
+
* If no id is selected, the empty string is passed, in order to
|
|
22
|
+
* match the API of all other inputs who never pass `undefined`.
|
|
23
|
+
*/
|
|
24
|
+
onUpdateValue: Function,
|
|
25
|
+
/**
|
|
26
|
+
* The options which are allowed and suggested for this input.
|
|
27
|
+
* The options are filtered based on the user input.
|
|
28
|
+
*/
|
|
29
|
+
options: {
|
|
30
|
+
type: Array,
|
|
31
|
+
default: () => []
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* @see {@link nValInputProps.optional}
|
|
35
|
+
*/
|
|
36
|
+
optional: nValInputProps.optional,
|
|
37
|
+
/**
|
|
38
|
+
* @see {@link nValInputProps.form}
|
|
39
|
+
*/
|
|
40
|
+
form: nValInputProps.form,
|
|
41
|
+
/**
|
|
42
|
+
* @see {@link nValInputProps.error}
|
|
43
|
+
*/
|
|
44
|
+
error: nValInputProps.error,
|
|
45
|
+
/**
|
|
46
|
+
* @see {@link nValInputProps.errorMessage}
|
|
47
|
+
*/
|
|
48
|
+
errorMessage: nValInputProps.errorMessage,
|
|
49
|
+
/**
|
|
50
|
+
* If set to `true` the list is hidden even if there are still matching items in the list.
|
|
51
|
+
*/
|
|
52
|
+
hideList: nSuggestionListProps.hideList,
|
|
53
|
+
/**
|
|
54
|
+
* @see {@link nSuggestionListProps.maxItems}
|
|
55
|
+
*/
|
|
56
|
+
maxItems: nSuggestionListProps.maxItems,
|
|
57
|
+
/**
|
|
58
|
+
* @see {@link nSuggestionListProps.listItem}
|
|
59
|
+
*/
|
|
60
|
+
listItem: nSuggestionListProps.listItem
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* The `NInputSelect` is very similar to the {@link NSelect}, but instead of a select input it is a regular input.
|
|
64
|
+
* The user is forced to use a value from the specified options of the input.
|
|
65
|
+
* While they type, the list of options is shown to them and filtered based on their input.
|
|
66
|
+
*/
|
|
67
|
+
export default createComponent('NInputSelect', nInputSelectProps, props => {
|
|
68
|
+
const inputRef = ref();
|
|
69
|
+
const inputValue = ref('');
|
|
70
|
+
watch(() => props.value, newValue => {
|
|
71
|
+
if (newValue) {
|
|
72
|
+
const chosenOption = Id.find(props.options, newValue);
|
|
73
|
+
if (chosenOption) inputValue.value = chosenOption.label;
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
immediate: true
|
|
77
|
+
});
|
|
78
|
+
const filteredOptions = computed(() => props.options.filter(option => option.label.includes(inputValue.value || '')));
|
|
79
|
+
const matchedOption = computed(() => {
|
|
80
|
+
const matches = props.options.filter(option => option.label === inputValue.value);
|
|
81
|
+
return matches.length > 0 ? matches[0] : null;
|
|
82
|
+
});
|
|
83
|
+
watchRef(matchedOption, newOption => props.onUpdateValue?.(newOption?.id || ''));
|
|
84
|
+
return () => _createVNode(NSuggestionList, {
|
|
85
|
+
"items": filteredOptions.value,
|
|
86
|
+
"onSelect": props.onUpdateValue,
|
|
87
|
+
"inputValue": inputValue.value,
|
|
88
|
+
"hideList": props.hideList || matchedOption.value != null || filteredOptions.value.length == 0,
|
|
89
|
+
"maxItems": props.maxItems,
|
|
90
|
+
"listItem": props.listItem,
|
|
91
|
+
"input": ({
|
|
92
|
+
onFocus,
|
|
93
|
+
onBlur
|
|
94
|
+
}) => _createVNode(NValInput, _mergeProps({
|
|
95
|
+
"ref": inputRef
|
|
96
|
+
}, {
|
|
97
|
+
...props,
|
|
98
|
+
...vModelForRef(inputValue)
|
|
99
|
+
}, {
|
|
100
|
+
"rules": option(props.options.map(opt => opt.label)),
|
|
101
|
+
"onFocus": () => {
|
|
102
|
+
onFocus();
|
|
103
|
+
props.onFocus?.();
|
|
104
|
+
},
|
|
105
|
+
"onBlur": onBlur,
|
|
106
|
+
"disableBlurValidation": true
|
|
107
|
+
}), null),
|
|
108
|
+
"onRequestInputFocus": () => inputRef.value?.focus(),
|
|
109
|
+
"onRealBlur": () => {
|
|
110
|
+
props.onBlur?.();
|
|
111
|
+
inputRef?.value?.validate();
|
|
112
|
+
}
|
|
113
|
+
}, null);
|
|
114
|
+
});
|
|
@@ -199,10 +199,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
199
199
|
tooltipMaxWidth: import("../utils/tailwind").TWMaxWidth;
|
|
200
200
|
disabled: boolean;
|
|
201
201
|
error: boolean;
|
|
202
|
-
rules: import("../utils/validation").ValidationRule | import("../utils/validation").ValidationRule[];
|
|
203
202
|
autocomplete: string;
|
|
204
203
|
hideLabel: boolean;
|
|
205
204
|
optional: boolean;
|
|
205
|
+
rules: import("../utils/validation").ValidationRule | import("../utils/validation").ValidationRule[];
|
|
206
206
|
hideErrorMessage: boolean;
|
|
207
207
|
disableBlurValidation: boolean;
|
|
208
208
|
maxItems: number;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createVNode as _createVNode, mergeProps as _mergeProps } from "vue";
|
|
2
|
+
import { createComponent, createProps } from '../utils/component';
|
|
3
|
+
import { Id } from '../utils/identifiable';
|
|
4
|
+
import { computed, ref } from 'vue';
|
|
5
|
+
import NSuggestionList, { nSuggestionListProps } from './NSuggestionList';
|
|
6
|
+
import NValInput, { nValInputProps } from './NValInput';
|
|
7
|
+
export const nInputSuggestionProps = createProps({
|
|
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,
|
|
23
|
+
default: () => []
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* `NInputSuggestion` is an input, which shows a list of possible suggestions to the user
|
|
28
|
+
* which is filtered while typing. Contrary to {@link NInputSelect} the user is not required to choose any of the suggestions.
|
|
29
|
+
*/
|
|
30
|
+
export default createComponent('NInputSuggestion', nInputSuggestionProps, props => {
|
|
31
|
+
const suggestionItems = computed(() => props.suggestions.filter(suggestion => suggestion.includes(props.value || '')).map((value, index) => ({
|
|
32
|
+
id: index.toString(),
|
|
33
|
+
label: value
|
|
34
|
+
})));
|
|
35
|
+
const select = id => props.onUpdateValue?.(Id.find(suggestionItems.value, id)?.label || '');
|
|
36
|
+
const hideList = computed(() => props.hideList || suggestionItems.value.length == 0 || suggestionItems.value.filter(suggestion => suggestion.label !== props.value).length == 0);
|
|
37
|
+
const inputRef = ref();
|
|
38
|
+
return () => _createVNode(NSuggestionList, {
|
|
39
|
+
"items": suggestionItems.value,
|
|
40
|
+
"onSelect": id => select(id),
|
|
41
|
+
"inputValue": props.value || '',
|
|
42
|
+
"hideList": hideList.value,
|
|
43
|
+
"maxItems": props.maxItems,
|
|
44
|
+
"input": ({
|
|
45
|
+
onFocus,
|
|
46
|
+
onBlur
|
|
47
|
+
}) => _createVNode(NValInput, _mergeProps({
|
|
48
|
+
"ref": inputRef
|
|
49
|
+
}, props, {
|
|
50
|
+
"onFocus": () => {
|
|
51
|
+
onFocus();
|
|
52
|
+
props.onFocus?.();
|
|
53
|
+
},
|
|
54
|
+
"onBlur": onBlur,
|
|
55
|
+
"disableBlurValidation": true
|
|
56
|
+
}), null),
|
|
57
|
+
"onRequestInputFocus": () => inputRef.value?.focus(),
|
|
58
|
+
"onRealBlur": () => {
|
|
59
|
+
props.onBlur?.();
|
|
60
|
+
inputRef?.value?.validate();
|
|
61
|
+
}
|
|
62
|
+
}, null);
|
|
63
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createVNode as _createVNode } from "vue";
|
|
2
|
+
import { createComponent, createProps } from '../utils/component';
|
|
3
|
+
import { computed } from 'vue';
|
|
4
|
+
import { RouterLink } from 'vue-router';
|
|
5
|
+
export const nLinkProps = createProps({
|
|
6
|
+
/**
|
|
7
|
+
* The text of the link. Can also be set in the default slot.
|
|
8
|
+
*/
|
|
9
|
+
text: String,
|
|
10
|
+
/**
|
|
11
|
+
* The route of the link. If this is set,
|
|
12
|
+
* the link becomes a {@link RouterLink} and does not emit the `onClick` event.
|
|
13
|
+
*/
|
|
14
|
+
route: [Object, String],
|
|
15
|
+
/**
|
|
16
|
+
* The color of the link.
|
|
17
|
+
*/
|
|
18
|
+
color: {
|
|
19
|
+
type: String,
|
|
20
|
+
default: 'primary'
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* The text size, a standard tailwind text-size class.
|
|
24
|
+
*/
|
|
25
|
+
textSize: String,
|
|
26
|
+
/**
|
|
27
|
+
* The shade of the link.
|
|
28
|
+
*/
|
|
29
|
+
shade: {
|
|
30
|
+
type: Number,
|
|
31
|
+
default: 500
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* This is called when the link is clicked but only, if the `route` prop is not set.
|
|
35
|
+
* If the `route` prop is not set, the link will act as a regular button.
|
|
36
|
+
*/
|
|
37
|
+
onClick: Function
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* The `NLink` is a styled text which can be used as a {@link RouterLink} or a regular button.
|
|
41
|
+
*/
|
|
42
|
+
export default createComponent('NLink', nLinkProps, (props, {
|
|
43
|
+
slots
|
|
44
|
+
}) => {
|
|
45
|
+
const hoverShade = computed(() => {
|
|
46
|
+
const shade = props.shade;
|
|
47
|
+
if (shade <= 500) return shade + 100;else return shade - 200;
|
|
48
|
+
});
|
|
49
|
+
const classes = computed(() => ['font-medium focus:outline-none focus-visible:ring-2 rounded-sm ring-offset-2 hover:underline text-left', `${props.textSize} text-${props.color}-${props.shade} hover:text-${props.color}-${hoverShade.value} focus-visible:ring-${props.color}-${props.shade}`]);
|
|
50
|
+
return () => props.route ? _createVNode(RouterLink, {
|
|
51
|
+
"to": props.route,
|
|
52
|
+
"class": classes.value
|
|
53
|
+
}, {
|
|
54
|
+
default: () => [slots.default?.() || props.text]
|
|
55
|
+
}) : _createVNode("button", {
|
|
56
|
+
"onClick": props.onClick,
|
|
57
|
+
"class": classes.value
|
|
58
|
+
}, [slots.default?.() || props.text]);
|
|
59
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createVNode as _createVNode } from "vue";
|
|
2
|
+
import { createComponent, createProps } from '../utils/component';
|
|
3
|
+
export const nListProps = createProps({
|
|
4
|
+
/**
|
|
5
|
+
* The items which are displayed in the list.
|
|
6
|
+
*/
|
|
7
|
+
items: {
|
|
8
|
+
type: Array,
|
|
9
|
+
default: () => []
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* The `NList` displays key-value data in an appealing way.
|
|
14
|
+
*/
|
|
15
|
+
export default createComponent('NList', nListProps, props => {
|
|
16
|
+
return () => _createVNode("dl", null, [props.items.map((item, index) => _createVNode("div", {
|
|
17
|
+
"key": index,
|
|
18
|
+
"class": ['py-5 px-4 sm:grid sm:grid-cols-3 sm:gap-4', index % 2 === 1 ? 'bg-white' : 'bg-default-50']
|
|
19
|
+
}, [_createVNode("dt", {
|
|
20
|
+
"class": "text-sm font-medium text-default-500"
|
|
21
|
+
}, [item.title]), _createVNode("dd", {
|
|
22
|
+
"class": "mt-1 text-sm sm:mt-0 sm:col-span-2"
|
|
23
|
+
}, [item.text])]))]);
|
|
24
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createVNode as _createVNode } from "vue";
|
|
2
|
+
import { createComponent, createProps } from '../utils/component';
|
|
3
|
+
import { computed, useCssVars } from 'vue';
|
|
4
|
+
import './NLoadingIndicator.css';
|
|
5
|
+
export const nLoadingIndicator = createProps({
|
|
6
|
+
/**
|
|
7
|
+
* The color of the loading-indicator.
|
|
8
|
+
*/
|
|
9
|
+
color: {
|
|
10
|
+
type: String,
|
|
11
|
+
default: 'primary'
|
|
12
|
+
},
|
|
13
|
+
/**
|
|
14
|
+
* The shade of the loading-indicator.
|
|
15
|
+
*/
|
|
16
|
+
shade: {
|
|
17
|
+
type: Number,
|
|
18
|
+
default: 400
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* The height of the loading-indicator in px.
|
|
22
|
+
*/
|
|
23
|
+
size: {
|
|
24
|
+
type: Number,
|
|
25
|
+
default: 10
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* The `NLoadingIndicator` is a styled loading indicator.
|
|
30
|
+
*/
|
|
31
|
+
export default createComponent('NLoadingIndicator', nLoadingIndicator, props => {
|
|
32
|
+
const gap = computed(() => props.size / 13 * 24);
|
|
33
|
+
const totalWidth = computed(() => gap.value * 2 + props.size);
|
|
34
|
+
useCssVars(() => ({
|
|
35
|
+
'n-loading-indicator-gap': `${gap.value}px`
|
|
36
|
+
}));
|
|
37
|
+
return () => _createVNode("div", {
|
|
38
|
+
"class": "lds-ellipsis",
|
|
39
|
+
"style": `height:${props.size}px;width:${totalWidth.value}px`
|
|
40
|
+
}, [_createVNode("div", {
|
|
41
|
+
"class": `bg-${props.color}-${props.shade}`,
|
|
42
|
+
"style": `height:${props.size}px;width:${props.size}px;left:0px`
|
|
43
|
+
}, null), _createVNode("div", {
|
|
44
|
+
"class": `bg-${props.color}-${props.shade}`,
|
|
45
|
+
"style": `height:${props.size}px;width:${props.size}px;left:0px`
|
|
46
|
+
}, null), _createVNode("div", {
|
|
47
|
+
"class": `bg-${props.color}-${props.shade}`,
|
|
48
|
+
"style": `height:${props.size}px;width:${props.size}px;left:${gap.value}px`
|
|
49
|
+
}, null), _createVNode("div", {
|
|
50
|
+
"class": `bg-${props.color}-${props.shade}`,
|
|
51
|
+
"style": `height:${props.size}px;width:${props.size}px;left:${2 * gap.value}px`
|
|
52
|
+
}, null)]);
|
|
53
|
+
});
|