@ganpatiinfo/gids-web-dom-reference 7.2.0 → 8.0.0
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/CHANGELOG.md +39 -0
- package/dist/components/GidsButton/GidsButton.d.ts +1 -1
- package/dist/components/GidsButton/GidsButton.d.ts.map +1 -1
- package/dist/components/GidsButton/GidsButton.js +2 -2
- package/dist/components/GidsButton/GidsButton.js.map +1 -1
- package/dist/components/GidsDropdownItem/GidsDropdownItem.d.ts +10 -0
- package/dist/components/GidsDropdownItem/GidsDropdownItem.d.ts.map +1 -0
- package/dist/components/GidsDropdownItem/GidsDropdownItem.js +31 -0
- package/dist/components/GidsDropdownItem/GidsDropdownItem.js.map +1 -0
- package/dist/components/GidsDropdownMenu/GidsDropdownMenu.d.ts +7 -0
- package/dist/components/GidsDropdownMenu/GidsDropdownMenu.d.ts.map +1 -0
- package/dist/components/GidsDropdownMenu/GidsDropdownMenu.js +24 -0
- package/dist/components/GidsDropdownMenu/GidsDropdownMenu.js.map +1 -0
- package/dist/components/GidsDropdownMenuGroup/GidsDropdownMenuGroup.d.ts +7 -0
- package/dist/components/GidsDropdownMenuGroup/GidsDropdownMenuGroup.d.ts.map +1 -0
- package/dist/components/GidsDropdownMenuGroup/GidsDropdownMenuGroup.js +13 -0
- package/dist/components/GidsDropdownMenuGroup/GidsDropdownMenuGroup.js.map +1 -0
- package/dist/components/GidsEditButton/GidsEditButton.d.ts +8 -0
- package/dist/components/GidsEditButton/GidsEditButton.d.ts.map +1 -0
- package/dist/components/GidsEditButton/GidsEditButton.js +44 -0
- package/dist/components/GidsEditButton/GidsEditButton.js.map +1 -0
- package/dist/components/GidsListItem/GidsListItem.d.ts +11 -0
- package/dist/components/GidsListItem/GidsListItem.d.ts.map +1 -0
- package/dist/components/GidsListItem/GidsListItem.js +196 -0
- package/dist/components/GidsListItem/GidsListItem.js.map +1 -0
- package/dist/components/GidsMenu/GidsMenu.d.ts +7 -0
- package/dist/components/GidsMenu/GidsMenu.d.ts.map +1 -0
- package/dist/components/GidsMenu/GidsMenu.js +34 -0
- package/dist/components/GidsMenu/GidsMenu.js.map +1 -0
- package/dist/components/GidsMenuGroup/GidsMenuGroup.d.ts +7 -0
- package/dist/components/GidsMenuGroup/GidsMenuGroup.d.ts.map +1 -0
- package/dist/components/GidsMenuGroup/GidsMenuGroup.js +31 -0
- package/dist/components/GidsMenuGroup/GidsMenuGroup.js.map +1 -0
- package/dist/components/GidsPopover/GidsPopover.d.ts +7 -0
- package/dist/components/GidsPopover/GidsPopover.d.ts.map +1 -0
- package/dist/components/GidsPopover/GidsPopover.js +16 -0
- package/dist/components/GidsPopover/GidsPopover.js.map +1 -0
- package/dist/components/GidsTooltip/GidsTooltip.d.ts +6 -0
- package/dist/components/GidsTooltip/GidsTooltip.d.ts.map +1 -0
- package/dist/components/GidsTooltip/GidsTooltip.js +20 -0
- package/dist/components/GidsTooltip/GidsTooltip.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/childrenValidationUtils.d.ts +9 -0
- package/dist/utils/childrenValidationUtils.d.ts.map +1 -0
- package/dist/utils/childrenValidationUtils.js +27 -0
- package/dist/utils/childrenValidationUtils.js.map +1 -0
- package/package.json +45 -45
- package/src/components/GidsButton/GidsButton.ts +2 -1
- package/src/components/GidsDropdownItem/GidsDropdownItem.ts +62 -0
- package/src/components/GidsDropdownMenu/GidsDropdownMenu.ts +43 -0
- package/src/components/GidsDropdownMenuGroup/GidsDropdownMenuGroup.ts +26 -0
- package/src/components/GidsEditButton/GidsEditButton.ts +71 -0
- package/src/components/GidsListItem/GidsListItem.ts +281 -0
- package/src/components/GidsMenu/GidsMenu.ts +64 -0
- package/src/components/GidsMenuGroup/GidsMenuGroup.ts +51 -0
- package/src/components/GidsPopover/GidsPopover.ts +32 -0
- package/src/components/GidsTooltip/GidsTooltip.ts +37 -0
- package/src/index.ts +10 -0
- package/src/utils/childrenValidationUtils.ts +47 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClassValue,
|
|
3
|
+
GidsListItemWebProps,
|
|
4
|
+
GidsListItemWebUtils,
|
|
5
|
+
} from '@ganpatiinfo/gids-web-shared';
|
|
6
|
+
import {
|
|
7
|
+
appendAsChildren,
|
|
8
|
+
DomChildren,
|
|
9
|
+
DomNodeOrString,
|
|
10
|
+
} from '../../utils/domUtils';
|
|
11
|
+
import { GidsEditButtonDom } from '../GidsEditButton/GidsEditButton';
|
|
12
|
+
import { GidsDividerDom } from '../GidsDivider/GidsDivider';
|
|
13
|
+
import { GidsIconDom } from '../GidsIcon/GidsIcon';
|
|
14
|
+
import { GidsListItemSelectEventDetail } from '@ganpatiinfo/gids-core-shared';
|
|
15
|
+
|
|
16
|
+
const { getGidsListItemClassNames } = GidsListItemWebUtils;
|
|
17
|
+
|
|
18
|
+
export interface GidsListItemDomProps extends GidsListItemWebProps<
|
|
19
|
+
DomNodeOrString,
|
|
20
|
+
DomChildren,
|
|
21
|
+
DomNodeOrString,
|
|
22
|
+
DomNodeOrString
|
|
23
|
+
> {
|
|
24
|
+
name?: string;
|
|
25
|
+
onPressEditButton?: (this: HTMLButtonElement, event: Event) => void;
|
|
26
|
+
extraClasses?: ClassValue;
|
|
27
|
+
onPressListItem?: (event: CustomEvent<GidsListItemSelectEventDetail>) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const GidsListItemDom = (
|
|
31
|
+
props: GidsListItemDomProps,
|
|
32
|
+
): HTMLButtonElement => {
|
|
33
|
+
const {
|
|
34
|
+
index,
|
|
35
|
+
defaultSelectedIndex,
|
|
36
|
+
children,
|
|
37
|
+
disabled = false,
|
|
38
|
+
selected,
|
|
39
|
+
editButton,
|
|
40
|
+
onPressEditButton,
|
|
41
|
+
onPressListItem,
|
|
42
|
+
leadingAccessory,
|
|
43
|
+
leadingSupport,
|
|
44
|
+
leadingParagraph,
|
|
45
|
+
trailingContent,
|
|
46
|
+
trailingAccessory,
|
|
47
|
+
trailingSupport,
|
|
48
|
+
trailingParagraph,
|
|
49
|
+
divider,
|
|
50
|
+
extraClasses,
|
|
51
|
+
value,
|
|
52
|
+
name,
|
|
53
|
+
} = props;
|
|
54
|
+
|
|
55
|
+
const listItem = document.createElement('button');
|
|
56
|
+
listItem.type = 'button';
|
|
57
|
+
listItem.className = getGidsListItemClassNames(
|
|
58
|
+
{ disabled, selected },
|
|
59
|
+
extraClasses,
|
|
60
|
+
);
|
|
61
|
+
listItem.setAttribute('role', 'list-item-option');
|
|
62
|
+
listItem.setAttribute('aria-selected', selected ? 'true' : 'false');
|
|
63
|
+
listItem.disabled = disabled;
|
|
64
|
+
if (name) {
|
|
65
|
+
listItem.name = name;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof value === 'string') {
|
|
69
|
+
listItem.value = value;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const mainContainer = document.createElement('div');
|
|
73
|
+
mainContainer.className = 'gids-list-item__main-container';
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
editButton !== undefined &&
|
|
77
|
+
editButton !== null &&
|
|
78
|
+
editButton !== 'none' &&
|
|
79
|
+
!disabled
|
|
80
|
+
) {
|
|
81
|
+
const editButtonNode = GidsEditButtonDom({
|
|
82
|
+
size: 'md',
|
|
83
|
+
editButtonType: editButton,
|
|
84
|
+
onPressEditButton,
|
|
85
|
+
});
|
|
86
|
+
// 2. Stop the event from bubbling up to mainContainer / listItem
|
|
87
|
+
editButtonNode.addEventListener('click', (event: MouseEvent) => {
|
|
88
|
+
event.stopPropagation();
|
|
89
|
+
});
|
|
90
|
+
mainContainer.append(editButtonNode);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (leadingAccessory !== undefined && leadingAccessory !== null) {
|
|
94
|
+
const leadingAccessoryContainer = document.createElement('div');
|
|
95
|
+
leadingAccessoryContainer.className = disabled
|
|
96
|
+
? 'gids-list-item__leading-accessory-container gids-list-item__accessory-content-disabled'
|
|
97
|
+
: 'gids-list-item__leading-accessory-container';
|
|
98
|
+
appendAsChildren(leadingAccessoryContainer, leadingAccessory);
|
|
99
|
+
appendAsChildren(mainContainer, leadingAccessoryContainer);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const middleContentContainer = document.createElement('div');
|
|
103
|
+
middleContentContainer.className = 'gids-list-item__middle-content-container';
|
|
104
|
+
|
|
105
|
+
const leadingContentContainer = document.createElement('div');
|
|
106
|
+
leadingContentContainer.className =
|
|
107
|
+
'gids-list-item__leading-content-container';
|
|
108
|
+
|
|
109
|
+
if (children !== undefined && children !== null) {
|
|
110
|
+
if (typeof children === 'string') {
|
|
111
|
+
const leadingLabel = document.createElement('span');
|
|
112
|
+
leadingLabel.className = disabled
|
|
113
|
+
? 'gids-list-item__leading-content-label gids-list-item__text-content-disabled'
|
|
114
|
+
: 'gids-list-item__leading-content-label';
|
|
115
|
+
leadingLabel.textContent = children;
|
|
116
|
+
|
|
117
|
+
appendAsChildren(leadingContentContainer, leadingLabel);
|
|
118
|
+
} else {
|
|
119
|
+
appendAsChildren(leadingContentContainer, children);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (
|
|
124
|
+
(leadingSupport !== undefined && leadingSupport !== null) ||
|
|
125
|
+
(leadingParagraph !== undefined && leadingParagraph !== null)
|
|
126
|
+
) {
|
|
127
|
+
const leadingSupportContent = document.createElement('div');
|
|
128
|
+
leadingSupportContent.className = 'gids-list-item__leading-support-content';
|
|
129
|
+
|
|
130
|
+
if (leadingSupport !== undefined && leadingSupport !== null) {
|
|
131
|
+
if (typeof leadingSupport === 'string') {
|
|
132
|
+
const leadingContentSupportingText = document.createElement('p');
|
|
133
|
+
leadingContentSupportingText.className = disabled
|
|
134
|
+
? 'gids-list-item__leading-content-supporting-text gids-list-item__text-content-disabled'
|
|
135
|
+
: 'gids-list-item__leading-content-supporting-text';
|
|
136
|
+
leadingContentSupportingText.textContent = leadingSupport;
|
|
137
|
+
|
|
138
|
+
appendAsChildren(leadingSupportContent, leadingContentSupportingText);
|
|
139
|
+
} else {
|
|
140
|
+
appendAsChildren(leadingSupportContent, leadingSupport);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (leadingParagraph !== undefined && leadingParagraph !== null) {
|
|
145
|
+
if (typeof leadingParagraph === 'string') {
|
|
146
|
+
const leadingContentParagraphText = document.createElement('p');
|
|
147
|
+
leadingContentParagraphText.className = disabled
|
|
148
|
+
? 'gids-list-item__leading-content-paragraph-text gids-list-item__text-content-disabled'
|
|
149
|
+
: 'gids-list-item__leading-content-paragraph-text';
|
|
150
|
+
leadingContentParagraphText.textContent = leadingParagraph;
|
|
151
|
+
|
|
152
|
+
appendAsChildren(leadingSupportContent, leadingContentParagraphText);
|
|
153
|
+
} else {
|
|
154
|
+
appendAsChildren(leadingSupportContent, leadingParagraph);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
appendAsChildren(leadingContentContainer, leadingSupportContent);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const trailingContentContainer = document.createElement('div');
|
|
162
|
+
trailingContentContainer.className =
|
|
163
|
+
'gids-list-item__trailing-content-container';
|
|
164
|
+
|
|
165
|
+
if (trailingContent !== undefined && trailingContent !== null) {
|
|
166
|
+
if (typeof trailingContent === 'string') {
|
|
167
|
+
const trailingLabel = document.createElement('span');
|
|
168
|
+
trailingLabel.className = disabled
|
|
169
|
+
? 'gids-list-item__trailing-content-label gids-list-item__text-content-disabled'
|
|
170
|
+
: 'gids-list-item__trailing-content-label';
|
|
171
|
+
trailingLabel.textContent = trailingContent;
|
|
172
|
+
|
|
173
|
+
appendAsChildren(trailingContentContainer, trailingLabel);
|
|
174
|
+
} else {
|
|
175
|
+
appendAsChildren(trailingContentContainer, trailingContent);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (
|
|
180
|
+
(trailingSupport !== undefined && trailingSupport !== null) ||
|
|
181
|
+
(trailingParagraph !== undefined && trailingParagraph !== null)
|
|
182
|
+
) {
|
|
183
|
+
const trailingSupportContent = document.createElement('div');
|
|
184
|
+
trailingSupportContent.className =
|
|
185
|
+
'gids-list-item__trailing-support-content';
|
|
186
|
+
|
|
187
|
+
if (trailingSupport !== undefined && trailingSupport !== null) {
|
|
188
|
+
if (typeof trailingSupport === 'string') {
|
|
189
|
+
const trailingContentSupportingText = document.createElement('p');
|
|
190
|
+
trailingContentSupportingText.className = disabled
|
|
191
|
+
? 'gids-list-item__trailing-content-supporting-text gids-list-item__text-content-disabled'
|
|
192
|
+
: 'gids-list-item__trailing-content-supporting-text';
|
|
193
|
+
trailingContentSupportingText.textContent = trailingSupport;
|
|
194
|
+
|
|
195
|
+
appendAsChildren(trailingSupportContent, trailingContentSupportingText);
|
|
196
|
+
} else {
|
|
197
|
+
appendAsChildren(trailingSupportContent, trailingSupport);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (trailingParagraph !== undefined && trailingParagraph !== null) {
|
|
202
|
+
if (typeof trailingParagraph === 'string') {
|
|
203
|
+
const trailingContentParagraphText = document.createElement('p');
|
|
204
|
+
trailingContentParagraphText.className = disabled
|
|
205
|
+
? 'gids-list-item__trailing-content-paragraph-text gids-list-item__text-content-disabled'
|
|
206
|
+
: 'gids-list-item__trailing-content-paragraph-text';
|
|
207
|
+
trailingContentParagraphText.textContent = trailingParagraph;
|
|
208
|
+
|
|
209
|
+
appendAsChildren(trailingSupportContent, trailingContentParagraphText);
|
|
210
|
+
} else {
|
|
211
|
+
appendAsChildren(trailingSupportContent, trailingParagraph);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
appendAsChildren(trailingContentContainer, trailingSupportContent);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
appendAsChildren(middleContentContainer, leadingContentContainer);
|
|
219
|
+
appendAsChildren(middleContentContainer, trailingContentContainer);
|
|
220
|
+
appendAsChildren(mainContainer, middleContentContainer);
|
|
221
|
+
|
|
222
|
+
const trailingAccessoryContainer = document.createElement('div');
|
|
223
|
+
trailingAccessoryContainer.className = disabled
|
|
224
|
+
? 'gids-list-item__trailing-accessory-container gids-list-item__accessory-content-disabled'
|
|
225
|
+
: 'gids-list-item__trailing-accessory-container';
|
|
226
|
+
if (selected) {
|
|
227
|
+
trailingAccessoryContainer.append(
|
|
228
|
+
GidsIconDom({
|
|
229
|
+
name: 'checkmark',
|
|
230
|
+
size: 'md',
|
|
231
|
+
appearance: 'regular',
|
|
232
|
+
}),
|
|
233
|
+
);
|
|
234
|
+
appendAsChildren(mainContainer, trailingAccessoryContainer);
|
|
235
|
+
} else {
|
|
236
|
+
if (trailingAccessory !== undefined && trailingAccessory !== null) {
|
|
237
|
+
appendAsChildren(trailingAccessoryContainer, trailingAccessory);
|
|
238
|
+
appendAsChildren(mainContainer, trailingAccessoryContainer);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
appendAsChildren(listItem, mainContainer);
|
|
243
|
+
if (divider && !selected) {
|
|
244
|
+
const dividerWrapper = document.createElement('div');
|
|
245
|
+
dividerWrapper.className = 'gids-list-item__divider';
|
|
246
|
+
|
|
247
|
+
dividerWrapper.append(
|
|
248
|
+
GidsDividerDom({
|
|
249
|
+
orientation: 'horizontal',
|
|
250
|
+
}),
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
appendAsChildren(listItem, dividerWrapper);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// --- ADD THIS CODE BLOCK BEFORE THE END OF THE FUNCTION ---
|
|
257
|
+
if (onPressListItem) {
|
|
258
|
+
listItem.addEventListener('click', (event: MouseEvent) => {
|
|
259
|
+
if (event?.defaultPrevented || disabled) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// Create a CustomEvent containing your specific detail payload
|
|
263
|
+
const customEvent = new CustomEvent<GidsListItemSelectEventDetail>(
|
|
264
|
+
'onPressListItem',
|
|
265
|
+
{
|
|
266
|
+
bubbles: true,
|
|
267
|
+
composed: true,
|
|
268
|
+
detail: {
|
|
269
|
+
selectedIndex: index,
|
|
270
|
+
defaultSelectedIndex, // Toggles or passes current state
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
// If your Storybook/wrapper expects the custom event directly in the callback:
|
|
276
|
+
onPressListItem(customEvent);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return listItem;
|
|
281
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GidsMenuWebProps,
|
|
3
|
+
GidsMenuWebUtils,
|
|
4
|
+
} from '@ganpatiinfo/gids-web-shared';
|
|
5
|
+
import {
|
|
6
|
+
appendAsChildren,
|
|
7
|
+
DomChildren,
|
|
8
|
+
DomNodeOrString,
|
|
9
|
+
} from '../../utils/domUtils.js';
|
|
10
|
+
import { GidsHeadingDom } from '../GidsHeading/GidsHeading.js';
|
|
11
|
+
import { testDomChildrenValidity } from '../../utils/childrenValidationUtils.js';
|
|
12
|
+
|
|
13
|
+
const { getGidsMenuClassNames } = GidsMenuWebUtils;
|
|
14
|
+
|
|
15
|
+
export interface GidsMenuDomProps extends GidsMenuWebProps<
|
|
16
|
+
DomChildren,
|
|
17
|
+
DomNodeOrString
|
|
18
|
+
> {
|
|
19
|
+
extraClasses?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const GidsMenuDom = ({
|
|
23
|
+
children,
|
|
24
|
+
extraClasses,
|
|
25
|
+
heading,
|
|
26
|
+
supportingText,
|
|
27
|
+
supportingTextTypography,
|
|
28
|
+
...restProps
|
|
29
|
+
}: GidsMenuDomProps): HTMLDivElement => {
|
|
30
|
+
const menu = document.createElement('div');
|
|
31
|
+
menu.className = getGidsMenuClassNames(extraClasses);
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
(heading !== undefined && heading !== null && heading !== '') ||
|
|
35
|
+
(supportingText !== undefined &&
|
|
36
|
+
supportingText !== null &&
|
|
37
|
+
supportingText !== '')
|
|
38
|
+
) {
|
|
39
|
+
menu.append(
|
|
40
|
+
GidsHeadingDom({
|
|
41
|
+
heading,
|
|
42
|
+
supportingText,
|
|
43
|
+
supportingTextTypography: supportingTextTypography ?? 'eyebrow-medium',
|
|
44
|
+
...restProps,
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
testDomChildrenValidity({
|
|
50
|
+
children,
|
|
51
|
+
classNameToBeValidated: 'gids-list-item',
|
|
52
|
+
childrenNameToBeValidated: 'GidsListItemDom',
|
|
53
|
+
currentComponentName: 'GidsMenu',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (children !== undefined && children !== null) {
|
|
57
|
+
const childrenContainer = document.createElement('div');
|
|
58
|
+
childrenContainer.className = 'gids-menu__children';
|
|
59
|
+
appendAsChildren(childrenContainer, children);
|
|
60
|
+
appendAsChildren(menu, childrenContainer);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return menu;
|
|
64
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GidsMenuGroupWebProps,
|
|
3
|
+
GidsMenuGroupWebUtils,
|
|
4
|
+
} from '@ganpatiinfo/gids-web-shared';
|
|
5
|
+
import { appendAsChildren, DomChildren } from '../../utils/domUtils.js';
|
|
6
|
+
import { GidsSpinnerDom } from '../GidsSpinner/GidsSpinner.js';
|
|
7
|
+
import { testDomChildrenValidity } from '../../utils/childrenValidationUtils.js';
|
|
8
|
+
|
|
9
|
+
const { getGidsMenuGroupClassNames } = GidsMenuGroupWebUtils;
|
|
10
|
+
|
|
11
|
+
export interface GidsMenuGroupDomProps extends GidsMenuGroupWebProps<DomChildren> {
|
|
12
|
+
extraClasses?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const GidsMenuGroupDom = ({
|
|
16
|
+
type = 'no-options',
|
|
17
|
+
supportingText = 'No options',
|
|
18
|
+
children,
|
|
19
|
+
extraClasses,
|
|
20
|
+
}: GidsMenuGroupDomProps): HTMLDivElement => {
|
|
21
|
+
const menuGroup = document.createElement('div');
|
|
22
|
+
menuGroup.className = getGidsMenuGroupClassNames({ type }, extraClasses);
|
|
23
|
+
|
|
24
|
+
if (type === 'loading') {
|
|
25
|
+
menuGroup.append(
|
|
26
|
+
GidsSpinnerDom({
|
|
27
|
+
indeterminate: true,
|
|
28
|
+
size: 'md',
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (type === 'no-options') {
|
|
34
|
+
const noOptionText = document.createElement('span');
|
|
35
|
+
noOptionText.textContent = supportingText;
|
|
36
|
+
appendAsChildren(menuGroup, noOptionText);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
testDomChildrenValidity({
|
|
40
|
+
children,
|
|
41
|
+
classNameToBeValidated: 'gids-menu',
|
|
42
|
+
childrenNameToBeValidated: 'GidsMenuDom',
|
|
43
|
+
currentComponentName: 'GidsMenuGroup',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (type === 'default' && children !== undefined && children !== null) {
|
|
47
|
+
appendAsChildren(menuGroup, children);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return menuGroup;
|
|
51
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GidsPopoverWebProps,
|
|
3
|
+
GidsPopoverWebUtils,
|
|
4
|
+
} from '@ganpatiinfo/gids-web-shared';
|
|
5
|
+
import { appendAsChildren, DomChildren } from '../../utils/domUtils.js';
|
|
6
|
+
|
|
7
|
+
const { getGidsPopoverClassNames } = GidsPopoverWebUtils;
|
|
8
|
+
|
|
9
|
+
export interface GidsPopoverDomProps extends GidsPopoverWebProps<DomChildren> {
|
|
10
|
+
extraClasses?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const GidsPopoverDom = ({
|
|
14
|
+
placement,
|
|
15
|
+
htmlFor,
|
|
16
|
+
extraClasses,
|
|
17
|
+
children,
|
|
18
|
+
}: GidsPopoverDomProps): HTMLElement => {
|
|
19
|
+
const popover = document.createElement('gids-popover');
|
|
20
|
+
popover.className = getGidsPopoverClassNames(extraClasses);
|
|
21
|
+
|
|
22
|
+
if (placement !== undefined) {
|
|
23
|
+
popover.setAttribute('placement', placement);
|
|
24
|
+
}
|
|
25
|
+
if (htmlFor !== undefined) {
|
|
26
|
+
popover.setAttribute('for', htmlFor);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
appendAsChildren(popover, children);
|
|
30
|
+
|
|
31
|
+
return popover;
|
|
32
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { GidsTooltipWebProps } from '@ganpatiinfo/gids-web-shared';
|
|
2
|
+
import { GidsTooltipWebUtils } from '@ganpatiinfo/gids-web-shared';
|
|
3
|
+
|
|
4
|
+
const { getGidsTooltipClassNames } = GidsTooltipWebUtils;
|
|
5
|
+
|
|
6
|
+
export interface GidsTooltipDomProps extends GidsTooltipWebProps {
|
|
7
|
+
extraClasses?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const GidsTooltipDom = ({
|
|
11
|
+
tooltipText,
|
|
12
|
+
placement,
|
|
13
|
+
htmlFor,
|
|
14
|
+
showWithoutDelay,
|
|
15
|
+
extraClasses,
|
|
16
|
+
}: GidsTooltipDomProps): HTMLElement => {
|
|
17
|
+
const tooltip = document.createElement('gids-tooltip');
|
|
18
|
+
tooltip.className = getGidsTooltipClassNames(extraClasses);
|
|
19
|
+
|
|
20
|
+
if (tooltipText !== undefined) {
|
|
21
|
+
tooltip.setAttribute('tooltip-text', tooltipText);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (placement !== undefined) {
|
|
25
|
+
tooltip.setAttribute('placement', placement);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (htmlFor !== undefined) {
|
|
29
|
+
tooltip.setAttribute('for', htmlFor);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (showWithoutDelay) {
|
|
33
|
+
tooltip.setAttribute('show-without-delay', '');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return tooltip;
|
|
37
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -71,8 +71,18 @@ export * from './components/GidsAccordionItemHeader/GidsAccordionItemHeader.js';
|
|
|
71
71
|
export * from './components/GidsAccordionItemContent/GidsAccordionItemContent.js';
|
|
72
72
|
export * from './components/GidsAccordionItem/GidsAccordionItem.js';
|
|
73
73
|
export * from './components/GidsAccordion/GidsAccordion.js';
|
|
74
|
+
export * from './components/GidsTooltip/GidsTooltip.js';
|
|
75
|
+
export * from './components/GidsPopover/GidsPopover.js';
|
|
76
|
+
export * from './components/GidsEditButton/GidsEditButton.js';
|
|
77
|
+
export * from './components/GidsListItem/GidsListItem.js';
|
|
78
|
+
export * from './components/GidsMenu/GidsMenu.js';
|
|
79
|
+
export * from './components/GidsMenuGroup/GidsMenuGroup.js';
|
|
80
|
+
export * from './components/GidsDropdownItem/GidsDropdownItem.js';
|
|
81
|
+
export * from './components/GidsDropdownMenu/GidsDropdownMenu.js';
|
|
82
|
+
export * from './components/GidsDropdownMenuGroup/GidsDropdownMenuGroup.js';
|
|
74
83
|
|
|
75
84
|
/**
|
|
76
85
|
* Utilities
|
|
77
86
|
*/
|
|
78
87
|
export * from './utils/domUtils.js';
|
|
88
|
+
export * from './utils/childrenValidationUtils.js';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DomChildren } from './domUtils';
|
|
2
|
+
|
|
3
|
+
export interface TestDomChildrenValidity {
|
|
4
|
+
children?: DomChildren;
|
|
5
|
+
classNameToBeValidated?: string;
|
|
6
|
+
childrenNameToBeValidated?: string;
|
|
7
|
+
currentComponentName?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const testDomChildrenValidity = ({
|
|
11
|
+
children,
|
|
12
|
+
classNameToBeValidated,
|
|
13
|
+
childrenNameToBeValidated,
|
|
14
|
+
currentComponentName,
|
|
15
|
+
}: TestDomChildrenValidity) => {
|
|
16
|
+
if (children !== undefined && children !== null) {
|
|
17
|
+
// --- STRICTOR DOM TYPE VALIDATION BLOCK ---
|
|
18
|
+
// Normalize children to an array to handle both single items and collections safely
|
|
19
|
+
const childrenArray = Array.isArray(children) ? children : [children];
|
|
20
|
+
|
|
21
|
+
for (const child of childrenArray) {
|
|
22
|
+
// 1. Ensure the child is a real DOM node/element (ignore raw strings if they aren't allowed)
|
|
23
|
+
if (child instanceof HTMLElement) {
|
|
24
|
+
// Standard Check A: Using a custom class list or dataset identifier if GidsListItem sets one
|
|
25
|
+
const isGidsListItem =
|
|
26
|
+
child.classList.contains(classNameToBeValidated ?? '') ||
|
|
27
|
+
child.dataset.component === childrenNameToBeValidated;
|
|
28
|
+
|
|
29
|
+
// Standard Check B (Alternative): If GidsListItem returns a custom web component type instance
|
|
30
|
+
// const isGidsListItem = child.tagName.toLowerCase() === 'gids-list-item';
|
|
31
|
+
|
|
32
|
+
if (!isGidsListItem) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`DOM Validation Error: ${currentComponentName} only accepts ${childrenNameToBeValidated} nodes as children. ` +
|
|
35
|
+
`Received an element with class layout: "${child.className}".`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
// If a string or a non-element node was passed illegally
|
|
40
|
+
throw new Error(
|
|
41
|
+
`DOM Validation Error: Invalid type passed to children. Expected ${childrenNameToBeValidated} DOM elements.`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// --- END OF VALIDATION BLOCK ---
|
|
46
|
+
}
|
|
47
|
+
};
|