mtrl 0.2.6 → 0.2.8

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 (226) hide show
  1. package/demo/build.ts +349 -0
  2. package/demo/index.html +110 -0
  3. package/demo/main.js +448 -0
  4. package/demo/styles.css +239 -0
  5. package/index.ts +18 -0
  6. package/package.json +14 -3
  7. package/server.ts +86 -0
  8. package/src/components/badge/api.ts +70 -63
  9. package/src/components/badge/badge.ts +16 -2
  10. package/src/components/badge/config.ts +66 -13
  11. package/src/components/badge/features.ts +51 -42
  12. package/src/components/badge/index.ts +27 -2
  13. package/src/components/badge/types.ts +62 -30
  14. package/src/components/bottom-app-bar/bottom-app-bar.ts +154 -0
  15. package/src/components/bottom-app-bar/config.ts +29 -0
  16. package/src/components/bottom-app-bar/index.ts +17 -0
  17. package/src/components/bottom-app-bar/types.ts +114 -0
  18. package/src/components/button/api.ts +5 -0
  19. package/src/components/button/button.ts +0 -1
  20. package/src/components/button/config.ts +6 -2
  21. package/src/components/button/index.ts +10 -2
  22. package/src/components/button/types.ts +20 -2
  23. package/src/components/card/card.ts +13 -25
  24. package/src/components/card/config.ts +83 -30
  25. package/src/components/card/content.ts +8 -10
  26. package/src/components/card/features.ts +4 -3
  27. package/src/components/card/index.ts +29 -2
  28. package/src/components/card/types.ts +33 -22
  29. package/src/components/checkbox/config.ts +3 -4
  30. package/src/components/checkbox/index.ts +1 -2
  31. package/src/components/checkbox/types.ts +12 -3
  32. package/src/components/chip/api.ts +170 -221
  33. package/src/components/chip/chip.ts +34 -302
  34. package/src/components/chip/config.ts +1 -2
  35. package/src/components/chip/index.ts +10 -2
  36. package/src/components/chip/types.ts +224 -35
  37. package/src/components/datepicker/api.ts +265 -0
  38. package/src/components/datepicker/config.ts +141 -0
  39. package/src/components/datepicker/datepicker.ts +341 -0
  40. package/src/components/datepicker/index.ts +12 -0
  41. package/src/components/datepicker/render.ts +450 -0
  42. package/src/components/datepicker/types.ts +397 -0
  43. package/src/components/datepicker/utils.ts +289 -0
  44. package/src/components/dialog/api.ts +55 -21
  45. package/src/components/dialog/config.ts +12 -9
  46. package/src/components/dialog/dialog.ts +6 -3
  47. package/src/components/dialog/features.ts +345 -151
  48. package/src/components/dialog/index.ts +38 -8
  49. package/src/components/dialog/types.ts +40 -14
  50. package/src/components/divider/config.ts +81 -0
  51. package/src/components/divider/divider.ts +37 -0
  52. package/src/components/divider/features.ts +207 -0
  53. package/src/components/divider/index.ts +9 -0
  54. package/src/components/divider/types.ts +55 -0
  55. package/src/components/extended-fab/api.ts +141 -0
  56. package/src/components/extended-fab/config.ts +112 -0
  57. package/src/components/extended-fab/extended-fab.ts +125 -0
  58. package/src/components/extended-fab/index.ts +9 -0
  59. package/src/components/extended-fab/types.ts +304 -0
  60. package/src/components/fab/api.ts +97 -0
  61. package/src/components/fab/config.ts +93 -0
  62. package/src/components/fab/fab.ts +67 -0
  63. package/src/components/fab/index.ts +9 -0
  64. package/src/components/fab/types.ts +251 -0
  65. package/src/components/list/config.ts +4 -5
  66. package/src/components/list/features.ts +6 -7
  67. package/src/components/list/index.ts +7 -9
  68. package/src/components/list/list-item.ts +12 -13
  69. package/src/components/list/types.ts +50 -5
  70. package/src/components/list/utils.ts +30 -3
  71. package/src/components/menu/features/items-manager.ts +9 -9
  72. package/src/components/menu/features/positioning.ts +7 -7
  73. package/src/components/menu/features/visibility.ts +7 -7
  74. package/src/components/menu/index.ts +7 -9
  75. package/src/components/menu/menu-item.ts +6 -6
  76. package/src/components/menu/menu.ts +22 -0
  77. package/src/components/menu/types.ts +29 -10
  78. package/src/components/menu/utils.ts +67 -0
  79. package/src/components/navigation/api.ts +78 -50
  80. package/src/components/navigation/config.ts +22 -10
  81. package/src/components/navigation/features/items.ts +284 -0
  82. package/src/components/navigation/index.ts +0 -6
  83. package/src/components/navigation/nav-item.ts +70 -33
  84. package/src/components/navigation/navigation.ts +53 -3
  85. package/src/components/navigation/types.ts +117 -70
  86. package/src/components/progress/api.ts +2 -3
  87. package/src/components/progress/config.ts +2 -3
  88. package/src/components/progress/index.ts +0 -1
  89. package/src/components/progress/progress.ts +1 -2
  90. package/src/components/progress/types.ts +186 -33
  91. package/src/components/radios/config.ts +1 -1
  92. package/src/components/radios/index.ts +0 -1
  93. package/src/components/radios/types.ts +0 -7
  94. package/src/components/search/api.ts +203 -0
  95. package/src/components/search/config.ts +86 -0
  96. package/src/components/search/features/index.ts +4 -0
  97. package/src/components/search/features/search.ts +717 -0
  98. package/src/components/search/features/states.ts +169 -0
  99. package/src/components/search/features/structure.ts +197 -0
  100. package/src/components/search/index.ts +7 -0
  101. package/src/components/search/search.ts +52 -0
  102. package/src/components/search/types.ts +175 -0
  103. package/src/components/segmented-button/config.ts +80 -0
  104. package/src/components/segmented-button/index.ts +4 -0
  105. package/src/components/segmented-button/segment.ts +154 -0
  106. package/src/components/segmented-button/segmented-button.ts +249 -0
  107. package/src/components/segmented-button/types.ts +254 -0
  108. package/src/components/slider/accessibility.md +5 -5
  109. package/src/components/slider/api.ts +41 -120
  110. package/src/components/slider/config.ts +51 -47
  111. package/src/components/slider/features/handlers.ts +495 -0
  112. package/src/components/slider/features/index.ts +1 -2
  113. package/src/components/slider/features/slider.ts +66 -84
  114. package/src/components/slider/features/states.ts +195 -0
  115. package/src/components/slider/features/structure.ts +136 -206
  116. package/src/components/slider/features/ui.ts +145 -206
  117. package/src/components/slider/index.ts +2 -11
  118. package/src/components/slider/slider.ts +9 -12
  119. package/src/components/slider/types.ts +67 -26
  120. package/src/components/snackbar/config.ts +2 -3
  121. package/src/components/snackbar/constants.ts +0 -32
  122. package/src/components/snackbar/index.ts +0 -1
  123. package/src/components/snackbar/position.ts +9 -1
  124. package/src/components/snackbar/types.ts +122 -46
  125. package/src/components/switch/config.ts +2 -3
  126. package/src/components/switch/index.ts +0 -1
  127. package/src/components/switch/types.ts +3 -2
  128. package/src/components/tabs/config.ts +3 -4
  129. package/src/components/tabs/features.ts +4 -2
  130. package/src/components/tabs/index.ts +0 -15
  131. package/src/components/tabs/indicator.ts +73 -13
  132. package/src/components/tabs/tab-api.ts +12 -4
  133. package/src/components/tabs/tab.ts +18 -6
  134. package/src/components/tabs/types.ts +23 -5
  135. package/src/components/textfield/config.ts +2 -3
  136. package/src/components/textfield/index.ts +0 -1
  137. package/src/components/textfield/types.ts +17 -3
  138. package/src/components/timepicker/README.md +277 -0
  139. package/src/components/timepicker/api.ts +632 -0
  140. package/src/components/timepicker/clockdial.ts +482 -0
  141. package/src/components/timepicker/config.ts +228 -0
  142. package/src/components/timepicker/index.ts +3 -0
  143. package/src/components/timepicker/render.ts +613 -0
  144. package/src/components/timepicker/timepicker.ts +117 -0
  145. package/src/components/timepicker/types.ts +336 -0
  146. package/src/components/timepicker/utils.ts +241 -0
  147. package/src/components/tooltip/api.ts +1 -1
  148. package/src/components/tooltip/config.ts +27 -6
  149. package/src/components/tooltip/index.ts +0 -1
  150. package/src/components/tooltip/types.ts +13 -3
  151. package/src/components/top-app-bar/config.ts +83 -0
  152. package/src/components/top-app-bar/index.ts +11 -0
  153. package/src/components/top-app-bar/top-app-bar.ts +316 -0
  154. package/src/components/top-app-bar/types.ts +140 -0
  155. package/src/core/build/_ripple.scss +6 -6
  156. package/src/core/build/ripple.ts +72 -95
  157. package/src/core/compose/features/icon.ts +3 -1
  158. package/src/core/compose/features/ripple.ts +4 -1
  159. package/src/core/compose/features/textlabel.ts +23 -2
  160. package/src/core/dom/create.ts +5 -0
  161. package/src/index.ts +9 -0
  162. package/src/styles/abstract/_theme.scss +9 -1
  163. package/src/styles/components/_badge.scss +182 -0
  164. package/src/styles/components/_bottom-app-bar.scss +103 -0
  165. package/src/{components/button/_styles.scss → styles/components/_button.scss} +0 -10
  166. package/src/{components/checkbox/_styles.scss → styles/components/_checkbox.scss} +0 -2
  167. package/src/styles/components/_datepicker.scss +358 -0
  168. package/src/styles/components/_dialog.scss +259 -0
  169. package/src/styles/components/_divider.scss +57 -0
  170. package/src/styles/components/_extended-fab.scss +267 -0
  171. package/src/styles/components/_fab.scss +225 -0
  172. package/src/{components/navigation/_styles.scss → styles/components/_navigation.scss} +1 -0
  173. package/src/styles/components/_search.scss +306 -0
  174. package/src/styles/components/_segmented-button.scss +117 -0
  175. package/src/{components/slider/_styles.scss → styles/components/_slider.scss} +83 -24
  176. package/src/{components/switch/_styles.scss → styles/components/_switch.scss} +0 -2
  177. package/src/{components/tabs/_styles.scss → styles/components/_tabs.scss} +95 -33
  178. package/src/{components/textfield/_styles.scss → styles/components/_textfield.scss} +70 -67
  179. package/src/styles/components/_timepicker.scss +451 -0
  180. package/src/styles/components/_top-app-bar.scss +225 -0
  181. package/src/styles/main.scss +98 -49
  182. package/src/styles/themes/_autumn.scss +21 -0
  183. package/src/styles/themes/_base-theme.scss +61 -0
  184. package/src/styles/themes/_baseline.scss +58 -0
  185. package/src/styles/themes/_bluekhaki.scss +125 -0
  186. package/src/styles/themes/_brownbeige.scss +125 -0
  187. package/src/styles/themes/_browngreen.scss +125 -0
  188. package/src/styles/themes/_forest.scss +6 -0
  189. package/src/styles/themes/_greenbeige.scss +125 -0
  190. package/src/styles/themes/_material.scss +125 -0
  191. package/src/styles/themes/_ocean.scss +6 -0
  192. package/src/styles/themes/_sageivory.scss +125 -0
  193. package/src/styles/themes/_spring.scss +6 -0
  194. package/src/styles/themes/_summer.scss +5 -0
  195. package/src/styles/themes/_sunset.scss +5 -0
  196. package/src/styles/themes/_tealcaramel.scss +125 -0
  197. package/src/styles/themes/_winter.scss +6 -0
  198. package/src/components/badge/_styles.scss +0 -174
  199. package/src/components/badge/constants.ts +0 -30
  200. package/src/components/button/constants.ts +0 -11
  201. package/src/components/card/constants.ts +0 -84
  202. package/src/components/dialog/_styles.scss +0 -213
  203. package/src/components/dialog/constants.ts +0 -32
  204. package/src/components/menu/constants.ts +0 -154
  205. package/src/components/navigation/constants.ts +0 -200
  206. package/src/components/navigation/features/items.js +0 -192
  207. package/src/components/progress/constants.ts +0 -29
  208. package/src/components/slider/features/appearance.ts +0 -94
  209. package/src/components/slider/features/disabled.ts +0 -68
  210. package/src/components/slider/features/events.ts +0 -164
  211. package/src/components/slider/features/interactions.ts +0 -396
  212. package/src/components/slider/features/keyboard.ts +0 -233
  213. package/src/components/switch/constants.ts +0 -80
  214. package/src/components/tabs/constants.ts +0 -89
  215. package/src/core/collection/adapters/mongodb.js +0 -232
  216. /package/src/{components/card/_styles.scss → styles/components/_card.scss} +0 -0
  217. /package/src/{components/carousel/_styles.scss → styles/components/_carousel.scss} +0 -0
  218. /package/src/{components/chip/_styles.scss → styles/components/_chip.scss} +0 -0
  219. /package/src/{components/list/_styles.scss → styles/components/_list.scss} +0 -0
  220. /package/src/{components/menu/_styles.scss → styles/components/_menu.scss} +0 -0
  221. /package/src/{components/progress/_styles.scss → styles/components/_progress.scss} +0 -0
  222. /package/src/{components/radios/_styles.scss → styles/components/_radios.scss} +0 -0
  223. /package/src/{components/sheet/_styles.scss → styles/components/_sheet.scss} +0 -0
  224. /package/src/{components/snackbar/_styles.scss → styles/components/_snackbar.scss} +0 -0
  225. /package/src/{components/tooltip/_styles.scss → styles/components/_tooltip.scss} +0 -0
  226. /package/src/styles/utilities/{_color.scss → _colors.scss} +0 -0
