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
@@ -0,0 +1,117 @@
1
+ // src/components/timepicker/timePicker.ts
2
+
3
+ import { PREFIX } from '../../core/config';
4
+ import { pipe } from '../../core/compose';
5
+ import { createBase, withElement } from '../../core/compose/component';
6
+ import {
7
+ withEvents,
8
+ withLifecycle
9
+ } from '../../core/compose/features';
10
+ import { TimePickerConfig, TimePickerComponent, TimeValue, TIME_PERIOD, TIME_FORMAT } from './types';
11
+ import { createBaseConfig, getContainerConfig, getModalConfig, getDialogConfig, getApiConfig } from './config';
12
+ import {
13
+ TIME_PICKER_TYPE,
14
+ TIME_PICKER_ORIENTATION,
15
+ EVENTS,
16
+ SELECTORS,
17
+ Z_INDEX
18
+ } from './config';
19
+ import { createTimePickerAPI } from './api';
20
+ import { renderTimePicker } from './render';
21
+ import { parseTime, formatTime } from './utils';
22
+
23
+ /**
24
+ * Creates a new TimePicker component
25
+ * @param {TimePickerConfig} config - TimePicker configuration object
26
+ * @returns {TimePickerComponent} TimePicker component instance
27
+ */
28
+ const createTimePicker = (config: TimePickerConfig = {}): TimePickerComponent => {
29
+ const baseConfig = createBaseConfig(config);
30
+
31
+ try {
32
+ // Create base component with container element
33
+ const baseComponent = pipe(
34
+ createBase,
35
+ withEvents(),
36
+ withElement(getContainerConfig(baseConfig)),
37
+ withLifecycle()
38
+ )(baseConfig);
39
+
40
+ // Create modal element
41
+ const modalElement = document.createElement('div');
42
+ modalElement.className = `${PREFIX}-time-picker-modal`;
43
+ modalElement.style.display = 'none';
44
+ modalElement.style.position = 'fixed';
45
+ modalElement.style.top = '0';
46
+ modalElement.style.left = '0';
47
+ modalElement.style.width = '100%';
48
+ modalElement.style.height = '100%';
49
+ modalElement.style.backgroundColor = 'rgba(0, 0, 0, 0.4)';
50
+ modalElement.style.zIndex = Z_INDEX.MODAL.toString();
51
+ modalElement.setAttribute('role', 'presentation');
52
+
53
+ // Create dialog element
54
+ const dialogElement = document.createElement('div');
55
+ dialogElement.className = [
56
+ `${PREFIX}-time-picker-dialog`,
57
+ `${PREFIX}-time-picker-dialog--${baseConfig.type}`,
58
+ `${PREFIX}-time-picker-dialog--${baseConfig.orientation}`,
59
+ `${PREFIX}-time-picker-dialog--${baseConfig.format}`
60
+ ].join(' ');
61
+ dialogElement.style.position = 'absolute';
62
+ dialogElement.style.top = '50%';
63
+ dialogElement.style.left = '50%';
64
+ dialogElement.style.transform = 'translate(-50%, -50%)';
65
+ dialogElement.style.zIndex = Z_INDEX.DIALOG.toString();
66
+
67
+ // Append dialog to modal
68
+ modalElement.appendChild(dialogElement);
69
+
70
+ // Append modal to container (document.body by default)
71
+ const container = typeof baseConfig.container === 'string'
72
+ ? document.querySelector(baseConfig.container) || document.body
73
+ : baseConfig.container || document.body;
74
+
75
+ container.appendChild(modalElement);
76
+
77
+ // Parse initial time value
78
+ let timeValue: TimeValue;
79
+ if (baseConfig.value) {
80
+ timeValue = parseTime(baseConfig.value, baseConfig.format);
81
+ } else {
82
+ // Default to current time
83
+ const now = new Date();
84
+ timeValue = {
85
+ hours: now.getHours(),
86
+ minutes: now.getMinutes(),
87
+ seconds: baseConfig.showSeconds ? now.getSeconds() : 0,
88
+ period: now.getHours() >= 12 ? TIME_PERIOD.PM : TIME_PERIOD.AM
89
+ };
90
+ }
91
+
92
+ // Render initial time picker content
93
+ renderTimePicker(dialogElement, timeValue, baseConfig);
94
+
95
+ // Create time picker API
96
+ const timePicker = createTimePickerAPI(
97
+ baseComponent,
98
+ modalElement,
99
+ dialogElement,
100
+ timeValue,
101
+ baseConfig,
102
+ getApiConfig(baseComponent)
103
+ );
104
+
105
+ // Open time picker if initially open
106
+ if (baseConfig.isOpen) {
107
+ setTimeout(() => timePicker.open(), 0);
108
+ }
109
+
110
+ return timePicker;
111
+ } catch (error) {
112
+ console.error('TimePicker creation error:', error);
113
+ throw new Error(`Failed to create time picker: ${(error as Error).message}`);
114
+ }
115
+ };
116
+
117
+ export default createTimePicker;
@@ -0,0 +1,336 @@
1
+ // src/components/timepicker/types.ts
2
+
3
+ /**
4
+ * Time picker display type
5
+ * @enum {string}
6
+ */
7
+ export enum TIME_PICKER_TYPE {
8
+ /** Clock dial-based time picker */
9
+ DIAL = 'dial',
10
+ /** Text input-based time picker */
11
+ INPUT = 'input'
12
+ }
13
+
14
+ /**
15
+ * Time picker orientation
16
+ * @enum {string}
17
+ */
18
+ export enum TIME_PICKER_ORIENTATION {
19
+ /** Vertical layout (default on mobile) */
20
+ VERTICAL = 'vertical',
21
+ /** Horizontal layout */
22
+ HORIZONTAL = 'horizontal'
23
+ }
24
+
25
+ /**
26
+ * Time format (12-hour or 24-hour)
27
+ * @enum {string}
28
+ */
29
+ export enum TIME_FORMAT {
30
+ /** 12-hour format with AM/PM */
31
+ AMPM = '12h',
32
+ /** 24-hour format */
33
+ MILITARY = '24h'
34
+ }
35
+
36
+ /**
37
+ * Period of day for 12-hour format
38
+ * @enum {string}
39
+ */
40
+ export enum TIME_PERIOD {
41
+ /** Morning */
42
+ AM = 'AM',
43
+ /** Afternoon/Evening */
44
+ PM = 'PM'
45
+ }
46
+
47
+ /**
48
+ * Configuration interface for the TimePicker component
49
+ * @category Components
50
+ */
51
+ export interface TimePickerConfig {
52
+ /**
53
+ * Initial time value in 24-hour format (HH:MM)
54
+ * @example '14:30'
55
+ */
56
+ value?: string;
57
+
58
+ /**
59
+ * Type of time picker to display
60
+ * @default TIME_PICKER_TYPE.DIAL
61
+ */
62
+ type?: TIME_PICKER_TYPE;
63
+
64
+ /**
65
+ * Time format to use (12h or 24h)
66
+ * @default TIME_FORMAT.AMPM
67
+ */
68
+ format?: TIME_FORMAT;
69
+
70
+ /**
71
+ * Layout orientation for the time picker
72
+ * @default TIME_PICKER_ORIENTATION.VERTICAL
73
+ */
74
+ orientation?: TIME_PICKER_ORIENTATION;
75
+
76
+ /**
77
+ * Title text for the time picker
78
+ * @example 'Select departure time'
79
+ */
80
+ title?: string;
81
+
82
+ /**
83
+ * Whether to show seconds selector
84
+ * @default false
85
+ */
86
+ showSeconds?: boolean;
87
+
88
+ /**
89
+ * Additional CSS classes to add to the time picker
90
+ * @example 'custom-picker dark-theme'
91
+ */
92
+ class?: string;
93
+
94
+ /**
95
+ * Component prefix for class names
96
+ * @default 'mtrl'
97
+ */
98
+ prefix?: string;
99
+
100
+ /**
101
+ * Component name used in class generation
102
+ */
103
+ componentName?: string;
104
+
105
+ /**
106
+ * Whether to close the picker when time is selected
107
+ * @default true
108
+ */
109
+ closeOnSelect?: boolean;
110
+
111
+ /**
112
+ * Minimum selectable time in 24-hour format (HH:MM)
113
+ * @example '09:00'
114
+ */
115
+ minTime?: string;
116
+
117
+ /**
118
+ * Maximum selectable time in 24-hour format (HH:MM)
119
+ * @example '18:00'
120
+ */
121
+ maxTime?: string;
122
+
123
+ /**
124
+ * Step interval for minute selection in minutes
125
+ * @default 1
126
+ */
127
+ minuteStep?: number;
128
+
129
+ /**
130
+ * Step interval for second selection in seconds
131
+ * @default 1
132
+ */
133
+ secondStep?: number;
134
+
135
+ /**
136
+ * Custom text for cancel button
137
+ * @default 'Cancel'
138
+ */
139
+ cancelText?: string;
140
+
141
+ /**
142
+ * Custom text for confirm button
143
+ * @default 'OK'
144
+ */
145
+ confirmText?: string;
146
+
147
+ /**
148
+ * Whether the time picker is initially visible (for inline mode)
149
+ * @default false
150
+ */
151
+ isOpen?: boolean;
152
+
153
+ /**
154
+ * CSS selector or HTMLElement to append the time picker to
155
+ * @default document.body
156
+ */
157
+ container?: string | HTMLElement;
158
+
159
+ /**
160
+ * Custom icon for the clock button
161
+ */
162
+ clockIcon?: string;
163
+
164
+ /**
165
+ * Custom icon for the keyboard button
166
+ */
167
+ keyboardIcon?: string;
168
+
169
+ /**
170
+ * Callback when time is changed
171
+ */
172
+ onChange?: (time: string) => void;
173
+
174
+ /**
175
+ * Callback when time picker is opened
176
+ */
177
+ onOpen?: () => void;
178
+
179
+ /**
180
+ * Callback when time picker is closed
181
+ */
182
+ onClose?: () => void;
183
+
184
+ /**
185
+ * Callback when time is confirmed
186
+ */
187
+ onConfirm?: (time: string) => void;
188
+
189
+ /**
190
+ * Callback when time picker is canceled
191
+ */
192
+ onCancel?: () => void;
193
+ }
194
+
195
+ /**
196
+ * Time value object
197
+ * @category Components
198
+ */
199
+ export interface TimeValue {
200
+ /** Hours (0-23) */
201
+ hours: number;
202
+ /** Minutes (0-59) */
203
+ minutes: number;
204
+ /** Seconds (0-59), optional */
205
+ seconds?: number;
206
+ /** AM/PM for 12-hour format */
207
+ period?: TIME_PERIOD;
208
+ }
209
+
210
+ /**
211
+ * TimePicker component interface
212
+ * @category Components
213
+ */
214
+ export interface TimePickerComponent {
215
+ /** The time picker's container DOM element */
216
+ element: HTMLElement;
217
+
218
+ /** Modal container element */
219
+ modalElement: HTMLElement;
220
+
221
+ /** Dialog container element */
222
+ dialogElement: HTMLElement;
223
+
224
+ /** Whether the time picker is currently open */
225
+ isOpen: boolean;
226
+
227
+ /**
228
+ * Opens the time picker
229
+ * @returns The time picker component for chaining
230
+ */
231
+ open: () => TimePickerComponent;
232
+
233
+ /**
234
+ * Closes the time picker
235
+ * @returns The time picker component for chaining
236
+ */
237
+ close: () => TimePickerComponent;
238
+
239
+ /**
240
+ * Toggles the time picker open/closed state
241
+ * @returns The time picker component for chaining
242
+ */
243
+ toggle: () => TimePickerComponent;
244
+
245
+ /**
246
+ * Gets the current time value
247
+ * @returns Current time string in 24-hour format (HH:MM or HH:MM:SS)
248
+ */
249
+ getValue: () => string;
250
+
251
+ /**
252
+ * Gets the current time as a TimeValue object
253
+ * @returns Current time object with hours, minutes, seconds, and period
254
+ */
255
+ getTimeObject: () => TimeValue;
256
+
257
+ /**
258
+ * Sets the time value
259
+ * @param time - Time string in 24-hour format (HH:MM or HH:MM:SS)
260
+ * @returns The time picker component for chaining
261
+ */
262
+ setValue: (time: string) => TimePickerComponent;
263
+
264
+ /**
265
+ * Sets the time picker type (dial or input)
266
+ * @param type - Time picker type
267
+ * @returns The time picker component for chaining
268
+ */
269
+ setType: (type: TIME_PICKER_TYPE) => TimePickerComponent;
270
+
271
+ /**
272
+ * Gets the current time picker type
273
+ * @returns Current time picker type
274
+ */
275
+ getType: () => TIME_PICKER_TYPE;
276
+
277
+ /**
278
+ * Sets the time format (12h or 24h)
279
+ * @param format - Time format
280
+ * @returns The time picker component for chaining
281
+ */
282
+ setFormat: (format: TIME_FORMAT) => TimePickerComponent;
283
+
284
+ /**
285
+ * Gets the current time format
286
+ * @returns Current time format
287
+ */
288
+ getFormat: () => TIME_FORMAT;
289
+
290
+ /**
291
+ * Sets the time picker orientation
292
+ * @param orientation - Time picker orientation
293
+ * @returns The time picker component for chaining
294
+ */
295
+ setOrientation: (orientation: TIME_PICKER_ORIENTATION) => TimePickerComponent;
296
+
297
+ /**
298
+ * Gets the current time picker orientation
299
+ * @returns Current time picker orientation
300
+ */
301
+ getOrientation: () => TIME_PICKER_ORIENTATION;
302
+
303
+ /**
304
+ * Sets the time picker title
305
+ * @param title - Title text
306
+ * @returns The time picker component for chaining
307
+ */
308
+ setTitle: (title: string) => TimePickerComponent;
309
+
310
+ /**
311
+ * Gets the current time picker title
312
+ * @returns Current title text
313
+ */
314
+ getTitle: () => string;
315
+
316
+ /**
317
+ * Destroys the time picker component and cleans up resources
318
+ */
319
+ destroy: () => void;
320
+
321
+ /**
322
+ * Adds an event listener to the time picker
323
+ * @param event - Event name ('change', 'open', 'close', etc.)
324
+ * @param handler - Event handler function
325
+ * @returns The time picker component for chaining
326
+ */
327
+ on: (event: string, handler: Function) => TimePickerComponent;
328
+
329
+ /**
330
+ * Removes an event listener from the time picker
331
+ * @param event - Event name
332
+ * @param handler - Event handler function
333
+ * @returns The time picker component for chaining
334
+ */
335
+ off: (event: string, handler: Function) => TimePickerComponent;
336
+ }
@@ -0,0 +1,241 @@
1
+ // src/components/timepicker/utils.ts
2
+
3
+ import { TimeValue, TIME_PERIOD, TIME_FORMAT } from './types';
4
+
5
+ /**
6
+ * Pads a number with leading zeros to ensure two-digit format
7
+ * @param {number} num - Number to pad
8
+ * @returns {string} Padded number string
9
+ */
10
+ export const padZero = (num: number): string => {
11
+ return num.toString().padStart(2, '0');
12
+ };
13
+
14
+ /**
15
+ * Converts a time string to a TimeValue object
16
+ * @param {string} timeString - Time string in 24-hour format (HH:MM or HH:MM:SS)
17
+ * @param {TIME_FORMAT} format - Time format (12h or 24h)
18
+ * @returns {TimeValue} Parsed time value
19
+ */
20
+ export const parseTime = (timeString: string, format: TIME_FORMAT): TimeValue => {
21
+ try {
22
+ const parts = timeString.split(':');
23
+ let hours = parseInt(parts[0], 10);
24
+ const minutes = parseInt(parts[1], 10);
25
+ const seconds = parts[2] ? parseInt(parts[2], 10) : 0;
26
+
27
+ // Validate time components
28
+ if (
29
+ isNaN(hours) || hours < 0 || hours > 23 ||
30
+ isNaN(minutes) || minutes < 0 || minutes > 59 ||
31
+ isNaN(seconds) || seconds < 0 || seconds > 59
32
+ ) {
33
+ throw new Error('Invalid time format');
34
+ }
35
+
36
+ // Determine period for 12-hour format
37
+ const period = hours >= 12 ? TIME_PERIOD.PM : TIME_PERIOD.AM;
38
+
39
+ return { hours, minutes, seconds, period };
40
+ } catch (error) {
41
+ console.error('Error parsing time:', error);
42
+
43
+ // Return current time as fallback
44
+ const now = new Date();
45
+ const hours = now.getHours();
46
+ const minutes = now.getMinutes();
47
+ const seconds = now.getSeconds();
48
+ const period = hours >= 12 ? TIME_PERIOD.PM : TIME_PERIOD.AM;
49
+
50
+ return { hours, minutes, seconds, period };
51
+ }
52
+ };
53
+
54
+ /**
55
+ * Formats a TimeValue object as a time string
56
+ * @param {TimeValue} timeValue - Time value to format
57
+ * @param {boolean} use24HourFormat - Whether to use 24-hour format
58
+ * @returns {string} Formatted time string
59
+ */
60
+ export const formatTime = (timeValue: TimeValue, use24HourFormat: boolean): string => {
61
+ const { hours, minutes, seconds } = timeValue;
62
+
63
+ if (use24HourFormat) {
64
+ if (seconds !== undefined) {
65
+ return `${padZero(hours)}:${padZero(minutes)}:${padZero(seconds)}`;
66
+ }
67
+ return `${padZero(hours)}:${padZero(minutes)}`;
68
+ } else {
69
+ // Convert 24-hour to 12-hour display format
70
+ let displayHours = hours % 12;
71
+ if (displayHours === 0) {
72
+ displayHours = 12;
73
+ }
74
+
75
+ if (seconds !== undefined) {
76
+ return `${padZero(displayHours)}:${padZero(minutes)}:${padZero(seconds)} ${timeValue.period}`;
77
+ }
78
+ return `${padZero(displayHours)}:${padZero(minutes)} ${timeValue.period}`;
79
+ }
80
+ };
81
+
82
+ /**
83
+ * Converts 12-hour format to 24-hour format
84
+ * @param {number} hours - Hours in 12-hour format (1-12)
85
+ * @param {TIME_PERIOD} period - Period (AM or PM)
86
+ * @returns {number} Hours in 24-hour format (0-23)
87
+ */
88
+ export const convertTo24Hour = (hours: number, period: TIME_PERIOD): number => {
89
+ if (period === TIME_PERIOD.AM) {
90
+ return hours === 12 ? 0 : hours;
91
+ } else {
92
+ return hours === 12 ? 12 : hours + 12;
93
+ }
94
+ };
95
+
96
+ /**
97
+ * Converts 24-hour format to 12-hour format
98
+ * @param {number} hours24 - Hours in 24-hour format (0-23)
99
+ * @returns {object} Object with hours in 12-hour format and period
100
+ */
101
+ export const convertTo12Hour = (hours24: number): { hours: number; period: TIME_PERIOD } => {
102
+ const period = hours24 >= 12 ? TIME_PERIOD.PM : TIME_PERIOD.AM;
103
+ let hours12 = hours24 % 12;
104
+ if (hours12 === 0) {
105
+ hours12 = 12;
106
+ }
107
+
108
+ return { hours: hours12, period };
109
+ };
110
+
111
+ /**
112
+ * Calculates angle for clock dial based on time value
113
+ * @param {number} value - Time value (hour 0-23 or minute/second 0-59)
114
+ * @param {number} max - Maximum value (12 for hours in 12h format, 24 for 24h, 60 for minutes/seconds)
115
+ * @returns {number} Angle in degrees
116
+ */
117
+ export const getAngle = (value: number, max: number): number => {
118
+ return (value / max) * 360;
119
+ };
120
+
121
+ /**
122
+ * Calculates coordinates for a point on a circle
123
+ * @param {number} radius - Circle radius
124
+ * @param {number} angle - Angle in degrees
125
+ * @returns {object} Coordinates { x, y }
126
+ */
127
+ export const getCoordinates = (radius: number, angle: number): { x: number; y: number } => {
128
+ // Convert angle to radians and adjust to start from top (subtract 90 degrees)
129
+ // In CSS, 0 degrees is at 3 o'clock position, so we subtract 90 to start from 12 o'clock
130
+ const radians = ((angle - 90) * Math.PI) / 180;
131
+
132
+ return {
133
+ x: radius * Math.cos(radians),
134
+ y: radius * Math.sin(radians)
135
+ };
136
+ };
137
+
138
+ /**
139
+ * Calculates time value from click position on dial
140
+ * @param {number} centerX - X coordinate of the dial center
141
+ * @param {number} centerY - Y coordinate of the dial center
142
+ * @param {number} clickX - X coordinate of the click position
143
+ * @param {number} clickY - Y coordinate of the click position
144
+ * @param {number} max - Maximum value (12 for hours in 12h format, 24 for 24h, 60 for minutes/seconds)
145
+ * @param {number} innerRadius - Inner radius for 24-hour clock inner ring
146
+ * @param {number} outerRadius - Outer radius for dial
147
+ * @returns {number} Calculated time value
148
+ */
149
+ export const getTimeFromPosition = (
150
+ centerX: number,
151
+ centerY: number,
152
+ clickX: number,
153
+ clickY: number,
154
+ max: number,
155
+ innerRadius?: number,
156
+ outerRadius?: number
157
+ ): number => {
158
+ // Calculate angle from center to click position
159
+ const deltaX = clickX - centerX;
160
+ const deltaY = clickY - centerY;
161
+
162
+ // Calculate angle in degrees (0 at top, clockwise)
163
+ let angle = Math.atan2(deltaY, deltaX) * (180 / Math.PI) + 90;
164
+ if (angle < 0) {
165
+ angle += 360;
166
+ }
167
+
168
+ // Calculate distance from center
169
+ const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
170
+
171
+ // For 24h clock, check if click is in inner or outer ring
172
+ if (max === 24 && innerRadius && outerRadius) {
173
+ const isInnerRing = distance < (innerRadius + outerRadius) / 2;
174
+
175
+ // Calculate value based on angle
176
+ let value = Math.round((angle / 360) * 12);
177
+ if (value === 0) {
178
+ value = 12;
179
+ }
180
+
181
+ // Adjust for inner ring (add 12 hours)
182
+ if (isInnerRing) {
183
+ value = value === 12 ? 0 : value + 12;
184
+ }
185
+
186
+ return value;
187
+ }
188
+
189
+ // For standard 12h clock or minutes/seconds
190
+ let value = Math.round((angle / 360) * max);
191
+ if (value === max) {
192
+ value = 0;
193
+ }
194
+
195
+ return value;
196
+ };
197
+
198
+ /**
199
+ * Checks if a time is within min/max constraints
200
+ * @param {TimeValue} time - Time value to check
201
+ * @param {string} minTime - Minimum time in 24-hour format (HH:MM or HH:MM:SS)
202
+ * @param {string} maxTime - Maximum time in 24-hour format (HH:MM or HH:MM:SS)
203
+ * @returns {boolean} Whether the time is within constraints
204
+ */
205
+ export const isTimeWithinConstraints = (
206
+ time: TimeValue,
207
+ minTime?: string,
208
+ maxTime?: string
209
+ ): boolean => {
210
+ if (!minTime && !maxTime) {
211
+ return true;
212
+ }
213
+
214
+ const timeToCheck = time.hours * 3600 + time.minutes * 60 + (time.seconds || 0);
215
+
216
+ if (minTime) {
217
+ const minParts = minTime.split(':');
218
+ const minHours = parseInt(minParts[0], 10);
219
+ const minMinutes = parseInt(minParts[1], 10);
220
+ const minSeconds = minParts[2] ? parseInt(minParts[2], 10) : 0;
221
+ const minValue = minHours * 3600 + minMinutes * 60 + minSeconds;
222
+
223
+ if (timeToCheck < minValue) {
224
+ return false;
225
+ }
226
+ }
227
+
228
+ if (maxTime) {
229
+ const maxParts = maxTime.split(':');
230
+ const maxHours = parseInt(maxParts[0], 10);
231
+ const maxMinutes = parseInt(maxParts[1], 10);
232
+ const maxSeconds = maxParts[2] ? parseInt(maxParts[2], 10) : 0;
233
+ const maxValue = maxHours * 3600 + maxMinutes * 60 + maxSeconds;
234
+
235
+ if (timeToCheck > maxValue) {
236
+ return false;
237
+ }
238
+ }
239
+
240
+ return true;
241
+ };
@@ -1,6 +1,6 @@
1
1
  // src/components/tooltip/api.ts
2
2
  import { TooltipComponent } from './types';
3
- import { TOOLTIP_POSITIONS, DEFAULT_OFFSET, DEFAULT_ARROW_SIZE } from './constants';
3
+ import { TOOLTIP_POSITIONS, DEFAULT_OFFSET, DEFAULT_ARROW_SIZE } from './config';
4
4
 
5
5
  interface ApiOptions {
6
6
  lifecycle: {