mtrl 0.2.5 → 0.2.7

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 (196) hide show
  1. package/index.ts +18 -0
  2. package/package.json +1 -1
  3. package/src/components/badge/_styles.scss +123 -115
  4. package/src/components/badge/api.ts +57 -59
  5. package/src/components/badge/badge.ts +16 -2
  6. package/src/components/badge/config.ts +65 -11
  7. package/src/components/badge/constants.ts +22 -12
  8. package/src/components/badge/features.ts +44 -40
  9. package/src/components/badge/types.ts +42 -30
  10. package/src/components/bottom-app-bar/_styles.scss +103 -0
  11. package/src/components/bottom-app-bar/bottom-app-bar.ts +196 -0
  12. package/src/components/bottom-app-bar/config.ts +73 -0
  13. package/src/components/bottom-app-bar/index.ts +11 -0
  14. package/src/components/bottom-app-bar/types.ts +108 -0
  15. package/src/components/button/_styles.scss +0 -66
  16. package/src/components/button/api.ts +5 -0
  17. package/src/components/button/button.ts +0 -2
  18. package/src/components/button/config.ts +5 -0
  19. package/src/components/button/constants.ts +0 -6
  20. package/src/components/button/index.ts +2 -2
  21. package/src/components/button/types.ts +7 -7
  22. package/src/components/card/_styles.scss +67 -25
  23. package/src/components/card/api.ts +54 -3
  24. package/src/components/card/card.ts +25 -6
  25. package/src/components/card/config.ts +189 -22
  26. package/src/components/card/constants.ts +20 -19
  27. package/src/components/card/content.ts +299 -2
  28. package/src/components/card/features.ts +158 -4
  29. package/src/components/card/index.ts +31 -9
  30. package/src/components/card/types.ts +166 -15
  31. package/src/components/checkbox/_styles.scss +0 -2
  32. package/src/components/chip/chip.ts +1 -9
  33. package/src/components/chip/constants.ts +0 -10
  34. package/src/components/chip/index.ts +1 -1
  35. package/src/components/chip/types.ts +1 -4
  36. package/src/components/datepicker/_styles.scss +358 -0
  37. package/src/components/datepicker/api.ts +272 -0
  38. package/src/components/datepicker/config.ts +144 -0
  39. package/src/components/datepicker/constants.ts +98 -0
  40. package/src/components/datepicker/datepicker.ts +346 -0
  41. package/src/components/datepicker/index.ts +9 -0
  42. package/src/components/datepicker/render.ts +452 -0
  43. package/src/components/datepicker/types.ts +268 -0
  44. package/src/components/datepicker/utils.ts +290 -0
  45. package/src/components/dialog/_styles.scss +174 -128
  46. package/src/components/dialog/api.ts +48 -13
  47. package/src/components/dialog/config.ts +9 -5
  48. package/src/components/dialog/dialog.ts +6 -3
  49. package/src/components/dialog/features.ts +290 -130
  50. package/src/components/dialog/types.ts +7 -4
  51. package/src/components/divider/_styles.scss +57 -0
  52. package/src/components/divider/config.ts +81 -0
  53. package/src/components/divider/divider.ts +37 -0
  54. package/src/components/divider/features.ts +207 -0
  55. package/src/components/divider/index.ts +5 -0
  56. package/src/components/divider/types.ts +55 -0
  57. package/src/components/extended-fab/_styles.scss +267 -0
  58. package/src/components/extended-fab/api.ts +141 -0
  59. package/src/components/extended-fab/config.ts +108 -0
  60. package/src/components/extended-fab/constants.ts +36 -0
  61. package/src/components/extended-fab/extended-fab.ts +125 -0
  62. package/src/components/extended-fab/index.ts +4 -0
  63. package/src/components/extended-fab/types.ts +287 -0
  64. package/src/components/fab/_styles.scss +225 -0
  65. package/src/components/fab/api.ts +97 -0
  66. package/src/components/fab/config.ts +94 -0
  67. package/src/components/fab/constants.ts +41 -0
  68. package/src/components/fab/fab.ts +67 -0
  69. package/src/components/fab/index.ts +4 -0
  70. package/src/components/fab/types.ts +234 -0
  71. package/src/components/navigation/_styles.scss +1 -0
  72. package/src/components/navigation/api.ts +78 -50
  73. package/src/components/navigation/features/items.ts +280 -0
  74. package/src/components/navigation/nav-item.ts +72 -23
  75. package/src/components/navigation/navigation.ts +54 -2
  76. package/src/components/navigation/types.ts +210 -188
  77. package/src/components/progress/_styles.scss +0 -65
  78. package/src/components/progress/config.ts +1 -2
  79. package/src/components/progress/constants.ts +0 -14
  80. package/src/components/progress/index.ts +1 -1
  81. package/src/components/progress/progress.ts +1 -4
  82. package/src/components/progress/types.ts +1 -4
  83. package/src/components/radios/_styles.scss +0 -45
  84. package/src/components/radios/api.ts +85 -60
  85. package/src/components/radios/config.ts +1 -2
  86. package/src/components/radios/constants.ts +0 -9
  87. package/src/components/radios/index.ts +1 -1
  88. package/src/components/radios/radio.ts +34 -11
  89. package/src/components/radios/radios.ts +2 -1
  90. package/src/components/radios/types.ts +1 -7
  91. package/src/components/search/_styles.scss +306 -0
  92. package/src/components/search/api.ts +203 -0
  93. package/src/components/search/config.ts +87 -0
  94. package/src/components/search/constants.ts +21 -0
  95. package/src/components/search/features/index.ts +4 -0
  96. package/src/components/search/features/search.ts +718 -0
  97. package/src/components/search/features/states.ts +165 -0
  98. package/src/components/search/features/structure.ts +198 -0
  99. package/src/components/search/index.ts +10 -0
  100. package/src/components/search/search.ts +52 -0
  101. package/src/components/search/types.ts +163 -0
  102. package/src/components/segmented-button/_styles.scss +117 -0
  103. package/src/components/segmented-button/config.ts +67 -0
  104. package/src/components/segmented-button/constants.ts +42 -0
  105. package/src/components/segmented-button/index.ts +4 -0
  106. package/src/components/segmented-button/segment.ts +155 -0
  107. package/src/components/segmented-button/segmented-button.ts +250 -0
  108. package/src/components/segmented-button/types.ts +219 -0
  109. package/src/components/slider/_styles.scss +221 -168
  110. package/src/components/slider/accessibility.md +59 -0
  111. package/src/components/slider/api.ts +41 -120
  112. package/src/components/slider/config.ts +51 -49
  113. package/src/components/slider/features/handlers.ts +495 -0
  114. package/src/components/slider/features/index.ts +1 -2
  115. package/src/components/slider/features/slider.ts +66 -84
  116. package/src/components/slider/features/states.ts +195 -0
  117. package/src/components/slider/features/structure.ts +141 -184
  118. package/src/components/slider/features/ui.ts +150 -201
  119. package/src/components/slider/index.ts +2 -11
  120. package/src/components/slider/slider.ts +9 -12
  121. package/src/components/slider/types.ts +39 -24
  122. package/src/components/switch/_styles.scss +0 -2
  123. package/src/components/tabs/_styles.scss +346 -154
  124. package/src/components/tabs/api.ts +178 -400
  125. package/src/components/tabs/config.ts +46 -52
  126. package/src/components/tabs/constants.ts +85 -8
  127. package/src/components/tabs/features.ts +403 -0
  128. package/src/components/tabs/index.ts +60 -3
  129. package/src/components/tabs/indicator.ts +285 -0
  130. package/src/components/tabs/responsive.ts +144 -0
  131. package/src/components/tabs/scroll-indicators.ts +149 -0
  132. package/src/components/tabs/state.ts +186 -0
  133. package/src/components/tabs/tab-api.ts +258 -0
  134. package/src/components/tabs/tab.ts +255 -0
  135. package/src/components/tabs/tabs.ts +50 -31
  136. package/src/components/tabs/types.ts +332 -128
  137. package/src/components/tabs/utils.ts +107 -0
  138. package/src/components/textfield/_styles.scss +0 -98
  139. package/src/components/textfield/config.ts +2 -3
  140. package/src/components/textfield/constants.ts +0 -14
  141. package/src/components/textfield/index.ts +2 -2
  142. package/src/components/textfield/textfield.ts +0 -2
  143. package/src/components/textfield/types.ts +1 -4
  144. package/src/components/timepicker/README.md +277 -0
  145. package/src/components/timepicker/_styles.scss +451 -0
  146. package/src/components/timepicker/api.ts +632 -0
  147. package/src/components/timepicker/clockdial.ts +482 -0
  148. package/src/components/timepicker/config.ts +130 -0
  149. package/src/components/timepicker/constants.ts +138 -0
  150. package/src/components/timepicker/index.ts +8 -0
  151. package/src/components/timepicker/render.ts +613 -0
  152. package/src/components/timepicker/timepicker.ts +117 -0
  153. package/src/components/timepicker/types.ts +336 -0
  154. package/src/components/timepicker/utils.ts +241 -0
  155. package/src/components/top-app-bar/_styles.scss +225 -0
  156. package/src/components/top-app-bar/config.ts +83 -0
  157. package/src/components/top-app-bar/index.ts +11 -0
  158. package/src/components/top-app-bar/top-app-bar.ts +316 -0
  159. package/src/components/top-app-bar/types.ts +140 -0
  160. package/src/core/build/_ripple.scss +6 -6
  161. package/src/core/build/ripple.ts +72 -95
  162. package/src/core/compose/component.ts +1 -1
  163. package/src/core/compose/features/badge.ts +79 -0
  164. package/src/core/compose/features/icon.ts +3 -1
  165. package/src/core/compose/features/index.ts +3 -1
  166. package/src/core/compose/features/ripple.ts +4 -1
  167. package/src/core/compose/features/textlabel.ts +26 -2
  168. package/src/core/dom/create.ts +5 -0
  169. package/src/index.ts +9 -0
  170. package/src/styles/abstract/_theme.scss +115 -3
  171. package/src/styles/themes/_autumn.scss +21 -0
  172. package/src/styles/themes/_base-theme.scss +61 -0
  173. package/src/styles/themes/_baseline.scss +58 -0
  174. package/src/styles/themes/_bluekhaki.scss +125 -0
  175. package/src/styles/themes/_brownbeige.scss +125 -0
  176. package/src/styles/themes/_browngreen.scss +125 -0
  177. package/src/styles/themes/_forest.scss +6 -0
  178. package/src/styles/themes/_greenbeige.scss +125 -0
  179. package/src/styles/themes/_material.scss +125 -0
  180. package/src/styles/themes/_ocean.scss +6 -0
  181. package/src/styles/themes/_sageivory.scss +125 -0
  182. package/src/styles/themes/_spring.scss +6 -0
  183. package/src/styles/themes/_summer.scss +5 -0
  184. package/src/styles/themes/_sunset.scss +5 -0
  185. package/src/styles/themes/_tealcaramel.scss +125 -0
  186. package/src/styles/themes/_winter.scss +6 -0
  187. package/src/components/card/actions.ts +0 -48
  188. package/src/components/card/header.ts +0 -88
  189. package/src/components/card/media.ts +0 -52
  190. package/src/components/navigation/features/items.js +0 -192
  191. package/src/components/slider/features/appearance.ts +0 -94
  192. package/src/components/slider/features/disabled.ts +0 -43
  193. package/src/components/slider/features/events.ts +0 -164
  194. package/src/components/slider/features/interactions.ts +0 -261
  195. package/src/components/slider/features/keyboard.ts +0 -112
  196. package/src/core/collection/adapters/mongodb.js +0 -232
