@naptics/vue-collection 0.0.4 → 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.
Files changed (45) hide show
  1. package/i18n/index.js +4 -4
  2. package/index.js +1 -1
  3. package/package.json +1 -1
  4. package/utils/breakpoints.js +21 -21
  5. package/utils/component.js +9 -17
  6. package/utils/deferred.js +12 -12
  7. package/utils/identifiable.js +29 -27
  8. package/utils/stringMaxLength.js +13 -8
  9. package/utils/tailwind.js +1 -1
  10. package/utils/utils.js +5 -5
  11. package/utils/vModel.js +73 -82
  12. package/utils/validation.js +81 -55
  13. package/utils/vue.js +5 -7
  14. package/components/NAlert.jsx +0 -69
  15. package/components/NBadge.jsx +0 -58
  16. package/components/NBreadcrub.jsx +0 -64
  17. package/components/NButton.jsx +0 -58
  18. package/components/NCheckbox.jsx +0 -38
  19. package/components/NCheckboxLabel.jsx +0 -42
  20. package/components/NCrudModal.jsx +0 -89
  21. package/components/NDialog.jsx +0 -144
  22. package/components/NDropdown.jsx +0 -92
  23. package/components/NDropzone.jsx +0 -211
  24. package/components/NForm.jsx +0 -26
  25. package/components/NFormModal.jsx +0 -48
  26. package/components/NIconButton.jsx +0 -71
  27. package/components/NIconCircle.jsx +0 -67
  28. package/components/NInput.jsx +0 -97
  29. package/components/NInputPhone.jsx +0 -32
  30. package/components/NInputSelect.jsx +0 -89
  31. package/components/NInputSuggestion.jsx +0 -48
  32. package/components/NLink.jsx +0 -58
  33. package/components/NList.jsx +0 -24
  34. package/components/NLoadingIndicator.jsx +0 -42
  35. package/components/NModal.jsx +0 -170
  36. package/components/NPagination.jsx +0 -104
  37. package/components/NSearchbar.jsx +0 -58
  38. package/components/NSearchbarList.jsx +0 -20
  39. package/components/NSelect.jsx +0 -81
  40. package/components/NSuggestionList.jsx +0 -157
  41. package/components/NTable.jsx +0 -146
  42. package/components/NTableAction.jsx +0 -35
  43. package/components/NTextArea.jsx +0 -108
  44. package/components/NTooltip.jsx +0 -161
  45. package/components/NValInput.jsx +0 -101
