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

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 (129) hide show
  1. package/eslint.config.cjs +0 -2
  2. package/package.json +31 -30
  3. package/postcss.config.js +1 -4
  4. package/src/demo/App.css +47 -3
  5. package/src/demo/components/ComponentSection.tsx +1 -1
  6. package/src/demo/views/NavigationView.tsx +1 -1
  7. package/src/demo/views/presentation/TooltipView.tsx +1 -1
  8. package/src/lib/components/NAlert.tsx +3 -3
  9. package/src/lib/components/NBadge.tsx +1 -1
  10. package/src/lib/components/NButton.tsx +6 -4
  11. package/src/lib/components/NCheckbox.tsx +2 -2
  12. package/src/lib/components/NDialog.tsx +2 -2
  13. package/src/lib/components/NDropdown.tsx +11 -9
  14. package/src/lib/components/NDropzone.tsx +4 -4
  15. package/src/lib/components/NIconButton.tsx +2 -2
  16. package/src/lib/components/NInput.tsx +1 -1
  17. package/src/lib/components/NLink.tsx +1 -1
  18. package/src/lib/components/NModal.tsx +4 -4
  19. package/src/lib/components/NPagination.css +4 -2
  20. package/src/lib/components/NPagination.tsx +1 -1
  21. package/src/lib/components/NSearchbar.tsx +1 -1
  22. package/src/lib/components/NSelect.tsx +1 -1
  23. package/src/lib/components/NSuggestionList.tsx +1 -1
  24. package/src/lib/components/NTable.css +2 -0
  25. package/src/lib/components/NTableAction.tsx +1 -1
  26. package/src/lib/components/NTextArea.tsx +1 -1
  27. package/src/lib/components/NTooltip.css +2 -0
  28. package/src/lib/components/NTooltip.tsx +1 -1
  29. package/src/lib/utils/component.tsx +1 -1
  30. package/tsconfig.lib.json +1 -0
  31. package/vite.config.ts +2 -0
  32. package/components/NAlert.d.ts +0 -29
  33. package/components/NAlert.js +0 -84
  34. package/components/NBadge.d.ts +0 -73
  35. package/components/NBadge.js +0 -64
  36. package/components/NBreadcrub.d.ts +0 -69
  37. package/components/NBreadcrub.js +0 -71
  38. package/components/NButton.d.ts +0 -64
  39. package/components/NButton.js +0 -72
  40. package/components/NCheckbox.d.ts +0 -20
  41. package/components/NCheckbox.js +0 -43
  42. package/components/NCheckboxLabel.d.ts +0 -26
  43. package/components/NCheckboxLabel.js +0 -42
  44. package/components/NCrudModal.d.ts +0 -118
  45. package/components/NCrudModal.js +0 -120
  46. package/components/NDialog.d.ts +0 -81
  47. package/components/NDialog.js +0 -161
  48. package/components/NDropdown.d.ts +0 -67
  49. package/components/NDropdown.js +0 -115
  50. package/components/NDropzone.d.ts +0 -61
  51. package/components/NDropzone.js +0 -218
  52. package/components/NForm.d.ts +0 -21
  53. package/components/NForm.js +0 -29
  54. package/components/NFormModal.d.ts +0 -75
  55. package/components/NFormModal.js +0 -59
  56. package/components/NIconButton.d.ts +0 -83
  57. package/components/NIconButton.js +0 -88
  58. package/components/NIconCircle.d.ts +0 -49
  59. package/components/NIconCircle.js +0 -67
  60. package/components/NInput.css +0 -11
  61. package/components/NInput.d.ts +0 -94
  62. package/components/NInput.js +0 -110
  63. package/components/NInputPhone.d.ts +0 -58
  64. package/components/NInputPhone.js +0 -47
  65. package/components/NInputSelect.d.ts +0 -103
  66. package/components/NInputSelect.js +0 -115
  67. package/components/NInputSuggestion.d.ts +0 -79
  68. package/components/NInputSuggestion.js +0 -64
  69. package/components/NLink.d.ts +0 -47
  70. package/components/NLink.js +0 -67
  71. package/components/NList.d.ts +0 -37
  72. package/components/NList.js +0 -40
  73. package/components/NLoadingIndicator.css +0 -46
  74. package/components/NLoadingIndicator.d.ts +0 -29
  75. package/components/NLoadingIndicator.js +0 -54
  76. package/components/NModal.d.ts +0 -133
  77. package/components/NModal.js +0 -232
  78. package/components/NPagination.css +0 -15
  79. package/components/NPagination.d.ts +0 -37
  80. package/components/NPagination.js +0 -105
  81. package/components/NSearchbar.d.ts +0 -39
  82. package/components/NSearchbar.js +0 -64
  83. package/components/NSearchbarList.d.ts +0 -33
  84. package/components/NSearchbarList.js +0 -41
  85. package/components/NSelect.d.ts +0 -82
  86. package/components/NSelect.js +0 -101
  87. package/components/NSuggestionList.d.ts +0 -153
  88. package/components/NSuggestionList.js +0 -160
  89. package/components/NTable.css +0 -3
  90. package/components/NTable.d.ts +0 -97
  91. package/components/NTable.js +0 -128
  92. package/components/NTableAction.d.ts +0 -30
  93. package/components/NTableAction.js +0 -50
  94. package/components/NTextArea.d.ts +0 -96
  95. package/components/NTextArea.js +0 -133
  96. package/components/NTooltip.css +0 -37
  97. package/components/NTooltip.d.ts +0 -152
  98. package/components/NTooltip.js +0 -241
  99. package/components/NValInput.d.ts +0 -159
  100. package/components/NValInput.js +0 -113
  101. package/components/ValidatedForm.d.ts +0 -39
  102. package/components/ValidatedForm.js +0 -35
  103. package/i18n/de/vue-collection.json +0 -58
  104. package/i18n/en/vue-collection.json +0 -58
  105. package/i18n/index.d.ts +0 -40
  106. package/i18n/index.js +0 -31
  107. package/index.d.ts +0 -2
  108. package/index.js +0 -2
  109. package/tailwind.config.js +0 -38
  110. package/utils/breakpoints.d.ts +0 -18
  111. package/utils/breakpoints.js +0 -40
  112. package/utils/component.d.ts +0 -57
  113. package/utils/component.js +0 -79
  114. package/utils/deferred.d.ts +0 -13
  115. package/utils/deferred.js +0 -17
  116. package/utils/identifiable.d.ts +0 -56
  117. package/utils/identifiable.js +0 -81
  118. package/utils/stringMaxLength.d.ts +0 -14
  119. package/utils/stringMaxLength.js +0 -23
  120. package/utils/tailwind.d.ts +0 -4
  121. package/utils/tailwind.js +0 -1
  122. package/utils/utils.d.ts +0 -47
  123. package/utils/utils.js +0 -56
  124. package/utils/vModel.d.ts +0 -182
  125. package/utils/vModel.js +0 -224
  126. package/utils/validation.d.ts +0 -90
  127. package/utils/validation.js +0 -147
  128. package/utils/vue.d.ts +0 -13
  129. package/utils/vue.js +0 -21
