mtrl 0.2.7 → 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 (164) 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/package.json +14 -3
  6. package/server.ts +86 -0
  7. package/src/components/badge/api.ts +23 -14
  8. package/src/components/badge/badge.ts +2 -2
  9. package/src/components/badge/config.ts +10 -11
  10. package/src/components/badge/features.ts +15 -10
  11. package/src/components/badge/index.ts +27 -2
  12. package/src/components/badge/types.ts +28 -8
  13. package/src/components/bottom-app-bar/bottom-app-bar.ts +2 -44
  14. package/src/components/bottom-app-bar/config.ts +1 -45
  15. package/src/components/bottom-app-bar/index.ts +7 -1
  16. package/src/components/bottom-app-bar/types.ts +7 -1
  17. package/src/components/button/button.ts +0 -1
  18. package/src/components/button/config.ts +1 -2
  19. package/src/components/button/index.ts +10 -2
  20. package/src/components/button/types.ts +14 -2
  21. package/src/components/card/config.ts +17 -9
  22. package/src/components/card/content.ts +8 -10
  23. package/src/components/card/features.ts +4 -6
  24. package/src/components/card/index.ts +29 -2
  25. package/src/components/card/types.ts +6 -23
  26. package/src/components/checkbox/config.ts +3 -4
  27. package/src/components/checkbox/index.ts +1 -2
  28. package/src/components/checkbox/types.ts +12 -3
  29. package/src/components/chip/api.ts +170 -221
  30. package/src/components/chip/chip.ts +34 -302
  31. package/src/components/chip/config.ts +1 -2
  32. package/src/components/chip/index.ts +10 -2
  33. package/src/components/chip/types.ts +224 -35
  34. package/src/components/datepicker/api.ts +18 -25
  35. package/src/components/datepicker/config.ts +9 -12
  36. package/src/components/datepicker/datepicker.ts +7 -12
  37. package/src/components/datepicker/index.ts +10 -7
  38. package/src/components/datepicker/render.ts +16 -18
  39. package/src/components/datepicker/types.ts +164 -35
  40. package/src/components/datepicker/utils.ts +1 -2
  41. package/src/components/dialog/api.ts +7 -8
  42. package/src/components/dialog/config.ts +3 -4
  43. package/src/components/dialog/features.ts +56 -22
  44. package/src/components/dialog/index.ts +38 -8
  45. package/src/components/dialog/types.ts +33 -10
  46. package/src/components/divider/index.ts +5 -1
  47. package/src/components/extended-fab/config.ts +6 -2
  48. package/src/components/extended-fab/index.ts +7 -2
  49. package/src/components/extended-fab/types.ts +21 -4
  50. package/src/components/fab/config.ts +3 -4
  51. package/src/components/fab/fab.ts +1 -1
  52. package/src/components/fab/index.ts +7 -2
  53. package/src/components/fab/types.ts +21 -4
  54. package/src/components/list/config.ts +4 -5
  55. package/src/components/list/features.ts +6 -7
  56. package/src/components/list/index.ts +7 -9
  57. package/src/components/list/list-item.ts +12 -13
  58. package/src/components/list/types.ts +50 -5
  59. package/src/components/list/utils.ts +30 -3
  60. package/src/components/menu/features/items-manager.ts +9 -9
  61. package/src/components/menu/features/positioning.ts +7 -7
  62. package/src/components/menu/features/visibility.ts +7 -7
  63. package/src/components/menu/index.ts +7 -9
  64. package/src/components/menu/menu-item.ts +6 -6
  65. package/src/components/menu/menu.ts +22 -0
  66. package/src/components/menu/types.ts +29 -10
  67. package/src/components/menu/utils.ts +67 -0
  68. package/src/components/navigation/config.ts +22 -10
  69. package/src/components/navigation/features/items.ts +31 -27
  70. package/src/components/navigation/index.ts +0 -6
  71. package/src/components/navigation/nav-item.ts +12 -24
  72. package/src/components/navigation/navigation.ts +4 -6
  73. package/src/components/navigation/types.ts +228 -203
  74. package/src/components/progress/api.ts +2 -3
  75. package/src/components/progress/config.ts +2 -3
  76. package/src/components/progress/index.ts +0 -1
  77. package/src/components/progress/progress.ts +1 -2
  78. package/src/components/progress/types.ts +186 -33
  79. package/src/components/radios/config.ts +1 -1
  80. package/src/components/radios/index.ts +0 -1
  81. package/src/components/radios/types.ts +0 -7
  82. package/src/components/search/config.ts +1 -2
  83. package/src/components/search/features/search.ts +14 -15
  84. package/src/components/search/features/states.ts +5 -1
  85. package/src/components/search/features/structure.ts +3 -4
  86. package/src/components/search/index.ts +0 -3
  87. package/src/components/search/types.ts +18 -6
  88. package/src/components/segmented-button/config.ts +20 -7
  89. package/src/components/segmented-button/segment.ts +6 -7
  90. package/src/components/segmented-button/segmented-button.ts +4 -5
  91. package/src/components/segmented-button/types.ts +37 -2
  92. package/src/components/slider/types.ts +34 -8
  93. package/src/components/snackbar/config.ts +2 -3
  94. package/src/components/snackbar/constants.ts +0 -32
  95. package/src/components/snackbar/index.ts +0 -1
  96. package/src/components/snackbar/position.ts +9 -1
  97. package/src/components/snackbar/types.ts +122 -46
  98. package/src/components/switch/config.ts +2 -3
  99. package/src/components/switch/index.ts +0 -1
  100. package/src/components/switch/types.ts +3 -2
  101. package/src/components/tabs/config.ts +3 -4
  102. package/src/components/tabs/index.ts +0 -15
  103. package/src/components/tabs/tab-api.ts +12 -4
  104. package/src/components/tabs/tab.ts +18 -6
  105. package/src/components/tabs/types.ts +13 -3
  106. package/src/components/textfield/config.ts +2 -3
  107. package/src/components/textfield/index.ts +0 -1
  108. package/src/components/textfield/types.ts +17 -3
  109. package/src/components/timepicker/api.ts +1 -1
  110. package/src/components/timepicker/clockdial.ts +1 -1
  111. package/src/components/timepicker/config.ts +102 -4
  112. package/src/components/timepicker/index.ts +1 -6
  113. package/src/components/timepicker/render.ts +1 -1
  114. package/src/components/timepicker/timepicker.ts +1 -1
  115. package/src/components/tooltip/api.ts +1 -1
  116. package/src/components/tooltip/config.ts +27 -6
  117. package/src/components/tooltip/index.ts +0 -1
  118. package/src/components/tooltip/types.ts +13 -3
  119. package/src/core/compose/features/textlabel.ts +0 -3
  120. package/src/{components/tabs/_styles.scss → styles/components/_tabs.scss} +1 -1
  121. package/src/{components/textfield/_styles.scss → styles/components/_textfield.scss} +70 -67
  122. package/src/styles/main.scss +98 -49
  123. package/src/components/badge/constants.ts +0 -40
  124. package/src/components/button/constants.ts +0 -11
  125. package/src/components/card/constants.ts +0 -84
  126. package/src/components/datepicker/constants.ts +0 -98
  127. package/src/components/dialog/constants.ts +0 -32
  128. package/src/components/extended-fab/constants.ts +0 -36
  129. package/src/components/fab/constants.ts +0 -41
  130. package/src/components/menu/constants.ts +0 -154
  131. package/src/components/navigation/constants.ts +0 -200
  132. package/src/components/progress/constants.ts +0 -29
  133. package/src/components/search/constants.ts +0 -21
  134. package/src/components/segmented-button/constants.ts +0 -42
  135. package/src/components/switch/constants.ts +0 -80
  136. package/src/components/tabs/constants.ts +0 -89
  137. package/src/components/timepicker/constants.ts +0 -138
  138. /package/src/{components/badge/_styles.scss → styles/components/_badge.scss} +0 -0
  139. /package/src/{components/bottom-app-bar/_styles.scss → styles/components/_bottom-app-bar.scss} +0 -0
  140. /package/src/{components/button/_styles.scss → styles/components/_button.scss} +0 -0
  141. /package/src/{components/card/_styles.scss → styles/components/_card.scss} +0 -0
  142. /package/src/{components/carousel/_styles.scss → styles/components/_carousel.scss} +0 -0
  143. /package/src/{components/checkbox/_styles.scss → styles/components/_checkbox.scss} +0 -0
  144. /package/src/{components/chip/_styles.scss → styles/components/_chip.scss} +0 -0
  145. /package/src/{components/datepicker/_styles.scss → styles/components/_datepicker.scss} +0 -0
  146. /package/src/{components/dialog/_styles.scss → styles/components/_dialog.scss} +0 -0
  147. /package/src/{components/divider/_styles.scss → styles/components/_divider.scss} +0 -0
  148. /package/src/{components/extended-fab/_styles.scss → styles/components/_extended-fab.scss} +0 -0
  149. /package/src/{components/fab/_styles.scss → styles/components/_fab.scss} +0 -0
  150. /package/src/{components/list/_styles.scss → styles/components/_list.scss} +0 -0
  151. /package/src/{components/menu/_styles.scss → styles/components/_menu.scss} +0 -0
  152. /package/src/{components/navigation/_styles.scss → styles/components/_navigation.scss} +0 -0
  153. /package/src/{components/progress/_styles.scss → styles/components/_progress.scss} +0 -0
  154. /package/src/{components/radios/_styles.scss → styles/components/_radios.scss} +0 -0
  155. /package/src/{components/search/_styles.scss → styles/components/_search.scss} +0 -0
  156. /package/src/{components/segmented-button/_styles.scss → styles/components/_segmented-button.scss} +0 -0
  157. /package/src/{components/sheet/_styles.scss → styles/components/_sheet.scss} +0 -0
  158. /package/src/{components/slider/_styles.scss → styles/components/_slider.scss} +0 -0
  159. /package/src/{components/snackbar/_styles.scss → styles/components/_snackbar.scss} +0 -0
  160. /package/src/{components/switch/_styles.scss → styles/components/_switch.scss} +0 -0
  161. /package/src/{components/timepicker/_styles.scss → styles/components/_timepicker.scss} +0 -0
  162. /package/src/{components/tooltip/_styles.scss → styles/components/_tooltip.scss} +0 -0
  163. /package/src/{components/top-app-bar/_styles.scss → styles/components/_top-app-bar.scss} +0 -0
  164. /package/src/styles/utilities/{_color.scss → _colors.scss} +0 -0