@@ -1,161 +0,0 @@
1
- import { createComponent, createProps } from '../utils/component';
2
- import { uniqueId } from '../utils/utils';
3
- import { computed, onMounted, ref, watch, onUnmounted, Transition } from 'vue';
4
- import { createPopper } from '@popperjs/core';
5
- import { watchRef } from '../utils/vue';
6
- import './NTooltip.css';
7
- export const nTooltipProps = createProps({
8
- /**
9
- * The text content of the tooltip.
10
- */
11
- text: String,
12
- /**
13
- * A slot to replace the content of the tooltip. This will override the `text` prop.
14
- */
15
- content: Function,
16
- /**
17
- * If set to `true` the tooltip is shown constantly.
18
- */
19
- show: Boolean,
20
- /**
21
- * If set to `true` the tooltip is hidden constantly.
22
- */
23
- hide: Boolean,
24
- /**
25
- * If set to `true` the `block` class is applied to the tooltip.
26
- * This should be set if the content in the default slot is also block.
27
- */
28
- block: Boolean,
29
- /**
30
- * The placement of the tooltip.
31
- */
32
- placement: {
33
- type: String,
34
- default: 'auto',
35
- },
36
- /**
37
- * The maximum width of the tooltip.
38
- */
39
- maxWidth: {
40
- type: String,
41
- default: 'max-w-xs',
42
- },
43
- });
44
- /**
45
- * These props are made to use on a component which implements the tooltip
46
- * and wants it to be controllable via the own props.
47
- * e.g. `text` is now called `tooltipText`.
48
- * They can be mapped to the normal tooltip props with {@link mapTooltipProps}
49
- */
50
- export const nToolTipPropsForImplementor = {
51
- /**
52
- * Adds a tooltip to the component with the specified text.
53
- * @see {@link nTooltipProps.text}
54
- */
55
- tooltipText: nTooltipProps.text,
56
- /**
57
- * A slot for the tooltip of this component.
58
- * If the slot is set, the tooltip with the specified content is added to the component.
59
- * @see {@link nTooltipProps.content}
60
- */
61
- tooltipContent: nTooltipProps.content,
62
- /**
63
- * @see {@link nTooltipProps.hide}
64
- */
65
- tooltipHide: nTooltipProps.hide,
66
- /**
67
- * @see {@link nTooltipProps.show}
68
- */
69
- tooltipShow: nTooltipProps.show,
70
- /**
71
- * @see {@link nTooltipProps.placement}
72
- */
73
- tooltipPlacement: nTooltipProps.placement,
74
- /**
75
- * @see {@link nTooltipProps.maxWidth}
76
- */
77
- tooltipMaxWidth: nTooltipProps.maxWidth,
78
- };
79
- /**
80
- * Maps the {@link nToolTipPropsForImplementor} props to normal tooltip props
81
- * @returns an object containing the normal tooltip props.
82
- */
83
- export function mapTooltipProps(props) {
84
- return {
85
- text: props.tooltipText,
86
- content: props.tooltipContent,
87
- hide: props.tooltipHide,
88
- show: props.tooltipShow,
89
- placement: props.tooltipPlacement,
90
- maxWidth: props.tooltipMaxWidth,
91
- };
92
- }
93
- /**
94
- * The `NTooltip` is a wrapper for any component which adds a tooltip to it.
95
- * Any component can just be passed in the default slot and a tooltip will be added to it.
96
- * Note that this component disappears when neither the `text` nor the `content`
97
- * prop is passed as the tooltip would then be empty.
98
- * If this is the case, the default slot will just be rendered inside a div.
99
- * @example
100
- * <NTooltip text="Hello">
101
- * <NButton />
102
- * </NTooltip>
103
- */
104
- export default createComponent('NTooltip', nTooltipProps, (props, { slots }) => {
105
- return () => (<div class={props.block ? 'block' : 'inline-block'}>
106
- {props.content || props.text ? (<NTooltipBase {...props}>{slots.default?.()}</NTooltipBase>) : (slots.default?.())}
107
- </div>);
108
- });
109
- const NTooltipBase = createComponent('NTooltipBase', nTooltipProps, (props, { slots }) => {
110
- let popperInstance = null;
111
- const contentId = `content-${uniqueId()}`;
112
- const tooltipId = `tooltip-${uniqueId()}`;
113
- function createTooltip() {
114
- const content = document.getElementById(contentId);
115
- const tooltip = document.getElementById(tooltipId);
116
- if (content && tooltip) {
117
- popperInstance = createPopper(content, tooltip, {
118
- placement: props.placement,
119
- modifiers: [
120
- {
121
- name: 'offset',
122
- options: {
123
- offset: [0, 8],
124
- },
125
- },
126
- ],
127
- });
128
- }
129
- else {
130
- console.error('Could not create tooltip. HTML elements for content or tooltip were not found.');
131
- }
132
- }
133
- function destroyTooltip() {
134
- popperInstance?.destroy();
135
- popperInstance = null;
136
- }
137
- onMounted(createTooltip);
138
- onUnmounted(destroyTooltip);
139
- watch(() => props.placement, newPlacement => popperInstance?.setOptions({ placement: newPlacement }));
140
- const isHoveringContent = ref(false);
141
- const isHoveringTooltip = ref(false);
142
- const isHovering = computed(() => isHoveringContent.value || isHoveringTooltip.value);
143
- const showTooltip = computed(() => props.show || (!props.hide && isHovering.value));
144
- watchRef(showTooltip, () => popperInstance?.update());
145
- return () => (<>
146
- <div class="p-[10px] -m-[10px]" onMouseleave={() => setTimeout(() => (isHoveringContent.value = false), 10)}>
147
- <div id={contentId} onMouseenter={() => (isHoveringContent.value = true)}>
148
- {slots.default?.()}
149
- </div>
150
- </div>
151
-
152
- <Transition enterActiveClass="transition-opacity ease-out duration-100" enterFromClass="opacity-0" enterToClass="opacity-100" leaveActiveClass="transition-opacity ease-in duration-75" leaveFromClass="opacity-100" leaveToClass="opacity-0">
153
- <div id={tooltipId} role="tooltip" onMouseenter={() => (isHoveringTooltip.value = true)} onMouseleave={() => (isHoveringTooltip.value = false)} v-show={showTooltip.value} class={[isHovering.value ? 'z-20' : 'z-10', props.maxWidth, 'tooltip']}>
154
- <div class="bg-white rounded-md py-2 px-4 shadow-lg border-default-200 border text-sm font-normal text-default-700">
155
- {props.content?.() || props.text}
156
- </div>
157
- <div data-popper-arrow class="arrow"/>
158
- </div>
159
- </Transition>
160
- </>);
161
- });
@@ -1,101 +0,0 @@
1
- import { createComponent, createProps } from '../utils/component';
2
- import { computed } from 'vue';
3
- import { ref, reactive, watch } from 'vue';
4
- import NInput, { nInputProps } from './NInput';
5
- import { validate, required } from '../utils/validation';
6
- export const validationProps = createProps({
7
- /**
8
- * If set to `true` this input is always valid when its value is empty.
9
- * If set to `false` the input receives the {@link required} rule. Default is `false`.
10
- */
11
- optional: Boolean,
12
- /**
13
- * The rules which this input is checked with.
14
- * The rules are checked sequentially and the error of the first failed rule is displayed.
15
- * If `optional` is set to false, the rule {@link required} will be checked first.
16
- */
17
- rules: {
18
- type: [Function, Array],
19
- default: () => [],
20
- },
21
- /**
22
- * The form, which this input will be added to.
23
- * On initialization, this input will call {@link ValidatedForm.addInput} passing itself to the form.
24
- */
25
- form: Object,
26
- /**
27
- * Overrides the internal error state. If set to true, it will always display an error.
28
- */
29
- error: Boolean,
30
- /**
31
- * Overrides the internal error message. If set, this message is always displayed.
32
- */
33
- errorMessage: String,
34
- /**
35
- * If set to `true` the error message is not shown.
36
- * However, the input is still marked red if it is in an error state.
37
- */
38
- hideErrorMessage: Boolean,
39
- /**
40
- * Disables the validation on blur. Should only be used in special occasions.
41
- */
42
- disableBlurValidation: Boolean,
43
- });
44
- export const nValInputProps = createProps({
45
- ...nInputProps,
46
- ...validationProps,
47
- /**
48
- * A slot to replace the input.
49
- */
50
- input: Function,
51
- });
52
- /**
53
- * The `NValInput` is a `NInput` with custom validation.
54
- */
55
- export default createComponent('NValInput', nValInputProps, (props, context) => {
56
- const rules = computed(() => {
57
- const otherRules = Array.isArray(props.rules) ? props.rules : [props.rules];
58
- return props.optional ? otherRules : [required, ...otherRules];
59
- });
60
- const validationResult = ref();
61
- const validateRules = (input) => {
62
- const result = validate(input, rules.value);
63
- validationResult.value = result;
64
- return result;
65
- };
66
- const showError = computed(() => props.error || (validationResult.value != null && !validationResult.value.isValid));
67
- const showErrorMessage = computed(() => !props.hideErrorMessage && showError.value);
68
- const errorMessage = computed(() => props.errorMessage || validationResult.value?.errorMessage);
69
- const validateIfError = (value = props.value) => {
70
- if (showError.value)
71
- validateRules(value);
72
- };
73
- watch(() => props.value, () => validateIfError());
74
- watch(() => rules.value, () => validateIfError());
75
- const onBlur = () => {
76
- if (!props.disableBlurValidation)
77
- validateRules(props.value);
78
- props.onBlur?.();
79
- };
80
- const onUpdateValue = (newValue) => {
81
- validateIfError(newValue);
82
- props.onUpdateValue?.(newValue);
83
- };
84
- const inputSlotProps = reactive({
85
- onBlur,
86
- onUpdateValue,
87
- error: showError,
88
- });
89
- const inputRef = ref();
90
- const expose = {
91
- validate: () => validateRules(props.value),
92
- reset: () => (validationResult.value = undefined),
93
- focus: () => inputRef.value?.focus(),
94
- };
95
- context.expose(expose);
96
- props.form?.addInput(expose);
97
- return () => (<div>
98
- {props.input?.(inputSlotProps) || <NInput ref={inputRef} {...{ ...props, ...inputSlotProps }}/>}
99
- {showErrorMessage.value && <p class="text-red-500 text-xs mt-1">{errorMessage.value}</p>}
100
- </div>);
101
- });