@ganpatiinfo/gids-web-dom-reference 2.1.1 → 3.1.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/components/GidsCheckbox/GidsCheckbox.js.map +1 -1
  3. package/dist/components/GidsPagination/GidsPagination.d.ts +8 -0
  4. package/dist/components/GidsPagination/GidsPagination.d.ts.map +1 -0
  5. package/dist/components/GidsPagination/GidsPagination.js +169 -0
  6. package/dist/components/GidsPagination/GidsPagination.js.map +1 -0
  7. package/dist/components/GidsRadio/GidsRadio.d.ts.map +1 -1
  8. package/dist/components/GidsRadio/GidsRadio.js.map +1 -1
  9. package/dist/components/GidsSectionNotice/GidsSectionNotice.d.ts.map +1 -1
  10. package/dist/components/GidsSectionNotice/GidsSectionNotice.js.map +1 -1
  11. package/dist/components/GidsSegmentedControl/GidsSegmentedControl.d.ts +9 -0
  12. package/dist/components/GidsSegmentedControl/GidsSegmentedControl.d.ts.map +1 -0
  13. package/dist/components/GidsSegmentedControl/GidsSegmentedControl.js +45 -0
  14. package/dist/components/GidsSegmentedControl/GidsSegmentedControl.js.map +1 -0
  15. package/dist/components/GidsSegmentedTabItem/GidsSegmentedTabItem.d.ts +9 -0
  16. package/dist/components/GidsSegmentedTabItem/GidsSegmentedTabItem.d.ts.map +1 -0
  17. package/dist/components/GidsSegmentedTabItem/GidsSegmentedTabItem.js +40 -0
  18. package/dist/components/GidsSegmentedTabItem/GidsSegmentedTabItem.js.map +1 -0
  19. package/dist/components/GidsSwitch/GidsSwitch.d.ts.map +1 -1
  20. package/dist/components/GidsSwitch/GidsSwitch.js.map +1 -1
  21. package/dist/components/_GidsCheckboxControl/GidsCheckboxControl.d.ts.map +1 -1
  22. package/dist/components/_GidsCheckboxControl/GidsCheckboxControl.js +1 -1
  23. package/dist/components/_GidsCheckboxControl/GidsCheckboxControl.js.map +1 -1
  24. package/dist/components/_GidsPaginationItem/GidsPaginationItem.d.ts +9 -0
  25. package/dist/components/_GidsPaginationItem/GidsPaginationItem.d.ts.map +1 -0
  26. package/dist/components/_GidsPaginationItem/GidsPaginationItem.js +26 -0
  27. package/dist/components/_GidsPaginationItem/GidsPaginationItem.js.map +1 -0
  28. package/dist/components/_GidsRadioControl/GidsRadioControl.d.ts.map +1 -1
  29. package/dist/components/_GidsRadioControl/GidsRadioControl.js +1 -1
  30. package/dist/components/_GidsRadioControl/GidsRadioControl.js.map +1 -1
  31. package/dist/components/_GidsSwitchControl/GidsSwitchControl.d.ts.map +1 -1
  32. package/dist/components/_GidsSwitchControl/GidsSwitchControl.js +1 -1
  33. package/dist/components/_GidsSwitchControl/GidsSwitchControl.js.map +1 -1
  34. package/dist/index.d.ts +4 -0
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +4 -0
  37. package/dist/index.js.map +1 -1
  38. package/package.json +7 -7
  39. package/src/components/GidsCheckbox/GidsCheckbox.ts +1 -1
  40. package/src/components/GidsPagination/GidsPagination.ts +233 -0
  41. package/src/components/GidsRadio/GidsRadio.ts +4 -1
  42. package/src/components/GidsSectionNotice/GidsSectionNotice.ts +74 -74
  43. package/src/components/GidsSegmentedControl/GidsSegmentedControl.ts +75 -0
  44. package/src/components/GidsSegmentedTabItem/GidsSegmentedTabItem.ts +75 -0
  45. package/src/components/GidsSwitch/GidsSwitch.ts +55 -52
  46. package/src/components/_GidsCheckboxControl/GidsCheckboxControl.ts +4 -1
  47. package/src/components/_GidsPaginationItem/GidsPaginationItem.ts +65 -0
  48. package/src/components/_GidsRadioControl/GidsRadioControl.ts +4 -1
  49. package/src/components/_GidsSwitchControl/GidsSwitchControl.ts +4 -1
  50. package/src/index.ts +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ganpatiinfo/gids-web-dom-reference",