@@ -1,142 +1,330 @@
1
1
  // src/components/chip/types.ts
2
- import { CHIP_VARIANTS } from './constants';
2
+
3
+ /**
4
+ * Chip variant types
5
+ * @category Components
6
+ */
7
+ export type ChipVariant = 'filled' | 'outlined' | 'elevated' | 'assist' | 'filter' | 'input' | 'suggestion';
3
8
 
4
9
  /**
5
10
  * Configuration interface for the Chip component
11
+ * @category Components
6
12
  */
7
13
  export interface ChipConfig {
8
- /** Chip variant (filled, outlined, elevated, assist, filter, input, suggestion) */
9
- variant?: keyof typeof CHIP_VARIANTS | string;
14
+ /**
15
+ * Chip variant that determines visual styling
16
+ * @default 'filled'
17
+ */
18
+ variant?: ChipVariant | string;
10
19
 
11
- /** Whether the chip is initially disabled */
20
+ /**
21
+ * Whether the chip is initially disabled
22
+ * @default false
23
+ */
12
24
  disabled?: boolean;
13
25
 
14
- /** Whether the chip is initially selected */
26
+ /**
27
+ * Whether the chip is initially selected
28
+ * @default false
29
+ */
15
30
  selected?: boolean;
16
31
 
17
- /** Initial chip text content */
32
+ /**
33
+ * Initial chip text content
34
+ * @example 'Category'
35
+ */
18
36
  text?: string;
19
37
 
20
- /** Initial chip icon HTML content */
38
+ /**
39
+ * Initial chip icon HTML content (alias for leadingIcon)
40
+ * @example '<svg>...</svg>'
41
+ */
21
42
  icon?: string;
22
43
 
23
- /** Optional leading icon HTML content */
44
+ /**
45
+ * Leading icon HTML content
46
+ * @example '<svg>...</svg>'
47
+ */
24
48
  leadingIcon?: string;
25
49
 
26
- /** Optional trailing icon HTML content */
50
+ /**
51
+ * Trailing icon HTML content
52
+ * @example '<svg>...</svg>'
53
+ */
27
54
  trailingIcon?: string;
28
55
 
29
- /** Additional CSS classes */
56
+ /**
57
+ * Additional CSS classes to add to the chip
58
+ * @example 'filter-tag category-item'
59
+ */
30
60
  class?: string;
31
61
 
32
- /** Chip value attribute */
62
+ /**
63
+ * Chip value attribute for identification
64
+ */
33
65
  value?: string;
34
66
 
35
- /** Whether to enable ripple effect */
67
+ /**
68
+ * Whether to enable ripple effect
69
+ * @default true
70
+ */
36
71
  ripple?: boolean;
72
+
73
+ /**
74
+ * Component prefix for class names
75
+ * @default 'mtrl'
76
+ */
77
+ prefix?: string;
78
+
79
+ /**
80
+ * Component name used in class generation
81
+ */
82
+ componentName?: string;
37
83
 
38
- /** Ripple effect configuration */
84
+ /**
85
+ * Ripple effect configuration
86
+ */
39
87
  rippleConfig?: {
88
+ /** Duration of the ripple animation in milliseconds */
40
89
  duration?: number;
90
+ /** Timing function for the ripple animation */
41
91
  timing?: string;
92
+ /** Opacity values for ripple start and end [start, end] */
42
93
  opacity?: [string, string];
43
94
  };
44
95
 
45
- /** Function called when the trailing icon is clicked */
96
+ /**
97
+ * Flag to make any chip variant selectable
98
+ * @default false
99
+ */
100
+ selectable?: boolean;
101
+
102
+ /**
103
+ * Function called when the trailing icon is clicked
104
+ */
46
105
  onTrailingIconClick?: (chip: ChipComponent) => void;
47
106
 
48
- /** Function called when the chip is selected */
107
+ /**
108
+ * Function called when the chip is selected
109
+ */
49
110
  onSelect?: (chip: ChipComponent) => void;
111
+
112
+ /**
113
+ * Function called when the chip selection changes
114
+ */
115
+ onChange?: (chip: ChipComponent) => void;
50
116
  }
