@naptics/vue-collection 1.0.0-beta.1 → 1.0.0-beta.3

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 (200) hide show
  1. package/lib/components/NAlert.d.ts +29 -0
  2. package/lib/components/NAlert.js +84 -0
  3. package/lib/components/NBadge.d.ts +73 -0
  4. package/lib/components/NBadge.js +64 -0
  5. package/lib/components/NBreadcrub.d.ts +69 -0
  6. package/lib/components/NBreadcrub.js +71 -0
  7. package/lib/components/NButton.d.ts +64 -0
  8. package/lib/components/NButton.js +70 -0
  9. package/lib/components/NCheckbox.d.ts +20 -0
  10. package/lib/components/NCheckbox.js +43 -0
  11. package/lib/components/NCheckboxLabel.d.ts +26 -0
  12. package/lib/components/NCheckboxLabel.js +42 -0
  13. package/lib/components/NCrudModal.d.ts +118 -0
  14. package/lib/components/NCrudModal.js +120 -0
  15. package/lib/components/NDialog.d.ts +81 -0
  16. package/lib/components/NDialog.js +161 -0
  17. package/lib/components/NDropdown.d.ts +67 -0
  18. package/lib/components/NDropdown.js +115 -0
  19. package/lib/components/NDropzone.d.ts +61 -0
  20. package/lib/components/NDropzone.js +218 -0
  21. package/lib/components/NForm.d.ts +21 -0
  22. package/lib/components/NForm.js +29 -0
  23. package/lib/components/NFormModal.d.ts +75 -0
  24. package/lib/components/NFormModal.js +59 -0
  25. package/lib/components/NIconButton.d.ts +83 -0
  26. package/lib/components/NIconButton.js +88 -0
  27. package/lib/components/NIconCircle.d.ts +49 -0
  28. package/lib/components/NIconCircle.js +67 -0
  29. package/lib/components/NInput.d.ts +94 -0
  30. package/lib/components/NInput.js +110 -0
  31. package/lib/components/NInputPhone.d.ts +58 -0
  32. package/lib/components/NInputPhone.js +47 -0
  33. package/lib/components/NInputSelect.d.ts +103 -0
  34. package/lib/components/NInputSelect.js +115 -0
  35. package/lib/components/NInputSuggestion.d.ts +79 -0
  36. package/lib/components/NInputSuggestion.js +64 -0
  37. package/lib/components/NLink.d.ts +47 -0
  38. package/lib/components/NLink.js +67 -0
  39. package/lib/components/NList.d.ts +37 -0
  40. package/lib/components/NList.js +40 -0
  41. package/lib/components/NLoadingIndicator.d.ts +29 -0
  42. package/lib/components/NLoadingIndicator.js +54 -0
  43. package/lib/components/NModal.d.ts +133 -0
  44. package/lib/components/NModal.js +235 -0
  45. package/{src/lib → lib}/components/NPagination.css +1 -1
  46. package/lib/components/NPagination.d.ts +37 -0
  47. package/lib/components/NPagination.js +105 -0
  48. package/lib/components/NSearchbar.d.ts +39 -0
  49. package/lib/components/NSearchbar.js +64 -0
  50. package/lib/components/NSearchbarList.d.ts +33 -0
  51. package/lib/components/NSearchbarList.js +41 -0
  52. package/lib/components/NSelect.d.ts +82 -0
  53. package/lib/components/NSelect.js +101 -0
  54. package/lib/components/NSuggestionList.d.ts +153 -0
  55. package/lib/components/NSuggestionList.js +160 -0
  56. package/{src/lib → lib}/components/NTable.css +1 -1
  57. package/lib/components/NTable.d.ts +97 -0
  58. package/lib/components/NTable.js +128 -0
  59. package/lib/components/NTableAction.d.ts +30 -0
  60. package/lib/components/NTableAction.js +50 -0
  61. package/lib/components/NTextArea.d.ts +96 -0
  62. package/lib/components/NTextArea.js +133 -0
  63. package/{src/lib → lib}/components/NTooltip.css +1 -1
  64. package/lib/components/NTooltip.d.ts +152 -0
  65. package/lib/components/NTooltip.js +241 -0
  66. package/lib/components/NValInput.d.ts +156 -0
  67. package/lib/components/NValInput.js +113 -0
  68. package/lib/components/ValidatedForm.d.ts +39 -0
  69. package/lib/components/ValidatedForm.js +35 -0
  70. package/{src/lib/i18n/index.ts → lib/i18n/index.d.ts} +9 -23
  71. package/lib/i18n/index.js +31 -0
  72. package/lib/index.d.ts +2 -0
  73. package/lib/index.js +2 -0
  74. package/lib/utils/breakpoints.d.ts +18 -0
  75. package/lib/utils/breakpoints.js +40 -0
  76. package/lib/utils/component.d.ts +57 -0
  77. package/lib/utils/component.js +79 -0
  78. package/lib/utils/deferred.d.ts +13 -0
  79. package/lib/utils/deferred.js +17 -0
  80. package/lib/utils/identifiable.d.ts +56 -0
  81. package/lib/utils/identifiable.js +81 -0
  82. package/lib/utils/stringMaxLength.d.ts +14 -0
  83. package/lib/utils/stringMaxLength.js +23 -0
  84. package/lib/utils/tailwind.d.ts +4 -0
  85. package/lib/utils/tailwind.js +1 -0
  86. package/lib/utils/utils.d.ts +47 -0
  87. package/lib/utils/utils.js +56 -0
  88. package/{src/lib/utils/vModel.ts → lib/utils/vModel.d.ts} +48 -126
  89. package/lib/utils/vModel.js +224 -0
  90. package/lib/utils/validation.d.ts +90 -0
  91. package/lib/utils/validation.js +147 -0
  92. package/lib/utils/vue.d.ts +13 -0
  93. package/lib/utils/vue.js +21 -0
  94. package/package.json +7 -4
  95. package/.github/workflows/build.yml +0 -26
  96. package/.github/workflows/deploy-demo.yml +0 -46
  97. package/.github/workflows/deploy-lib.yml +0 -59
  98. package/.gitlab-ci.yml +0 -57
  99. package/.nvmrc +0 -1
  100. package/.prettierrc +0 -8
  101. package/.vscode/extensions.json +0 -10
  102. package/.vscode/launch.json +0 -23
  103. package/.vscode/settings.json +0 -13
  104. package/babel.config.json +0 -3
  105. package/env.d.ts +0 -15
  106. package/eslint.config.cjs +0 -27
  107. package/index.html +0 -13
  108. package/postcss.config.js +0 -3
  109. package/public/favicon.ico +0 -0
  110. package/scripts/build-lib.sh +0 -52
  111. package/scripts/sync-node-types.js +0 -70
  112. package/src/demo/App.css +0 -53
  113. package/src/demo/App.tsx +0 -5
  114. package/src/demo/components/ColorGrid.tsx +0 -26
  115. package/src/demo/components/ComponentGrid.tsx +0 -26
  116. package/src/demo/components/ComponentSection.tsx +0 -30
  117. package/src/demo/components/VariantSection.tsx +0 -18
  118. package/src/demo/i18n/de.ts +0 -7
  119. package/src/demo/i18n/en.ts +0 -7
  120. package/src/demo/i18n/index.ts +0 -24
  121. package/src/demo/main.ts +0 -13
  122. package/src/demo/router/index.ts +0 -21
  123. package/src/demo/views/HomeView.tsx +0 -94
  124. package/src/demo/views/NavigationView.tsx +0 -43
  125. package/src/demo/views/presentation/AlertView.tsx +0 -40
  126. package/src/demo/views/presentation/BadgeView.tsx +0 -61
  127. package/src/demo/views/presentation/BreadcrumbView.tsx +0 -52
  128. package/src/demo/views/presentation/ButtonView.tsx +0 -49
  129. package/src/demo/views/presentation/CheckboxView.tsx +0 -59
  130. package/src/demo/views/presentation/DropdownView.tsx +0 -59
  131. package/src/demo/views/presentation/DropzoneView.tsx +0 -39
  132. package/src/demo/views/presentation/IconButtonView.tsx +0 -47
  133. package/src/demo/views/presentation/IconCircleView.tsx +0 -38
  134. package/src/demo/views/presentation/InputView.tsx +0 -179
  135. package/src/demo/views/presentation/LinkView.tsx +0 -60
  136. package/src/demo/views/presentation/ListView.tsx +0 -29
  137. package/src/demo/views/presentation/LoadingIndicatorView.tsx +0 -38
  138. package/src/demo/views/presentation/ModalView.tsx +0 -210
  139. package/src/demo/views/presentation/PaginationView.tsx +0 -25
  140. package/src/demo/views/presentation/SearchbarView.tsx +0 -80
  141. package/src/demo/views/presentation/TableView.tsx +0 -146
  142. package/src/demo/views/presentation/TooltipView.tsx +0 -92
  143. package/src/lib/components/NAlert.tsx +0 -85
  144. package/src/lib/components/NBadge.tsx +0 -75
  145. package/src/lib/components/NBreadcrub.tsx +0 -97
  146. package/src/lib/components/NButton.tsx +0 -82
  147. package/src/lib/components/NCheckbox.tsx +0 -55
  148. package/src/lib/components/NCheckboxLabel.tsx +0 -51
  149. package/src/lib/components/NCrudModal.tsx +0 -133
  150. package/src/lib/components/NDialog.tsx +0 -182
  151. package/src/lib/components/NDropdown.tsx +0 -169
  152. package/src/lib/components/NDropzone.tsx +0 -265
  153. package/src/lib/components/NForm.tsx +0 -32
  154. package/src/lib/components/NFormModal.tsx +0 -66
  155. package/src/lib/components/NIconButton.tsx +0 -92
  156. package/src/lib/components/NIconCircle.tsx +0 -78
  157. package/src/lib/components/NInput.tsx +0 -139
  158. package/src/lib/components/NInputPhone.tsx +0 -53
  159. package/src/lib/components/NInputSelect.tsx +0 -126
  160. package/src/lib/components/NInputSuggestion.tsx +0 -80
  161. package/src/lib/components/NLink.tsx +0 -82
  162. package/src/lib/components/NList.tsx +0 -67
  163. package/src/lib/components/NLoadingIndicator.tsx +0 -63
  164. package/src/lib/components/NModal.tsx +0 -243
  165. package/src/lib/components/NPagination.tsx +0 -131
  166. package/src/lib/components/NSearchbar.tsx +0 -78
  167. package/src/lib/components/NSearchbarList.tsx +0 -47
  168. package/src/lib/components/NSelect.tsx +0 -128
  169. package/src/lib/components/NSuggestionList.tsx +0 -216
  170. package/src/lib/components/NTable.tsx +0 -247
  171. package/src/lib/components/NTableAction.tsx +0 -49
  172. package/src/lib/components/NTextArea.tsx +0 -159
  173. package/src/lib/components/NTooltip.tsx +0 -289
  174. package/src/lib/components/NValInput.tsx +0 -163
  175. package/src/lib/components/ValidatedForm.ts +0 -71
  176. package/src/lib/components/__tests__/NButton.spec.tsx +0 -26
  177. package/src/lib/components/__tests__/NCheckbox.spec.tsx +0 -39
  178. package/src/lib/index.ts +0 -2
  179. package/src/lib/jsx.d.ts +0 -13
  180. package/src/lib/utils/__tests__/identifiable.spec.ts +0 -72
  181. package/src/lib/utils/__tests__/validation.spec.ts +0 -92
  182. package/src/lib/utils/breakpoints.ts +0 -47
  183. package/src/lib/utils/component.tsx +0 -131
  184. package/src/lib/utils/deferred.ts +0 -28
  185. package/src/lib/utils/identifiable.ts +0 -87
  186. package/src/lib/utils/stringMaxLength.ts +0 -25
  187. package/src/lib/utils/tailwind.ts +0 -41
  188. package/src/lib/utils/utils.ts +0 -90
  189. package/src/lib/utils/validation.ts +0 -189
  190. package/src/lib/utils/vue.ts +0 -25
  191. package/tsconfig.config.json +0 -9
  192. package/tsconfig.demo.json +0 -19
  193. package/tsconfig.json +0 -16
  194. package/tsconfig.lib.json +0 -19
  195. package/tsconfig.vitest.json +0 -8
  196. package/vite.config.ts +0 -30
  197. /package/{src/lib → lib}/components/NInput.css +0 -0
  198. /package/{src/lib → lib}/components/NLoadingIndicator.css +0 -0
  199. /package/{src/lib → lib}/i18n/de/vue-collection.json +0 -0
  200. /package/{src/lib → lib}/i18n/en/vue-collection.json +0 -0