@@ -8,10 +8,8 @@ import {
8
8
  OUTSIDE_MONTH_CLASS,
9
9
  RANGE_START_CLASS,
10
10
  RANGE_END_CLASS,
11
- RANGE_MIDDLE_CLASS,
12
- DATEPICKER_VIEWS,
13
- DATEPICKER_VARIANTS
14
- } from './constants';
11
+ RANGE_MIDDLE_CLASS
12
+ } from './types';
15
13
  import { CalendarDate } from './types';
16
14
  import {
17
15
  generateCalendarDates,
@@ -71,8 +69,8 @@ export const renderHeader = ({
71
69
  html: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"></polyline></svg>',
72
70
  attrs: {
73
71
  type: 'button',
74
- 'aria-label': currentView === DATEPICKER_VIEWS.DAY ? 'Previous month' :
75
- currentView === DATEPICKER_VIEWS.MONTH ? 'Previous year' : 'Previous year range'
72
+ 'aria-label': currentView === 'day' ? 'Previous month' :
73
+ currentView === 'month' ? 'Previous year' : 'Previous year range'
76
74
  }
77
75
  });
78
76
 
@@ -83,8 +81,8 @@ export const renderHeader = ({
83
81
  html: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>',
84
82
  attrs: {
85
83
  type: 'button',
86
- 'aria-label': currentView === DATEPICKER_VIEWS.DAY ? 'Next month' :
87
- currentView === DATEPICKER_VIEWS.MONTH ? 'Next year' : 'Next year range'
84
+ 'aria-label': currentView === 'day' ? 'Next month' :
85
+ currentView === 'month' ? 'Next year' : 'Next year range'
88
86
  }
89
87
  });
90
88
 
@@ -92,22 +90,22 @@ export const renderHeader = ({
92
90
  monthButton.addEventListener('click', (event) => {
93
91
  // Prevent event from bubbling up
94
92
  event.stopPropagation();
95
- emit('viewChange', { view: DATEPICKER_VIEWS.MONTH });
93
+ emit('viewChange', { view: 'month' });
96
94
  });
97
95
 
98
96
  yearButton.addEventListener('click', (event) => {
99
97
  // Prevent event from bubbling up
100
98
  event.stopPropagation();
101
- emit('viewChange', { view: DATEPICKER_VIEWS.YEAR });
99
+ emit('viewChange', { view: 'year' });
102
100
  });
103
101
 
104
102
  prevButton.addEventListener('click', (event) => {
105
103
  // Prevent event from bubbling up
106
104
  event.stopPropagation();
107
105
 
108
- if (currentView === DATEPICKER_VIEWS.DAY) {
106
+ if (currentView === 'day') {
109
107
  emit('prevMonth');
110
- } else if (currentView === DATEPICKER_VIEWS.MONTH) {
108
+ } else if (currentView === 'month') {
111
109
  emit('prevYear');
112
110
  } else {
113
111
  emit('prevYearRange');
@@ -118,9 +116,9 @@ export const renderHeader = ({
118
116
  // Prevent event from bubbling up
119
117
  event.stopPropagation();
120
118
 
121
- if (currentView === DATEPICKER_VIEWS.DAY) {
119
+ if (currentView === 'day') {
122
120
  emit('nextMonth');
123
- } else if (currentView === DATEPICKER_VIEWS.MONTH) {
121
+ } else if (currentView === 'month') {
124
122
  emit('nextYear');
125
123
  } else {
126
124
  emit('nextYearRange');
@@ -406,7 +404,7 @@ export const renderCalendar = (state: any, emit: Function): HTMLElement => {
406
404
  calendar.appendChild(header);
407
405
 
408
406
  // Render content based on current view
409
- if (currentView === DATEPICKER_VIEWS.DAY) {
407
+ if (currentView === 'day') {
410
408
  const weekdays = renderWeekdays(prefix);
411
409
  calendar.appendChild(weekdays);
412
410
 
@@ -421,7 +419,7 @@ export const renderCalendar = (state: any, emit: Function): HTMLElement => {
421
419
  emit
422
420
  });
423
421
  calendar.appendChild(days);
424
- } else if (currentView === DATEPICKER_VIEWS.MONTH) {
422
+ } else if (currentView === 'month') {
425
423
  const months = renderMonthSelection({
426
424
  currentYear,
427
425
  currentMonth,
@@ -429,7 +427,7 @@ export const renderCalendar = (state: any, emit: Function): HTMLElement => {
429
427
  emit
430
428
  });
431
429
  calendar.appendChild(months);
432
- } else if (currentView === DATEPICKER_VIEWS.YEAR) {
430
+ } else if (currentView === 'year') {
433
431
  const years = renderYearSelection({
434
432
  currentYear,
435
433
  prefix,
@@ -439,7 +437,7 @@ export const renderCalendar = (state: any, emit: Function): HTMLElement => {
439
437
  }
440
438
 
441
439
  // Only add footer for modal variants
442
- if (variant !== DATEPICKER_VARIANTS.DOCKED) {
440
+ if (variant !== 'docked') {
443
441
  const footer = renderFooter({
444
442
  variant,
445
443
  prefix,
@@ -1,9 +1,90 @@
1
1
  // src/components/datepicker/types.ts
2
- import {
3
- DATEPICKER_VARIANTS,
4
- DATEPICKER_VIEWS,
5
- DATEPICKER_SELECTION_MODES
6
- } from './constants';
2
+
3
+ /**
4
+ * DatePicker variant types
5
+ * @category Components
6
+ */
7
+ export type DatePickerVariant = 'docked' | 'modal' | 'modal-input';
8
+
9
+ /**
10
+ * DatePicker view types
11
+ * @category Components
12
+ */
13
+ export type DatePickerView = 'day' | 'month' | 'year';
14
+
15
+ /**
16
+ * DatePicker selection mode types
17
+ * @category Components
18
+ */
19
+ export type DatePickerSelectionMode = 'single' | 'range';
20
+
21
+ /**
22
+ * Day names for the calendar
23
+ * @internal
24
+ */
25
+ export const DAY_NAMES = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
26
+
27
+ /**
28
+ * Month names for the calendar
29
+ * @internal
30
+ */
31
+ export const MONTH_NAMES = [
32
+ 'January', 'February', 'March', 'April',
33
+ 'May', 'June', 'July', 'August',
34
+ 'September', 'October', 'November', 'December'
35
+ ];
36
+
37
+ /**
38
+ * Month names abbreviated
39
+ * @internal
40
+ */
41
+ export const MONTH_NAMES_SHORT = [
42
+ 'Jan', 'Feb', 'Mar', 'Apr',
43
+ 'May', 'Jun', 'Jul', 'Aug',
44
+ 'Sep', 'Oct', 'Nov', 'Dec'
45
+ ];
46
+
47
+ /**
48
+ * Default format for displaying dates
49
+ * @internal
50
+ */
51
+ export const DEFAULT_DATE_FORMAT = 'MM/DD/YYYY';
52
+
53
+ /**
54
+ * CSS class name for today's date
55
+ * @internal
56
+ */
57
+ export const TODAY_CLASS = 'today';
58
+
59
+ /**
60
+ * CSS class name for selected date
61
+ * @internal
62
+ */
63
+ export const SELECTED_CLASS = 'selected';
64
+
65
+ /**
66
+ * CSS class name for dates outside the current month
67
+ * @internal
68
+ */
69
+ export const OUTSIDE_MONTH_CLASS = 'outside-month';
70
+
71
+ /**
72
+ * CSS class for the first date in a range
73
+ * @internal
74
+ */
75
+ export const RANGE_START_CLASS = 'range-start';
76
+
77
+ /**
78
+ * CSS class for the last date in a range
79
+ * @internal
80
+ */
81
+ export const RANGE_END_CLASS = 'range-end';
82
+
83
+ /**
84
+ * CSS class for dates between start and end in a range
85
+ * @internal
86
+ */
87
+ export const RANGE_MIDDLE_CLASS = 'range-middle';
7
88
 
8
89
  /**
9
90
  * Configuration interface for the DatePicker component
@@ -14,7 +95,7 @@ export interface DatePickerConfig {
14
95
  * DatePicker variant that determines display style
15
96
  * @default 'docked'
16
97
  */
17
- variant?: keyof typeof DATEPICKER_VARIANTS | string;
98
+ variant?: DatePickerVariant | string;
18
99
 
19
100
  /**
20
101
  * Whether the datepicker is initially disabled
@@ -26,13 +107,13 @@ export interface DatePickerConfig {
26
107
  * Initial view to display (day, month, year)
27
108
  * @default 'day'
28
109
  */
29
- initialView?: keyof typeof DATEPICKER_VIEWS | string;
110
+ initialView?: DatePickerView | string;
30
111
 
31
112
  /**
32
113
  * Selection mode for the datepicker (single or range)
33
114
  * @default 'single'
34
115
  */
35
- selectionMode?: keyof typeof DATEPICKER_SELECTION_MODES | string;
116
+ selectionMode?: DatePickerSelectionMode | string;
36
117
 
37
118
  /**
38
119
  * Initial selected date(s)
@@ -141,6 +222,39 @@ export interface CalendarDate {
141
222
  isRangeMiddle?: boolean;
142
223
  }
143
224
 
225
+ /**
226
+ * Calendar API interface for managing calendar navigation
227
+ * @category Components
228
+ */
229
+ export interface CalendarAPI {
230
+ /** Updates the calendar view to display a specific month/year */
231
+ goToDate: (date: Date) => void;
232
+
233
+ /** Moves to the next month */
234
+ nextMonth: () => void;
235
+
236
+ /** Moves to the previous month */
237
+ prevMonth: () => void;
238
+
239
+ /** Moves to the next year */
240
+ nextYear: () => void;
241
+
242
+ /** Moves to the previous year */
243
+ prevYear: () => void;
244
+
245
+ /** Switches to day selection view */
246
+ showDayView: () => void;
247
+
248
+ /** Switches to month selection view */
249
+ showMonthView: () => void;
250
+
251
+ /** Switches to year selection view */
252
+ showYearView: () => void;
253
+
254
+ /** Gets the current calendar view */
255
+ getCurrentView: () => string;
256
+ }
257
+
144
258
  /**
145
259
  * DatePicker component interface
146
260
  * @category Components
@@ -153,35 +267,31 @@ export interface DatePickerComponent {
153
267
  input: HTMLInputElement;
154
268
 
155
269
  /** API for managing calendar and selected dates */
156
- calendar: {
157
- /** Updates the calendar view to display a specific month/year */
158
- goToDate: (date: Date) => void;
159
-
160
- /** Moves to the next month */
161
- nextMonth: () => void;
162
-
163
- /** Moves to the previous month */
164
- prevMonth: () => void;
165
-
166
- /** Moves to the next year */
167
- nextYear: () => void;
168
-
169
- /** Moves to the previous year */
170
- prevYear: () => void;
171
-
172
- /** Switches to day selection view */
173
- showDayView: () => void;
174
-
175
- /** Switches to month selection view */
176
- showMonthView: () => void;
177
-
178
- /** Switches to year selection view */
179
- showYearView: () => void;
180
-
181
- /** Gets the current calendar view */
182
- getCurrentView: () => string;
270
+ calendar: CalendarAPI;
271
+
272
+ /** API for managing disabled state */
273
+ disabled: {
274
+ /** Enables the datepicker */
275
+ enable: () => void;
276
+ /** Disables the datepicker */
277
+ disable: () => void;
278
+ /** Checks if the datepicker is disabled */
279
+ isDisabled: () => boolean;
280
+ };
281
+
282
+ /** API for managing component lifecycle */
283
+ lifecycle: {
284
+ /** Destroys the component and cleans up resources */
285
+ destroy: () => void;
183
286
  };
184
287
 
288
+ /**
289
+ * Gets a class name with the component's prefix
290
+ * @param name - Base class name
291
+ * @returns Prefixed class name
292
+ */
293
+ getClass: (name: string) => string;
294
+
185
295
  /**
186
296
  * Opens the datepicker dropdown/modal
187
297
  * @returns The datepicker component for chaining
@@ -265,4 +375,23 @@ export interface DatePickerComponent {
265
375
  * @returns The datepicker component for chaining
266
376
  */
267
377
  off: (event: string, handler: Function) => DatePickerComponent;
378
+ }
379
+
380
+ /**
381
+ * API options interface for withAPI function
382
+ * @internal
383
+ */
384
+ export interface ApiOptions {
385
+ disabled: {
386
+ enable: () => void;
387
+ disable: () => void;
388
+ };
389
+ lifecycle: {
390
+ destroy: () => void;
391
+ };
392
+ events: {
393
+ on: (event: string, handler: Function) => any;
394
+ off: (event: string, handler: Function) => any;
395
+ emit: (event: string, data: any) => any;
396
+ };
268
397
  }
@@ -1,6 +1,5 @@
1
1
  // src/components/datepicker/utils.ts
2
- import { CalendarDate } from './types';
3
- import { MONTH_NAMES, MONTH_NAMES_SHORT } from './constants';
2
+ import { CalendarDate, MONTH_NAMES, MONTH_NAMES_SHORT } from './types';
4
3
 
5
4
  /**
6
5
  * Parses a date from various input types
@@ -1,6 +1,5 @@
1
1
  // src/components/dialog/api.ts (partial update)
2
- import { DialogComponent, DialogEvent, DialogButton, DialogConfirmOptions } from './types';
3
- import { DIALOG_SIZES, DIALOG_ANIMATIONS, DIALOG_FOOTER_ALIGNMENTS, DIALOG_EVENTS } from './constants';
2
+ import { DialogComponent, DialogEvent, DialogButton, DialogConfirmOptions, DialogFooterAlignment, DialogSize, DialogEventType } from './types';
4
3
  import { removeClass } from '../../core/dom/classes';
5
4
 
6
5
  interface ApiOptions {
@@ -25,14 +24,14 @@ interface ApiOptions {
25
24
  addButton: (button: DialogButton) => void;
26
25
  removeButton: (indexOrText: number | string) => void;
27
26
  getButtons: () => DialogButton[];
28
- setFooterAlignment: (alignment: keyof typeof DIALOG_FOOTER_ALIGNMENTS | DIALOG_FOOTER_ALIGNMENTS) => void;
27
+ setFooterAlignment: (alignment: DialogFooterAlignment | string) => void;
29
28
  };
30
29
  focus: {
31
30
  trapFocus: () => void;
32
31
  releaseFocus: () => void;
33
32
  };
34
33
  size: {
35
- setSize: (size: keyof typeof DIALOG_SIZES | DIALOG_SIZES) => void;
34
+ setSize: (size: DialogSize | string) => void;
36
35
  };
37
36
  dividers: {
38
37
  toggleHeaderDivider: (show: boolean) => void;
@@ -188,7 +187,7 @@ export const withAPI = (options: ApiOptions) =>
188
187
  * @param {string} alignment - Footer alignment
189
188
  * @returns {DialogComponent} Dialog component instance for chaining
190
189
  */
191
- setFooterAlignment(alignment: keyof typeof DIALOG_FOOTER_ALIGNMENTS | DIALOG_FOOTER_ALIGNMENTS) {
190
+ setFooterAlignment(alignment: DialogFooterAlignment | string) {
192
191
  options.buttons.setFooterAlignment(alignment);
193
192
  return this;
194
193
  },
@@ -216,7 +215,7 @@ export const withAPI = (options: ApiOptions) =>
216
215
  * @param {string} size - Size variant
217
216
  * @returns {DialogComponent} Dialog component instance for chaining
218
217
  */
219
- setSize(size: keyof typeof DIALOG_SIZES | DIALOG_SIZES) {
218
+ setSize(size: DialogSize | string) {
220
219
  options.size.setSize(size);
221
220
  return this;
222
221
  },
@@ -227,7 +226,7 @@ export const withAPI = (options: ApiOptions) =>
227
226
  * @param {Function} handler - Event handler
228
227
  * @returns {DialogComponent} Dialog component instance for chaining
229
228
  */
230
- on(event: keyof typeof DIALOG_EVENTS | DIALOG_EVENTS, handler: (event: DialogEvent) => void) {
229
+ on(event: DialogEventType | string, handler: (event: DialogEvent) => void) {
231
230
  options.events.on(event, handler);
232
231
  return this;
233
232
  },
@@ -238,7 +237,7 @@ export const withAPI = (options: ApiOptions) =>
238
237
  * @param {Function} handler - Event handler
239
238
  * @returns {DialogComponent} Dialog component instance for chaining
240
239
  */
241
- off(event: keyof typeof DIALOG_EVENTS | DIALOG_EVENTS, handler: (event: DialogEvent) => void) {
240
+ off(event: DialogEventType | string, handler: (event: DialogEvent) => void) {
242
241
  options.events.off(event, handler);
243
242
  return this;
244
243
  },
@@ -4,15 +4,14 @@ import {
4
4
  createElementConfig
5
5
  } from '../../core/config/component-config';
6
6
  import { DialogConfig } from './types';
7
- import { DIALOG_SIZES, DIALOG_ANIMATIONS, DIALOG_FOOTER_ALIGNMENTS } from './constants';
8
7
 
9
8
  /**
10
9
  * Default configuration for the Dialog component
11
10
  */
12
11
  export const defaultConfig: DialogConfig = {
13
- size: DIALOG_SIZES.MEDIUM,
14
- animation: DIALOG_ANIMATIONS.SCALE,
15
- footerAlignment: DIALOG_FOOTER_ALIGNMENTS.RIGHT,
12
+ size: 'medium',
13
+ animation: 'scale',
14
+ footerAlignment: 'right',
16
15
  open: false,
17
16
  closeButton: true,
18
17
  closeOnOverlayClick: true,
@@ -1,13 +1,40 @@
1
1
  // src/components/dialog/features.ts (partial updated code)
2
2
 
3
3
  import { getOverlayConfig } from './config';
4
- import { DIALOG_SIZES, DIALOG_ANIMATIONS, DIALOG_FOOTER_ALIGNMENTS, DIALOG_EVENTS } from './constants';
5
- import { DialogConfig, DialogButton, DialogEvent } from './types';
4
+ import { DialogConfig, DialogButton } from './types';
6
5
  import createButton from '../button';
7
6
  import { createDivider } from '../divider'; // Import the divider component
8
- import { BUTTON_VARIANTS } from '../button/constants';
9
7
  import { addClass, removeClass, hasClass } from '../../core/dom/classes';
10
8
 
9
+ // Common constants for internal use
10
+ const SIZE_MEDIUM = 'medium';
11
+ const ANIMATION_SCALE = 'scale';
12
+ const FOOTER_ALIGNMENT_RIGHT = 'right';
13
+ const EVENT_BEFORE_OPEN = 'beforeopen';
14
+ const EVENT_OPEN = 'open';
15
+ const EVENT_AFTER_OPEN = 'afteropen';
16
+ const EVENT_BEFORE_CLOSE = 'beforeclose';
17
+ const EVENT_CLOSE = 'close';
18
+ const EVENT_AFTER_CLOSE = 'afterclose';
19
+
20
+ // Common button variants for internal use
21
+ const BUTTON_VARIANT_TEXT = 'text';
22
+ const BUTTON_VARIANT_FILLED = 'filled';
23
+
24
+ // Arrays for class management
25
+ const ALL_SIZES = ['small', 'medium', 'large', 'fullwidth', 'fullscreen'];
26
+ const ALL_ANIMATIONS = ['scale', 'slide-up', 'slide-down', 'fade'];
27
+ const ALL_FOOTER_ALIGNMENTS = ['right', 'left', 'center', 'space-between'];
28
+
29
+ const DIALOG_EVENTS = {
30
+ OPEN: 'open',
31
+ CLOSE: 'close',
32
+ BEFORE_OPEN: 'beforeopen',
33
+ BEFORE_CLOSE: 'beforeclose',
34
+ AFTER_OPEN: 'afteropen',
35
+ AFTER_CLOSE: 'afterclose'
36
+ };
37
+
11
38
  /**
12
39
  * Creates the dialog DOM structure with proper divider handling
13
40
  * @param config Dialog configuration
@@ -102,8 +129,8 @@ export const withStructure = (config: DialogConfig) => component => {
102
129
  footer.classList.add(component.getClass('dialog-footer'));
103
130
 
104
131
  // Apply footer alignment
105
- const alignment = config.footerAlignment || DIALOG_FOOTER_ALIGNMENTS.RIGHT;
106
- if (alignment !== DIALOG_FOOTER_ALIGNMENTS.RIGHT) {
132
+ const alignment = config.footerAlignment || 'right';
133
+ if (alignment !== 'right') {
107
134
  addClass(footer, `${component.getClass('dialog-footer')}--${alignment}`);
108
135
  }
109
136
 
@@ -132,14 +159,14 @@ export const withStructure = (config: DialogConfig) => component => {
132
159
  addClass(component.element, component.getClass('dialog'));
133
160
 
134
161
  // Apply size class
135
- const size = config.size || DIALOG_SIZES.MEDIUM;
136
- if (size !== DIALOG_SIZES.MEDIUM) {
162
+ const size = config.size || 'medium';
163
+ if (size !== 'medium') {
137
164
  addClass(component.element, `${component.getClass('dialog')}--${size}`);
138
165
  }
139
166
 
140
167
  // Apply animation class
141
- const animation = config.animation || DIALOG_ANIMATIONS.SCALE;
142
- if (animation !== DIALOG_ANIMATIONS.SCALE) {
168
+ const animation = config.animation || 'scale';
169
+ if (animation !== 'scale') {
143
170
  addClass(component.element, `${component.getClass('dialog')}--${animation}`);
144
171
  }
145
172
 
@@ -282,7 +309,7 @@ export const withDivider = () => component => {
282
309
  const addButton = (footer: HTMLElement, buttonConfig: DialogButton, component: any) => {
283
310
  const {
284
311
  text,
285
- variant = BUTTON_VARIANTS.TEXT,
312
+ variant = 'text', // Using string literal directly instead of BUTTON_VARIANTS.TEXT
286
313
  onClick,
287
314
  closeDialog = true,
288
315
  autofocus = false,
@@ -718,8 +745,8 @@ export const withButtons = () => component => {
718
745
  footer.classList.add(component.getClass('dialog-footer'));
719
746
 
720
747
  // Apply footer alignment
721
- const alignment = component.config.footerAlignment || DIALOG_FOOTER_ALIGNMENTS.RIGHT;
722
- if (alignment !== DIALOG_FOOTER_ALIGNMENTS.RIGHT) {
748
+ const alignment = component.config.footerAlignment || 'right';
749
+ if (alignment !== 'right') {
723
750
  addClass(footer, `${component.getClass('dialog-footer')}--${alignment}`);
724
751
  }
725
752
 
@@ -774,18 +801,21 @@ export const withButtons = () => component => {
774
801
  * Sets footer alignment
775
802
  * @param alignment Footer alignment
776
803
  */
777
- setFooterAlignment(alignment: keyof typeof DIALOG_FOOTER_ALIGNMENTS | DIALOG_FOOTER_ALIGNMENTS) {
804
+ setFooterAlignment(alignment: string) {
778
805
  if (!component.structure.footer) return;
779
806
 
807
+ // Define all possible alignments
808
+ const ALL_ALIGNMENTS = ['right', 'left', 'center', 'space-between'];
809
+
780
810
  // Remove existing alignment classes
781
- Object.values(DIALOG_FOOTER_ALIGNMENTS).forEach(align => {
782
- if (align !== DIALOG_FOOTER_ALIGNMENTS.RIGHT) {
811
+ ALL_ALIGNMENTS.forEach(align => {
812
+ if (align !== 'right') {
783
813
  removeClass(component.structure.footer, `${component.getClass('dialog-footer')}--${align}`);
784
814
  }
785
815
  });
786
816
 
787
817
  // Add new alignment class if not right (default)
788
- if (alignment !== DIALOG_FOOTER_ALIGNMENTS.RIGHT) {
818
+ if (alignment !== 'right') {
789
819
  addClass(component.structure.footer, `${component.getClass('dialog-footer')}--${alignment}`);
790
820
  }
791
821
  }
@@ -805,14 +835,17 @@ export const withSize = () => component => {
805
835
  * Sets dialog size
806
836
  * @param size Size variant
807
837
  */
808
- setSize(size: keyof typeof DIALOG_SIZES | DIALOG_SIZES) {
838
+ setSize(size: string) {
839
+ // Define all possible sizes
840
+ const ALL_SIZES = ['small', 'medium', 'large', 'fullwidth', 'fullscreen'];
841
+
809
842
  // Remove existing size classes
810
- Object.values(DIALOG_SIZES).forEach(sizeValue => {
843
+ ALL_SIZES.forEach(sizeValue => {
811
844
  removeClass(component.element, `${component.getClass('dialog')}--${sizeValue}`);
812
845
  });
813
846
 
814
847
  // Add new size class if not medium (default)
815
- if (size !== DIALOG_SIZES.MEDIUM) {
848
+ if (size !== 'medium') {
816
849
  addClass(component.element, `${component.getClass('dialog')}--${size}`);
817
850
  }
818
851
  }
@@ -834,9 +867,10 @@ export const withConfirm = () => component => {
834
867
  message,
835
868
  confirmText = 'Yes',
836
869
  cancelText = 'No',
837
- confirmVariant = BUTTON_VARIANTS.FILLED,
838
- cancelVariant = BUTTON_VARIANTS.TEXT,
839
- size = DIALOG_SIZES.SMALL
870
+ // Use string literals directly
871
+ confirmVariant = 'filled',
872
+ cancelVariant = 'text',
873
+ size = 'small'
840
874
  } = options;
841
875
 
842
876
  // Set dialog properties
@@ -1,15 +1,45 @@
1
1
  // src/components/dialog/index.ts
2
2
  export { default } from './dialog';
3
- export {
4
- DIALOG_SIZES,
5
- DIALOG_ANIMATIONS,
6
- DIALOG_FOOTER_ALIGNMENTS,
7
- DIALOG_EVENTS
8
- } from './constants';
9
3
  export {
10
4
  DialogConfig,
11
5
  DialogComponent,
12
6
  DialogButton,
13
7
  DialogEvent,
14
- DialogConfirmOptions
15
- } from './types';
8
+ DialogConfirmOptions,
9
+ DialogSize,
10
+ DialogAnimation,
11
+ DialogFooterAlignment,
12
+ DialogEventType
13
+ } from './types';
14
+
15
+ // Export common dialog constants for convenience and backward compatibility
16
+ export const DIALOG_SIZES = {
17
+ SMALL: 'small',
18
+ MEDIUM: 'medium',
19
+ LARGE: 'large',
20
+ FULLWIDTH: 'fullwidth',
21
+ FULLSCREEN: 'fullscreen'
22
+ } as const;
23
+
24
+ export const DIALOG_ANIMATIONS = {
25
+ SCALE: 'scale',
26
+ SLIDE_UP: 'slide-up',
27
+ SLIDE_DOWN: 'slide-down',
28
+ FADE: 'fade'
29
+ } as const;
30
+
31
+ export const DIALOG_FOOTER_ALIGNMENTS = {
32
+ RIGHT: 'right',
33
+ LEFT: 'left',
34
+ CENTER: 'center',
35
+ SPACE_BETWEEN: 'space-between'
36
+ } as const;
37
+
38
+ export const DIALOG_EVENTS = {
39
+ OPEN: 'open',
40
+ CLOSE: 'close',
41
+ BEFORE_OPEN: 'beforeopen',
42
+ BEFORE_CLOSE: 'beforeclose',
43
+ AFTER_OPEN: 'afteropen',
44
+ AFTER_CLOSE: 'afterclose'
45
+ } as const;