51
117
 
52
118
  /**
53
- * Icon API interface
119
+ * Icon API interface for managing chip icons
120
+ * @category Components
54
121
  */
55
122
  export interface IconAPI {
123
+ /**
124
+ * Sets the icon HTML content
125
+ * @param html - HTML string for the icon
126
+ * @returns The icon API for chaining
127
+ */
56
128
  setIcon: (html: string) => IconAPI;
129
+
130
+ /**
131
+ * Gets the current icon HTML content
132
+ * @returns HTML string for the icon
133
+ */
57
134
  getIcon: () => string;
135
+
136
+ /**
137
+ * Gets the icon DOM element
138
+ * @returns The icon element or null if not present
139
+ */
58
140
  getElement: () => HTMLElement | null;
59
141
  }
60
142
 
61
143
  /**
62
- * Text API interface
144
+ * Text API interface for managing chip text
145
+ * @category Components
63
146
  */
64
147
  export interface TextAPI {
148
+ /**
149
+ * Sets the text content
150
+ * @param content - Text content
151
+ * @returns The text API for chaining
152
+ */
65
153
  setText: (content: string) => TextAPI;
154
+
155
+ /**
156
+ * Gets the current text content
157
+ * @returns Chip text content
158
+ */
66
159
  getText: () => string;
160
+
161
+ /**
162
+ * Gets the text DOM element
163
+ * @returns The text element or null if not present
164
+ */
67
165
  getElement: () => HTMLElement | null;
68
166
  }