@@ -0,0 +1,50 @@
1
+ import { Fragment as _Fragment, createVNode as _createVNode, isVNode as _isVNode } from "vue";
2
+ import { createComponent } from '../utils/component';
3
+ import { RouterLink } from 'vue-router';
4
+ import { nButtonProps } from './NButton';
5
+ function _isSlot(s) {
6
+ return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !_isVNode(s);
7
+ }
8
+ export const nTableActionProps = {
9
+ /**
10
+ * The route of the action. If set the component will be a {@link RouterLink}.
11
+ */
12
+ route: [String, Object],
13
+ /**
14
+ * The text of the action.
15
+ */
16
+ text: String,
17
+ /**
18
+ * The html attribute, which indicates the type of the button.
19
+ */
20
+ type: nButtonProps.type,
21
+ /**
22
+ * This is called when the action is clicked.
23
+ * It is only called when the `route` prop is not set on the action.
24
+ */
25
+ onClick: Function
26
+ };
27
+ /**
28
+ * The `NTableAction` is a button or {@link RouterLink} which is styled to fit into a table.
29
+ * It is basically styled as an emphasized text in the table.
30
+ */
31
+ const Component = createComponent('NTableAction', nTableActionProps, (props, {
32
+ slots
33
+ }) => {
34
+ const content = () => slots.default?.() || _createVNode(_Fragment, null, [props.text]);
35
+ const classes = ['text-left font-medium focus:outline-hidden focus-visible:ring-2 focus-visible:ring-default-900 rounded-xs ring-offset-2 text-default-900 hover:underline hover:text-default-700 cursor-pointer'];
36
+ return () => {
37
+ let _slot;
38
+ return props.route ? _createVNode(RouterLink, {
39
+ "to": props.route,
40
+ "class": classes
41
+ }, _isSlot(_slot = content()) ? _slot : {
42
+ default: () => [_slot]
43
+ }) : _createVNode("button", {
44
+ "type": props.type,
45
+ "class": classes,
46
+ "onClick": props.onClick
47
+ }, [content()]);
48
+ };
49
+ });
50
+ export { Component as NTableAction, Component as default };
@@ -0,0 +1,96 @@
1
+ import { type PropType } from 'vue';
2
+ export declare const nTextAreaProps: {
3
+ readonly disableValidation: BooleanConstructor;
4
+ readonly optional: BooleanConstructor;
5
+ readonly rules: {
6
+ readonly type: PropType<import("../utils/validation").ValidationRule[] | import("../utils/validation").ValidationRule>;
7
+ readonly default: () => never[];
8
+ };
9
+ readonly form: PropType<import("./ValidatedForm").ValidatedForm>;
10
+ readonly error: BooleanConstructor;
11
+ readonly errorMessage: StringConstructor;
12
+ readonly hideErrorMessage: BooleanConstructor;
13
+ readonly disableBlurValidation: BooleanConstructor;
14
+ readonly tooltipText: StringConstructor;
15
+ readonly tooltipContent: PropType<() => JSX.Element>;
16
+ readonly tooltipHide: BooleanConstructor;
17
+ readonly tooltipShow: BooleanConstructor;
18
+ readonly tooltipPlacement: {
19
+ readonly type: PropType<import("./NTooltip").TooltipPlacement>;
20
+ readonly default: "auto";
21
+ };
22
+ readonly tooltipMaxWidth: {
23
+ readonly type: PropType<import("../utils/tailwind").TWMaxWidth>;
24
+ readonly default: "max-w-xs";
25
+ };
26
+ readonly tooltipWrapperClass: StringConstructor;
27
+ readonly tooltipContentClass: StringConstructor;
28
+ readonly tooltipArrowClass: StringConstructor;
29
+ readonly tooltipDelay: {
30
+ readonly type: NumberConstructor;
31
+ readonly default: 0;
32
+ };
33
+ /**
34
+ * The name of the text area. Is displayed as a label above the text area.
35
+ */
36
+ readonly name: StringConstructor;
37
+ /**
38
+ * The placeholder of the text area.
39
+ */
40
+ readonly placeholder: StringConstructor;
41
+ /**
42
+ * The html autocomplete attribute of the text area.
43
+ */
44
+ readonly autocomplete: {
45
+ readonly type: StringConstructor;
46
+ readonly default: "off";
47
+ };
48
+ /**
49
+ * If set to `true`, the text area is resizable in y-direction.
50
+ */
51
+ readonly resizable: {
52
+ readonly type: BooleanConstructor;
53
+ readonly default: true;
54
+ };
55
+ /**
56
+ * The initial height of the text area in terms of
57
+ * how many text rows fit inside the text area.
58
+ * The height can be change if {@link nTextAreaProps.resizable} is `true`
59
+ */
60
+ readonly rows: NumberConstructor;
61
+ /**
62
+ * The maximum length of the input string. Entering longer strings are simply
63
+ * prevented, but no error message is shown to the user.
64
+ */
65
+ readonly maxLength: NumberConstructor;
66
+ /**
67
+ * If set to `true` the text area is disabled and no interaction is possible.
68
+ */
69
+ readonly disabled: BooleanConstructor;
70
+ /**
71
+ * If set to `true` the text area's label is hidden.
72
+ */
73
+ readonly hideLabel: BooleanConstructor;
74
+ /**
75
+ * Adds the classes directly to the input (e.g. for shadow).
76
+ */
77
+ readonly inputClass: StringConstructor;
78
+ /**
79
+ * This is called when the text area reveices focus.
80
+ */
81
+ readonly onFocus: PropType<() => void>;
82
+ /**
83
+ * This is called when the text area looses focus.
84
+ */
85
+ readonly onBlur: PropType<() => void>;
86
+ readonly value: PropType<string>;
87
+ readonly onUpdateValue: PropType<(newValue: string) => void>;
88
+ };
89
+ export type NTextAreaExposed = {
90
+ /**
91
+ * Request focus on the text area.
92
+ */
93
+ focus(): void;
94
+ };
95
+ declare const Component: import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
96
+ export { Component as NTextArea, Component as default };
@@ -0,0 +1,133 @@
1
+ import { mergeProps as _mergeProps, createVNode as _createVNode, vShow as _vShow, withDirectives as _withDirectives } from "vue";
2
+ import { createComponent } 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 { vModelProps } from '../utils/vModel';
7
+ import NValInput, { validationProps } from './NValInput';
8
+ const nTextAreaBaseProps = {
9
+ ...vModelProps(String),
10
+ /**
11
+ * The name of the text area. Is displayed as a label above the text area.
12
+ */
13
+ name: String,
14
+ /**
15
+ * The placeholder of the text area.
16
+ */
17
+ placeholder: String,
18
+ /**
19
+ * The html autocomplete attribute of the text area.
20
+ */
21
+ autocomplete: {
22
+ type: String,
23
+ default: 'off'
24
+ },
25
+ /**
26
+ * If set to `true`, the text area is resizable in y-direction.
27
+ */
28
+ resizable: {
29
+ type: Boolean,
30
+ default: true
31
+ },
32
+ /**
33
+ * The initial height of the text area in terms of
34
+ * how many text rows fit inside the text area.
35
+ * The height can be change if {@link nTextAreaProps.resizable} is `true`
36
+ */
37
+ rows: Number,
38
+ /**
39
+ * The maximum length of the input string. Entering longer strings are simply
40
+ * prevented, but no error message is shown to the user.
41
+ */
42
+ maxLength: Number,
43
+ /**
44
+ * If set to `true` the text area is displayed with a red border.
45
+ */
46
+ error: Boolean,
47
+ /**
48
+ * If set to `true` the text area is disabled and no interaction is possible.
49
+ */
50
+ disabled: Boolean,
51
+ /**
52
+ * If set to `true` the text area's label is hidden.
53
+ */
54
+ hideLabel: Boolean,
55
+ /**
56
+ * Adds the classes directly to the input (e.g. for shadow).
57
+ */
58
+ inputClass: String,
59
+ /**
60
+ * This is called when the text area reveices focus.
61
+ */
62
+ onFocus: Function,
63
+ /**
64
+ * This is called when the text area looses focus.
65
+ */
66
+ onBlur: Function,
67
+ ...nToolTipPropsForImplementor
68
+ };
69
+ export const nTextAreaProps = {
70
+ ...nTextAreaBaseProps,
71
+ ...validationProps
72
+ };
73
+ const Component = createComponent('NTextArea', nTextAreaProps, (props, context) => {
74
+ const textAreaRef = ref();
75
+ const exposed = {
76
+ focus: () => textAreaRef.value?.focus()
77
+ };
78
+ context.expose(exposed);
79
+ return () => _createVNode(NValInput, _mergeProps(props, {
80
+ "input": ({
81
+ error,
82
+ onBlur,
83
+ onUpdateValue
84
+ }) => _createVNode(NTextAreaBase, _mergeProps({
85
+ "ref": textAreaRef
86
+ }, {
87
+ ...props,
88
+ error,
89
+ onBlur,
90
+ onUpdateValue
91
+ }), null)
92
+ }), null);
93
+ });
94
+ export { Component as NTextArea, Component as default };
95
+ /**
96
+ * The `NTextArea` wraps the html text area with all the features from {@link NInput} and {@link NValInput}.
97
+ */
98
+ const NTextAreaBase = createComponent('NTextAreaBase', nTextAreaBaseProps, (props, context) => {
99
+ const textAreaRef = ref();
100
+ const exposed = {
101
+ focus: () => textAreaRef.value?.focus()
102
+ };
103
+ context.expose(exposed);
104
+ return () => _createVNode("div", null, [props.name && !props.hideLabel && _createVNode("label", {
105
+ "for": props.name,
106
+ "class": ['block text-sm font-medium mb-1', props.disabled ? 'text-default-300' : 'text-default-700']
107
+ }, [props.name]), _createVNode(NTooltip, _mergeProps({
108
+ "block": true
109
+ }, mapTooltipProps(props)), {
110
+ default: () => [_createVNode("div", {
111
+ "class": "relative"
112
+ }, [_createVNode("textarea", {
113
+ "ref": textAreaRef,
114
+ "name": props.name,
115
+ "value": props.value,
116
+ "onInput": event => props.onUpdateValue?.(event.target.value),
117
+ "placeholder": props.placeholder,
118
+ "autocomplete": props.autocomplete,
119
+ "disabled": props.disabled,
120
+ "rows": props.rows,
121
+ "maxlength": props.maxLength,
122
+ "onFocus": () => props.onFocus?.(),
123
+ "onBlur": () => props.onBlur?.(),
124
+ "onInvalid": event => event.preventDefault(),
125
+ "class": ['block w-full rounded-md border focus:outline-hidden focus:ring-1 ', 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', props.resizable ? 'resize-y' : 'resize-none', props.inputClass]
126
+ }, null), _withDirectives(_createVNode("div", {
127
+ "class": "absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none"
128
+ }, [_createVNode(ExclamationCircleIcon, {
129
+ "class": "h-5 w-5 text-red-700",
130
+ "aria-hidden": "true"
131
+ }, null)]), [[_vShow, props.error]])])]
132
+ })]);
133
+ });
@@ -1,4 +1,4 @@
1
- @reference "../../demo/App.css";
1
+ @reference "tailwindcss";
2
2
 
3
3
  .arrow,
4
4
  .arrow::before {
@@ -0,0 +1,152 @@
1
+ import { type ExtractedProps } from '../utils/component';
2
+ import type { TWMaxWidth } from '../utils/tailwind';
3
+ import { type PropType } from 'vue';
4
+ import './NTooltip.css';
5
+ export declare const nTooltipProps: {
6
+ /**
7
+ * The text content of the tooltip.
8
+ */
9
+ readonly text: StringConstructor;
10
+ /**
11
+ * A slot to replace the content of the tooltip. This will override the `text` prop.
12
+ */
13
+ readonly content: PropType<() => JSX.Element>;
14
+ /**
15
+ * If set to `true` the tooltip is shown constantly.
16
+ */
17
+ readonly show: BooleanConstructor;
18
+ /**
19
+ * If set to `true` the tooltip is hidden constantly.
20
+ */
21
+ readonly hide: BooleanConstructor;
22
+ /**
23
+ * If set to `true` the `block` class is applied to the tooltip.
24
+ * This should be set if the content in the default slot is also block.
25
+ */
26
+ readonly block: BooleanConstructor;
27
+ /**
28
+ * The placement of the tooltip.
29
+ */
30
+ readonly placement: {
31
+ readonly type: PropType<TooltipPlacement>;
32
+ readonly default: "auto";
33
+ };
34
+ /**
35
+ * The maximum width of the tooltip.
36
+ */
37
+ readonly maxWidth: {
38
+ readonly type: PropType<TWMaxWidth>;
39
+ readonly default: "max-w-xs";
40
+ };
41
+ /**
42
+ * Adds the classes to the (invisible) wrapper element.
43
+ */
44
+ readonly wrapperClass: StringConstructor;
45
+ /**
46
+ * Adds the classes to the container of the tooltips content.
47
+ */
48
+ readonly contentClass: StringConstructor;
49
+ /**
50
+ * Adds the classes to the tooltip arrow. Make sure to use `before:` classes
51
+ * to target the arrow (which is the before element).
52
+ */
53
+ readonly arrowClass: StringConstructor;
54
+ /**
55
+ * The delay in milliseconds before the tooltip is shown.
56
+ * @default 0
57
+ */
58
+ readonly delay: {
59
+ readonly type: NumberConstructor;
60
+ readonly default: 0;
61
+ };
62
+ };
63
+ /**
64
+ * These props are made to use on a component which implements the tooltip
65
+ * and wants it to be controllable via the own props.
66
+ * e.g. `text` is now called `tooltipText`.
67
+ * They can be mapped to the normal tooltip props with {@link mapTooltipProps}
68
+ */
69
+ export declare const nToolTipPropsForImplementor: {
70
+ /**
71
+ * Adds a tooltip to the component with the specified text.
72
+ * @see {@link nTooltipProps.text}
73
+ */
74
+ tooltipText: StringConstructor;
75
+ /**
76
+ * A slot for the tooltip of this component.
77
+ * If the slot is set, the tooltip with the specified content is added to the component.
78
+ * @see {@link nTooltipProps.content}
79
+ */
80
+ tooltipContent: PropType<() => JSX.Element>;
81
+ /**
82
+ * @see {@link nTooltipProps.hide}
83
+ */
84
+ tooltipHide: BooleanConstructor;
85
+ /**
86
+ * @see {@link nTooltipProps.show}
87
+ */
88
+ tooltipShow: BooleanConstructor;
89
+ /**
90
+ * @see {@link nTooltipProps.placement}
91
+ */
92
+ tooltipPlacement: {
93
+ readonly type: PropType<TooltipPlacement>;
94
+ readonly default: "auto";
95
+ };
96
+ /**
97
+ * @see {@link nTooltipProps.maxWidth}
98
+ */
99
+ tooltipMaxWidth: {
100
+ readonly type: PropType<TWMaxWidth>;
101
+ readonly default: "max-w-xs";
102
+ };
103
+ /**
104
+ * @see {@link nTooltipProps.wrapperClass}
105
+ */
106
+ tooltipWrapperClass: StringConstructor;
107
+ /**
108
+ * @see {@link nTooltipProps.contentClass}
109
+ */
110
+ tooltipContentClass: StringConstructor;
111
+ /**
112
+ * @see {@link nTooltipProps.arrowClass}
113
+ */
114
+ tooltipArrowClass: StringConstructor;
115
+ /**
116
+ * @see {@link nTooltipProps.delay}
117
+ */
118
+ tooltipDelay: {
119
+ readonly type: NumberConstructor;
120
+ readonly default: 0;
121
+ };
122
+ };
123
+ /**
124
+ * Maps the {@link nToolTipPropsForImplementor} props to normal tooltip props
125
+ * @returns an object containing the normal tooltip props.
126
+ */
127
+ export declare function mapTooltipProps(props: ExtractedProps<typeof nToolTipPropsForImplementor>): {
128
+ text: string | undefined;
129
+ content: (() => JSX.Element) | undefined;
130
+ hide: boolean;
131
+ show: boolean;
132
+ placement: TooltipPlacement;
133
+ maxWidth: TWMaxWidth;
134
+ wrapperClass: string | undefined;
135
+ contentClass: string | undefined;
136
+ arrowClass: string | undefined;
137
+ delay: number;
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
+ declare const Component: import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
151
+ export { Component as NTooltip, Component as default };
152
+ export type TooltipPlacement = 'auto' | 'auto-start' | 'auto-end' | 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'right' | 'right-start' | 'right-end' | 'left' | 'left-start' | 'left-end';
@@ -0,0 +1,241 @@
1
+ import { createVNode as _createVNode, Fragment as _Fragment, vShow as _vShow, withDirectives as _withDirectives } from "vue";
2
+ import { createComponent } from '../utils/component';
3
+ import { uniqueId } from '../utils/utils';
4
+ import { computed, onMounted, ref, watch, onUnmounted, Transition } from 'vue';
5
+ import { createPopper } from '@popperjs/core';
6
+ import { watchRef } from '../utils/vue';
7
+ import './NTooltip.css';
8
+ export const nTooltipProps = {
9
+ /**
10
+ * The text content of the tooltip.
11
+ */
12
+ text: String,
13
+ /**
14
+ * A slot to replace the content of the tooltip. This will override the `text` prop.
15
+ */
16
+ content: Function,
17
+ /**
18
+ * If set to `true` the tooltip is shown constantly.
19
+ */
20
+ show: Boolean,
21
+ /**
22
+ * If set to `true` the tooltip is hidden constantly.
23
+ */
24
+ hide: Boolean,
25
+ /**
26
+ * If set to `true` the `block` class is applied to the tooltip.
27
+ * This should be set if the content in the default slot is also block.
28
+ */
29
+ block: Boolean,
30
+ /**
31
+ * The placement of the tooltip.
32
+ */
33
+ placement: {
34
+ type: String,
35
+ default: 'auto'
36
+ },
37
+ /**
38
+ * The maximum width of the tooltip.
39
+ */
40
+ maxWidth: {
41
+ type: String,
42
+ default: 'max-w-xs'
43
+ },
44
+ /**
45
+ * Adds the classes to the (invisible) wrapper element.
46
+ */
47
+ wrapperClass: String,
48
+ /**
49
+ * Adds the classes to the container of the tooltips content.
50
+ */
51
+ contentClass: String,
52
+ /**
53
+ * Adds the classes to the tooltip arrow. Make sure to use `before:` classes
54
+ * to target the arrow (which is the before element).
55
+ */
56
+ arrowClass: String,
57
+ /**
58
+ * The delay in milliseconds before the tooltip is shown.
59
+ * @default 0
60
+ */
61
+ delay: {
62
+ type: Number,
63
+ default: 0
64
+ }
65
+ };
66
+ /**
67
+ * These props are made to use on a component which implements the tooltip
68
+ * and wants it to be controllable via the own props.
69
+ * e.g. `text` is now called `tooltipText`.
70
+ * They can be mapped to the normal tooltip props with {@link mapTooltipProps}
71
+ */
72
+ export const nToolTipPropsForImplementor = {
73
+ /**
74
+ * Adds a tooltip to the component with the specified text.
75
+ * @see {@link nTooltipProps.text}
76
+ */
77
+ tooltipText: nTooltipProps.text,
78
+ /**
79
+ * A slot for the tooltip of this component.
80
+ * If the slot is set, the tooltip with the specified content is added to the component.
81
+ * @see {@link nTooltipProps.content}
82
+ */
83
+ tooltipContent: nTooltipProps.content,
84
+ /**
85
+ * @see {@link nTooltipProps.hide}
86
+ */
87
+ tooltipHide: nTooltipProps.hide,
88
+ /**
89
+ * @see {@link nTooltipProps.show}
90
+ */
91
+ tooltipShow: nTooltipProps.show,
92
+ /**
93
+ * @see {@link nTooltipProps.placement}
94
+ */
95
+ tooltipPlacement: nTooltipProps.placement,
96
+ /**
97
+ * @see {@link nTooltipProps.maxWidth}
98
+ */
99
+ tooltipMaxWidth: nTooltipProps.maxWidth,
100
+ /**
101
+ * @see {@link nTooltipProps.wrapperClass}
102
+ */
103
+ tooltipWrapperClass: nTooltipProps.wrapperClass,
104
+ /**
105
+ * @see {@link nTooltipProps.contentClass}
106
+ */
107
+ tooltipContentClass: nTooltipProps.contentClass,
108
+ /**
109
+ * @see {@link nTooltipProps.arrowClass}
110
+ */
111
+ tooltipArrowClass: nTooltipProps.arrowClass,
112
+ /**
113
+ * @see {@link nTooltipProps.delay}
114
+ */
115
+ tooltipDelay: nTooltipProps.delay
116
+ };
117
+ /**
118
+ * Maps the {@link nToolTipPropsForImplementor} props to normal tooltip props
119
+ * @returns an object containing the normal tooltip props.
120
+ */
121
+ export function mapTooltipProps(props) {
122
+ return {
123
+ text: props.tooltipText,
124
+ content: props.tooltipContent,
125
+ hide: props.tooltipHide,
126
+ show: props.tooltipShow,
127
+ placement: props.tooltipPlacement,
128
+ maxWidth: props.tooltipMaxWidth,
129
+ wrapperClass: props.tooltipWrapperClass,
130
+ contentClass: props.tooltipContentClass,
131
+ arrowClass: props.tooltipArrowClass,
132
+ delay: props.tooltipDelay
133
+ };
134
+ }
135
+ /**
136
+ * The `NTooltip` is a wrapper for any component which adds a tooltip to it.
137
+ * Any component can just be passed in the default slot and a tooltip will be added to it.
138
+ * Note that this component disappears when neither the `text` nor the `content`
139
+ * prop is passed as the tooltip would then be empty.
140
+ * If this is the case, the default slot will just be rendered inside a div.
141
+ * @example
142
+ * <NTooltip text="Hello">
143
+ * <NButton />
144
+ * </NTooltip>
145
+ */
146
+ const Component = createComponent('NTooltip', nTooltipProps, (props, {
147
+ slots
148
+ }) => {
149
+ return () => _createVNode("div", {
150
+ "class": [props.block ? 'block' : 'inline-block', props.wrapperClass]
151
+ }, [props.content || props.text ? _createVNode(NTooltipBase, props, {
152
+ default: () => [slots.default?.()]
153
+ }) : slots.default?.()]);
154
+ });
155
+ export { Component as NTooltip, Component as default };
156
+ const NTooltipBase = createComponent('NTooltipBase', nTooltipProps, (props, {
157
+ slots
158
+ }) => {
159
+ let popperInstance = null;
160
+ const contentId = `content-${uniqueId()}`;
161
+ const tooltipId = `tooltip-${uniqueId()}`;
162
+ function createTooltip() {
163
+ const content = document.getElementById(contentId);
164
+ const tooltip = document.getElementById(tooltipId);
165
+ if (content && tooltip) {
166
+ popperInstance = createPopper(content, tooltip, {
167
+ placement: props.placement,
168
+ modifiers: [{
169
+ name: 'offset',
170
+ options: {
171
+ offset: [0, 8]
172
+ }
173
+ }]
174
+ });
175
+ } else {
176
+ console.error('Could not create tooltip. HTML elements for content or tooltip were not found.');
177
+ }
178
+ }
179
+ function destroyTooltip() {
180
+ popperInstance?.destroy();
181
+ popperInstance = null;
182
+ }
183
+ onMounted(createTooltip);
184
+ onUnmounted(() => {
185
+ if (hoverTimeout) {
186
+ clearTimeout(hoverTimeout);
187
+ }
188
+ destroyTooltip();
189
+ });
190
+ watch(() => props.placement, newPlacement => popperInstance?.setOptions({
191
+ placement: newPlacement
192
+ }));
193
+ const isHoveringContent = ref(false);
194
+ const isHoveringTooltip = ref(false);
195
+ const isHovering = computed(() => isHoveringContent.value || isHoveringTooltip.value);
196
+ const delayedIsHovering = ref(false);
197
+ let hoverTimeout = null;
198
+ const showTooltip = computed(() => props.show || !props.hide && (props.delay > 0 ? delayedIsHovering.value : isHovering.value));
199
+ watch(isHovering, hovering => {
200
+ if (hoverTimeout) {
201
+ clearTimeout(hoverTimeout);
202
+ hoverTimeout = null;
203
+ }
204
+ if (hovering && props.delay > 0) {
205
+ hoverTimeout = setTimeout(() => {
206
+ delayedIsHovering.value = true;
207
+ hoverTimeout = null;
208
+ }, props.delay);
209
+ } else {
210
+ delayedIsHovering.value = hovering;
211
+ }
212
+ });
213
+ watchRef(showTooltip, () => popperInstance?.update());
214
+ return () => _createVNode(_Fragment, null, [_createVNode("div", {
215
+ "class": "p-[10px] m-[-10px]",
216
+ "onMouseleave": () => setTimeout(() => isHoveringContent.value = false, 10)
217
+ }, [_createVNode("div", {
218
+ "id": contentId,
219
+ "onMouseenter": () => isHoveringContent.value = true
220
+ }, [slots.default?.()])]), _createVNode(Transition, {
221
+ "enterActiveClass": "transition-opacity ease-out duration-100",
222
+ "enterFromClass": "opacity-0",
223
+ "enterToClass": "opacity-100",
224
+ "leaveActiveClass": "transition-opacity ease-in duration-75",
225
+ "leaveFromClass": "opacity-100",
226
+ "leaveToClass": "opacity-0"
227
+ }, {
228
+ default: () => [_withDirectives(_createVNode("div", {
229
+ "id": tooltipId,
230
+ "role": "tooltip",
231
+ "onMouseenter": () => isHoveringTooltip.value = true,
232
+ "onMouseleave": () => isHoveringTooltip.value = false,
233
+ "class": [isHovering.value ? 'z-20' : 'z-10', props.maxWidth, 'tooltip']
234
+ }, [_createVNode("div", {
235
+ "class": `bg-white rounded-md py-2 px-4 shadow-lg border-default-200 border text-sm whitespace-normal font-normal text-default-700 ${props.contentClass}`
236
+ }, [props.content?.() || props.text]), _createVNode("div", {
237
+ "data-popper-arrow": true,
238
+ "class": `arrow ${props.arrowClass}`
239
+ }, null)]), [[_vShow, showTooltip.value]])]
240
+ })]);
241
+ });