@@ -1,48 +1,67 @@
1
1
  // src/components/tabs/tabs.ts
2
- import { PREFIX } from '../../core/config';
3
2
  import { pipe } from '../../core/compose';
4
- import { createBase, withElement } from '../../core/compose/component';
5
- import {
6
- withEvents,
7
- withVariant,
8
- withDisabled,
9
- withLifecycle
10
- } from '../../core/compose/features';
11
- import { withAPI } from './api';
12
- import { TabsConfig } from './types';
13
- import { TABS_VARIANTS } from './constants';
14
- import { createBaseConfig, getElementConfig, getApiConfig } from './config';
3
+ import { createBase } from '../../core/compose/component';
4
+ import { withEvents, withLifecycle } from '../../core/compose/features';
5
+ import { withAPI, getApiConfig } from './api';
6
+ import {
7
+ withTabsManagement,
8
+ withScrollable,
9
+ withDivider,
10
+ withIndicator
11
+ } from './features';
12
+ import { createTabsConfig, getTabsElementConfig } from './config';
13
+ import { TabsConfig, TabsComponent } from './types';
14
+ import { addTabStateStyles } from './state';
15
+ import { setupKeyboardNavigation } from './utils';
15
16
 
16
17
  /**
17
- * Creates a new Tabs component
18
+ * Creates a new Tabs component following MD3 guidelines
18
19
  * @param {TabsConfig} config - Tabs configuration object
19
20
  * @returns {TabsComponent} Tabs component instance
21
+ * @example
22
+ * ```typescript
23
+ * // Create basic tabs with three items
24
+ * const tabs = createTabs({
25
+ * tabs: [
26
+ * { text: 'Home', value: 'home', state: 'active' },
27
+ * { text: 'Products', value: 'products' },
28
+ * { text: 'About', value: 'about' }
29
+ * ]
30
+ * });
31
+ *
32
+ * // Add tabs to DOM
33
+ * document.body.appendChild(tabs.element);
34
+ *
35
+ * // Listen for tab changes
36
+ * tabs.on('change', (e) => {
37
+ * console.log(`Active tab: ${e.value}`);
38
+ * });
39
+ * ```
20
40
  */