69
167
 
70
168
  /**
71
169
  * Chip component interface
170
+ * @category Components
72
171
  */
73
172
  export interface ChipComponent {
173
+ /** The chip's DOM element */
74
174
  element: HTMLElement;
175
+
176
+ /** API for managing chip text */
75
177
  text: TextAPI;
178
+
179
+ /** API for managing chip icons */
76
180
  icon: IconAPI;
181
+
182
+ /** API for managing disabled state */
77
183
  disabled: {
184
+ /** Enables the chip */
78
185
  enable: () => void;
186
+ /** Disables the chip */
79
187
  disable: () => void;
188
+ /** Checks if the chip is disabled */
80
189
  isDisabled: () => boolean;
81
190
  };
191
+
192
+ /** API for managing component lifecycle */
82
193
  lifecycle: {
194
+ /** Destroys the component and cleans up resources */
83
195
  destroy: () => void;
84
196
  };
85
197
 
86
- /** Gets the class with the specified name */
198
+ /**
199
+ * Gets a class name with the component's prefix
200
+ * @param name - Base class name
201
+ * @returns Prefixed class name
202
+ */
87
203
  getClass: (name: string) => string;
88
204
 
89
- /** Gets the chip's value */
205
+ /**
206
+ * Gets the chip's value attribute
207
+ * @returns Chip value
208
+ */
90
209
  getValue: () => string | null;
91
210
 
92
- /** Sets the chip's value */
211
+ /**
212
+ * Sets the chip's value attribute
213
+ * @param value - New value
214
+ * @returns The chip component for chaining
215
+ */
93
216
  setValue: (value: string) => ChipComponent;
94
217
 
95
- /** Enables the chip */
218
+ /**
219
+ * Enables the chip (removes disabled attribute)
220
+ * @returns The chip component for chaining
221
+ */
96
222
  enable: () => ChipComponent;
97
223
 
98
- /** Disables the chip */
224
+ /**
225
+ * Disables the chip (adds disabled attribute)
226
+ * @returns The chip component for chaining
227
+ */
99
228
  disable: () => ChipComponent;
100
229
 
101
- /** Sets the chip's text content */
230
+ /**
231
+ * Checks if the chip is disabled
232
+ * @returns True if the chip is disabled
233
+ */
234
+ isDisabled: () => boolean;
235
+
236
+ /**
237
+ * Sets the chip's text content
238
+ * @param content - Text content
239
+ * @returns The chip component for chaining
240
+ */
102
241
  setText: (content: string) => ChipComponent;
103
242
 
104
- /** Gets the chip's text content */
243
+ /**
244
+ * Gets the chip's text content
245
+ * @returns Chip text content
246
+ */
105
247
  getText: () => string;
106
248
 
107
- /** Sets the chip's icon */
249
+ /**
250
+ * Sets the chip's icon (alias for setLeadingIcon)
251
+ * @param icon - Icon HTML content
252
+ * @returns The chip component for chaining
253
+ */
108
254
  setIcon: (icon: string) => ChipComponent;
109
255
 
110
- /** Gets the chip's icon */
256
+ /**
257
+ * Gets the chip's icon HTML content
258
+ * @returns Icon HTML
259
+ */
111
260
  getIcon: () => string;
112
261
 
113
- /** Sets the chip's trailing icon */
114
- setTrailingIcon: (icon: string) => ChipComponent;
262
+ /**
263
+ * Sets the chip's leading icon
264
+ * @param icon - Icon HTML content
265
+ * @returns The chip component for chaining
266
+ */
267
+ setLeadingIcon: (icon: string) => ChipComponent;
268
+
269
+ /**
270
+ * Sets the chip's trailing icon
271
+ * @param icon - Icon HTML content
272
+ * @param onClick - Optional click handler for the trailing icon
273
+ * @returns The chip component for chaining
274
+ */
275
+ setTrailingIcon: (icon: string, onClick?: (chip: ChipComponent) => void) => ChipComponent;
115
276
 
116
- /** Checks if the chip is selected */
277
+ /**
278
+ * Checks if the chip is selected
279
+ * @returns True if the chip is selected
280
+ */
117
281
  isSelected: () => boolean;
118
282
 
119
- /** Sets the chip's selected state */
283
+ /**
284
+ * Sets the chip's selected state
285
+ * @param selected - Whether the chip should be selected
286
+ * @returns The chip component for chaining
287
+ */
120
288
  setSelected: (selected: boolean) => ChipComponent;
121
289
 
122
- /** Toggles the chip's selected state */
290
+ /**
291
+ * Toggles the chip's selected state
292
+ * @returns The chip component for chaining
293
+ */
123
294
  toggleSelected: () => ChipComponent;
124
295
 
125
- /** Destroys the chip component and cleans up resources */
296
+ /**
297
+ * Destroys the chip component and cleans up resources
298
+ */
126
299
  destroy: () => void;
127
300
 
128
- /** Adds event listener */
301
+ /**
302
+ * Adds an event listener to the chip
303
+ * @param event - Event name ('click', 'focus', etc.)
304
+ * @param handler - Event handler function
305
+ * @returns The chip component for chaining
306
+ */
129
307
  on: (event: string, handler: Function) => ChipComponent;
130
308
 
131
- /** Removes event listener */
309
+ /**
310
+ * Removes an event listener from the chip
311
+ * @param event - Event name
312
+ * @param handler - Event handler function
313
+ * @returns The chip component for chaining
314
+ */
132
315
  off: (event: string, handler: Function) => ChipComponent;
133
316
 
134
- /** Add CSS classes */
317
+ /**
318
+ * Adds CSS classes to the chip element
319
+ * @param classes - One or more class names to add
320
+ * @returns The chip component for chaining
321
+ */
135
322
  addClass: (...classes: string[]) => ChipComponent;
136
323
  }
