@naptics/vue-collection 1.0.0-beta.1 → 1.0.0-beta.2
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/lib/components/NAlert.d.ts +29 -0
- package/lib/components/NAlert.js +84 -0
- package/lib/components/NBadge.d.ts +73 -0
- package/lib/components/NBadge.js +64 -0
- package/lib/components/NBreadcrub.d.ts +69 -0
- package/lib/components/NBreadcrub.js +71 -0
- package/lib/components/NButton.d.ts +64 -0
- package/lib/components/NButton.js +70 -0
- package/lib/components/NCheckbox.d.ts +20 -0
- package/lib/components/NCheckbox.js +43 -0
- package/lib/components/NCheckboxLabel.d.ts +26 -0
- package/lib/components/NCheckboxLabel.js +42 -0
- package/lib/components/NCrudModal.d.ts +118 -0
- package/lib/components/NCrudModal.js +120 -0
- package/lib/components/NDialog.d.ts +81 -0
- package/lib/components/NDialog.js +161 -0
- package/lib/components/NDropdown.d.ts +67 -0
- package/lib/components/NDropdown.js +115 -0
- package/lib/components/NDropzone.d.ts +61 -0
- package/lib/components/NDropzone.js +218 -0
- package/lib/components/NForm.d.ts +21 -0
- package/lib/components/NForm.js +29 -0
- package/lib/components/NFormModal.d.ts +75 -0
- package/lib/components/NFormModal.js +59 -0
- package/lib/components/NIconButton.d.ts +83 -0
- package/lib/components/NIconButton.js +88 -0
- package/lib/components/NIconCircle.d.ts +49 -0
- package/lib/components/NIconCircle.js +67 -0
- package/lib/components/NInput.d.ts +94 -0
- package/lib/components/NInput.js +110 -0
- package/lib/components/NInputPhone.d.ts +58 -0
- package/lib/components/NInputPhone.js +47 -0
- package/lib/components/NInputSelect.d.ts +103 -0
- package/lib/components/NInputSelect.js +115 -0
- package/lib/components/NInputSuggestion.d.ts +79 -0
- package/lib/components/NInputSuggestion.js +64 -0
- package/lib/components/NLink.d.ts +47 -0
- package/lib/components/NLink.js +67 -0
- package/lib/components/NList.d.ts +37 -0
- package/lib/components/NList.js +40 -0
- package/lib/components/NLoadingIndicator.d.ts +29 -0
- package/lib/components/NLoadingIndicator.js +54 -0
- package/lib/components/NModal.d.ts +133 -0
- package/lib/components/NModal.js +235 -0
- package/{src/lib → lib}/components/NPagination.css +1 -1
- package/lib/components/NPagination.d.ts +37 -0
- package/lib/components/NPagination.js +105 -0
- package/lib/components/NSearchbar.d.ts +39 -0
- package/lib/components/NSearchbar.js +64 -0
- package/lib/components/NSearchbarList.d.ts +33 -0
- package/lib/components/NSearchbarList.js +41 -0
- package/lib/components/NSelect.d.ts +82 -0
- package/lib/components/NSelect.js +101 -0
- package/lib/components/NSuggestionList.d.ts +153 -0
- package/lib/components/NSuggestionList.js +160 -0
- package/{src/lib → lib}/components/NTable.css +1 -1
- package/lib/components/NTable.d.ts +97 -0
- package/lib/components/NTable.js +128 -0
- package/lib/components/NTableAction.d.ts +30 -0
- package/lib/components/NTableAction.js +50 -0
- package/lib/components/NTextArea.d.ts +96 -0
- package/lib/components/NTextArea.js +133 -0
- package/{src/lib → lib}/components/NTooltip.css +1 -1
- package/lib/components/NTooltip.d.ts +152 -0
- package/lib/components/NTooltip.js +241 -0
- package/lib/components/NValInput.d.ts +156 -0
- package/lib/components/NValInput.js +113 -0
- package/lib/components/ValidatedForm.d.ts +39 -0
- package/lib/components/ValidatedForm.js +35 -0
- package/{src/lib/i18n/index.ts → lib/i18n/index.d.ts} +9 -23
- package/lib/i18n/index.js +31 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/utils/breakpoints.d.ts +18 -0
- package/lib/utils/breakpoints.js +40 -0
- package/lib/utils/component.d.ts +57 -0
- package/lib/utils/component.js +79 -0
- package/lib/utils/deferred.d.ts +13 -0
- package/lib/utils/deferred.js +17 -0
- package/lib/utils/identifiable.d.ts +56 -0
- package/lib/utils/identifiable.js +81 -0
- package/lib/utils/stringMaxLength.d.ts +14 -0
- package/lib/utils/stringMaxLength.js +23 -0
- package/lib/utils/tailwind.d.ts +4 -0
- package/lib/utils/tailwind.js +1 -0
- package/lib/utils/utils.d.ts +47 -0
- package/lib/utils/utils.js +56 -0
- package/{src/lib/utils/vModel.ts → lib/utils/vModel.d.ts} +48 -126
- package/lib/utils/vModel.js +224 -0
- package/lib/utils/validation.d.ts +90 -0
- package/lib/utils/validation.js +147 -0
- package/lib/utils/vue.d.ts +13 -0
- package/lib/utils/vue.js +21 -0
- package/package.json +6 -2
- package/.github/workflows/build.yml +0 -26
- package/.github/workflows/deploy-demo.yml +0 -46
- package/.github/workflows/deploy-lib.yml +0 -59
- package/.gitlab-ci.yml +0 -57
- package/.nvmrc +0 -1
- package/.prettierrc +0 -8
- package/.vscode/extensions.json +0 -10
- package/.vscode/launch.json +0 -23
- package/.vscode/settings.json +0 -13
- package/babel.config.json +0 -3
- package/env.d.ts +0 -15
- package/eslint.config.cjs +0 -27
- package/index.html +0 -13
- package/postcss.config.js +0 -3
- package/public/favicon.ico +0 -0
- package/scripts/build-lib.sh +0 -52
- package/scripts/sync-node-types.js +0 -70
- package/src/demo/App.css +0 -53
- package/src/demo/App.tsx +0 -5
- package/src/demo/components/ColorGrid.tsx +0 -26
- package/src/demo/components/ComponentGrid.tsx +0 -26
- package/src/demo/components/ComponentSection.tsx +0 -30
- package/src/demo/components/VariantSection.tsx +0 -18
- package/src/demo/i18n/de.ts +0 -7
- package/src/demo/i18n/en.ts +0 -7
- package/src/demo/i18n/index.ts +0 -24
- package/src/demo/main.ts +0 -13
- package/src/demo/router/index.ts +0 -21
- package/src/demo/views/HomeView.tsx +0 -94
- package/src/demo/views/NavigationView.tsx +0 -43
- package/src/demo/views/presentation/AlertView.tsx +0 -40
- package/src/demo/views/presentation/BadgeView.tsx +0 -61
- package/src/demo/views/presentation/BreadcrumbView.tsx +0 -52
- package/src/demo/views/presentation/ButtonView.tsx +0 -49
- package/src/demo/views/presentation/CheckboxView.tsx +0 -59
- package/src/demo/views/presentation/DropdownView.tsx +0 -59
- package/src/demo/views/presentation/DropzoneView.tsx +0 -39
- package/src/demo/views/presentation/IconButtonView.tsx +0 -47
- package/src/demo/views/presentation/IconCircleView.tsx +0 -38
- package/src/demo/views/presentation/InputView.tsx +0 -179
- package/src/demo/views/presentation/LinkView.tsx +0 -60
- package/src/demo/views/presentation/ListView.tsx +0 -29
- package/src/demo/views/presentation/LoadingIndicatorView.tsx +0 -38
- package/src/demo/views/presentation/ModalView.tsx +0 -210
- package/src/demo/views/presentation/PaginationView.tsx +0 -25
- package/src/demo/views/presentation/SearchbarView.tsx +0 -80
- package/src/demo/views/presentation/TableView.tsx +0 -146
- package/src/demo/views/presentation/TooltipView.tsx +0 -92
- package/src/lib/components/NAlert.tsx +0 -85
- package/src/lib/components/NBadge.tsx +0 -75
- package/src/lib/components/NBreadcrub.tsx +0 -97
- package/src/lib/components/NButton.tsx +0 -82
- package/src/lib/components/NCheckbox.tsx +0 -55
- package/src/lib/components/NCheckboxLabel.tsx +0 -51
- package/src/lib/components/NCrudModal.tsx +0 -133
- package/src/lib/components/NDialog.tsx +0 -182
- package/src/lib/components/NDropdown.tsx +0 -169
- package/src/lib/components/NDropzone.tsx +0 -265
- package/src/lib/components/NForm.tsx +0 -32
- package/src/lib/components/NFormModal.tsx +0 -66
- package/src/lib/components/NIconButton.tsx +0 -92
- package/src/lib/components/NIconCircle.tsx +0 -78
- package/src/lib/components/NInput.tsx +0 -139
- package/src/lib/components/NInputPhone.tsx +0 -53
- package/src/lib/components/NInputSelect.tsx +0 -126
- package/src/lib/components/NInputSuggestion.tsx +0 -80
- package/src/lib/components/NLink.tsx +0 -82
- package/src/lib/components/NList.tsx +0 -67
- package/src/lib/components/NLoadingIndicator.tsx +0 -63
- package/src/lib/components/NModal.tsx +0 -243
- package/src/lib/components/NPagination.tsx +0 -131
- package/src/lib/components/NSearchbar.tsx +0 -78
- package/src/lib/components/NSearchbarList.tsx +0 -47
- package/src/lib/components/NSelect.tsx +0 -128
- package/src/lib/components/NSuggestionList.tsx +0 -216
- package/src/lib/components/NTable.tsx +0 -247
- package/src/lib/components/NTableAction.tsx +0 -49
- package/src/lib/components/NTextArea.tsx +0 -159
- package/src/lib/components/NTooltip.tsx +0 -289
- package/src/lib/components/NValInput.tsx +0 -163
- package/src/lib/components/ValidatedForm.ts +0 -71
- package/src/lib/components/__tests__/NButton.spec.tsx +0 -26
- package/src/lib/components/__tests__/NCheckbox.spec.tsx +0 -39
- package/src/lib/index.ts +0 -2
- package/src/lib/jsx.d.ts +0 -13
- package/src/lib/utils/__tests__/identifiable.spec.ts +0 -72
- package/src/lib/utils/__tests__/validation.spec.ts +0 -92
- package/src/lib/utils/breakpoints.ts +0 -47
- package/src/lib/utils/component.tsx +0 -131
- package/src/lib/utils/deferred.ts +0 -28
- package/src/lib/utils/identifiable.ts +0 -87
- package/src/lib/utils/stringMaxLength.ts +0 -25
- package/src/lib/utils/tailwind.ts +0 -41
- package/src/lib/utils/utils.ts +0 -90
- package/src/lib/utils/validation.ts +0 -189
- package/src/lib/utils/vue.ts +0 -25
- package/tsconfig.config.json +0 -9
- package/tsconfig.demo.json +0 -19
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -19
- package/tsconfig.vitest.json +0 -8
- package/vite.config.ts +0 -30
- /package/{src/lib → lib}/components/NInput.css +0 -0
- /package/{src/lib → lib}/components/NLoadingIndicator.css +0 -0
- /package/{src/lib → lib}/i18n/de/vue-collection.json +0 -0
- /package/{src/lib → lib}/i18n/en/vue-collection.json +0 -0
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { createComponent, type ExtractedProps } from '../utils/component'
|
|
2
|
-
import { uniqueId } from '../utils/utils'
|
|
3
|
-
import type { TWMaxWidth } from '../utils/tailwind'
|
|
4
|
-
import { computed, onMounted, ref, watch, type PropType, onUnmounted, Transition } from 'vue'
|
|
5
|
-
import { createPopper, type Instance as PopperInstance } from '@popperjs/core'
|
|
6
|
-
import { watchRef } from '../utils/vue'
|
|
7
|
-
import './NTooltip.css'
|
|
8
|
-
|
|
9
|
-
export const nTooltipProps = {
|
|
10
|
-
/**
|
|
11
|
-
* The text content of the tooltip.
|
|
12
|
-
*/
|
|
13
|
-
text: String,
|
|
14
|
-
/**
|
|
15
|
-
* A slot to replace the content of the tooltip. This will override the `text` prop.
|
|
16
|
-
*/
|
|
17
|
-
content: Function as PropType<() => JSX.Element>,
|
|
18
|
-
/**
|
|
19
|
-
* If set to `true` the tooltip is shown constantly.
|
|
20
|
-
*/
|
|
21
|
-
show: Boolean,
|
|
22
|
-
/**
|
|
23
|
-
* If set to `true` the tooltip is hidden constantly.
|
|
24
|
-
*/
|
|
25
|
-
hide: Boolean,
|
|
26
|
-
/**
|
|
27
|
-
* If set to `true` the `block` class is applied to the tooltip.
|
|
28
|
-
* This should be set if the content in the default slot is also block.
|
|
29
|
-
*/
|
|
30
|
-
block: Boolean,
|
|
31
|
-
/**
|
|
32
|
-
* The placement of the tooltip.
|
|
33
|
-
*/
|
|
34
|
-
placement: {
|
|
35
|
-
type: String as PropType<TooltipPlacement>,
|
|
36
|
-
default: 'auto',
|
|
37
|
-
},
|
|
38
|
-
/**
|
|
39
|
-
* The maximum width of the tooltip.
|
|
40
|
-
*/
|
|
41
|
-
maxWidth: {
|
|
42
|
-
type: String as PropType<TWMaxWidth>,
|
|
43
|
-
default: 'max-w-xs',
|
|
44
|
-
},
|
|
45
|
-
/**
|
|
46
|
-
* Adds the classes to the (invisible) wrapper element.
|
|
47
|
-
*/
|
|
48
|
-
wrapperClass: String,
|
|
49
|
-
/**
|
|
50
|
-
* Adds the classes to the container of the tooltips content.
|
|
51
|
-
*/
|
|
52
|
-
contentClass: String,
|
|
53
|
-
/**
|
|
54
|
-
* Adds the classes to the tooltip arrow. Make sure to use `before:` classes
|
|
55
|
-
* to target the arrow (which is the before element).
|
|
56
|
-
*/
|
|
57
|
-
arrowClass: String,
|
|
58
|
-
/**
|
|
59
|
-
* The delay in milliseconds before the tooltip is shown.
|
|
60
|
-
* @default 0
|
|
61
|
-
*/
|
|
62
|
-
delay: {
|
|
63
|
-
type: Number,
|
|
64
|
-
default: 0,
|
|
65
|
-
},
|
|
66
|
-
} as const
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* These props are made to use on a component which implements the tooltip
|
|
70
|
-
* and wants it to be controllable via the own props.
|
|
71
|
-
* e.g. `text` is now called `tooltipText`.
|
|
72
|
-
* They can be mapped to the normal tooltip props with {@link mapTooltipProps}
|
|
73
|
-
*/
|
|
74
|
-
export const nToolTipPropsForImplementor = {
|
|
75
|
-
/**
|
|
76
|
-
* Adds a tooltip to the component with the specified text.
|
|
77
|
-
* @see {@link nTooltipProps.text}
|
|
78
|
-
*/
|
|
79
|
-
tooltipText: nTooltipProps.text,
|
|
80
|
-
/**
|
|
81
|
-
* A slot for the tooltip of this component.
|
|
82
|
-
* If the slot is set, the tooltip with the specified content is added to the component.
|
|
83
|
-
* @see {@link nTooltipProps.content}
|
|
84
|
-
*/
|
|
85
|
-
tooltipContent: nTooltipProps.content,
|
|
86
|
-
/**
|
|
87
|
-
* @see {@link nTooltipProps.hide}
|
|
88
|
-
*/
|
|
89
|
-
tooltipHide: nTooltipProps.hide,
|
|
90
|
-
/**
|
|
91
|
-
* @see {@link nTooltipProps.show}
|
|
92
|
-
*/
|
|
93
|
-
tooltipShow: nTooltipProps.show,
|
|
94
|
-
/**
|
|
95
|
-
* @see {@link nTooltipProps.placement}
|
|
96
|
-
*/
|
|
97
|
-
tooltipPlacement: nTooltipProps.placement,
|
|
98
|
-
/**
|
|
99
|
-
* @see {@link nTooltipProps.maxWidth}
|
|
100
|
-
*/
|
|
101
|
-
tooltipMaxWidth: nTooltipProps.maxWidth,
|
|
102
|
-
/**
|
|
103
|
-
* @see {@link nTooltipProps.wrapperClass}
|
|
104
|
-
*/
|
|
105
|
-
tooltipWrapperClass: nTooltipProps.wrapperClass,
|
|
106
|
-
/**
|
|
107
|
-
* @see {@link nTooltipProps.contentClass}
|
|
108
|
-
*/
|
|
109
|
-
tooltipContentClass: nTooltipProps.contentClass,
|
|
110
|
-
/**
|
|
111
|
-
* @see {@link nTooltipProps.arrowClass}
|
|
112
|
-
*/
|
|
113
|
-
tooltipArrowClass: nTooltipProps.arrowClass,
|
|
114
|
-
/**
|
|
115
|
-
* @see {@link nTooltipProps.delay}
|
|
116
|
-
*/
|
|
117
|
-
tooltipDelay: nTooltipProps.delay,
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Maps the {@link nToolTipPropsForImplementor} props to normal tooltip props
|
|
122
|
-
* @returns an object containing the normal tooltip props.
|
|
123
|
-
*/
|
|
124
|
-
export function mapTooltipProps(props: ExtractedProps<typeof nToolTipPropsForImplementor>) {
|
|
125
|
-
return {
|
|
126
|
-
text: props.tooltipText,
|
|
127
|
-
content: props.tooltipContent,
|
|
128
|
-
hide: props.tooltipHide,
|
|
129
|
-
show: props.tooltipShow,
|
|
130
|
-
placement: props.tooltipPlacement,
|
|
131
|
-
maxWidth: props.tooltipMaxWidth,
|
|
132
|
-
wrapperClass: props.tooltipWrapperClass,
|
|
133
|
-
contentClass: props.tooltipContentClass,
|
|
134
|
-
arrowClass: props.tooltipArrowClass,
|
|
135
|
-
delay: props.tooltipDelay,
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* The `NTooltip` is a wrapper for any component which adds a tooltip to it.
|
|
141
|
-
* Any component can just be passed in the default slot and a tooltip will be added to it.
|
|
142
|
-
* Note that this component disappears when neither the `text` nor the `content`
|
|
143
|
-
* prop is passed as the tooltip would then be empty.
|
|
144
|
-
* If this is the case, the default slot will just be rendered inside a div.
|
|
145
|
-
* @example
|
|
146
|
-
* <NTooltip text="Hello">
|
|
147
|
-
* <NButton />
|
|
148
|
-
* </NTooltip>
|
|
149
|
-
*/
|
|
150
|
-
const Component = createComponent('NTooltip', nTooltipProps, (props, { slots }) => {
|
|
151
|
-
return () => (
|
|
152
|
-
<div class={[props.block ? 'block' : 'inline-block', props.wrapperClass]}>
|
|
153
|
-
{props.content || props.text ? (
|
|
154
|
-
<NTooltipBase {...props}>{slots.default?.()}</NTooltipBase>
|
|
155
|
-
) : (
|
|
156
|
-
slots.default?.()
|
|
157
|
-
)}
|
|
158
|
-
</div>
|
|
159
|
-
)
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
export { Component as NTooltip, Component as default }
|
|
163
|
-
|
|
164
|
-
const NTooltipBase = createComponent('NTooltipBase', nTooltipProps, (props, { slots }) => {
|
|
165
|
-
let popperInstance: PopperInstance | null = null
|
|
166
|
-
const contentId = `content-${uniqueId()}`
|
|
167
|
-
const tooltipId = `tooltip-${uniqueId()}`
|
|
168
|
-
|
|
169
|
-
function createTooltip() {
|
|
170
|
-
const content = document.getElementById(contentId)
|
|
171
|
-
const tooltip = document.getElementById(tooltipId)
|
|
172
|
-
if (content && tooltip) {
|
|
173
|
-
popperInstance = createPopper(content, tooltip, {
|
|
174
|
-
placement: props.placement,
|
|
175
|
-
modifiers: [
|
|
176
|
-
{
|
|
177
|
-
name: 'offset',
|
|
178
|
-
options: {
|
|
179
|
-
offset: [0, 8],
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
],
|
|
183
|
-
})
|
|
184
|
-
} else {
|
|
185
|
-
console.error('Could not create tooltip. HTML elements for content or tooltip were not found.')
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function destroyTooltip() {
|
|
190
|
-
popperInstance?.destroy()
|
|
191
|
-
popperInstance = null
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
onMounted(createTooltip)
|
|
195
|
-
onUnmounted(() => {
|
|
196
|
-
if (hoverTimeout) {
|
|
197
|
-
clearTimeout(hoverTimeout)
|
|
198
|
-
}
|
|
199
|
-
destroyTooltip()
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
watch(
|
|
203
|
-
() => props.placement,
|
|
204
|
-
newPlacement => popperInstance?.setOptions({ placement: newPlacement })
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
const isHoveringContent = ref(false)
|
|
208
|
-
const isHoveringTooltip = ref(false)
|
|
209
|
-
const isHovering = computed(() => isHoveringContent.value || isHoveringTooltip.value)
|
|
210
|
-
const delayedIsHovering = ref(false)
|
|
211
|
-
let hoverTimeout: ReturnType<typeof setTimeout> | null = null
|
|
212
|
-
|
|
213
|
-
const showTooltip = computed(
|
|
214
|
-
() => props.show || (!props.hide && (props.delay > 0 ? delayedIsHovering.value : isHovering.value))
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
watch(isHovering, hovering => {
|
|
218
|
-
if (hoverTimeout) {
|
|
219
|
-
clearTimeout(hoverTimeout)
|
|
220
|
-
hoverTimeout = null
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (hovering && props.delay > 0) {
|
|
224
|
-
hoverTimeout = setTimeout(() => {
|
|
225
|
-
delayedIsHovering.value = true
|
|
226
|
-
hoverTimeout = null
|
|
227
|
-
}, props.delay)
|
|
228
|
-
} else {
|
|
229
|
-
delayedIsHovering.value = hovering
|
|
230
|
-
}
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
watchRef(showTooltip, () => popperInstance?.update())
|
|
234
|
-
|
|
235
|
-
return () => (
|
|
236
|
-
<>
|
|
237
|
-
<div
|
|
238
|
-
class="p-[10px] m-[-10px]"
|
|
239
|
-
onMouseleave={() => setTimeout(() => (isHoveringContent.value = false), 10)}
|
|
240
|
-
>
|
|
241
|
-
<div id={contentId} onMouseenter={() => (isHoveringContent.value = true)}>
|
|
242
|
-
{slots.default?.()}
|
|
243
|
-
</div>
|
|
244
|
-
</div>
|
|
245
|
-
|
|
246
|
-
<Transition
|
|
247
|
-
enterActiveClass="transition-opacity ease-out duration-100"
|
|
248
|
-
enterFromClass="opacity-0"
|
|
249
|
-
enterToClass="opacity-100"
|
|
250
|
-
leaveActiveClass="transition-opacity ease-in duration-75"
|
|
251
|
-
leaveFromClass="opacity-100"
|
|
252
|
-
leaveToClass="opacity-0"
|
|
253
|
-
>
|
|
254
|
-
<div
|
|
255
|
-
id={tooltipId}
|
|
256
|
-
role="tooltip"
|
|
257
|
-
onMouseenter={() => (isHoveringTooltip.value = true)}
|
|
258
|
-
onMouseleave={() => (isHoveringTooltip.value = false)}
|
|
259
|
-
v-show={showTooltip.value}
|
|
260
|
-
class={[isHovering.value ? 'z-20' : 'z-10', props.maxWidth, 'tooltip']}
|
|
261
|
-
>
|
|
262
|
-
<div
|
|
263
|
-
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}`}
|
|
264
|
-
>
|
|
265
|
-
{props.content?.() || props.text}
|
|
266
|
-
</div>
|
|
267
|
-
<div data-popper-arrow class={`arrow ${props.arrowClass}`} />
|
|
268
|
-
</div>
|
|
269
|
-
</Transition>
|
|
270
|
-
</>
|
|
271
|
-
)
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
export type TooltipPlacement =
|
|
275
|
-
| 'auto'
|
|
276
|
-
| 'auto-start'
|
|
277
|
-
| 'auto-end'
|
|
278
|
-
| 'top'
|
|
279
|
-
| 'top-start'
|
|
280
|
-
| 'top-end'
|
|
281
|
-
| 'bottom'
|
|
282
|
-
| 'bottom-start'
|
|
283
|
-
| 'bottom-end'
|
|
284
|
-
| 'right'
|
|
285
|
-
| 'right-start'
|
|
286
|
-
| 'right-end'
|
|
287
|
-
| 'left'
|
|
288
|
-
| 'left-start'
|
|
289
|
-
| 'left-end'
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { createComponentWithSlots } from '../utils/component'
|
|
2
|
-
import { computed, onMounted, onUnmounted } from 'vue'
|
|
3
|
-
import { ref, reactive, type PropType, watch } from 'vue'
|
|
4
|
-
import NInput, { nInputProps, type NInputExposed } from './NInput'
|
|
5
|
-
import {
|
|
6
|
-
type ValidationRule,
|
|
7
|
-
type ValidationResult,
|
|
8
|
-
validate,
|
|
9
|
-
type InputValue,
|
|
10
|
-
required,
|
|
11
|
-
validResult,
|
|
12
|
-
} from '../utils/validation'
|
|
13
|
-
import type { ValidatedForm } from './ValidatedForm'
|
|
14
|
-
|
|
15
|
-
export const validationProps = {
|
|
16
|
-
/**
|
|
17
|
-
* If set to `true` this inputs validation will always succeed and all validation
|
|
18
|
-
* rules are ignored. Default is `false`.
|
|
19
|
-
*/
|
|
20
|
-
disableValidation: Boolean,
|
|
21
|
-
/**
|
|
22
|
-
* If set to `true` this input is always valid when its value is empty.
|
|
23
|
-
* If set to `false` the input receives the {@link required} rule. Default is `false`.
|
|
24
|
-
*/
|
|
25
|
-
optional: Boolean,
|
|
26
|
-
/**
|
|
27
|
-
* The rules which this input is checked with.
|
|
28
|
-
* The rules are checked sequentially and the error of the first failed rule is displayed.
|
|
29
|
-
* If `optional` is set to false, the rule {@link required} will be checked first.
|
|
30
|
-
*/
|
|
31
|
-
rules: {
|
|
32
|
-
type: [Function, Array] as PropType<ValidationRule[] | ValidationRule>,
|
|
33
|
-
default: () => [],
|
|
34
|
-
},
|
|
35
|
-
/**
|
|
36
|
-
* The form, which this input will be added to.
|
|
37
|
-
* On initialization, this input will call {@link ValidatedForm.addInput} passing itself to the form.
|
|
38
|
-
*/
|
|
39
|
-
form: Object as PropType<ValidatedForm>,
|
|
40
|
-
/**
|
|
41
|
-
* Overrides the internal error state. If set to true, it will always display an error.
|
|
42
|
-
*/
|
|
43
|
-
error: Boolean,
|
|
44
|
-
/**
|
|
45
|
-
* Overrides the internal error message. If set, this message is always displayed.
|
|
46
|
-
*/
|
|
47
|
-
errorMessage: String,
|
|
48
|
-
/**
|
|
49
|
-
* If set to `true` the error message is not shown.
|
|
50
|
-
* However, the input is still marked red if it is in an error state.
|
|
51
|
-
*/
|
|
52
|
-
hideErrorMessage: Boolean,
|
|
53
|
-
/**
|
|
54
|
-
* Disables the validation on blur. Should only be used in special occasions.
|
|
55
|
-
*/
|
|
56
|
-
disableBlurValidation: Boolean,
|
|
57
|
-
} as const
|
|
58
|
-
|
|
59
|
-
export const nValInputProps = {
|
|
60
|
-
...nInputProps,
|
|
61
|
-
...validationProps,
|
|
62
|
-
/**
|
|
63
|
-
* A slot to replace the input.
|
|
64
|
-
*/
|
|
65
|
-
input: Function as PropType<(props: InputSlotProps) => JSX.Element>,
|
|
66
|
-
} as const
|
|
67
|
-
|
|
68
|
-
export type InputSlotProps = {
|
|
69
|
-
onBlur(): void
|
|
70
|
-
onUpdateValue(newValue: string): void
|
|
71
|
-
error: boolean
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The exposed functions of NValInput
|
|
76
|
-
*/
|
|
77
|
-
export type NValInputExposed = {
|
|
78
|
-
/**
|
|
79
|
-
* Validates the input and returns the validation result
|
|
80
|
-
*/
|
|
81
|
-
validate: () => ValidationResult
|
|
82
|
-
/**
|
|
83
|
-
* Resets the validation state of the input.
|
|
84
|
-
*/
|
|
85
|
-
reset: () => void
|
|
86
|
-
} & NInputExposed
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* The `NValInput` is a `NInput` with custom validation.
|
|
90
|
-
*/
|
|
91
|
-
const Component = createComponentWithSlots('NValInput', nValInputProps, ['input'], (props, context) => {
|
|
92
|
-
const rules = computed(() => {
|
|
93
|
-
const otherRules = Array.isArray(props.rules) ? props.rules : [props.rules]
|
|
94
|
-
return props.optional ? otherRules : [required, ...otherRules]
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
const validationResult = ref<ValidationResult>()
|
|
98
|
-
const validateRules = (input: InputValue) => {
|
|
99
|
-
const result = props.disableValidation ? validResult() : validate(input, rules.value)
|
|
100
|
-
validationResult.value = result
|
|
101
|
-
return result
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const showError = computed(() => props.error || (validationResult.value != null && !validationResult.value.isValid))
|
|
105
|
-
const showErrorMessage = computed(() => !props.hideErrorMessage && showError.value)
|
|
106
|
-
const errorMessage = computed(() => props.errorMessage || validationResult.value?.errorMessage)
|
|
107
|
-
|
|
108
|
-
const validateIfError = (value = props.value) => {
|
|
109
|
-
if (showError.value) validateRules(value)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
watch(
|
|
113
|
-
() => props.value,
|
|
114
|
-
() => validateIfError()
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
watch(
|
|
118
|
-
() => rules.value,
|
|
119
|
-
() => validateIfError()
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
watch(
|
|
123
|
-
() => props.disableValidation,
|
|
124
|
-
() => validateIfError()
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
const onBlur = () => {
|
|
128
|
-
if (!props.disableBlurValidation) validateRules(props.value)
|
|
129
|
-
props.onBlur?.()
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const onUpdateValue = (newValue: string) => {
|
|
133
|
-
validateIfError(newValue)
|
|
134
|
-
props.onUpdateValue?.(newValue)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const inputSlotProps: InputSlotProps = reactive({
|
|
138
|
-
onBlur,
|
|
139
|
-
onUpdateValue,
|
|
140
|
-
error: showError,
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
const inputRef = ref<NInputExposed>()
|
|
144
|
-
const expose: NValInputExposed = {
|
|
145
|
-
validate: () => validateRules(props.value),
|
|
146
|
-
reset: () => (validationResult.value = undefined),
|
|
147
|
-
focus: () => inputRef.value?.focus(),
|
|
148
|
-
}
|
|
149
|
-
context.expose(expose)
|
|
150
|
-
|
|
151
|
-
let assignedId: string | undefined = undefined
|
|
152
|
-
onMounted(() => (assignedId = props.form?.addInput(expose)))
|
|
153
|
-
onUnmounted(() => assignedId && props.form?.removeInput(assignedId))
|
|
154
|
-
|
|
155
|
-
return () => (
|
|
156
|
-
<div>
|
|
157
|
-
{props.input?.(inputSlotProps) || <NInput ref={inputRef} {...{ ...props, ...inputSlotProps }} />}
|
|
158
|
-
{showErrorMessage.value && <p class="text-red-500 text-xs mt-1">{errorMessage.value}</p>}
|
|
159
|
-
</div>
|
|
160
|
-
)
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
export { Component as NValInput, Component as default }
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { Id, type Identifiable } from '../utils/identifiable'
|
|
2
|
-
import { uniqueId } from '../utils/utils'
|
|
3
|
-
import type { ValidationResult } from '../utils/validation'
|
|
4
|
-
import type { NValInputExposed } from './NValInput'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A ValidatedForm groups different inputs together and provides functions, which operate on all inputs at the same time.
|
|
8
|
-
* With a form multiple inputs can be validated together by calling the validate function.
|
|
9
|
-
* @example
|
|
10
|
-
* const form = createValidatedForm()
|
|
11
|
-
* <NValInput ... form={form} />
|
|
12
|
-
* <NValInput ... form={form} />
|
|
13
|
-
* const onClick = () => form.validate()
|
|
14
|
-
*/
|
|
15
|
-
export type ValidatedForm = {
|
|
16
|
-
/**
|
|
17
|
-
* Adds the input to the list of this form and returns the assigned `id`.
|
|
18
|
-
* If this form is passed to a `<NValInput />` via the props, will add itself to this form.
|
|
19
|
-
* @returns the newly assigned `id` of the added input.
|
|
20
|
-
* @example
|
|
21
|
-
* <NValInput ... form={form} />
|
|
22
|
-
*/
|
|
23
|
-
addInput(input: NValInputExposed): string
|
|
24
|
-
/**
|
|
25
|
-
* Removes the input with the given `id` from this form.
|
|
26
|
-
*/
|
|
27
|
-
removeInput(id: string): void
|
|
28
|
-
/**
|
|
29
|
-
* Validates all inputs of the form. If inputs are invalid they will show it visually.
|
|
30
|
-
* The first invalid validation result is returned.
|
|
31
|
-
*/
|
|
32
|
-
validate(): ValidationResult
|
|
33
|
-
/**
|
|
34
|
-
* Resets the validation state of all inputs.
|
|
35
|
-
*/
|
|
36
|
-
reset(): void
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Creates a new ValidatedForm.
|
|
41
|
-
* @returns the instance of the new form.
|
|
42
|
-
*/
|
|
43
|
-
export function createValidatedForm(): ValidatedForm {
|
|
44
|
-
return new ValidatedFormImpl()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
class ValidatedFormImpl implements ValidatedForm {
|
|
48
|
-
inputs: (NValInputExposed & Identifiable)[] = []
|
|
49
|
-
|
|
50
|
-
addInput(input: NValInputExposed): string {
|
|
51
|
-
const id = `input-${uniqueId()}`
|
|
52
|
-
this.inputs.push({ id, ...input })
|
|
53
|
-
return id
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
removeInput(id: string): void {
|
|
57
|
-
Id.remove(this.inputs, id)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
validate(): ValidationResult {
|
|
61
|
-
const results = this.inputs.map(input => input.validate())
|
|
62
|
-
// return first invalid result
|
|
63
|
-
for (const result of results) if (result && !result.isValid) return result
|
|
64
|
-
// else return valid result
|
|
65
|
-
return { isValid: true }
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
reset(): void {
|
|
69
|
-
this.inputs.forEach(input => input.reset())
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { mount } from '@vue/test-utils'
|
|
3
|
-
import NButton from '../NButton'
|
|
4
|
-
|
|
5
|
-
describe('<NButton>', () => {
|
|
6
|
-
it('shows text', () => {
|
|
7
|
-
const button = mount(() => <NButton>Click me!</NButton>)
|
|
8
|
-
expect(button.text()).toMatch('Click me!')
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it('calls onClick when clicked', async () => {
|
|
12
|
-
const onClick = vi.fn()
|
|
13
|
-
const button = mount(() => <NButton onClick={onClick} />).get('button')
|
|
14
|
-
await button.trigger('click')
|
|
15
|
-
expect(onClick).toHaveBeenCalledOnce()
|
|
16
|
-
await button.trigger('click')
|
|
17
|
-
expect(onClick).toHaveBeenCalledTimes(2)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('does not call onClick when disabled', async () => {
|
|
21
|
-
const onClick = vi.fn()
|
|
22
|
-
const button = mount(() => <NButton onClick={onClick} disabled={true} />).get('button')
|
|
23
|
-
await button.trigger('click')
|
|
24
|
-
expect(onClick).not.toHaveBeenCalled()
|
|
25
|
-
})
|
|
26
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { mount } from '@vue/test-utils'
|
|
2
|
-
import { describe, expect, test, vi } from 'vitest'
|
|
3
|
-
import NCheckbox from '../NCheckbox'
|
|
4
|
-
|
|
5
|
-
describe('<NCheckbox>', () => {
|
|
6
|
-
test('handles value and calls onUpdateValue correctly', async () => {
|
|
7
|
-
const onUpdateValue = vi.fn()
|
|
8
|
-
|
|
9
|
-
let checkbox = mount(() => <NCheckbox value={false} onUpdateValue={onUpdateValue} />).get('input')
|
|
10
|
-
await checkbox.trigger('click')
|
|
11
|
-
expect(onUpdateValue).toHaveBeenLastCalledWith(true)
|
|
12
|
-
expect(onUpdateValue).toHaveBeenCalledTimes(1)
|
|
13
|
-
|
|
14
|
-
// test twice (should not have changed because we did not change the value)
|
|
15
|
-
await checkbox.trigger('click')
|
|
16
|
-
expect(onUpdateValue).toHaveBeenLastCalledWith(true)
|
|
17
|
-
expect(onUpdateValue).toHaveBeenCalledTimes(2)
|
|
18
|
-
|
|
19
|
-
onUpdateValue.mockReset()
|
|
20
|
-
checkbox = mount(() => <NCheckbox value={true} onUpdateValue={onUpdateValue} />).get('input')
|
|
21
|
-
|
|
22
|
-
await checkbox.trigger('click')
|
|
23
|
-
expect(onUpdateValue).toHaveBeenLastCalledWith(false)
|
|
24
|
-
expect(onUpdateValue).toHaveBeenCalledTimes(1)
|
|
25
|
-
|
|
26
|
-
// test twice (should not have changed because we did not change the value)
|
|
27
|
-
await checkbox.trigger('click')
|
|
28
|
-
expect(onUpdateValue).toHaveBeenLastCalledWith(false)
|
|
29
|
-
expect(onUpdateValue).toHaveBeenCalledTimes(2)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test('does not call onUpdateValue when disabled', async () => {
|
|
33
|
-
const onUpdateValue = vi.fn()
|
|
34
|
-
|
|
35
|
-
const checkbox = mount(() => <NCheckbox disabled onUpdateValue={onUpdateValue} />).get('input')
|
|
36
|
-
await checkbox.trigger('click')
|
|
37
|
-
expect(onUpdateValue).not.toHaveBeenCalled()
|
|
38
|
-
})
|
|
39
|
-
})
|
package/src/lib/index.ts
DELETED
package/src/lib/jsx.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import { Id } from '../identifiable'
|
|
3
|
-
|
|
4
|
-
const one = { id: 'id1', label: 'one' }
|
|
5
|
-
const two = { id: 'id2', label: 'two' }
|
|
6
|
-
const three = { id: 'id3', label: 'three' }
|
|
7
|
-
const four = { id: 'id4', label: 'four' }
|
|
8
|
-
const all = [one, two, three, four]
|
|
9
|
-
|
|
10
|
-
describe('identifiable', () => {
|
|
11
|
-
test('find', () => {
|
|
12
|
-
expect(Id.find(all, 'id1')).toMatchObject(one)
|
|
13
|
-
expect(Id.find(all, 'id3')).toMatchObject(three)
|
|
14
|
-
// check if the first is picked if multiple
|
|
15
|
-
expect(Id.find([...all, { id: 'id2', label: 'new' }], 'id2')).toMatchObject(two)
|
|
16
|
-
// check if undefined is returned if not found
|
|
17
|
-
expect(Id.find(all, 'id')).toBeUndefined()
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
test('contains', () => {
|
|
21
|
-
expect(Id.contains(all, 'id1')).toBe(true)
|
|
22
|
-
expect(Id.contains(all, 'id3')).toBe(true)
|
|
23
|
-
expect(Id.contains(all, 'id5')).toBe(false)
|
|
24
|
-
expect(Id.contains(all, 'id')).toBe(false)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
test('insert', () => {
|
|
28
|
-
const before = [one, two, three]
|
|
29
|
-
let modify = [...before]
|
|
30
|
-
|
|
31
|
-
let after = Id.insert(modify, two, one)
|
|
32
|
-
// Check if array is still the same
|
|
33
|
-
expect(after).toMatchObject(before)
|
|
34
|
-
// Check if the reference is the same
|
|
35
|
-
expect(after).toBe(modify)
|
|
36
|
-
|
|
37
|
-
modify = [...before]
|
|
38
|
-
after = Id.insert(modify, four, three)
|
|
39
|
-
expect(after).toMatchObject([one, two, three, four])
|
|
40
|
-
|
|
41
|
-
modify = [...before]
|
|
42
|
-
const twoModified = { id: 'id2', label: 'twoooo' }
|
|
43
|
-
after = Id.insert(modify, twoModified)
|
|
44
|
-
expect(after).toMatchObject([one, twoModified, three])
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('remove', () => {
|
|
48
|
-
const before = [one, two, three]
|
|
49
|
-
let modify = [...before]
|
|
50
|
-
|
|
51
|
-
let after = Id.remove(modify, 'id')
|
|
52
|
-
// Check if array is still the same
|
|
53
|
-
expect(after).toMatchObject(before)
|
|
54
|
-
// Check if the reference is the same
|
|
55
|
-
expect(after).toBe(modify)
|
|
56
|
-
|
|
57
|
-
modify = [...before]
|
|
58
|
-
after = Id.remove(modify, 'id2')
|
|
59
|
-
expect(after).toMatchObject([one, three])
|
|
60
|
-
|
|
61
|
-
modify = [one, two, three, four]
|
|
62
|
-
after = Id.remove(modify, 'id1', 'id3')
|
|
63
|
-
expect(after).toMatchObject([two, four])
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('areSameArrays', () => {
|
|
67
|
-
const allDifferent = all.map(item => ({ ...item, label: 'different' }))
|
|
68
|
-
expect(Id.areSameArrays(all, allDifferent)).toBe(true)
|
|
69
|
-
expect(Id.areSameArrays(all, allDifferent.slice(1))).toBe(false)
|
|
70
|
-
expect(Id.areSameArrays(all, allDifferent.reverse())).toBe(false)
|
|
71
|
-
})
|
|
72
|
-
})
|