21
- const createTabs = (config: TabsConfig = {}) => {
22
- const baseConfig = createBaseConfig(config);
41
+ const createTabs = (config: TabsConfig = {}): TabsComponent => {
42
+ const baseConfig = createTabsConfig(config);
43
+
44
+ // Add ripple styles for state transitions
45
+ addTabStateStyles();
23
46
 
24
47
  try {
25
- const tabs = pipe(
48
+ // Build the tabs component with all features
49
+ const component = pipe(
26
50
  createBase,
27
51
  withEvents(),
28
- withElement(getElementConfig(baseConfig)),
29
- withVariant(baseConfig),
30
- withDisabled(baseConfig),
52
+ getTabsElementConfig(baseConfig),
53
+ withScrollable(baseConfig),
54
+ withTabsManagement(baseConfig),
55
+ withDivider(baseConfig),
56
+ withIndicator(baseConfig), // Add indicator feature
31
57
  withLifecycle(),
32
58
  comp => withAPI(getApiConfig(comp))(comp)
33
59
  )(baseConfig);
34
-
35
- // Initialize tabs
36
- if (baseConfig.items && baseConfig.items.length > 0) {
37
- tabs.setItems(baseConfig.items);
38
- }
39
-
40
- // Set active tab if specified
41
- if (baseConfig.activeIndex !== undefined) {
42
- tabs.setActiveTab(baseConfig.activeIndex);
43
- }
44
-
45
- return tabs;
60
+
61
+ // Set up keyboard navigation
62
+ setupKeyboardNavigation(component);
63
+
64
+ return component;
46
65
  } catch (error) {
47
66
  console.error('Tabs creation error:', error);
48
67
  throw new Error(`Failed to create tabs: ${(error as Error).message}`);
@@ -1,36 +1,148 @@
1
1
  // src/components/tabs/types.ts
2
- import { TABS_VARIANTS } from './constants';
2
+ import { TABS_VARIANTS, TAB_STATES, TAB_LAYOUT } from './constants';
3
+ import { BadgeComponent } from '../badge/types';
4
+ import { TabIndicator } from './indicator';
3
5
 
4
6
  /**
5
- * Tab item configuration
7
+ * Configuration for the tab indicator
6
8
  * @category Components
7
9
  */
8
- export interface TabItem {
10
+ export interface IndicatorConfig {
11
+ /** Height of the indicator in pixels */
12
+ height?: number;
13
+ /**
14
+ * Width strategy for the indicator
15
+ * - 'fixed': Uses a fixed width defined by fixedWidth
16
+ * - 'dynamic': Uses half the tab width
17
+ * - 'content': Uses the text content width
18
+ * - 'auto': Adapts based on variant (primary: text width, secondary: full tab width)
19
+ */
20
+ widthStrategy?: 'fixed' | 'dynamic' | 'content' | 'auto';
21
+ /** Fixed width in pixels (when using fixed strategy) */
22
+ fixedWidth?: number;
23
+ /** Animation duration in milliseconds */
24
+ animationDuration?: number;
25
+ /** Animation timing function */
26
+ animationTiming?: string;
27
+ /** Custom color for the indicator */
28
+ color?: string;
29
+ /** Tab variant (primary or secondary) */
30
+ variant?: string;
31
+ }
32
+
33
+ /**
34
+ * Tab change event data interface
35
+ * @category Events
36
+ */
37
+ export interface TabChangeEventData {
9
38
  /**
10
- * Unique identifier for the tab
39
+ * The tab component that was activated
11
40
  */
12
- id: string;
41
+ tab: TabComponent;
13
42
 
14
43
  /**
15
- * Display label for the tab
44
+ * The value of the activated tab
16
45
  */
17
- label: string;
46
+ value: string;
47
+ }
48
+
49
+ /**
50
+ * Configuration interface for a single Tab
51
+ * @category Components
52
+ */
53
+ export interface TabConfig {
54
+ /**
55
+ * Tab state that determines if it's the active destination
56
+ * @default 'inactive'
57
+ */
58
+ state?: keyof typeof TAB_STATES | string;
18
59
 
19
- /**
20
- * Optional icon HTML content
60
+ /**
61
+ * Whether the tab is initially disabled
62
+ * @default false
63
+ */
64
+ disabled?: boolean;
65
+
66
+ /**
67
+ * Initial tab text content (label)
68
+ * @example 'Home'
69
+ */
70
+ text?: string;
71
+
72
+ /**
73
+ * Initial tab icon HTML content
74
+ * @example '<svg>...</svg>'
21
75
  */
22
76
  icon?: string;
23
77
 
78
+ /**
79
+ * Badge text or value to display (if applicable)
80
+ * @example '5'
81
+ */
82
+ badge?: string | number;
83
+
24
84
  /**
25
- * Whether the tab is disabled
26
- * @default false
85
+ * Badge configuration object
86
+ * Pass additional options for the badge component
27
87
  */
28
- disabled?: boolean;
88
+ badgeConfig?: {
89
+ variant?: string;
90
+ color?: string;
91
+ size?: string;
92
+ position?: string;
93
+ max?: number;
94
+ };
95
+
96
+ /**
97
+ * Icon size in pixels or other CSS units
98
+ * @default '24px'
99
+ */
100
+ iconSize?: string;
101
+
102
+ /**
103
+ * Additional CSS classes to add to the tab
104
+ * @example 'home-tab main-navigation'
105
+ */
106
+ class?: string;
107
+
108
+ /**
109
+ * Tab value attribute for identifying the selected tab
110
+ */
111
+ value?: string;
112
+
113
+ /**
114
+ * Whether to enable ripple effect
115
+ * @default true
116
+ */
117
+ ripple?: boolean;
118
+
119
+ /**
120
+ * Component prefix for class names
121
+ * @default 'mtrl'
122
+ */
123
+ prefix?: string;
124
+
125
+ /**
126
+ * Component name used in class generation
127
+ */
128
+ componentName?: string;
129
+
130
+ /**
131
+ * Ripple effect configuration
132
+ */
133
+ rippleConfig?: {
134
+ /** Duration of the ripple animation in milliseconds */
135
+ duration?: number;
136
+ /** Timing function for the ripple animation */
137
+ timing?: string;
138
+ /** Opacity values for ripple start and end [start, end] */
139
+ opacity?: [string, string];
140
+ };
29
141
 
30
142
  /**
31
- * Additional data to associate with this tab
143
+ * Variant of the tab
32
144
  */
33
- data?: any;
145
+ variant?: string;
34
146
  }
35
147
 
36
148
  /**
@@ -39,209 +151,301 @@ export interface TabItem {
39
151
  */
40
152
  export interface TabsConfig {
41
153
  /**
42
- * Tabs variant that determines visual styling
154
+ * Tabs variant (primary or secondary)
43
155
  * @default 'primary'
44
156
  */
45
157
  variant?: keyof typeof TABS_VARIANTS | string;
46
158
 
47
159
  /**
48
- * Initial tab items
160
+ * Initial tabs to create
49
161
  */
50
- items?: TabItem[];
162
+ tabs?: TabConfig[];
51
163
 
52
164
  /**
53
- * Index of the initially active tab
54
- * @default 0
165
+ * Whether to show the divider
166
+ * @default true
55
167
  */
56
- activeIndex?: number;
168
+ showDivider?: boolean;
57
169
 
58
170
  /**
59
- * Whether the tabs component is initially disabled
60
- * @default false
171
+ * Whether to enable horizontal scrolling
172
+ * @default true
61
173
  */
62
- disabled?: boolean;
174
+ scrollable?: boolean;
63
175
 
64
176
  /**
65
- * Whether to show tab indicator
66
- * @default true
177
+ * Additional CSS classes for the container
67
178
  */
68
- showIndicator?: boolean;
179
+ class?: string;
69
180
 
70
181
  /**
71
- * Whether to enable animated transitions
72
- * @default true
182
+ * Component prefix for class names
183
+ * @default 'mtrl'
73
184
  */
74
- animated?: boolean;
185
+ prefix?: string;
75
186
 
76
187
  /**
77
- * Whether tabs should be scrollable when they overflow
78
- * @default true
188
+ * Event handlers configuration
79
189
  */
80
- scrollable?: boolean;
190
+ on?: {
191
+ /**
192
+ * Tab change event handler
193
+ */
194
+ change?: (event: TabChangeEventData) => void;
195
+
196
+ /**
197
+ * Event handlers for other events
198
+ */
199
+ [key: string]: Function | undefined;
200
+ };
81
201
 
82
202
  /**
83
- * Additional CSS classes to add to the tabs component
203
+ * Tab indicator configuration
84
204
  */
85
- class?: string;
205
+ indicator?: IndicatorConfig;
86
206
 
87
207
  /**
88
- * Component prefix for class names
89
- * @default 'mtrl'
208
+ * Tab indicator height in pixels
209
+ * @deprecated Use indicator.height instead
90
210
  */
91
- prefix?: string;
211
+ indicatorHeight?: number;
92
212
 
93
213
  /**
94
- * Component name used in class generation
214
+ * Tab indicator width strategy
215
+ * @deprecated Use indicator.widthStrategy instead
95
216
  */
96
- componentName?: string;
217
+ indicatorWidthStrategy?: 'fixed' | 'dynamic' | 'content';
97
218
  }
98
219
 
99
220
  /**
100
- * Tabs component interface
221
+ * Icon API interface for managing tab icons
101
222
  * @category Components
102
223
  */
103
- export interface TabsComponent {
104
- /** The tabs container DOM element */
105
- element: HTMLElement;
106
-
107
- /** The tabs list DOM element */
108
- tabsListElement: HTMLElement;
109
-
110
- /** The tab indicator DOM element */
111
- indicatorElement: HTMLElement;
112
-
113
- /** API for managing disabled state */
114
- disabled: {
115
- /** Enables the tabs component */
116
- enable: () => void;
117
- /** Disables the tabs component */
118
- disable: () => void;
119
- /** Checks if the tabs component is disabled */
120
- isDisabled: () => boolean;
121
- };
122
-
123
- /** API for managing component lifecycle */
124
- lifecycle: {
125
- /** Destroys the component and cleans up resources */
126
- destroy: () => void;
127
- };
224
+ export interface IconAPI {
225
+ /**
226
+ * Sets the icon HTML content
227
+ * @param html - HTML string for the icon
228
+ * @returns The icon API for chaining
229
+ */
230
+ setIcon: (html: string) => IconAPI;
128
231
 
129
232
  /**
130
- * Gets a class name with the component's prefix
131
- * @param name - Base class name
132
- * @returns Prefixed class name
233
+ * Gets the current icon HTML content
234
+ * @returns HTML string for the icon
133
235
  */
134
- getClass: (name: string) => string;
236
+ getIcon: () => string;
135
237
 
136
238
  /**
137
- * Enables the tabs component
138
- * @returns The tabs component for chaining
239
+ * Gets the icon DOM element
240
+ * @returns The icon element or null if not present
139
241
  */
140
- enable: () => TabsComponent;
242
+ getElement: () => HTMLElement | null;
243
+ }
244
+
245
+ /**
246
+ * Text API interface for managing tab text
247
+ * @category Components
248
+ */
249
+ export interface TextAPI {
250
+ /**
251
+ * Sets the text content
252
+ * @param content - Text content
253
+ * @returns The text API for chaining
254
+ */
255
+ setText: (content: string) => TextAPI;
141
256
 
142
257
  /**
143
- * Disables the tabs component
144
- * @returns The tabs component for chaining
258
+ * Gets the current text content
259
+ * @returns Tab text content
145
260
  */
146
- disable: () => TabsComponent;
261
+ getText: () => string;
147
262
 
148
263
  /**
149
- * Gets all tab items
150
- * @returns Array of tab items
264
+ * Gets the text DOM element
265
+ * @returns The text element or null if not present
151
266
  */
152
- getItems: () => TabItem[];
267
+ getElement: () => HTMLElement | null;
268
+ }
269
+
270
+ /**
271
+ * Tab component interface
272
+ * @category Components
273
+ */
274
+ export interface TabComponent {
275
+ /** The tab's DOM element */
276
+ element: HTMLElement;
277
+
278
+ /** The tab's badge component (if any) */
279
+ badge?: BadgeComponent;
280
+
281
+ /** Gets a class name with the component's prefix */
282
+ getClass: (name: string) => string;
283
+
284
+ /** Gets the tab's value attribute */
285
+ getValue: () => string;
286
+
287
+ /** Sets the tab's value attribute */
288
+ setValue: (value: string) => TabComponent;
289
+
290
+ /** Activates the tab (sets active state) */
291
+ activate: () => TabComponent;
292
+
293
+ /** Deactivates the tab (sets inactive state) */
294
+ deactivate: () => TabComponent;
295
+
296
+ /** Checks if the tab is active */
297
+ isActive: () => boolean;
298
+
299
+ /** Enables the tab (removes disabled attribute) */
300
+ enable: () => TabComponent;
301
+
302
+ /** Disables the tab (adds disabled attribute) */
303
+ disable: () => TabComponent;
304
+
305
+ /** Sets the tab's text content */
306
+ setText: (content: string) => TabComponent;
307
+
308
+ /** Gets the tab's text content */
309
+ getText: () => string;
310
+
311
+ /** Sets the tab's icon */
312
+ setIcon: (icon: string) => TabComponent;
313
+
314
+ /** Gets the tab's icon HTML content */
315
+ getIcon: () => string;
153
316
 
317
+ /** Sets the tab's badge */
318
+ setBadge: (content: string | number) => TabComponent;
319
+
320
+ /** Gets the tab's badge content */
321
+ getBadge: () => string;
322
+
323
+ /** Shows the tab's badge */
324
+ showBadge: () => TabComponent;
325
+
326
+ /** Hides the tab's badge */
327
+ hideBadge: () => TabComponent;
328
+
329
+ /** Gets the badge component instance */
330
+ getBadgeComponent: () => BadgeComponent | undefined;
331
+
332
+ /** Updates the tab's layout style based on content */
333
+ updateLayoutStyle: () => void;
334
+
335
+ /** Adds an event listener to the tab */
336
+ on: (event: string, handler: Function) => TabComponent;
337
+
338
+ /** Removes an event listener from the tab */
339
+ off: (event: string, handler: Function) => TabComponent;
340
+
341
+ /** Destroys the tab component and cleans up resources */
342
+ destroy: () => void;
343
+
344
+ /** API for managing disabled state */
345
+ disabled?: {
346
+ enable: () => void;
347
+ disable: () => void;
348
+ isDisabled: () => boolean;
349
+ };
350
+
351
+ /** API for managing component lifecycle */
352
+ lifecycle?: {
353
+ destroy: () => void;
354
+ };
355
+ }
356
+
357
+ /**
358
+ * Tabs component interface
359
+ * @category Components
360
+ */
361
+ export interface TabsComponent {
154
362
  /**
155
- * Sets tab items, replacing any existing tabs
156
- * @param items - Array of tab items
157
- * @returns The tabs component for chaining
363
+ * Container element
158
364
  */
159
- setItems: (items: TabItem[]) => TabsComponent;
365
+ element: HTMLElement;
160
366
 
161
367
  /**
162
- * Adds a new tab
163
- * @param item - Tab item configuration
164
- * @param index - Optional index to insert at (appends if omitted)
165
- * @returns The tabs component for chaining
368
+ * Creates and adds a new tab to the tabs component
369
+ * @param config - Tab configuration
370
+ * @returns The created tab component
166
371
  */
167
- addTab: (item: TabItem, index?: number) => TabsComponent;
372
+ addTab: (config: TabConfig) => TabComponent;
168
373
 
169
374
  /**
170
- * Removes a tab by ID or index
171
- * @param idOrIndex - Tab ID or index
172
- * @returns The tabs component for chaining
375
+ * Adds a pre-created tab to the tabs component
376
+ * @param tab - Tab component to add
377
+ * @returns Tabs component for chaining
173
378
  */
174
- removeTab: (idOrIndex: string | number) => TabsComponent;
379
+ add: (tab: TabComponent) => TabsComponent;
175
380
 
176
381
  /**
177
- * Gets the currently active tab
178
- * @returns The active tab item or null if none active
382
+ * Gets all tabs in the container
383
+ * @returns Array of tab components
179
384
  */
180
- getActiveTab: () => TabItem | null;
385
+ getTabs: () => TabComponent[];
181
386
 
182
387
  /**
183
- * Gets the index of the currently active tab
184
- * @returns The active tab index or -1 if none active
388
+ * Gets the active tab
389
+ * @returns Active tab or null if none
185
390
  */
186
- getActiveIndex: () => number;
391
+ getActiveTab: () => TabComponent | null;
187
392
 
188
393
  /**
189
- * Sets the active tab by index
190
- * @param index - Index of the tab to activate
191
- * @returns The tabs component for chaining
394
+ * Gets the indicator component
395
+ * @returns Tab indicator component
192
396
  */
193
- setActiveTab: (index: number) => TabsComponent;
397
+ getIndicator?: () => TabIndicator;
194
398
 
195
399
  /**
196
- * Sets the active tab by ID
197
- * @param id - ID of the tab to activate
198
- * @returns The tabs component for chaining
400
+ * Sets a tab as active
401
+ * @param tabOrValue - Tab component or tab value
402
+ * @returns Tabs component for chaining
199
403
  */
200
- setActiveTabById: (id: string) => TabsComponent;
404
+ setActiveTab: (tabOrValue: TabComponent | string) => TabsComponent;
201
405
 
202
406
  /**
203
- * Destroys the tabs component and cleans up resources
407
+ * Removes a tab from the container
408
+ * @param tabOrValue - Tab component or tab value
409
+ * @returns Tabs component for chaining
204
410
  */
205
- destroy: () => void;
411
+ removeTab: (tabOrValue: TabComponent | string) => TabsComponent;
206
412
 
207
413
  /**
208
- * Adds an event listener to the tabs component
209
- * @param event - Event name ('change', 'click', etc.)
210
- * @param handler - Event handler function
211
- * @returns The tabs component for chaining
414
+ * Adds an event listener
415
+ * @param event - Event name
416
+ * @param handler - Event handler
417
+ * @returns Tabs component for chaining
212
418
  */
213
419
  on: (event: string, handler: Function) => TabsComponent;
214
420
 
215
421
  /**
216
- * Removes an event listener from the tabs component
422
+ * Removes an event listener
217
423
  * @param event - Event name
218
- * @param handler - Event handler function
219
- * @returns The tabs component for chaining
424
+ * @param handler - Event handler
425
+ * @returns Tabs component for chaining
220
426
  */
221
427
  off: (event: string, handler: Function) => TabsComponent;
222
- }
223
-
224
- /**
225
- * Event data for tab change events
226
- */
227
- export interface TabChangeEventData {
428
+
228
429
  /**
229
- * Index of the newly activated tab
430
+ * Emit an event
431
+ * @param event - Event name
432
+ * @param data - Event data
433
+ * @returns Tabs component for chaining
230
434
  */
231
- index: number;
435
+ emit?: (event: string, data: any) => TabsComponent;
232
436
 
233
437
  /**
234
- * The newly activated tab item
438
+ * Destroys the tabs component and all tabs
235
439
  */
236
- tab: TabItem;
440
+ destroy: () => void;
237
441
 
238
442
  /**
239
- * Index of the previously active tab or -1
443
+ * Tab click event handler
240
444
  */
241
- previousIndex: number;
445
+ handleTabClick: (event: any, tab: TabComponent) => void;
242
446
 
243
447
  /**
244
- * The previously active tab item or null
448
+ * Scroll container for scrollable tabs
245
449
  */
246
- previousTab: TabItem | null;
450
+ scrollContainer?: HTMLElement;
247
451
  }