137
324
 
138
325
  /**
139
326
  * API options interface
327
+ * @internal
140
328
  */
141
329
  export interface ApiOptions {
142
330
  disabled: {
@@ -150,6 +338,7 @@ export interface ApiOptions {
150
338
 
151
339
  /**
152
340
  * Base component interface
341
+ * @internal
153
342
  */
154
343
  export interface BaseComponent {
155
344
  element: HTMLElement;
@@ -0,0 +1,265 @@
1
+ // src/components/datepicker/api.ts
2
+ import { DatePickerComponent, ApiOptions } from './types';
3
+ import {
4
+ formatDate,
5
+ parseDate,
6
+ addMonths,
7
+ addYears
8
+ } from './utils';
9
+
10
+ /**
11
+ * Enhances a datepicker component with API methods
12
+ * @param {object} state - Current state of the datepicker
13
+ * @param {ApiOptions} options - API configuration options
14
+ * @returns {Function} Higher-order function that adds API methods to component
15
+ * @internal This is an internal utility for the DatePicker component
16
+ */
17
+ export const withAPI = (state: any, { disabled, lifecycle, events }: ApiOptions) =>
18
+ (component: any): DatePickerComponent => {
19
+ // Calendar navigation API
20
+ const calendar = {
21
+ goToDate(date: Date): void {
22
+ const validDate = parseDate(date);
23
+ if (!validDate) return;
24
+
25
+ state.currentMonth = validDate.getMonth();
26
+ state.currentYear = validDate.getFullYear();
27
+
28
+ // Update calendar view
29
+ state.updateCalendar();
30
+ },
31
+
32
+ nextMonth(): void {
33
+ const newDate = addMonths(new Date(state.currentYear, state.currentMonth, 1), 1);
34
+ state.currentMonth = newDate.getMonth();
35
+ state.currentYear = newDate.getFullYear();
36
+
37
+ // Update calendar view
38
+ state.updateCalendar();
39
+ },
40
+
41
+ prevMonth(): void {
42
+ const newDate = addMonths(new Date(state.currentYear, state.currentMonth, 1), -1);
43
+ state.currentMonth = newDate.getMonth();
44
+ state.currentYear = newDate.getFullYear();
45
+
46
+ // Update calendar view
47
+ state.updateCalendar();
48
+ },
49
+
50
+ nextYear(): void {
51
+ state.currentYear += 1;
52
+
53
+ // Update calendar view
54
+ state.updateCalendar();
55
+ },
56
+
57
+ prevYear(): void {
58
+ state.currentYear -= 1;
59
+
60
+ // Update calendar view
61
+ state.updateCalendar();
62
+ },
63
+
64
+ showDayView(): void {
65
+ state.currentView = 'day';
66
+ state.updateCalendar();
67
+ },
68
+
69
+ showMonthView(): void {
70
+ state.currentView = 'month';
71
+ state.updateCalendar();
72
+ },
73
+
74
+ showYearView(): void {
75
+ state.currentView = 'year';
76
+ state.updateCalendar();
77
+ },
78
+
79
+ getCurrentView(): string {
80
+ return state.currentView;
81
+ }
82
+ };
83
+
84
+ return {
85
+ ...component as any,
86
+ element: component.element,
87
+ input: state.input,
88
+ calendar,
89
+
90
+ open(): DatePickerComponent {
91
+ state.isOpen = true;
92
+ state.render();
93
+ events.emit('open', { value: this.getValue() });
94
+ return this;
95
+ },
96
+
97
+ close(): DatePickerComponent {
98
+ state.isOpen = false;
99
+ state.render();
100
+ events.emit('close', { value: this.getValue() });
101
+ return this;
102
+ },
103
+
104
+ getValue(): Date | [Date, Date] | null {
105
+ if (!state.selectedDate) return null;
106
+
107
+ // Range selection
108
+ if (state.selectionMode === 'range' && state.rangeEndDate) {
109
+ return [new Date(state.selectedDate), new Date(state.rangeEndDate)];
110
+ }
111
+
112
+ // Single selection
113
+ return new Date(state.selectedDate);
114
+ },
115
+
116
+ setValue(value: Date | string | [Date | string, Date | string]): DatePickerComponent {
117
+ // Handle range selection
118
+ if (Array.isArray(value) && state.selectionMode === 'range') {
119
+ const start = parseDate(value[0]);
120
+ const end = parseDate(value[1]);
121
+
122
+ if (start && end) {
123
+ state.selectedDate = start;
124
+ state.rangeEndDate = end;
125
+
126
+ // Ensure start date is before end date
127
+ if (start > end) {
128
+ state.selectedDate = end;
129
+ state.rangeEndDate = start;
130
+ }
131
+
132
+ // Update input value
133
+ state.updateInputValue();
134
+
135
+ // Update calendar if it's open
136
+ if (state.isOpen) {
137
+ // Set current month/year to the start date's month/year
138
+ state.currentMonth = state.selectedDate.getMonth();
139
+ state.currentYear = state.selectedDate.getFullYear();
140
+ state.updateCalendar();
141
+ }
142
+
143
+ events.emit('change', {
144
+ value: this.getValue(),
145
+ formattedValue: this.getFormattedValue()
146
+ });
147
+ }
148
+
149
+ return this;
150
+ }
151
+
152
+ // Handle single date selection
153
+ const parsedDate = parseDate(value as Date | string);
154
+ if (parsedDate) {
155
+ state.selectedDate = parsedDate;
156
+ state.rangeEndDate = null;
157
+
158
+ // Update input value
159
+ state.updateInputValue();
160
+
161
+ // Update calendar if it's open
162
+ if (state.isOpen) {
163
+ state.currentMonth = parsedDate.getMonth();
164
+ state.currentYear = parsedDate.getFullYear();
165
+ state.updateCalendar();
166
+ }
167
+
168
+ events.emit('change', {
169
+ value: this.getValue(),
170
+ formattedValue: this.getFormattedValue()
171
+ });
172
+ }
173
+
174
+ return this;
175
+ },
176
+
177
+ getFormattedValue(): string {
178
+ if (!state.selectedDate) return '';
179
+
180
+ // Range selection
181
+ if (state.selectionMode === 'range' && state.rangeEndDate) {
182
+ const startStr = formatDate(state.selectedDate, state.dateFormat);
183
+ const endStr = formatDate(state.rangeEndDate, state.dateFormat);
184
+ return `${startStr} - ${endStr}`;
185
+ }
186
+
187
+ // Single selection
188
+ return formatDate(state.selectedDate, state.dateFormat);
189
+ },
190
+
191
+ clear(): DatePickerComponent {
192
+ state.selectedDate = null;
193
+ state.rangeEndDate = null;
194
+ state.updateInputValue();
195
+
196
+ if (state.isOpen) {
197
+ state.updateCalendar();
198
+ }
199
+
200
+ events.emit('change', { value: null, formattedValue: '' });
201
+ return this;
202
+ },
203
+
204
+ enable(): DatePickerComponent {
205
+ disabled.enable();
206
+ state.input.disabled = false;
207
+ return this;
208
+ },
209
+
210
+ disable(): DatePickerComponent {
211
+ disabled.disable();
212
+ state.input.disabled = true;
213
+ return this;
214
+ },
215
+
216
+ setMinDate(date: Date | string): DatePickerComponent {
217
+ const parsedDate = parseDate(date);
218
+ if (parsedDate) {
219
+ state.minDate = parsedDate;
220
+
221
+ // Update calendar if it's open
222
+ if (state.isOpen) {
223
+ state.updateCalendar();
224
+ }
225
+ }
226
+ return this;
227
+ },
228
+
229
+ setMaxDate(date: Date | string): DatePickerComponent {
230
+ const parsedDate = parseDate(date);
231
+ if (parsedDate) {
232
+ state.maxDate = parsedDate;
233
+
234
+ // Update calendar if it's open
235
+ if (state.isOpen) {
236
+ state.updateCalendar();
237
+ }
238
+ }
239
+ return this;
240
+ },
241
+
242
+ destroy(): void {
243
+ // Clean up event listeners
244
+ document.removeEventListener('click', state.outsideClickHandler);
245
+
246
+ // Remove DOM elements
247
+ if (state.calendarElement && state.calendarElement.parentNode) {
248
+ state.calendarElement.parentNode.removeChild(state.calendarElement);
249
+ }
250
+
251
+ // Call the lifecycle destroy method
252
+ lifecycle.destroy();
253
+ },
254
+
255
+ on(event: string, handler: Function): DatePickerComponent {
256
+ events.on(event, handler);
257
+ return this;
258
+ },
259
+
260
+ off(event: string, handler: Function): DatePickerComponent {
261
+ events.off(event, handler);
262
+ return this;
263
+ }
264
+ };
265
+ };