3
- "version": "2.1.1",
3
+ "version": "3.1.0",
4
4
  "private": false,
5
5
  "description": "DOM for components reference implementations",
6
6
  "homepage": "https://ganpatiinfosystem.vercel.app/",
@@ -24,14 +24,14 @@
24
24
  "directory": "packages/private/web-dom-reference"
25
25
  },
26
26
  "dependencies": {
27
- "@ganpatiinfo/gids-core-shared": "2.1.1",
28
- "@ganpatiinfo/gids-web-shared": "2.1.1"
27
+ "@ganpatiinfo/gids-core-shared": "3.1.0",
28
+ "@ganpatiinfo/gids-web-shared": "3.1.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "@ganpatiinfo/gids-web-theme-interface": "2.0.7",
32
- "@jest/globals": "29.7.0",
33
- "@types/jasmine": "5.1.7",
34
- "expect": "29.7.0"
31
+ "@ganpatiinfo/gids-web-theme-interface": "3.1.0",
32
+ "@jest/globals": "^30.2.0",
33
+ "@types/jasmine": "^5.1.15",
34
+ "expect": "^30.2.0"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@jest/globals": {
@@ -54,7 +54,7 @@ export const GidsCheckboxDom = ({
54
54
  indeterminate,
55
55
  inputId: realInputId,
56
56
  name,
57
- value,
57
+ value,
58
58
  required,
59
59
  onChange,
60
60
  }),
@@ -0,0 +1,233 @@
1
+ import {
2
+ GidsPaginationCommonProps,
3
+ GidsPaginationCommonUtils,
4
+ } from '@ganpatiinfo/gids-core-shared';
5
+ import {
6
+ ClassValue,
7
+ GidsPaginationButtonParamsProps,
8
+ GidsPaginationWebUtils,
9
+ } from '@ganpatiinfo/gids-web-shared';
10
+ import { GidsPaginationItemDom } from '../_GidsPaginationItem/GidsPaginationItem.js';
11
+ import { IconName } from '@ganpatiinfo/gids-web-theme-interface';
12
+
13
+ const { getGidsPaginationClassNames, getGidsPaginationDotsClassNames } =
14
+ GidsPaginationWebUtils;
15
+ const { getPaginationsArr } = GidsPaginationCommonUtils;
16
+
17
+ export interface GidsPaginationDomProps
18
+ extends Omit<GidsPaginationCommonProps<string>, 'onClickItem'> {
19
+ extraClasses?: ClassValue;
20
+ onClickItem?: ({
21
+ event,
22
+ index,
23
+ page,
24
+ defaultPage,
25
+ type,
26
+ }: GidsPaginationButtonParamsProps<MouseEvent>) => void;
27
+ }
28
+
29
+ export const GidsPaginationDom = ({
30
+ selectColor = 'default',
31
+ variant = 'default',
32
+ shape = 'circled',
33
+ size = 'sm',
34
+ disabled = false,
35
+ count = 0,
36
+ defaultPage = 1,
37
+ page,
38
+ nextIcon,
39
+ previousIcon,
40
+ showFirstButton,
41
+ showLastButton,
42
+ hidePrevButton = false,
43
+ hideNextButton = false,
44
+ extraClasses,
45
+ onClickItem,
46
+ }: GidsPaginationDomProps): HTMLDivElement => {
47
+ const pagination = document.createElement('div');
48
+ pagination.className = getGidsPaginationClassNames(extraClasses);
49
+
50
+ if (count !== undefined && count > 0) {
51
+ let internalPage = 0;
52
+ if (defaultPage !== undefined && defaultPage > 0) {
53
+ internalPage = defaultPage;
54
+ }
55
+ if (page !== undefined && page > 0) {
56
+ internalPage = page;
57
+ }
58
+
59
+ if (showFirstButton) {
60
+ pagination.appendChild(
61
+ GidsPaginationItemDom({
62
+ selectColor: 'none',
63
+ selected: false,
64
+ variant,
65
+ shape,
66
+ size,
67
+ isIcon: true,
68
+ icon: 'backward',
69
+ disabled: internalPage <= 1 || disabled,
70
+ onClickItem: (event: MouseEvent) => {
71
+ if (onClickItem) {
72
+ onClickItem({
73
+ event,
74
+ index: 0,
75
+ page: 1,
76
+ defaultPage,
77
+ type: 'first',
78
+ });
79
+ }
80
+ },
81
+ }),
82
+ );
83
+ }
84
+
85
+ if (!hidePrevButton) {
86
+ const newPagenumber = internalPage > 1 ? internalPage - 1 : 1;
87
+ // if (internalPage <= 0) {
88
+ // newPagenumber = internalPage > 1 ? internalPage - 1 : 1;
89
+ // }
90
+ pagination.appendChild(
91
+ GidsPaginationItemDom({
92
+ selectColor: 'none',
93
+ selected: false,
94
+ variant,
95
+ shape,
96
+ size,
97
+ isIcon: true,
98
+ icon:
99
+ previousIcon !== undefined &&
100
+ previousIcon !== '' &&
101
+ previousIcon !== '(none)'
102
+ ? (previousIcon as IconName)
103
+ : 'chevron-left',
104
+ disabled: internalPage <= 1 || disabled,
105
+ onClickItem: (event: MouseEvent) => {
106
+ if (onClickItem) {
107
+ onClickItem({
108
+ event,
109
+ index: newPagenumber - 1,
110
+ page: newPagenumber,
111
+ defaultPage,
112
+ type: 'previous',
113
+ });
114
+ }
115
+ },
116
+ }),
117
+ );
118
+ }
119
+
120
+ const paginationsArr = getPaginationsArr({
121
+ pageNumber: internalPage,
122
+ count,
123
+ });
124
+
125
+ const newLength = paginationsArr.length;
126
+
127
+ Array.from({ length: newLength }, (_, i) => {
128
+ const dataObj = paginationsArr[i];
129
+
130
+ let selectedPage = false;
131
+ if (
132
+ internalPage > 0 &&
133
+ internalPage === Number(dataObj) &&
134
+ dataObj !== '...'
135
+ ) {
136
+ selectedPage = true;
137
+ }
138
+
139
+ if (dataObj === '...') {
140
+ const terminatorBlock = document.createElement('div');
141
+ terminatorBlock.className = getGidsPaginationDotsClassNames({ size });
142
+ terminatorBlock.textContent = '...';
143
+ pagination.appendChild(terminatorBlock);
144
+ return;
145
+ }
146
+ pagination.appendChild(
147
+ GidsPaginationItemDom({
148
+ selectColor,
149
+ variant,
150
+ shape,
151
+ size,
152
+ children: `${dataObj}`,
153
+ isIcon: false,
154
+ icon: '(none)',
155
+ disabled,
156
+ selected: selectedPage,
157
+ onClickItem: (event: MouseEvent) => {
158
+ if (onClickItem) {
159
+ onClickItem({
160
+ event,
161
+ index: Number(dataObj) - 1,
162
+ page: Number(dataObj),
163
+ defaultPage,
164
+ type: 'page',
165
+ });
166
+ }
167
+ },
168
+ }),
169
+ );
170
+ });
171
+
172
+ if (!hideNextButton) {
173
+ const newPagenumber = internalPage < count ? internalPage + 1 : count;
174
+ // if (internalPage <= 0) {
175
+ // newPagenumber = internalPage < count ? internalPage + 1 : count;
176
+ // }
177
+ pagination.appendChild(
178
+ GidsPaginationItemDom({
179
+ selectColor: 'none',
180
+ selected: false,
181
+ variant,
182
+ shape,
183
+ size,
184
+ isIcon: true,
185
+ icon:
186
+ nextIcon !== undefined && nextIcon !== '' && nextIcon !== '(none)'
187
+ ? (nextIcon as IconName)
188
+ : 'chevron-right',
189
+ disabled: internalPage >= count || disabled,
190
+ onClickItem: (event: MouseEvent) => {
191
+ if (onClickItem) {
192
+ onClickItem({
193
+ event,
194
+ index: newPagenumber - 1,
195
+ page: newPagenumber,
196
+ defaultPage,
197
+ type: 'next',
198
+ });
199
+ }
200
+ },
201
+ }),
202
+ );
203
+ }
204
+
205
+ if (showLastButton) {
206
+ pagination.appendChild(
207
+ GidsPaginationItemDom({
208
+ selectColor: 'none',
209
+ selected: false,
210
+ variant,
211
+ shape,
212
+ size,
213
+ isIcon: true,
214
+ icon: 'forward',
215
+ disabled: internalPage >= count || disabled,
216
+ onClickItem: (event: MouseEvent) => {
217
+ if (onClickItem) {
218
+ onClickItem({
219
+ event,
220
+ index: count - 1,
221
+ page: count,
222
+ defaultPage,
223
+ type: 'last',
224
+ });
225
+ }
226
+ },
227
+ }),
228
+ );
229
+ }
230
+ }
231
+
232
+ return pagination;
233
+ };
@@ -6,7 +6,10 @@ import {
6
6
  } from '@ganpatiinfo/gids-web-shared';
7
7
  import { GidsRadioControlDom } from '../_GidsRadioControl/GidsRadioControl.js';
8
8
  import { GidsLabelDom } from '../GidsLabel/GidsLabel.js';
9
- import { type DomChildren, type DomNodeOrString } from '../../utils/domUtils.js';
9
+ import {
10
+ type DomChildren,
11
+ type DomNodeOrString,
12
+ } from '../../utils/domUtils.js';
10
13
 
11
14
  const { getGidsRadioClassNames } = GidsRadioWebUtils;
12
15
 
@@ -1,12 +1,12 @@
1
1
  import {
2
- GidsSectionNoticeCommonUtils,
3
- type GidsSectionNoticeCommonProps,
2
+ GidsSectionNoticeCommonUtils,
3
+ type GidsSectionNoticeCommonProps,
4
4
  } from '@ganpatiinfo/gids-core-shared';
5
5
  import { GidsSectionNoticeWebUtils } from '@ganpatiinfo/gids-web-shared';
6
6
  import {
7
- appendAsChildren,
8
- type DomChildren,
9
- type DomNodeOrString,
7
+ appendAsChildren,
8
+ type DomChildren,
9
+ type DomNodeOrString,
10
10
  } from '../../utils/domUtils.js';
11
11
  import { type IconName } from '@ganpatiinfo/gids-web-theme-interface';
12
12
  import { GidsIconDom } from '../GidsIcon/GidsIcon.js';
@@ -17,89 +17,89 @@ const { getGidsSectionNoticeClassNames } = GidsSectionNoticeWebUtils;
17
17
  const { getSectionNoticeIconName } = GidsSectionNoticeCommonUtils;
18
18
 
19
19
  export interface GidsSectionNoticeDomProps
20
- extends GidsSectionNoticeCommonProps<DomNodeOrString, DomChildren> {
21
- onClickDismiss?: (event: MouseEvent) => void;
20
+ extends GidsSectionNoticeCommonProps<DomNodeOrString, DomChildren> {
21
+ onClickDismiss?: (event: MouseEvent) => void;
22
22
  }
23
23
 
24
24
  export const GidsSectionNoticeDom = ({
25
- appearance = 'information',
26
- title,
27
- supportingText,
28
- children,
29
- dismissible = true,
30
- onClickDismiss,
25
+ appearance = 'information',
26
+ title,
27
+ supportingText,
28
+ children,
29
+ dismissible = true,
30
+ onClickDismiss,
31
31
  }: GidsSectionNoticeDomProps): HTMLDivElement => {
32
- const sectionNotice = document.createElement('div');
33
- sectionNotice.className = getGidsSectionNoticeClassNames({ appearance });
32
+ const sectionNotice = document.createElement('div');
33
+ sectionNotice.className = getGidsSectionNoticeClassNames({ appearance });
34
34
 
35
- const innerContainer = document.createElement('div');
36
- innerContainer.className = 'gids-section-notice__inner-container';
35
+ const innerContainer = document.createElement('div');
36
+ innerContainer.className = 'gids-section-notice__inner-container';
37
37
 
38
- const leadingIconContainer = document.createElement('div');
39
- leadingIconContainer.className =
40
- 'gids-section-notice__leading-icon-container';
38
+ const leadingIconContainer = document.createElement('div');
39
+ leadingIconContainer.className =
40
+ 'gids-section-notice__leading-icon-container';
41
41
 
42
- const leadingIconName = getSectionNoticeIconName({ appearance }) as IconName;
42
+ const leadingIconName = getSectionNoticeIconName({ appearance }) as IconName;
43
43
 
44
- const leadingIcon = GidsIconDom({
45
- size: 'md',
46
- appearance: 'filled',
47
- name: leadingIconName,
48
- alt: '',
49
- className: `gids-section-notice__${appearance}-icon`,
50
- });
51
- leadingIconContainer.appendChild(leadingIcon);
52
- innerContainer.appendChild(leadingIconContainer);
44
+ const leadingIcon = GidsIconDom({
45
+ size: 'md',
46
+ appearance: 'filled',
47
+ name: leadingIconName,
48
+ alt: '',
49
+ className: `gids-section-notice__${appearance}-icon`,
50
+ });
51
+ leadingIconContainer.appendChild(leadingIcon);
52
+ innerContainer.appendChild(leadingIconContainer);
53
53
 
54
- const contentContainer = document.createElement('div');
55
- contentContainer.className = 'gids-section-notice__content-container';
54
+ const contentContainer = document.createElement('div');
55
+ contentContainer.className = 'gids-section-notice__content-container';
56
56
 
57
- const titleElement = document.createElement('div');
58
- titleElement.className = 'gids-section-notice__title';
59
- appendAsChildren(titleElement, title);
60
- contentContainer.appendChild(titleElement);
57
+ const titleElement = document.createElement('div');
58
+ titleElement.className = 'gids-section-notice__title';
59
+ appendAsChildren(titleElement, title);
60
+ contentContainer.appendChild(titleElement);
61
61
 
62
- if (supportingText) {
63
- const supportingTextElement = document.createElement('div');
64
- supportingTextElement.className = 'gids-section-notice__supporting-text';
65
- appendAsChildren(supportingTextElement, supportingText);
66
- contentContainer.appendChild(supportingTextElement);
67
- }
62
+ if (supportingText) {
63
+ const supportingTextElement = document.createElement('div');
64
+ supportingTextElement.className = 'gids-section-notice__supporting-text';
65
+ appendAsChildren(supportingTextElement, supportingText);
66
+ contentContainer.appendChild(supportingTextElement);
67
+ }
68
68
 
69
- if (children) {
70
- contentContainer.appendChild(
71
- GidsButtonGroupDom({
72
- layout: 'wrap',
73
- children: children,
74
- }),
75
- );
76
- }
69
+ if (children) {
70
+ contentContainer.appendChild(
71
+ GidsButtonGroupDom({
72
+ layout: 'wrap',
73
+ children: children,
74
+ }),
75
+ );
76
+ }
77
77
 
78
- innerContainer.appendChild(contentContainer);
78
+ innerContainer.appendChild(contentContainer);
79
79
 
80
- if (dismissible && onClickDismiss) {
81
- const leadingIcon = GidsIconDom({
82
- size: 'sm',
83
- appearance: 'filled',
84
- name: 'cross',
85
- alt: '',
86
- });
87
- const crossButton = GidsButtonDom({
88
- as: 'button',
89
- type: 'button',
90
- appearance: 'subtle',
91
- size: 'sm',
92
- width: 'intrinsic',
93
- leadingIcon: leadingIcon,
94
- });
95
- crossButton.addEventListener('click', onClickDismiss);
96
- const crossBtnContainer = document.createElement('div');
97
- crossBtnContainer.className = 'gids-section-notice__cross-button-container';
98
- crossBtnContainer.appendChild(crossButton);
99
- innerContainer.appendChild(crossBtnContainer);
100
- }
80
+ if (dismissible && onClickDismiss) {
81
+ const leadingIcon = GidsIconDom({
82
+ size: 'sm',
83
+ appearance: 'filled',
84
+ name: 'cross',
85
+ alt: '',
86
+ });
87
+ const crossButton = GidsButtonDom({
88
+ as: 'button',
89
+ type: 'button',
90
+ appearance: 'subtle',
91
+ size: 'sm',
92
+ width: 'intrinsic',
93
+ leadingIcon: leadingIcon,
94
+ });
95
+ crossButton.addEventListener('click', onClickDismiss);
96
+ const crossBtnContainer = document.createElement('div');
97
+ crossBtnContainer.className = 'gids-section-notice__cross-button-container';
98
+ crossBtnContainer.appendChild(crossButton);
99
+ innerContainer.appendChild(crossBtnContainer);
100
+ }
101
101
 
102
- sectionNotice.appendChild(innerContainer);
102
+ sectionNotice.appendChild(innerContainer);
103
103
 
104
- return sectionNotice;
104
+ return sectionNotice;
105
105
  };
@@ -0,0 +1,75 @@
1
+ import {
2
+ GidsSegmentedTabItemPressedReturnedProps,
3
+ type GidsSegmentedControlCommonProps,
4
+ } from '@ganpatiinfo/gids-core-shared';
5
+ import {
6
+ type ClassValue,
7
+ GidsSegmentedControlWebUtils,
8
+ } from '@ganpatiinfo/gids-web-shared';
9
+ import { type DomNodeOrString } from '../../utils/domUtils.js';
10
+ import { GidsSegmentedTabItemDom } from '../GidsSegmentedTabItem/GidsSegmentedTabItem.js';
11
+
12
+ const { getGidsSegmentedControlClassNames } = GidsSegmentedControlWebUtils;
13
+
14
+ export interface GidsSegmentedControlDomProps extends GidsSegmentedControlCommonProps<
15
+ DomNodeOrString,
16
+ string
17
+ > {
18
+ onPress?: (props: GidsSegmentedTabItemPressedReturnedProps) => void;
19
+ className?: ClassValue;
20
+ }
21
+
22
+ export const GidsSegmentedControlDom = ({
23
+ width = 'intrinsic',
24
+ tabItems,
25
+ onPress,
26
+ className,
27
+ }: GidsSegmentedControlDomProps): HTMLDivElement => {
28
+ const segmentedControl = document.createElement('div');
29
+ segmentedControl.className = getGidsSegmentedControlClassNames(
30
+ { width },
31
+ className,
32
+ );
33
+
34
+ if (tabItems && tabItems.length > 0) {
35
+ // This function renders (or re-renders) the tabs
36
+ const renderTabs = (selectedIndex?: number) => {
37
+ // Clear existing tabs
38
+ segmentedControl.innerHTML = '';
39
+
40
+ if (tabItems && tabItems.length > 0) {
41
+ tabItems.forEach((tabItem, index) => {
42
+ // Determine if this tab is selected
43
+ // Priority: 1. The newly clicked index, 2. The initial tabItem.selected state
44
+
45
+ let isSelected = false;
46
+ if (selectedIndex !== undefined && selectedIndex !== null) {
47
+ isSelected = index === selectedIndex;
48
+ } else {
49
+ isSelected = index === 0 ? true : false;
50
+ }
51
+
52
+ const tabElement = GidsSegmentedTabItemDom({
53
+ ...tabItem,
54
+ index,
55
+ selected: isSelected,
56
+ width: width,
57
+ onPress: (returnedProps) => {
58
+ // Re-render all tabs with the new selection
59
+ renderTabs(returnedProps.selectedIndex);
60
+ // Notify external listeners
61
+ if (onPress) onPress(returnedProps);
62
+ },
63
+ });
64
+
65
+ segmentedControl.appendChild(tabElement);
66
+ });
67
+ }
68
+ };
69
+
70
+ // Initial render
71
+ renderTabs();
72
+ }
73
+
74
+ return segmentedControl;
75
+ };
@@ -0,0 +1,75 @@
1
+ import {
2
+ type GidsSegmentedTabItemPressedReturnedProps,
3
+ type GidsSegmentedTabItemCommonProps,
4
+ } from '@ganpatiinfo/gids-core-shared';
5
+ import {
6
+ type ClassValue,
7
+ GidsSegmentedTabItemWebUtils,
8
+ } from '@ganpatiinfo/gids-web-shared';
9
+ import clsx from 'clsx';
10
+ import { type DomNodeOrString } from '../../utils/domUtils.js';
11
+ import { GidsBadgeDom } from '../GidsBadge/GidsBadge.js';
12
+
13
+ const { getGidsSegmentedTabItemClassNames } = GidsSegmentedTabItemWebUtils;
14
+
15
+ export interface GidsSegmentedTabItemDomProps extends GidsSegmentedTabItemCommonProps<
16
+ DomNodeOrString,
17
+ string
18
+ > {
19
+ onPress?: (props: GidsSegmentedTabItemPressedReturnedProps) => void;
20
+ className?: ClassValue;
21
+ }
22
+
23
+ export const GidsSegmentedTabItemDom = ({
24
+ index,
25
+ label,
26
+ selected = false,
27
+ badge = false,
28
+ badgeAccessibleText,
29
+ badgeAppearance = 'information',
30
+ onPress,
31
+ className,
32
+ width = 'intrinsic',
33
+ }: GidsSegmentedTabItemDomProps): HTMLButtonElement => {
34
+ const segmentedTabItem = document.createElement('button');
35
+ segmentedTabItem.className = getGidsSegmentedTabItemClassNames(
36
+ { selected, width },
37
+ className,
38
+ );
39
+ segmentedTabItem.setAttribute('data-gids-segmented-item', 'true');
40
+ segmentedTabItem.setAttribute('aria-selected', selected.toString());
41
+
42
+ segmentedTabItem.addEventListener('click', () => {
43
+ if (onPress) {
44
+ onPress({
45
+ selectedIndex: index,
46
+ });
47
+ }
48
+ });
49
+
50
+ if (label && label !== '') {
51
+ if (typeof label === 'string') {
52
+ const labelElement = document.createElement('label');
53
+ labelElement.className = clsx('gids-segmented-tab-item__label', {
54
+ 'gids-segmented-tab-item__selected-label': selected,
55
+ });
56
+ labelElement.textContent = label;
57
+ segmentedTabItem.appendChild(labelElement);
58
+ } else {
59
+ segmentedTabItem.appendChild(label);
60
+ }
61
+ }
62
+
63
+ if (badge) {
64
+ segmentedTabItem.appendChild(
65
+ GidsBadgeDom({
66
+ accessibleText: badgeAccessibleText,
67
+ appearance: badgeAppearance,
68
+ outline: false,
69
+ type: 'dot',
70
+ }),
71
+ );
72
+ }
73
+
74
+ return segmentedTabItem;
75
+ };