@naptics/vue-collection 0.0.3 → 0.0.5
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 +5 -1
- 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.js +46 -0
- package/components/NInputSelect.js +114 -0
- 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.js +128 -0
- package/components/NTooltip.js +178 -0
- package/components/NValInput.js +104 -0
- package/components/ValidatedForm.js +18 -18
- package/i18n/index.js +0 -4
- package/package.json +9 -2
- package/components/NAlert.jsx +0 -69
- package/components/NBadge.jsx +0 -58
- package/components/NBreadcrub.jsx +0 -64
- package/components/NButton.jsx +0 -58
- package/components/NCheckbox.jsx +0 -38
- package/components/NCheckboxLabel.jsx +0 -42
- package/components/NCrudModal.jsx +0 -89
- package/components/NDialog.jsx +0 -144
- package/components/NDropdown.jsx +0 -92
- package/components/NDropzone.jsx +0 -211
- package/components/NForm.jsx +0 -26
- package/components/NFormModal.jsx +0 -48
- package/components/NIconButton.jsx +0 -71
- package/components/NIconCircle.jsx +0 -67
- package/components/NInput.jsx +0 -97
- package/components/NInputPhone.jsx +0 -32
- package/components/NInputSelect.jsx +0 -89
- package/components/NInputSuggestion.jsx +0 -48
- package/components/NLink.jsx +0 -58
- package/components/NList.jsx +0 -24
- package/components/NLoadingIndicator.jsx +0 -42
- package/components/NModal.jsx +0 -170
- package/components/NPagination.jsx +0 -104
- package/components/NSearchbar.jsx +0 -58
- package/components/NSearchbarList.jsx +0 -20
- package/components/NSelect.jsx +0 -81
- package/components/NSuggestionList.jsx +0 -157
- package/components/NTable.jsx +0 -146
- package/components/NTableAction.jsx +0 -35
- package/components/NTextArea.jsx +0 -108
- package/components/NTooltip.jsx +0 -161
- package/components/NValInput.jsx +0 -101
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { withDirectives as _withDirectives, vShow as _vShow, Fragment as _Fragment, createVNode as _createVNode } from "vue";
|
|
2
|
+
import { createComponent, createProps } 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 = createProps({
|
|
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
|
+
/**
|
|
46
|
+
* These props are made to use on a component which implements the tooltip
|
|
47
|
+
* and wants it to be controllable via the own props.
|
|
48
|
+
* e.g. `text` is now called `tooltipText`.
|
|
49
|
+
* They can be mapped to the normal tooltip props with {@link mapTooltipProps}
|
|
50
|
+
*/
|
|
51
|
+
export const nToolTipPropsForImplementor = {
|
|
52
|
+
/**
|
|
53
|
+
* Adds a tooltip to the component with the specified text.
|
|
54
|
+
* @see {@link nTooltipProps.text}
|
|
55
|
+
*/
|
|
56
|
+
tooltipText: nTooltipProps.text,
|
|
57
|
+
/**
|
|
58
|
+
* A slot for the tooltip of this component.
|
|
59
|
+
* If the slot is set, the tooltip with the specified content is added to the component.
|
|
60
|
+
* @see {@link nTooltipProps.content}
|
|
61
|
+
*/
|
|
62
|
+
tooltipContent: nTooltipProps.content,
|
|
63
|
+
/**
|
|
64
|
+
* @see {@link nTooltipProps.hide}
|
|
65
|
+
*/
|
|
66
|
+
tooltipHide: nTooltipProps.hide,
|
|
67
|
+
/**
|
|
68
|
+
* @see {@link nTooltipProps.show}
|
|
69
|
+
*/
|
|
70
|
+
tooltipShow: nTooltipProps.show,
|
|
71
|
+
/**
|
|
72
|
+
* @see {@link nTooltipProps.placement}
|
|
73
|
+
*/
|
|
74
|
+
tooltipPlacement: nTooltipProps.placement,
|
|
75
|
+
/**
|
|
76
|
+
* @see {@link nTooltipProps.maxWidth}
|
|
77
|
+
*/
|
|
78
|
+
tooltipMaxWidth: nTooltipProps.maxWidth
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Maps the {@link nToolTipPropsForImplementor} props to normal tooltip props
|
|
82
|
+
* @returns an object containing the normal tooltip props.
|
|
83
|
+
*/
|
|
84
|
+
export function mapTooltipProps(props) {
|
|
85
|
+
return {
|
|
86
|
+
text: props.tooltipText,
|
|
87
|
+
content: props.tooltipContent,
|
|
88
|
+
hide: props.tooltipHide,
|
|
89
|
+
show: props.tooltipShow,
|
|
90
|
+
placement: props.tooltipPlacement,
|
|
91
|
+
maxWidth: props.tooltipMaxWidth
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The `NTooltip` is a wrapper for any component which adds a tooltip to it.
|
|
96
|
+
* Any component can just be passed in the default slot and a tooltip will be added to it.
|
|
97
|
+
* Note that this component disappears when neither the `text` nor the `content`
|
|
98
|
+
* prop is passed as the tooltip would then be empty.
|
|
99
|
+
* If this is the case, the default slot will just be rendered inside a div.
|
|
100
|
+
* @example
|
|
101
|
+
* <NTooltip text="Hello">
|
|
102
|
+
* <NButton />
|
|
103
|
+
* </NTooltip>
|
|
104
|
+
*/
|
|
105
|
+
export default createComponent('NTooltip', nTooltipProps, (props, {
|
|
106
|
+
slots
|
|
107
|
+
}) => {
|
|
108
|
+
return () => _createVNode("div", {
|
|
109
|
+
"class": props.block ? 'block' : 'inline-block'
|
|
110
|
+
}, [props.content || props.text ? _createVNode(NTooltipBase, props, {
|
|
111
|
+
default: () => [slots.default?.()]
|
|
112
|
+
}) : slots.default?.()]);
|
|
113
|
+
});
|
|
114
|
+
const NTooltipBase = createComponent('NTooltipBase', nTooltipProps, (props, {
|
|
115
|
+
slots
|
|
116
|
+
}) => {
|
|
117
|
+
let popperInstance = null;
|
|
118
|
+
const contentId = `content-${uniqueId()}`;
|
|
119
|
+
const tooltipId = `tooltip-${uniqueId()}`;
|
|
120
|
+
function createTooltip() {
|
|
121
|
+
const content = document.getElementById(contentId);
|
|
122
|
+
const tooltip = document.getElementById(tooltipId);
|
|
123
|
+
if (content && tooltip) {
|
|
124
|
+
popperInstance = createPopper(content, tooltip, {
|
|
125
|
+
placement: props.placement,
|
|
126
|
+
modifiers: [{
|
|
127
|
+
name: 'offset',
|
|
128
|
+
options: {
|
|
129
|
+
offset: [0, 8]
|
|
130
|
+
}
|
|
131
|
+
}]
|
|
132
|
+
});
|
|
133
|
+
} else {
|
|
134
|
+
console.error('Could not create tooltip. HTML elements for content or tooltip were not found.');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function destroyTooltip() {
|
|
138
|
+
popperInstance?.destroy();
|
|
139
|
+
popperInstance = null;
|
|
140
|
+
}
|
|
141
|
+
onMounted(createTooltip);
|
|
142
|
+
onUnmounted(destroyTooltip);
|
|
143
|
+
watch(() => props.placement, newPlacement => popperInstance?.setOptions({
|
|
144
|
+
placement: newPlacement
|
|
145
|
+
}));
|
|
146
|
+
const isHoveringContent = ref(false);
|
|
147
|
+
const isHoveringTooltip = ref(false);
|
|
148
|
+
const isHovering = computed(() => isHoveringContent.value || isHoveringTooltip.value);
|
|
149
|
+
const showTooltip = computed(() => props.show || !props.hide && isHovering.value);
|
|
150
|
+
watchRef(showTooltip, () => popperInstance?.update());
|
|
151
|
+
return () => _createVNode(_Fragment, null, [_createVNode("div", {
|
|
152
|
+
"class": "p-[10px] -m-[10px]",
|
|
153
|
+
"onMouseleave": () => setTimeout(() => isHoveringContent.value = false, 10)
|
|
154
|
+
}, [_createVNode("div", {
|
|
155
|
+
"id": contentId,
|
|
156
|
+
"onMouseenter": () => isHoveringContent.value = true
|
|
157
|
+
}, [slots.default?.()])]), _createVNode(Transition, {
|
|
158
|
+
"enterActiveClass": "transition-opacity ease-out duration-100",
|
|
159
|
+
"enterFromClass": "opacity-0",
|
|
160
|
+
"enterToClass": "opacity-100",
|
|
161
|
+
"leaveActiveClass": "transition-opacity ease-in duration-75",
|
|
162
|
+
"leaveFromClass": "opacity-100",
|
|
163
|
+
"leaveToClass": "opacity-0"
|
|
164
|
+
}, {
|
|
165
|
+
default: () => [_withDirectives(_createVNode("div", {
|
|
166
|
+
"id": tooltipId,
|
|
167
|
+
"role": "tooltip",
|
|
168
|
+
"onMouseenter": () => isHoveringTooltip.value = true,
|
|
169
|
+
"onMouseleave": () => isHoveringTooltip.value = false,
|
|
170
|
+
"class": [isHovering.value ? 'z-20' : 'z-10', props.maxWidth, 'tooltip']
|
|
171
|
+
}, [_createVNode("div", {
|
|
172
|
+
"class": "bg-white rounded-md py-2 px-4 shadow-lg border-default-200 border text-sm font-normal text-default-700"
|
|
173
|
+
}, [props.content?.() || props.text]), _createVNode("div", {
|
|
174
|
+
"data-popper-arrow": true,
|
|
175
|
+
"class": "arrow"
|
|
176
|
+
}, null)]), [[_vShow, showTooltip.value]])]
|
|
177
|
+
})]);
|
|
178
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createVNode as _createVNode, mergeProps as _mergeProps } from "vue";
|
|
2
|
+
import { createComponent, createProps } from '../utils/component';
|
|
3
|
+
import { computed } from 'vue';
|
|
4
|
+
import { ref, reactive, watch } from 'vue';
|
|
5
|
+
import NInput, { nInputProps } from './NInput';
|
|
6
|
+
import { validate, required } from '../utils/validation';
|
|
7
|
+
export const validationProps = createProps({
|
|
8
|
+
/**
|
|
9
|
+
* If set to `true` this input is always valid when its value is empty.
|
|
10
|
+
* If set to `false` the input receives the {@link required} rule. Default is `false`.
|
|
11
|
+
*/
|
|
12
|
+
optional: Boolean,
|
|
13
|
+
/**
|
|
14
|
+
* The rules which this input is checked with.
|
|
15
|
+
* The rules are checked sequentially and the error of the first failed rule is displayed.
|
|
16
|
+
* If `optional` is set to false, the rule {@link required} will be checked first.
|
|
17
|
+
*/
|
|
18
|
+
rules: {
|
|
19
|
+
type: [Function, Array],
|
|
20
|
+
default: () => []
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* The form, which this input will be added to.
|
|
24
|
+
* On initialization, this input will call {@link ValidatedForm.addInput} passing itself to the form.
|
|
25
|
+
*/
|
|
26
|
+
form: Object,
|
|
27
|
+
/**
|
|
28
|
+
* Overrides the internal error state. If set to true, it will always display an error.
|
|
29
|
+
*/
|
|
30
|
+
error: Boolean,
|
|
31
|
+
/**
|
|
32
|
+
* Overrides the internal error message. If set, this message is always displayed.
|
|
33
|
+
*/
|
|
34
|
+
errorMessage: String,
|
|
35
|
+
/**
|
|
36
|
+
* If set to `true` the error message is not shown.
|
|
37
|
+
* However, the input is still marked red if it is in an error state.
|
|
38
|
+
*/
|
|
39
|
+
hideErrorMessage: Boolean,
|
|
40
|
+
/**
|
|
41
|
+
* Disables the validation on blur. Should only be used in special occasions.
|
|
42
|
+
*/
|
|
43
|
+
disableBlurValidation: Boolean
|
|
44
|
+
});
|
|
45
|
+
export const nValInputProps = createProps({
|
|
46
|
+
...nInputProps,
|
|
47
|
+
...validationProps,
|
|
48
|
+
/**
|
|
49
|
+
* A slot to replace the input.
|
|
50
|
+
*/
|
|
51
|
+
input: Function
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* The `NValInput` is a `NInput` with custom validation.
|
|
55
|
+
*/
|
|
56
|
+
export default createComponent('NValInput', nValInputProps, (props, context) => {
|
|
57
|
+
const rules = computed(() => {
|
|
58
|
+
const otherRules = Array.isArray(props.rules) ? props.rules : [props.rules];
|
|
59
|
+
return props.optional ? otherRules : [required, ...otherRules];
|
|
60
|
+
});
|
|
61
|
+
const validationResult = ref();
|
|
62
|
+
const validateRules = input => {
|
|
63
|
+
const result = validate(input, rules.value);
|
|
64
|
+
validationResult.value = result;
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
const showError = computed(() => props.error || validationResult.value != null && !validationResult.value.isValid);
|
|
68
|
+
const showErrorMessage = computed(() => !props.hideErrorMessage && showError.value);
|
|
69
|
+
const errorMessage = computed(() => props.errorMessage || validationResult.value?.errorMessage);
|
|
70
|
+
const validateIfError = (value = props.value) => {
|
|
71
|
+
if (showError.value) validateRules(value);
|
|
72
|
+
};
|
|
73
|
+
watch(() => props.value, () => validateIfError());
|
|
74
|
+
watch(() => rules.value, () => validateIfError());
|
|
75
|
+
const onBlur = () => {
|
|
76
|
+
if (!props.disableBlurValidation) validateRules(props.value);
|
|
77
|
+
props.onBlur?.();
|
|
78
|
+
};
|
|
79
|
+
const onUpdateValue = newValue => {
|
|
80
|
+
validateIfError(newValue);
|
|
81
|
+
props.onUpdateValue?.(newValue);
|
|
82
|
+
};
|
|
83
|
+
const inputSlotProps = reactive({
|
|
84
|
+
onBlur,
|
|
85
|
+
onUpdateValue,
|
|
86
|
+
error: showError
|
|
87
|
+
});
|
|
88
|
+
const inputRef = ref();
|
|
89
|
+
const expose = {
|
|
90
|
+
validate: () => validateRules(props.value),
|
|
91
|
+
reset: () => validationResult.value = undefined,
|
|
92
|
+
focus: () => inputRef.value?.focus()
|
|
93
|
+
};
|
|
94
|
+
context.expose(expose);
|
|
95
|
+
props.form?.addInput(expose);
|
|
96
|
+
return () => _createVNode("div", null, [props.input?.(inputSlotProps) || _createVNode(NInput, _mergeProps({
|
|
97
|
+
"ref": inputRef
|
|
98
|
+
}, {
|
|
99
|
+
...props,
|
|
100
|
+
...inputSlotProps
|
|
101
|
+
}), null), showErrorMessage.value && _createVNode("p", {
|
|
102
|
+
"class": "text-red-500 text-xs mt-1"
|
|
103
|
+
}, [errorMessage.value])]);
|
|
104
|
+
});
|
|
@@ -3,23 +3,23 @@
|
|
|
3
3
|
* @returns the instance of the new form.
|
|
4
4
|
*/
|
|
5
5
|
export function createValidatedForm() {
|
|
6
|
-
|
|
6
|
+
return new ValidatedFormImpl();
|
|
7
7
|
}
|
|
8
8
|
class ValidatedFormImpl {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
9
|
+
inputs = [];
|
|
10
|
+
addInput(input) {
|
|
11
|
+
this.inputs.push(input);
|
|
12
|
+
}
|
|
13
|
+
validate() {
|
|
14
|
+
const results = this.inputs.map(input => input.validate());
|
|
15
|
+
// return first invalid result
|
|
16
|
+
for (const result of results) if (result && !result.isValid) return result;
|
|
17
|
+
// else return valid result
|
|
18
|
+
return {
|
|
19
|
+
isValid: true
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
reset() {
|
|
23
|
+
this.inputs.forEach(input => input.reset());
|
|
24
|
+
}
|
|
25
|
+
}
|
package/i18n/index.js
CHANGED
|
@@ -15,8 +15,6 @@ export function registerTranslationProvider(newProvider) {
|
|
|
15
15
|
* @returns the translated message.
|
|
16
16
|
*/
|
|
17
17
|
export function trsl(key, params) {
|
|
18
|
-
if (!provider)
|
|
19
|
-
console.warn('Vue Collection: No translation provider has been registered!');
|
|
20
18
|
return provider?.trsl(key, params) ?? key;
|
|
21
19
|
}
|
|
22
20
|
/**
|
|
@@ -29,7 +27,5 @@ export function trsl(key, params) {
|
|
|
29
27
|
* @see trsl
|
|
30
28
|
*/
|
|
31
29
|
export function trslc(key, count, params) {
|
|
32
|
-
if (!provider)
|
|
33
|
-
console.warn('Vue Collection: No translation provider has been registered!');
|
|
34
30
|
return provider?.trslc(key, count, params) ?? key;
|
|
35
31
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naptics/vue-collection",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"main": "./index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/naptics/vue-collection"
|
|
8
|
+
},
|
|
5
9
|
"scripts": {
|
|
6
10
|
"dev": "vite",
|
|
7
11
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
@@ -12,7 +16,7 @@
|
|
|
12
16
|
"build-demo": "run-p type-check-demo build-only-demo",
|
|
13
17
|
"build-lib": "run-p type-check-lib build-only-lib",
|
|
14
18
|
"build-only-demo": "vite build",
|
|
15
|
-
"build-only-lib": "
|
|
19
|
+
"build-only-lib": "bash ./scripts/build-lib.sh"
|
|
16
20
|
},
|
|
17
21
|
"dependencies": {
|
|
18
22
|
"@headlessui/vue": "^1.7.10",
|
|
@@ -24,6 +28,8 @@
|
|
|
24
28
|
"vue": "^3.2.36"
|
|
25
29
|
},
|
|
26
30
|
"devDependencies": {
|
|
31
|
+
"@babel/cli": "^7.21.0",
|
|
32
|
+
"@babel/core": "^7.21.3",
|
|
27
33
|
"@intlify/unplugin-vue-i18n": "^0.8.2",
|
|
28
34
|
"@rushstack/eslint-patch": "^1.2.0",
|
|
29
35
|
"@tailwindcss/forms": "^0.5.3",
|
|
@@ -31,6 +37,7 @@
|
|
|
31
37
|
"@types/node": "^18.14.0",
|
|
32
38
|
"@vitejs/plugin-vue": "^4.0.0",
|
|
33
39
|
"@vitejs/plugin-vue-jsx": "^3.0.0",
|
|
40
|
+
"@vue/babel-plugin-jsx": "^1.1.1",
|
|
34
41
|
"@vue/eslint-config-prettier": "^7.1.0",
|
|
35
42
|
"@vue/eslint-config-typescript": "^11.0.2",
|
|
36
43
|
"@vue/test-utils": "^2.3.0",
|
package/components/NAlert.jsx
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { createComponent, createProps } from '../utils/component';
|
|
2
|
-
import { CheckCircleIcon, ExclamationCircleIcon, InformationCircleIcon, XMarkIcon } from '@heroicons/vue/24/solid';
|
|
3
|
-
import { computed } from 'vue';
|
|
4
|
-
import NIconButton from './NIconButton';
|
|
5
|
-
import NLoadingIndicator from './NLoadingIndicator';
|
|
6
|
-
export const nAlertProps = createProps({
|
|
7
|
-
/**
|
|
8
|
-
* The variant of the alert. This defines its color and icon.
|
|
9
|
-
*/
|
|
10
|
-
variant: {
|
|
11
|
-
type: String,
|
|
12
|
-
default: 'success',
|
|
13
|
-
},
|
|
14
|
-
/**
|
|
15
|
-
* The text of the alert.
|
|
16
|
-
*/
|
|
17
|
-
text: String,
|
|
18
|
-
/**
|
|
19
|
-
* If set to `true` the X-button of the alert is hidden.
|
|
20
|
-
*/
|
|
21
|
-
hideX: Boolean,
|
|
22
|
-
/**
|
|
23
|
-
* This is called, when the X-button is clicked.
|
|
24
|
-
*/
|
|
25
|
-
onDismiss: Function,
|
|
26
|
-
});
|
|
27
|
-
/**
|
|
28
|
-
* The `NAlert` is a fully styled alert with multiple variants.
|
|
29
|
-
* It can be used as a normal blocking element or as part of an alert queue.
|
|
30
|
-
*/
|
|
31
|
-
export default createComponent('NAlert', nAlertProps, props => {
|
|
32
|
-
const variant = computed(() => VARIANTS[props.variant]);
|
|
33
|
-
return () => (<div class={`rounded-md p-3 shadow-lg bg-${variant.value.color}-50`}>
|
|
34
|
-
<div class="flex items-center">
|
|
35
|
-
<div class="flex flex-shrink-0 items-center">{variant.value.icon()}</div>
|
|
36
|
-
|
|
37
|
-
<div class="ml-3 flex-grow">
|
|
38
|
-
<p class={`text-sm font-medium text-${variant.value.color}-900`}>{props.text}</p>
|
|
39
|
-
</div>
|
|
40
|
-
|
|
41
|
-
{!props.hideX && (<div class="flex items-center flex-shrink-0 ml-3">
|
|
42
|
-
<NIconButton color={variant.value.color} size={5} icon={XMarkIcon} onClick={props.onDismiss}/>
|
|
43
|
-
</div>)}
|
|
44
|
-
</div>
|
|
45
|
-
</div>);
|
|
46
|
-
});
|
|
47
|
-
const icon = (icon, color) => () => <icon class={`h-5 w-5 text-${color}-500`}/>;
|
|
48
|
-
const VARIANTS = {
|
|
49
|
-
success: {
|
|
50
|
-
icon: icon(CheckCircleIcon, 'green'),
|
|
51
|
-
color: 'green',
|
|
52
|
-
},
|
|
53
|
-
info: {
|
|
54
|
-
icon: icon(InformationCircleIcon, 'blue'),
|
|
55
|
-
color: 'blue',
|
|
56
|
-
},
|
|
57
|
-
warning: {
|
|
58
|
-
icon: icon(ExclamationCircleIcon, 'yellow'),
|
|
59
|
-
color: 'yellow',
|
|
60
|
-
},
|
|
61
|
-
error: {
|
|
62
|
-
icon: icon(ExclamationCircleIcon, 'red'),
|
|
63
|
-
color: 'red',
|
|
64
|
-
},
|
|
65
|
-
loading: {
|
|
66
|
-
icon: () => <NLoadingIndicator color="blue" size={7} shade={500}/>,
|
|
67
|
-
color: 'blue',
|
|
68
|
-
},
|
|
69
|
-
};
|
package/components/NBadge.jsx
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { createComponent, createProps } from '../utils/component';
|
|
2
|
-
import NTooltip, { mapTooltipProps, nToolTipPropsForImplementor } from './NTooltip';
|
|
3
|
-
export const nBadgeProps = createProps({
|
|
4
|
-
/**
|
|
5
|
-
* The text of the badge. Can alternatively be passed in the default slot.
|
|
6
|
-
*/
|
|
7
|
-
text: String,
|
|
8
|
-
/**
|
|
9
|
-
* The text size, a standard tailwind text-size class.
|
|
10
|
-
*/
|
|
11
|
-
textSize: {
|
|
12
|
-
type: String,
|
|
13
|
-
default: 'text-sm',
|
|
14
|
-
},
|
|
15
|
-
/**
|
|
16
|
-
* The color of the badge.
|
|
17
|
-
*/
|
|
18
|
-
color: {
|
|
19
|
-
type: String,
|
|
20
|
-
default: 'primary',
|
|
21
|
-
},
|
|
22
|
-
/**
|
|
23
|
-
* The background shade of the badge.
|
|
24
|
-
*/
|
|
25
|
-
shade: {
|
|
26
|
-
type: Number,
|
|
27
|
-
default: 200,
|
|
28
|
-
},
|
|
29
|
-
/**
|
|
30
|
-
* The text shade of the badge.
|
|
31
|
-
*/
|
|
32
|
-
textShade: {
|
|
33
|
-
type: Number,
|
|
34
|
-
default: 900,
|
|
35
|
-
},
|
|
36
|
-
/**
|
|
37
|
-
* If set to `true` the badges text is all-caps. Default is `true`.
|
|
38
|
-
*/
|
|
39
|
-
allCaps: {
|
|
40
|
-
type: Boolean,
|
|
41
|
-
default: true,
|
|
42
|
-
},
|
|
43
|
-
...nToolTipPropsForImplementor,
|
|
44
|
-
});
|
|
45
|
-
/**
|
|
46
|
-
* The `NBadge` is a styled element to wrap a text.
|
|
47
|
-
*/
|
|
48
|
-
export default createComponent('NBadge', nBadgeProps, (props, { slots }) => {
|
|
49
|
-
return () => (<NTooltip {...mapTooltipProps(props)}>
|
|
50
|
-
<div class={[
|
|
51
|
-
'px-2 py-1 rounded-md font-semibold shadow',
|
|
52
|
-
`${props.textSize} bg-${props.color}-${props.shade} text-${props.color}-${props.textShade}`,
|
|
53
|
-
props.allCaps ? 'uppercase' : '',
|
|
54
|
-
]}>
|
|
55
|
-
{slots.default?.() || props.text}
|
|
56
|
-
</div>
|
|
57
|
-
</NTooltip>);
|
|
58
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { createComponent, createProps } from '../utils/component';
|
|
2
|
-
import { ChevronRightIcon } from '@heroicons/vue/24/solid';
|
|
3
|
-
import NLink from './NLink';
|
|
4
|
-
export const nBreadcrumbProps = createProps({
|
|
5
|
-
/**
|
|
6
|
-
* The items of the breadcrumb.
|
|
7
|
-
*/
|
|
8
|
-
items: {
|
|
9
|
-
type: Array,
|
|
10
|
-
default: () => [],
|
|
11
|
-
},
|
|
12
|
-
/**
|
|
13
|
-
* The color of the breadcrumbs text and icons.
|
|
14
|
-
*/
|
|
15
|
-
color: {
|
|
16
|
-
type: String,
|
|
17
|
-
default: 'primary',
|
|
18
|
-
},
|
|
19
|
-
/**
|
|
20
|
-
* The text-size of the breadcrumb labels.
|
|
21
|
-
*/
|
|
22
|
-
textSize: {
|
|
23
|
-
type: String,
|
|
24
|
-
default: 'text-base',
|
|
25
|
-
},
|
|
26
|
-
/**
|
|
27
|
-
* The icon which is used as a seperator between two breadcrumb items.
|
|
28
|
-
*/
|
|
29
|
-
icon: {
|
|
30
|
-
type: Function,
|
|
31
|
-
default: ChevronRightIcon,
|
|
32
|
-
},
|
|
33
|
-
/**
|
|
34
|
-
* The size of the icon in tailwind units.
|
|
35
|
-
*/
|
|
36
|
-
iconSize: {
|
|
37
|
-
type: Number,
|
|
38
|
-
default: 5,
|
|
39
|
-
},
|
|
40
|
-
/**
|
|
41
|
-
* A slot the replace the breadcrumb labels.
|
|
42
|
-
*/
|
|
43
|
-
item: Function,
|
|
44
|
-
/**
|
|
45
|
-
* A slot to replace the separators between the breadcrumb labels.
|
|
46
|
-
* The passsed item is the item before the seperator.
|
|
47
|
-
*/
|
|
48
|
-
seperator: Function,
|
|
49
|
-
});
|
|
50
|
-
/**
|
|
51
|
-
* The `NBreadcrumb` is a styled breadcrumb which can be used as a navigation in hierarchical views.
|
|
52
|
-
*/
|
|
53
|
-
export default createComponent('NBreadcrumb', nBreadcrumbProps, props => {
|
|
54
|
-
return () => (<div class="flex flex-wrap items-center">
|
|
55
|
-
{props.items.map((item, index) => (<>
|
|
56
|
-
{props.item?.(item, index) || (<NLink textSize={props.textSize} route={item.route} color={props.color}>
|
|
57
|
-
{item.label}
|
|
58
|
-
</NLink>)}
|
|
59
|
-
|
|
60
|
-
{index < props.items.length - 1 &&
|
|
61
|
-
(props.seperator?.(item, index) || (<props.icon class={`mx-2 w-${props.iconSize} h-${props.iconSize} text-${props.color}-500`}/>))}
|
|
62
|
-
</>))}
|
|
63
|
-
</div>);
|
|
64
|
-
});
|
package/components/NButton.jsx
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { createComponent, createProps } from '../utils/component';
|
|
2
|
-
import { computed } from 'vue';
|
|
3
|
-
import NLoadingIndicator from './NLoadingIndicator';
|
|
4
|
-
import NTooltip, { mapTooltipProps, nToolTipPropsForImplementor } from './NTooltip';
|
|
5
|
-
export const nButtonProps = createProps({
|
|
6
|
-
/**
|
|
7
|
-
* The color of the button.
|
|
8
|
-
*/
|
|
9
|
-
color: {
|
|
10
|
-
type: String,
|
|
11
|
-
default: 'primary',
|
|
12
|
-
},
|
|
13
|
-
/**
|
|
14
|
-
* The html attribute, which indicates the type of the button.
|
|
15
|
-
*/
|
|
16
|
-
type: {
|
|
17
|
-
type: String,
|
|
18
|
-
default: 'button',
|
|
19
|
-
},
|
|
20
|
-
/**
|
|
21
|
-
* If set to `true` the button is disabled and no interaction is possible.
|
|
22
|
-
*/
|
|
23
|
-
disabled: Boolean,
|
|
24
|
-
/**
|
|
25
|
-
* If set to `true` the button will show a loading animation.
|
|
26
|
-
* Setting `loading` to `true` will also disable the button.
|
|
27
|
-
*/
|
|
28
|
-
loading: Boolean,
|
|
29
|
-
/**
|
|
30
|
-
* If set to `true` the button will appear smaller.
|
|
31
|
-
*/
|
|
32
|
-
small: Boolean,
|
|
33
|
-
/**
|
|
34
|
-
* This is called, when the button is clicked.
|
|
35
|
-
*/
|
|
36
|
-
onClick: Function,
|
|
37
|
-
...nToolTipPropsForImplementor,
|
|
38
|
-
});
|
|
39
|
-
/**
|
|
40
|
-
* The `NButton` is a styled button.
|
|
41
|
-
*/
|
|
42
|
-
export default createComponent('NButton', nButtonProps, (props, { slots }) => {
|
|
43
|
-
const isDisabled = computed(() => props.loading || props.disabled);
|
|
44
|
-
return () => (<NTooltip {...mapTooltipProps(props)}>
|
|
45
|
-
<button disabled={isDisabled.value} type={props.type} class={[
|
|
46
|
-
`block w-full font-medium rounded-md focus:outline-none focus-visible:ring-2 shadow text-${props.color}-900 relative`,
|
|
47
|
-
isDisabled.value
|
|
48
|
-
? `bg-${props.color}-100 text-opacity-20 cursor-default`
|
|
49
|
-
: `bg-${props.color}-200 hover:bg-${props.color}-300 focus-visible:ring-${props.color}-500`,
|
|
50
|
-
props.small ? 'py-1 px-2 text-xs' : 'py-2 px-4 text-sm',
|
|
51
|
-
]} onClick={props.onClick}>
|
|
52
|
-
<span class={{ 'opacity-10': props.loading }}>{slots.default?.()}</span>
|
|
53
|
-
{props.loading && (<div class="absolute inset-0 flex items-center justify-center opacity-50">
|
|
54
|
-
<NLoadingIndicator color={props.color} size={props.small ? 4 : 6} shade={600}/>
|
|
55
|
-
</div>)}
|
|
56
|
-
</button>
|
|
57
|
-
</NTooltip>);
|
|
58
|
-
});
|
package/components/NCheckbox.jsx
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { createComponent, createProps } from '../utils/component';
|
|
2
|
-
import { vModelProps } from '../utils/vModel';
|
|
3
|
-
import { nextTick, ref } from 'vue';
|
|
4
|
-
export const nCheckboxProps = createProps({
|
|
5
|
-
...vModelProps(Boolean),
|
|
6
|
-
/**
|
|
7
|
-
* The color of the checkbox.
|
|
8
|
-
*/
|
|
9
|
-
color: {
|
|
10
|
-
type: String,
|
|
11
|
-
default: 'primary',
|
|
12
|
-
},
|
|
13
|
-
/**
|
|
14
|
-
* If set to `true` the checkbox is disabled and no interaction is possible.
|
|
15
|
-
*/
|
|
16
|
-
disabled: Boolean,
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* The `NCheckbox` is a styled checkbox.
|
|
20
|
-
*/
|
|
21
|
-
export default createComponent('NCheckbox', nCheckboxProps, props => {
|
|
22
|
-
const toggle = () => {
|
|
23
|
-
props.onUpdateValue?.(!props.value);
|
|
24
|
-
forceUpdate();
|
|
25
|
-
};
|
|
26
|
-
const checkBoxRef = ref();
|
|
27
|
-
const updateKey = ref(0);
|
|
28
|
-
const forceUpdate = () => {
|
|
29
|
-
updateKey.value += 1;
|
|
30
|
-
nextTick(() => checkBoxRef.value?.focus());
|
|
31
|
-
};
|
|
32
|
-
return () => (<input type="checkbox" ref={checkBoxRef} checked={props.value} disabled={props.disabled} onClick={toggle} key={updateKey.value} class={[
|
|
33
|
-
`h-5 w-5 border-default-300 rounded focus:outline-none focus:ring-0 focus-visible:ring-2 focus-visible:ring-${props.color}-500`,
|
|
34
|
-
props.disabled
|
|
35
|
-
? `cursor-default bg-default-100 text-${props.color}-200`
|
|
36
|
-
: `cursor-pointer text-${props.color}-400`,
|
|
37
|
-
]}/>);
|
|
38
|
-
});
|