@@ -1,101 +0,0 @@
1
- import { Fragment as _Fragment, createVNode as _createVNode, mergeProps as _mergeProps } from "vue";
2
- import { trsl } from '../i18n';
3
- import { createComponent } from '../utils/component';
4
- import { ref } from 'vue';
5
- import NTooltip, { mapTooltipProps, nToolTipPropsForImplementor } from './NTooltip';
6
- import NValInput, { nValInputProps } from './NValInput';
7
- export const nSelectProps = {
8
- /**
9
- * The id of the currently selected option of this input.
10
- */
11
- value: String,
12
- /**
13
- * This is called with the newly selected id when the selection has changed.
14
- * If no id is selected, the empty string is passed, in order to
15
- * match the API of all other inputs who never pass `undefined`.
16
- */
17
- onUpdateValue: Function,
18
- /**
19
- * The different options which can be selected.
20
- */
21
- options: {
22
- type: Array,
23
- default: () => []
24
- },
25
- /**
26
- * The value which is shown in the empty state.
27
- * The "nothing-option" will be called like this.
28
- */
29
- placeholder: {
30
- type: String,
31
- default: () => trsl('vue-collection.action.select')
32
- },
33
- /**
34
- * @see {@link nValInputProps.name}
35
- */
36
- name: nValInputProps.name,
37
- /**
38
- * @see {@link nValInputProps.optional}
39
- */
40
- optional: nValInputProps.optional,
41
- /**
42
- * @see {@link nValInputProps.disabled}
43
- */
44
- disabled: nValInputProps.disabled,
45
- /**
46
- * @see {@link nValInputProps.form}
47
- */
48
- form: nValInputProps.form,
49
- /**
50
- * @see {@link nValInputProps.hideLabel}
51
- */
52
- hideLabel: nValInputProps.hideLabel,
53
- /**
54
- * @see {@link nValInputProps.inputClass}
55
- */
56
- inputClass: nValInputProps.inputClass,
57
- ...nToolTipPropsForImplementor
58
- };
59
- /**
60
- * The `NSelect` is a styled html select-input.
61
- */
62
- const Component = createComponent('NSelect', nSelectProps, (props, context) => {
63
- const inputRef = ref();
64
- const exposed = {
65
- focus: () => inputRef.value?.focus(),
66
- validate: () => {
67
- if (inputRef.value == null) throw new Error('Can not validate NSelect as its input was undefined');
68
- return inputRef.value.validate();
69
- },
70
- reset: () => inputRef.value?.reset()
71
- };
72
- context.expose(exposed);
73
- return () => _createVNode(NValInput, _mergeProps({
74
- "ref": inputRef
75
- }, props, {
76
- "input": slotProps => _createVNode(_Fragment, null, [props.name && !props.hideLabel && _createVNode("label", {
77
- "for": props.name,
78
- "class": ['block text-sm font-medium mb-1', props.disabled ? 'text-default-300' : 'text-default-700']
79
- }, [props.name]), _createVNode(NTooltip, _mergeProps({
80
- "block": true
81
- }, mapTooltipProps(props)), {
82
- default: () => [_createVNode("select", {
83
- "name": props.name,
84
- "disabled": props.disabled,
85
- "value": props.value,
86
- "onChange": event => slotProps.onUpdateValue(event.target.value),
87
- "onBlur": slotProps.onBlur,
88
- "class": ['block w-full py-2 pl-4 pr-10 rounded-md border focus:outline-none focus:ring-1', props.disabled ? 'text-default-300 ' : 'text-default-900 ', slotProps.error ? 'border-red-500 focus:border-red-500 focus:ring-red-500' : 'border-default-300 focus:border-primary-500 focus:ring-primary-500', props.inputClass]
89
- }, [_createVNode("option", {
90
- "disabled": !props.optional,
91
- "selected": !props.value,
92
- "value": ""
93
- }, [props.placeholder]), props.options.map(option => _createVNode("option", {
94
- "key": option.id,
95
- "value": option.id,
96
- "selected": props.value == option.id
97
- }, [option.label]))])]
98
- })])
99
- }), null);
100
- });
101
- export { Component as NSelect, Component as default };
@@ -1,153 +0,0 @@
1
- import type { Identifiable } from '../utils/identifiable';
2
- import { type PropType } from 'vue';
3
- import type { AnyObject } from '../utils/utils';
4
- export declare const nSuggestionListPropsForConfig: {
5
- /**
6
- * The items which are available to show in the list. The first `maxItems` will be displayed.
7
- */
8
- readonly items: {
9
- readonly type: PropType<Array<SuggestionItem>>;
10
- readonly default: () => never[];
11
- };
12
- /**
13
- * The maximum items which are displayed in the list.
14
- */
15
- readonly maxItems: {
16
- readonly type: NumberConstructor;
17
- readonly default: () => number;
18
- };
19
- /**
20
- * If set to `true` the list is hidden.
21
- */
22
- readonly hideList: BooleanConstructor;
23
- /**
24
- * If set to `true` the list shows a loading indicator when the `items` array is empty.
25
- */
26
- readonly loading: BooleanConstructor;
27
- /**
28
- * This is called with the id of the selected item.
29
- */
30
- readonly onSelect: PropType<(id: string) => void>;
31
- /**
32
- * The slot for every item of the list.
33
- */
34
- readonly listItem: PropType<(props: ItemSlotProps) => JSX.Element>;
35
- /**
36
- * This function is called, when the input and the suggestion list are really blurred.
37
- * This means, it's not just the input temporarly beeing blurred because the user clicks on the item list,
38
- * but the focus has completely disappeared from the input and the list.
39
- */
40
- readonly onRealBlur: PropType<() => void>;
41
- };
42
- export declare const nSuggestionListPropsForInput: {
43
- /**
44
- * The slot for the input, which will be enhanced with the suggestion list.
45
- */
46
- readonly input: {
47
- readonly type: PropType<(props: InputSlotProps) => JSX.Element>;
48
- readonly required: true;
49
- };
50
- /**
51
- * When this function is called, the parent is required to call focus() on the input element.
52
- * It won't work properly if the parent does not request focus on the input.
53
- */
54
- readonly onRequestInputFocus: {
55
- readonly type: PropType<() => void>;
56
- readonly required: true;
57
- };
58
- /**
59
- * The current value of the input. This is just needed to display the «No results found for {value}» message.
60
- */
61
- readonly inputValue: {
62
- readonly type: StringConstructor;
63
- readonly required: true;
64
- };
65
- };
66
- export declare const nSuggestionListProps: {
67
- /**
68
- * The slot for the input, which will be enhanced with the suggestion list.
69
- */
70
- readonly input: {
71
- readonly type: PropType<(props: InputSlotProps) => JSX.Element>;
72
- readonly required: true;
73
- };
74
- /**
75
- * When this function is called, the parent is required to call focus() on the input element.
76
- * It won't work properly if the parent does not request focus on the input.
77
- */
78
- readonly onRequestInputFocus: {
79
- readonly type: PropType<() => void>;
80
- readonly required: true;
81
- };
82
- /**
83
- * The current value of the input. This is just needed to display the «No results found for {value}» message.
84
- */
85
- readonly inputValue: {
86
- readonly type: StringConstructor;
87
- readonly required: true;
88
- };
89
- /**
90
- * The items which are available to show in the list. The first `maxItems` will be displayed.
91
- */
92
- readonly items: {
93
- readonly type: PropType<Array<SuggestionItem>>;
94
- readonly default: () => never[];
95
- };
96
- /**
97
- * The maximum items which are displayed in the list.
98
- */
99
- readonly maxItems: {
100
- readonly type: NumberConstructor;
101
- readonly default: () => number;
102
- };
103
- /**
104
- * If set to `true` the list is hidden.
105
- */
106
- readonly hideList: BooleanConstructor;
107
- /**
108
- * If set to `true` the list shows a loading indicator when the `items` array is empty.
109
- */
110
- readonly loading: BooleanConstructor;
111
- /**
112
- * This is called with the id of the selected item.
113
- */
114
- readonly onSelect: PropType<(id: string) => void>;
115
- /**
116
- * The slot for every item of the list.
117
- */
118
- readonly listItem: PropType<(props: ItemSlotProps) => JSX.Element>;
119
- /**
120
- * This function is called, when the input and the suggestion list are really blurred.
121
- * This means, it's not just the input temporarly beeing blurred because the user clicks on the item list,
122
- * but the focus has completely disappeared from the input and the list.
123
- */
124
- readonly onRealBlur: PropType<() => void>;
125
- };
126
- export type InputSlotProps = {
127
- /**
128
- * Should be called when the input receives focus.
129
- */
130
- onFocus(): void;
131
- /**
132
- * Should be called when the input is blurred.
133
- */
134
- onBlur(): void;
135
- };
136
- export type ItemSlotProps<T extends Identifiable = SuggestionItem> = {
137
- /**
138
- * The current item of the list
139
- */
140
- item: T;
141
- /**
142
- * Is true, when the current item is highlighted ("hovered" with the keys)
143
- */
144
- highlighted: boolean;
145
- };
146
- export type SuggestionItem = Identifiable & {
147
- label?: string;
148
- } & AnyObject;
149
- /**
150
- * The `NSuggestionList` can be added to an input and adds a list below it which is shown when the input is focused.
151
- */
152
- declare const Component: import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
153
- export { Component as NSuggestionList, Component as default };
@@ -1,160 +0,0 @@
1
- import { createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
2
- import { trsl } from '../i18n';
3
- import { createComponentWithSlots } from '../utils/component';
4
- import { computed, ref } from 'vue';
5
- import NLoadingIndicator from './NLoadingIndicator';
6
- export const nSuggestionListPropsForConfig = {
7
- /**
8
- * The items which are available to show in the list. The first `maxItems` will be displayed.
9
- */
10
- items: {
11
- type: Array,
12
- default: () => []
13
- },
14
- /**
15
- * The maximum items which are displayed in the list.
16
- */
17
- maxItems: {
18
- type: Number,
19
- default: () => 8
20
- },
21
- /**
22
- * If set to `true` the list is hidden.
23
- */
24
- hideList: Boolean,
25
- /**
26
- * If set to `true` the list shows a loading indicator when the `items` array is empty.
27
- */
28
- loading: Boolean,
29
- /**
30
- * This is called with the id of the selected item.
31
- */
32
- onSelect: Function,
33
- /**
34
- * The slot for every item of the list.
35
- */
36
- listItem: Function,
37
- /**
38
- * This function is called, when the input and the suggestion list are really blurred.
39
- * This means, it's not just the input temporarly beeing blurred because the user clicks on the item list,
40
- * but the focus has completely disappeared from the input and the list.
41
- */
42
- onRealBlur: Function
43
- };
44
- export const nSuggestionListPropsForInput = {
45
- /**
46
- * The slot for the input, which will be enhanced with the suggestion list.
47
- */
48
- input: {
49
- type: Function,
50
- required: true
51
- },
52
- /**
53
- * When this function is called, the parent is required to call focus() on the input element.
54
- * It won't work properly if the parent does not request focus on the input.
55
- */
56
- onRequestInputFocus: {
57
- type: Function,
58
- required: true
59
- },
60
- /**
61
- * The current value of the input. This is just needed to display the «No results found for {value}» message.
62
- */
63
- inputValue: {
64
- type: String,
65
- required: true
66
- }
67
- };
68
- export const nSuggestionListProps = {
69
- ...nSuggestionListPropsForConfig,
70
- ...nSuggestionListPropsForInput
71
- };
72
- /**
73
- * The `NSuggestionList` can be added to an input and adds a list below it which is shown when the input is focused.
74
- */
75
- const Component = createComponentWithSlots('NSuggestionList', nSuggestionListProps, ['input', 'listItem'], props => {
76
- const selectedIndex = ref(null);
77
- const displayItems = computed(() => props.items.slice(0, props.maxItems));
78
- const isInFocus = ref(false);
79
- const showList = computed(() => isInFocus.value && !props.hideList);
80
- let listButtonClicked = false;
81
- const onFocus = () => isInFocus.value = true;
82
- const onListMouseDown = () => listButtonClicked = true;
83
- const onListMouseLeave = () => props.onRequestInputFocus();
84
- const onBlur = () => {
85
- if (!listButtonClicked) {
86
- isInFocus.value = false;
87
- props.onRealBlur?.();
88
- }
89
- listButtonClicked = false;
90
- };
91
- const onSelect = id => {
92
- props.onSelect?.(id);
93
- props.onRequestInputFocus();
94
- };
95
- const keydown = event => {
96
- if (event.key == 'ArrowDown') {
97
- event.preventDefault();
98
- nextItem();
99
- } else if (event.key == 'ArrowUp') {
100
- event.preventDefault();
101
- previoiusItem();
102
- } else if (event.key == 'Enter') {
103
- event.preventDefault();
104
- const index = selectedIndex.value;
105
- if (index != null && index < displayItems.value.length) {
106
- const item = displayItems.value[index];
107
- if (item) {
108
- onSelect(item.id);
109
- }
110
- }
111
- }
112
- };
113
- const nextItem = () => {
114
- adjustIndexToSize();
115
- const currentIndex = selectedIndex.value;
116
- let nextIndex = currentIndex == null ? 0 : currentIndex + 1;
117
- if (nextIndex >= displayItems.value.length) nextIndex = null;
118
- selectedIndex.value = nextIndex;
119
- };
120
- const previoiusItem = () => {
121
- adjustIndexToSize();
122
- const currentIndex = selectedIndex.value;
123
- let previousIndex = currentIndex == null ? displayItems.value.length - 1 : currentIndex - 1;
124
- if (previousIndex < 0) previousIndex = null;
125
- selectedIndex.value = previousIndex;
126
- };
127
- const adjustIndexToSize = () => {
128
- if (selectedIndex.value != null && selectedIndex.value >= displayItems.value.length) {
129
- selectedIndex.value = null;
130
- }
131
- };
132
- return () => _createVNode("div", {
133
- "onKeydown": keydown
134
- }, [props.input({
135
- onFocus,
136
- onBlur
137
- }), _createVNode("div", {
138
- "class": "relative"
139
- }, [showList.value && _createVNode("div", {
140
- "class": "bg-white rounded-md shadow-lg p-2 absolute top-2 left-0 min-w-full z-10"
141
- }, [_createVNode("ul", null, [displayItems.value.map((item, index) => _createVNode("li", {
142
- "key": item.id,
143
- "class": ['focus:outline-none hover:bg-default-50 rounded-md select-none p-2 cursor-pointer', selectedIndex.value === index ? 'bg-default-50' : ''],
144
- "onMousedown": onListMouseDown,
145
- "onMouseleave": onListMouseLeave,
146
- "onClick": () => onSelect(item.id)
147
- }, [props.listItem?.({
148
- item,
149
- highlighted: selectedIndex.value === index
150
- }) || item.label])), displayItems.value.length == 0 && _createVNode("div", {
151
- "class": "p-2 text-sm font-medium text-default-700"
152
- }, [props.loading ? _createVNode("div", {
153
- "class": "flex items-center space-x-2"
154
- }, [_createVNode(NLoadingIndicator, {
155
- "size": 6
156
- }, null), _createVNode("span", null, [_createTextVNode(" "), trsl('vue-collection.text.loading-search-results')])]) : _createVNode("div", null, [trsl('vue-collection.text.no-search-results', {
157
- input: props.inputValue
158
- })])])])])])]);
159
- });
160
- export { Component as NSuggestionList, Component as default };
@@ -1,3 +0,0 @@
1
- .table-heading {
2
- @apply text-left text-xs font-medium text-default-500 uppercase tracking-wider;
3
- }
@@ -1,97 +0,0 @@
1
- import { type TWBreakpoint } from '../utils/breakpoints';
2
- import { type PropType } from 'vue';
3
- import './NTable.css';
4
- export type TableItem = string | number | (() => JSX.Element);
5
- export type TableHeading = {
6
- /**
7
- * The key of the table heading. This should match the key of the items.
8
- */
9
- key: string;
10
- /**
11
- * The label of the table heading. If not set, no label is displayed.
12
- */
13
- label?: TableItem;
14
- /**
15
- * If set to `true` the whole column of this heading will be emphasized.
16
- */
17
- emph?: boolean;
18
- /**
19
- * This classes will be directly set to all cells in the column of this heading.
20
- */
21
- cellClass?: string;
22
- /**
23
- * This classes will be directly set on all cells of this heading, when they show up in the details.
24
- */
25
- detailsClass?: string;
26
- /**
27
- * If set the heading will become a details entry when the screen is smaller than the specified breakpoint.
28
- */
29
- breakpoint?: TWBreakpoint;
30
- /**
31
- * If set to `true`, this heading will always show up inside the details. If this is set the `breakpoint`
32
- * property has no effect, because the items always show up as details ignoring the breakpoint.
33
- */
34
- isDetail?: boolean;
35
- };
36
- export type TableRow = Record<string, TableItem> & {
37
- /**
38
- * The TableItem is used as the last element of the table and
39
- * merged together in one cell with the button to toggle the details.
40
- */
41
- action?: TableItem;
42
- /**
43
- * This classes will be applied to the whole table row.
44
- */
45
- rowClass?: string;
46
- /**
47
- * This classes will be applied to the whole details section of the row.
48
- */
49
- detailsClass?: string;
50
- };
51
- export declare const nTableProps: {
52
- /**
53
- * The headings of the table. These define which columns are shown in the table and in which order.
54
- */
55
- readonly headings: {
56
- readonly type: PropType<TableHeading[]>;
57
- readonly required: true;
58
- };
59
- /**
60
- * Adds the classes to all headings at the top of the table.
61
- */
62
- readonly headingsClass: StringConstructor;
63
- /**
64
- * Adds the classes to all headings in the details of the table.
65
- */
66
- readonly headingDetailsClass: StringConstructor;
67
- /**
68
- * The items of the table. They consist of an array of table rows.
69
- * Every tablerow is an object containing elements for the heading keys.
70
- * The elements can either be a primitive value or a function which returns a {@link JSX.Element}.
71
- * If the item should be treated as an action (e.g. icon-button to display at the end of the row)
72
- * the dedicated key 'action' can be used.
73
- * @see TableRow
74
- * @example
75
- * // These headings are defined
76
- * const headings: TableHeading[] = [
77
- * { key: 'id', label: 'ID' },
78
- * { key: 'name', label: 'Name' },
79
- * { key: 'status', label: 'Status' }
80
- * ]
81
- *
82
- * // Appropriate rows for these headings
83
- * const items: TableRow[] = [
84
- * { id: 1, name: 'Hubert', status: () => <NBadge ... />, action: ... }, // Row 1
85
- * { id: 2, name: 'Franzi', status: () => <NBadge ... />, action: ... } // Row 2
86
- * ]
87
- */
88
- readonly items: {
89
- readonly type: PropType<TableRow[]>;
90
- readonly default: () => never[];
91
- };
92
- };
93
- /**
94
- * The `NTable` is a styled html table which accepts data and displays it appropriately.
95
- */
96
- declare const Component: import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
97
- export { Component as NTable, Component as default };
@@ -1,128 +0,0 @@
1
- import { createVNode as _createVNode, Fragment as _Fragment } from "vue";
2
- import { isWidthBreakpoint } from '../utils/breakpoints';
3
- import { createComponent } from '../utils/component';
4
- import { ChevronLeftIcon } from '@heroicons/vue/24/solid';
5
- import { computed, Fragment, ref, watch } from 'vue';
6
- import NIconButton from './NIconButton';
7
- import './NTable.css';
8
- const N_TABLE_ACTION_KEY = 'action';
9
- export const nTableProps = {
10
- /**
11
- * The headings of the table. These define which columns are shown in the table and in which order.
12
- */
13
- headings: {
14
- type: Array,
15
- required: true
16
- },
17
- /**
18
- * Adds the classes to all headings at the top of the table.
19
- */
20
- headingsClass: String,
21
- /**
22
- * Adds the classes to all headings in the details of the table.
23
- */
24
- headingDetailsClass: String,
25
- /**
26
- * The items of the table. They consist of an array of table rows.
27
- * Every tablerow is an object containing elements for the heading keys.
28
- * The elements can either be a primitive value or a function which returns a {@link JSX.Element}.
29
- * If the item should be treated as an action (e.g. icon-button to display at the end of the row)
30
- * the dedicated key 'action' can be used.
31
- * @see TableRow
32
- * @example
33
- * // These headings are defined
34
- * const headings: TableHeading[] = [
35
- * { key: 'id', label: 'ID' },
36
- * { key: 'name', label: 'Name' },
37
- * { key: 'status', label: 'Status' }
38
- * ]
39
- *
40
- * // Appropriate rows for these headings
41
- * const items: TableRow[] = [
42
- * { id: 1, name: 'Hubert', status: () => <NBadge ... />, action: ... }, // Row 1
43
- * { id: 2, name: 'Franzi', status: () => <NBadge ... />, action: ... } // Row 2
44
- * ]
45
- */
46
- items: {
47
- type: Array,
48
- default: () => []
49
- }
50
- };
51
- /**
52
- * The `NTable` is a styled html table which accepts data and displays it appropriately.
53
- */
54
- const Component = createComponent('NTable', nTableProps, props => {
55
- const headings = computed(() => {
56
- // filter out details headings
57
- const headings = props.headings.filter(heading => !isHeadingDetail(heading));
58
- // The column for actions is shown if there are details
59
- // or if any of the items contain an element with the action-key.
60
- if (showDetails.value || props.items.filter(row => row.action != null).length != 0) {
61
- headings.push({
62
- key: N_TABLE_ACTION_KEY
63
- });
64
- }
65
- return headings;
66
- });
67
- const details = computed(() => props.headings.filter(isHeadingDetail));
68
- const showDetails = computed(() => details.value.length > 0);
69
- const detailsOpen = ref([]);
70
- const isDetailsOpen = index => detailsOpen.value[index] || false;
71
- const toggleDetailsOpen = index => detailsOpen.value[index] = !detailsOpen.value[index];
72
- // if the items change, reset all open details to closed
73
- // and create correct amount of booleans for all items
74
- watch(() => props.items, newItems => detailsOpen.value = Array({
75
- length: newItems.length
76
- }).map(() => false), {
77
- immediate: true
78
- });
79
- return () => _createVNode("div", {
80
- "class": "overflow-x-auto"
81
- }, [_createVNode("table", {
82
- "class": "min-w-full text-default-500 text-sm"
83
- }, [_createVNode("thead", {
84
- "class": "bg-default-50 "
85
- }, [_createVNode("tr", null, [headings.value.map(heading => _createVNode("th", {
86
- "key": heading.key,
87
- "scope": "col",
88
- "class": `p-4 table-heading ${props.headingsClass}`
89
- }, [buildItem(heading.label)]))])]), props.items.length > 0 && props.items.map((item, itemIndex) => _createVNode(_Fragment, {
90
- "key": itemIndex
91
- }, [_createVNode("tbody", {
92
- "class": ['border-default-200 border-t', itemIndex % 2 === 0 ? 'bg-white' : 'bg-default-50', item.rowClass]
93
- }, [_createVNode("tr", null, [headings.value.map(heading => _createVNode("td", {
94
- "key": itemIndex + '-' + heading.key,
95
- "class": "p-4"
96
- }, [_createVNode("div", {
97
- "class": ['flex', heading.emph ? 'font-medium text-default-900' : '', heading.cellClass, heading.key == N_TABLE_ACTION_KEY ? 'justify-end items-center space-x-3' : '']
98
- }, [item[heading.key] && buildItem(item[heading.key]), heading.key == N_TABLE_ACTION_KEY && showDetails.value && _createVNode("div", {
99
- "class": "inline-flex transition-transform duration-200",
100
- "style": {
101
- transform: isDetailsOpen(itemIndex) ? 'rotate(-90deg)' : 'rotate(0deg)',
102
- transformOrigin: 'center center'
103
- }
104
- }, [_createVNode(NIconButton, {
105
- "icon": ChevronLeftIcon,
106
- "onClick": () => toggleDetailsOpen(itemIndex)
107
- }, null)])])]))])]), showDetails.value && isDetailsOpen(itemIndex) && _createVNode("tbody", {
108
- "class": [itemIndex % 2 === 0 ? 'bg-white' : 'bg-default-50', item.detailsClass]
109
- }, [details.value.map((detail, detailIndex) => _createVNode("tr", {
110
- "key": `detail-${detailIndex}`
111
- }, [_createVNode("td", {
112
- "class": ['table-heading px-4 py-1', props.headingDetailsClass, details.value.length - 1 == detailIndex ? 'pb-4' : '']
113
- }, [buildItem(detail.label)]), _createVNode("td", {
114
- "class": ['px-4 py-1', details.value[detailIndex]?.detailsClass, details.value.length - 1 == detailIndex ? 'pb-4' : ''],
115
- "colspan": headings.value.length - 1
116
- }, [item[detail.key] && buildItem(item[detail.key])])]))])]))])]);
117
- });
118
- export { Component as NTable, Component as default };
119
- /**
120
- * Builds a JSX-Element out of the item
121
- */
122
- function buildItem(item) {
123
- if (item === undefined) return undefined;else if (typeof item == 'string' || typeof item == 'number') return _createVNode(_Fragment, null, [item]);else return item();
124
- }
125
- function isHeadingDetail(heading) {
126
- // take all headings which are details or below the breakpoint
127
- return heading.isDetail || heading.breakpoint !== undefined && !isWidthBreakpoint(heading.breakpoint).value;
128
- }
@@ -1,30 +0,0 @@
1
- import type { PropType } from 'vue';
2
- import { type RouteLocationRaw } from 'vue-router';
3
- export declare const nTableActionProps: {
4
- /**
5
- * The route of the action. If set the component will be a {@link RouterLink}.
6
- */
7
- readonly route: PropType<RouteLocationRaw>;
8
- /**
9
- * The text of the action.
10
- */
11
- readonly text: StringConstructor;
12
- /**
13
- * The html attribute, which indicates the type of the button.
14
- */
15
- readonly type: {
16
- readonly type: PropType<"submit" | "button" | "reset">;
17
- readonly default: "button";
18
- };
19
- /**
20
- * This is called when the action is clicked.
21
- * It is only called when the `route` prop is not set on the action.
22
- */
23
- readonly onClick: PropType<() => void>;
24
- };
25
- /**
26
- * The `NTableAction` is a button or {@link RouterLink} which is styled to fit into a table.
27
- * It is basically styled as an emphasized text in the table.
28
- */
29
- declare const Component: import("vue").DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, import("vue").PublicProps>;
30
- export { Component as NTableAction, Component as default };