mtrl 0.2.7 → 0.2.9
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.
- package/index.ts +2 -0
- package/package.json +14 -3
- package/src/components/badge/api.ts +23 -14
- package/src/components/badge/badge.ts +2 -2
- package/src/components/badge/config.ts +10 -11
- package/src/components/badge/features.ts +15 -10
- package/src/components/badge/index.ts +27 -2
- package/src/components/badge/types.ts +28 -8
- package/src/components/bottom-app-bar/bottom-app-bar.ts +2 -44
- package/src/components/bottom-app-bar/config.ts +1 -45
- package/src/components/bottom-app-bar/index.ts +7 -1
- package/src/components/bottom-app-bar/types.ts +7 -1
- package/src/components/button/button.ts +0 -1
- package/src/components/button/config.ts +1 -2
- package/src/components/button/index.ts +10 -2
- package/src/components/button/types.ts +14 -2
- package/src/components/card/config.ts +17 -9
- package/src/components/card/content.ts +8 -10
- package/src/components/card/features.ts +4 -6
- package/src/components/card/index.ts +29 -2
- package/src/components/card/types.ts +6 -23
- package/src/components/checkbox/config.ts +3 -4
- package/src/components/checkbox/index.ts +1 -2
- package/src/components/checkbox/types.ts +12 -3
- package/src/components/chip/api.ts +170 -221
- package/src/components/chip/chip.ts +34 -302
- package/src/components/chip/config.ts +1 -2
- package/src/components/chip/index.ts +10 -2
- package/src/components/chip/types.ts +224 -35
- package/src/components/datepicker/api.ts +18 -25
- package/src/components/datepicker/config.ts +9 -12
- package/src/components/datepicker/datepicker.ts +7 -12
- package/src/components/datepicker/index.ts +10 -7
- package/src/components/datepicker/render.ts +16 -18
- package/src/components/datepicker/types.ts +164 -35
- package/src/components/datepicker/utils.ts +1 -2
- package/src/components/dialog/api.ts +7 -8
- package/src/components/dialog/config.ts +3 -4
- package/src/components/dialog/features.ts +56 -22
- package/src/components/dialog/index.ts +38 -8
- package/src/components/dialog/types.ts +33 -10
- package/src/components/divider/index.ts +5 -1
- package/src/components/extended-fab/config.ts +6 -2
- package/src/components/extended-fab/index.ts +7 -2
- package/src/components/extended-fab/types.ts +21 -4
- package/src/components/fab/config.ts +3 -4
- package/src/components/fab/fab.ts +1 -1
- package/src/components/fab/index.ts +7 -2
- package/src/components/fab/types.ts +21 -4
- package/src/components/list/config.ts +4 -5
- package/src/components/list/features.ts +6 -7
- package/src/components/list/index.ts +7 -9
- package/src/components/list/list-item.ts +12 -13
- package/src/components/list/types.ts +50 -5
- package/src/components/list/utils.ts +30 -3
- package/src/components/menu/features/items-manager.ts +9 -9
- package/src/components/menu/features/positioning.ts +7 -7
- package/src/components/menu/features/visibility.ts +7 -7
- package/src/components/menu/index.ts +7 -9
- package/src/components/menu/menu-item.ts +6 -6
- package/src/components/menu/menu.ts +22 -0
- package/src/components/menu/types.ts +29 -10
- package/src/components/menu/utils.ts +67 -0
- package/src/components/navigation/api.ts +131 -96
- package/src/components/navigation/config.ts +22 -10
- package/src/components/navigation/features/controller.ts +273 -0
- package/src/components/navigation/features/items.ts +160 -87
- package/src/components/navigation/index.ts +0 -6
- package/src/components/navigation/nav-item.ts +12 -24
- package/src/components/navigation/navigation.ts +21 -8
- package/src/components/navigation/system-types.ts +124 -0
- package/src/components/navigation/system.ts +776 -0
- package/src/components/navigation/types.ts +228 -203
- package/src/components/progress/api.ts +2 -3
- package/src/components/progress/config.ts +2 -3
- package/src/components/progress/index.ts +0 -1
- package/src/components/progress/progress.ts +1 -2
- package/src/components/progress/types.ts +186 -33
- package/src/components/radios/config.ts +1 -1
- package/src/components/radios/index.ts +0 -1
- package/src/components/radios/types.ts +0 -7
- package/src/components/search/config.ts +1 -2
- package/src/components/search/features/search.ts +14 -15
- package/src/components/search/features/states.ts +5 -1
- package/src/components/search/features/structure.ts +3 -4
- package/src/components/search/index.ts +0 -3
- package/src/components/search/types.ts +18 -6
- package/src/components/segmented-button/config.ts +20 -7
- package/src/components/segmented-button/segment.ts +6 -7
- package/src/components/segmented-button/segmented-button.ts +4 -5
- package/src/components/segmented-button/types.ts +37 -2
- package/src/components/slider/config.ts +20 -2
- package/src/components/slider/features/controller.ts +761 -0
- package/src/components/slider/features/handlers.ts +18 -15
- package/src/components/slider/features/index.ts +3 -2
- package/src/components/slider/features/range.ts +104 -0
- package/src/components/slider/slider.ts +34 -14
- package/src/components/slider/structure.ts +152 -0
- package/src/components/slider/types.ts +34 -8
- package/src/components/snackbar/config.ts +2 -3
- package/src/components/snackbar/constants.ts +0 -32
- package/src/components/snackbar/index.ts +0 -1
- package/src/components/snackbar/position.ts +9 -1
- package/src/components/snackbar/types.ts +122 -46
- package/src/components/switch/config.ts +2 -3
- package/src/components/switch/index.ts +0 -1
- package/src/components/switch/types.ts +3 -2
- package/src/components/tabs/config.ts +3 -4
- package/src/components/tabs/index.ts +0 -15
- package/src/components/tabs/tab-api.ts +12 -4
- package/src/components/tabs/tab.ts +18 -6
- package/src/components/tabs/types.ts +13 -3
- package/src/components/textfield/api.ts +53 -0
- package/src/components/textfield/config.ts +2 -3
- package/src/components/textfield/features.ts +322 -0
- package/src/components/textfield/index.ts +0 -1
- package/src/components/textfield/textfield.ts +8 -0
- package/src/components/textfield/types.ts +29 -6
- package/src/components/timepicker/api.ts +1 -1
- package/src/components/timepicker/clockdial.ts +2 -5
- package/src/components/timepicker/config.ts +102 -4
- package/src/components/timepicker/index.ts +1 -6
- package/src/components/timepicker/render.ts +1 -1
- package/src/components/timepicker/timepicker.ts +1 -1
- package/src/components/tooltip/api.ts +1 -1
- package/src/components/tooltip/config.ts +27 -6
- package/src/components/tooltip/index.ts +0 -1
- package/src/components/tooltip/types.ts +13 -3
- package/src/core/compose/features/textinput.ts +15 -2
- package/src/core/compose/features/textlabel.ts +0 -3
- package/src/core/composition/features/dom.ts +33 -0
- package/src/core/composition/features/icon.ts +131 -0
- package/src/core/composition/features/index.ts +11 -0
- package/src/core/composition/features/label.ts +156 -0
- package/src/core/composition/features/structure.ts +22 -0
- package/src/core/composition/index.ts +26 -0
- package/src/core/index.ts +1 -1
- package/src/core/structure.ts +288 -0
- package/src/index.ts +1 -0
- package/src/styles/components/_navigation-mobile.scss +244 -0
- package/src/styles/components/_navigation-system.scss +151 -0
- package/src/{components/tabs/_styles.scss → styles/components/_tabs.scss} +1 -1
- package/src/{components/textfield/_styles.scss → styles/components/_textfield.scss} +314 -72
- package/src/styles/main.scss +98 -49
- package/src/components/badge/constants.ts +0 -40
- package/src/components/button/constants.ts +0 -11
- package/src/components/card/constants.ts +0 -84
- package/src/components/datepicker/constants.ts +0 -98
- package/src/components/dialog/constants.ts +0 -32
- package/src/components/extended-fab/constants.ts +0 -36
- package/src/components/fab/constants.ts +0 -41
- package/src/components/menu/constants.ts +0 -154
- package/src/components/navigation/constants.ts +0 -200
- package/src/components/progress/constants.ts +0 -29
- package/src/components/search/constants.ts +0 -21
- package/src/components/segmented-button/constants.ts +0 -42
- package/src/components/slider/features/slider.ts +0 -318
- package/src/components/slider/features/structure.ts +0 -181
- package/src/components/slider/features/ui.ts +0 -388
- package/src/components/switch/constants.ts +0 -80
- package/src/components/tabs/constants.ts +0 -89
- package/src/components/textfield/constants.ts +0 -100
- package/src/components/timepicker/constants.ts +0 -138
- /package/src/{components/badge/_styles.scss → styles/components/_badge.scss} +0 -0
- /package/src/{components/bottom-app-bar/_styles.scss → styles/components/_bottom-app-bar.scss} +0 -0
- /package/src/{components/button/_styles.scss → styles/components/_button.scss} +0 -0
- /package/src/{components/card/_styles.scss → styles/components/_card.scss} +0 -0
- /package/src/{components/carousel/_styles.scss → styles/components/_carousel.scss} +0 -0
- /package/src/{components/checkbox/_styles.scss → styles/components/_checkbox.scss} +0 -0
- /package/src/{components/chip/_styles.scss → styles/components/_chip.scss} +0 -0
- /package/src/{components/datepicker/_styles.scss → styles/components/_datepicker.scss} +0 -0
- /package/src/{components/dialog/_styles.scss → styles/components/_dialog.scss} +0 -0
- /package/src/{components/divider/_styles.scss → styles/components/_divider.scss} +0 -0
- /package/src/{components/extended-fab/_styles.scss → styles/components/_extended-fab.scss} +0 -0
- /package/src/{components/fab/_styles.scss → styles/components/_fab.scss} +0 -0
- /package/src/{components/list/_styles.scss → styles/components/_list.scss} +0 -0
- /package/src/{components/menu/_styles.scss → styles/components/_menu.scss} +0 -0
- /package/src/{components/navigation/_styles.scss → styles/components/_navigation.scss} +0 -0
- /package/src/{components/progress/_styles.scss → styles/components/_progress.scss} +0 -0
- /package/src/{components/radios/_styles.scss → styles/components/_radios.scss} +0 -0
- /package/src/{components/search/_styles.scss → styles/components/_search.scss} +0 -0
- /package/src/{components/segmented-button/_styles.scss → styles/components/_segmented-button.scss} +0 -0
- /package/src/{components/sheet/_styles.scss → styles/components/_sheet.scss} +0 -0
- /package/src/{components/slider/_styles.scss → styles/components/_slider.scss} +0 -0
- /package/src/{components/snackbar/_styles.scss → styles/components/_snackbar.scss} +0 -0
- /package/src/{components/switch/_styles.scss → styles/components/_switch.scss} +0 -0
- /package/src/{components/timepicker/_styles.scss → styles/components/_timepicker.scss} +0 -0
- /package/src/{components/tooltip/_styles.scss → styles/components/_tooltip.scss} +0 -0
- /package/src/{components/top-app-bar/_styles.scss → styles/components/_top-app-bar.scss} +0 -0
- /package/src/styles/utilities/{_color.scss → _colors.scss} +0 -0
|
@@ -1,142 +1,330 @@
|
|
|
1
1
|
// src/components/chip/types.ts
|
|
2
|
-
|
|
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
|
-
/**
|
|
9
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Chip variant that determines visual styling
|
|
16
|
+
* @default 'filled'
|
|
17
|
+
*/
|
|
18
|
+
variant?: ChipVariant | string;
|
|
10
19
|
|
|
11
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Whether the chip is initially disabled
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
12
24
|
disabled?: boolean;
|
|
13
25
|
|
|
14
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Whether the chip is initially selected
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
15
30
|
selected?: boolean;
|
|
16
31
|
|
|
17
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Initial chip text content
|
|
34
|
+
* @example 'Category'
|
|
35
|
+
*/
|
|
18
36
|
text?: string;
|
|
19
37
|
|
|
20
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Initial chip icon HTML content (alias for leadingIcon)
|
|
40
|
+
* @example '<svg>...</svg>'
|
|
41
|
+
*/
|
|
21
42
|
icon?: string;
|
|
22
43
|
|
|
23
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Leading icon HTML content
|
|
46
|
+
* @example '<svg>...</svg>'
|
|
47
|
+
*/
|
|
24
48
|
leadingIcon?: string;
|
|
25
49
|
|
|
26
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Trailing icon HTML content
|
|
52
|
+
* @example '<svg>...</svg>'
|
|
53
|
+
*/
|
|
27
54
|
trailingIcon?: string;
|
|
28
55
|
|
|
29
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Additional CSS classes to add to the chip
|
|
58
|
+
* @example 'filter-tag category-item'
|
|
59
|
+
*/
|
|
30
60
|
class?: string;
|
|
31
61
|
|
|
32
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Chip value attribute for identification
|
|
64
|
+
*/
|
|
33
65
|
value?: string;
|
|
34
66
|
|
|
35
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* Gets the chip's value attribute
|
|
207
|
+
* @returns Chip value
|
|
208
|
+
*/
|
|
90
209
|
getValue: () => string | null;
|
|
91
210
|
|
|
92
|
-
/**
|
|
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
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* Enables the chip (removes disabled attribute)
|
|
220
|
+
* @returns The chip component for chaining
|
|
221
|
+
*/
|
|
96
222
|
enable: () => ChipComponent;
|
|
97
223
|
|
|
98
|
-
/**
|
|
224
|
+
/**
|
|
225
|
+
* Disables the chip (adds disabled attribute)
|
|
226
|
+
* @returns The chip component for chaining
|
|
227
|
+
*/
|
|
99
228
|
disable: () => ChipComponent;
|
|
100
229
|
|
|
101
|
-
/**
|
|
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
|
-
/**
|
|
243
|
+
/**
|
|
244
|
+
* Gets the chip's text content
|
|
245
|
+
* @returns Chip text content
|
|
246
|
+
*/
|
|
105
247
|
getText: () => string;
|
|
106
248
|
|
|
107
|
-
/**
|
|
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
|
-
/**
|
|
256
|
+
/**
|
|
257
|
+
* Gets the chip's icon HTML content
|
|
258
|
+
* @returns Icon HTML
|
|
259
|
+
*/
|
|
111
260
|
getIcon: () => string;
|
|
112
261
|
|
|
113
|
-
/**
|
|
114
|
-
|
|
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
|
-
/**
|
|
277
|
+
/**
|
|
278
|
+
* Checks if the chip is selected
|
|
279
|
+
* @returns True if the chip is selected
|
|
280
|
+
*/
|
|
117
281
|
isSelected: () => boolean;
|
|
118
282
|
|
|
119
|
-
/**
|
|
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
|
-
/**
|
|
290
|
+
/**
|
|
291
|
+
* Toggles the chip's selected state
|
|
292
|
+
* @returns The chip component for chaining
|
|
293
|
+
*/
|
|
123
294
|
toggleSelected: () => ChipComponent;
|
|
124
295
|
|
|
125
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* Destroys the chip component and cleans up resources
|
|
298
|
+
*/
|
|
126
299
|
destroy: () => void;
|
|
127
300
|
|
|
128
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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;
|
|
@@ -1,29 +1,11 @@
|
|
|
1
1
|
// src/components/datepicker/api.ts
|
|
2
|
-
import { DatePickerComponent } from './types';
|
|
2
|
+
import { DatePickerComponent, ApiOptions } from './types';
|
|
3
3
|
import {
|
|
4
4
|
formatDate,
|
|
5
5
|
parseDate,
|
|
6
|
-
isSameDay,
|
|
7
|
-
generateCalendarDates,
|
|
8
6
|
addMonths,
|
|
9
7
|
addYears
|
|
10
8
|
} from './utils';
|
|
11
|
-
import { DATEPICKER_VIEWS, DATEPICKER_SELECTION_MODES } from './constants';
|
|
12
|
-
|
|
13
|
-
interface ApiOptions {
|
|
14
|
-
disabled: {
|
|
15
|
-
enable: () => void;
|
|
16
|
-
disable: () => void;
|
|
17
|
-
};
|
|
18
|
-
lifecycle: {
|
|
19
|
-
destroy: () => void;
|
|
20
|
-
};
|
|
21
|
-
events: {
|
|
22
|
-
on: (event: string, handler: Function) => any;
|
|
23
|
-
off: (event: string, handler: Function) => any;
|
|
24
|
-
emit: (event: string, data: any) => any;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
9
|
|
|
28
10
|
/**
|
|
29
11
|
* Enhances a datepicker component with API methods
|
|
@@ -80,17 +62,17 @@ export const withAPI = (state: any, { disabled, lifecycle, events }: ApiOptions)
|
|
|
80
62
|
},
|
|
81
63
|
|
|
82
64
|
showDayView(): void {
|
|
83
|
-
state.currentView =
|
|
65
|
+
state.currentView = 'day';
|
|
84
66
|
state.updateCalendar();
|
|
85
67
|
},
|
|
86
68
|
|
|
87
69
|
showMonthView(): void {
|
|
88
|
-
state.currentView =
|
|
70
|
+
state.currentView = 'month';
|
|
89
71
|
state.updateCalendar();
|
|
90
72
|
},
|
|
91
73
|
|
|
92
74
|
showYearView(): void {
|
|
93
|
-
state.currentView =
|
|
75
|
+
state.currentView = 'year';
|
|
94
76
|
state.updateCalendar();
|
|
95
77
|
},
|
|
96
78
|
|
|
@@ -123,7 +105,7 @@ export const withAPI = (state: any, { disabled, lifecycle, events }: ApiOptions)
|
|
|
123
105
|
if (!state.selectedDate) return null;
|
|
124
106
|
|
|
125
107
|
// Range selection
|
|
126
|
-
if (state.selectionMode ===
|
|
108
|
+
if (state.selectionMode === 'range' && state.rangeEndDate) {
|
|
127
109
|
return [new Date(state.selectedDate), new Date(state.rangeEndDate)];
|
|
128
110
|
}
|
|
129
111
|
|
|
@@ -133,7 +115,7 @@ export const withAPI = (state: any, { disabled, lifecycle, events }: ApiOptions)
|
|
|
133
115
|
|
|
134
116
|
setValue(value: Date | string | [Date | string, Date | string]): DatePickerComponent {
|
|
135
117
|
// Handle range selection
|
|
136
|
-
if (Array.isArray(value) && state.selectionMode ===
|
|
118
|
+
if (Array.isArray(value) && state.selectionMode === 'range') {
|
|
137
119
|
const start = parseDate(value[0]);
|
|
138
120
|
const end = parseDate(value[1]);
|
|
139
121
|
|
|
@@ -196,7 +178,7 @@ export const withAPI = (state: any, { disabled, lifecycle, events }: ApiOptions)
|
|
|
196
178
|
if (!state.selectedDate) return '';
|
|
197
179
|
|
|
198
180
|
// Range selection
|
|
199
|
-
if (state.selectionMode ===
|
|
181
|
+
if (state.selectionMode === 'range' && state.rangeEndDate) {
|
|
200
182
|
const startStr = formatDate(state.selectedDate, state.dateFormat);
|
|
201
183
|
const endStr = formatDate(state.rangeEndDate, state.dateFormat);
|
|
202
184
|
return `${startStr} - ${endStr}`;
|
|
@@ -221,11 +203,13 @@ export const withAPI = (state: any, { disabled, lifecycle, events }: ApiOptions)
|
|
|
221
203
|
|
|
222
204
|
enable(): DatePickerComponent {
|
|
223
205
|
disabled.enable();
|
|
206
|
+
state.input.disabled = false;
|
|
224
207
|
return this;
|
|
225
208
|
},
|
|
226
209
|
|
|
227
210
|
disable(): DatePickerComponent {
|
|
228
211
|
disabled.disable();
|
|
212
|
+
state.input.disabled = true;
|
|
229
213
|
return this;
|
|
230
214
|
},
|
|
231
215
|
|
|
@@ -256,6 +240,15 @@ export const withAPI = (state: any, { disabled, lifecycle, events }: ApiOptions)
|
|
|
256
240
|
},
|
|
257
241
|
|
|
258
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
|
|
259
252
|
lifecycle.destroy();
|
|
260
253
|
},
|
|
261
254
|
|
|
@@ -4,21 +4,18 @@ import {
|
|
|
4
4
|
createElementConfig,
|
|
5
5
|
BaseComponentConfig
|
|
6
6
|
} from '../../core/config/component-config';
|
|
7
|
-
import { DatePickerConfig } from './types';
|
|
8
7
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
DEFAULT_DATE_FORMAT
|
|
13
|
-
} from './constants';
|
|
8
|
+
DatePickerConfig,
|
|
9
|
+
DEFAULT_DATE_FORMAT
|
|
10
|
+
} from './types';
|
|
14
11
|
|
|
15
12
|
/**
|
|
16
13
|
* Default configuration for the DatePicker component
|
|
17
14
|
*/
|
|
18
15
|
export const defaultConfig: DatePickerConfig = {
|
|
19
|
-
variant:
|
|
20
|
-
initialView:
|
|
21
|
-
selectionMode:
|
|
16
|
+
variant: 'docked',
|
|
17
|
+
initialView: 'day',
|
|
18
|
+
selectionMode: 'single',
|
|
22
19
|
dateFormat: DEFAULT_DATE_FORMAT,
|
|
23
20
|
animate: true
|
|
24
21
|
};
|
|
@@ -33,7 +30,7 @@ export const createBaseConfig = (config: DatePickerConfig = {}): DatePickerConfi
|
|
|
33
30
|
|
|
34
31
|
// Set closeOnSelect default based on variant
|
|
35
32
|
if (baseConfig.closeOnSelect === undefined) {
|
|
36
|
-
baseConfig.closeOnSelect = baseConfig.variant !==
|
|
33
|
+
baseConfig.closeOnSelect = baseConfig.variant !== 'docked';
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
return baseConfig;
|
|
@@ -106,12 +103,12 @@ export const getCalendarConfig = (config: DatePickerConfig) => {
|
|
|
106
103
|
tag: 'div',
|
|
107
104
|
attrs: {
|
|
108
105
|
role: 'dialog',
|
|
109
|
-
'aria-modal': config.variant !==
|
|
106
|
+
'aria-modal': config.variant !== 'docked' ? 'true' : 'false'
|
|
110
107
|
},
|
|
111
108
|
className: [
|
|
112
109
|
`${config.prefix}-datepicker-calendar`,
|
|
113
110
|
`${config.prefix}-datepicker-${config.variant}`,
|
|
114
|
-
config.selectionMode ===
|
|
111
|
+
config.selectionMode === 'range' ?
|
|
115
112
|
`${config.prefix}-datepicker-range` : ''
|
|
116
113
|
],
|
|
117
114
|
forwardEvents: {
|
|
@@ -9,12 +9,7 @@ import {
|
|
|
9
9
|
} from '../../core/compose/features';
|
|
10
10
|
|
|
11
11
|
import { withAPI } from './api';
|
|
12
|
-
import { DatePickerConfig } from './types';
|
|
13
|
-
import {
|
|
14
|
-
DATEPICKER_VARIANTS,
|
|
15
|
-
DATEPICKER_VIEWS,
|
|
16
|
-
DATEPICKER_SELECTION_MODES
|
|
17
|
-
} from './constants';
|
|
12
|
+
import { DatePickerConfig, DatePickerComponent } from './types';
|
|
18
13
|
import {
|
|
19
14
|
createBaseConfig,
|
|
20
15
|
getContainerConfig,
|
|
@@ -37,7 +32,7 @@ import { createElement } from '../../core/dom/create';
|
|
|
37
32
|
* @param {DatePickerConfig} config - DatePicker configuration object
|
|
38
33
|
* @returns {DatePickerComponent} DatePicker component instance
|
|
39
34
|
*/
|
|
40
|
-
const createDatePicker = (config: DatePickerConfig = {}) => {
|
|
35
|
+
const createDatePicker = (config: DatePickerConfig = {}): DatePickerComponent => {
|
|
41
36
|
const baseConfig = createBaseConfig(config);
|
|
42
37
|
|
|
43
38
|
try {
|
|
@@ -68,7 +63,7 @@ const createDatePicker = (config: DatePickerConfig = {}) => {
|
|
|
68
63
|
}
|
|
69
64
|
|
|
70
65
|
// Format for range selection
|
|
71
|
-
if (this.selectionMode ===
|
|
66
|
+
if (this.selectionMode === 'range' && this.rangeEndDate) {
|
|
72
67
|
const startStr = formatDate(this.selectedDate, this.dateFormat);
|
|
73
68
|
const endStr = formatDate(this.rangeEndDate, this.dateFormat);
|
|
74
69
|
this.input.value = `${startStr} - ${endStr}`;
|
|
@@ -94,13 +89,13 @@ const createDatePicker = (config: DatePickerConfig = {}) => {
|
|
|
94
89
|
|
|
95
90
|
case 'monthSelected':
|
|
96
91
|
this.currentMonth = data.month;
|
|
97
|
-
this.currentView =
|
|
92
|
+
this.currentView = 'day';
|
|
98
93
|
this.updateCalendar();
|
|
99
94
|
break;
|
|
100
95
|
|
|
101
96
|
case 'yearSelected':
|
|
102
97
|
this.currentYear = data.year;
|
|
103
|
-
this.currentView =
|
|
98
|
+
this.currentView = 'month';
|
|
104
99
|
this.updateCalendar();
|
|
105
100
|
break;
|
|
106
101
|
|
|
@@ -152,7 +147,7 @@ const createDatePicker = (config: DatePickerConfig = {}) => {
|
|
|
152
147
|
|
|
153
148
|
handleDateSelection(date: Date): void {
|
|
154
149
|
// Range selection
|
|
155
|
-
if (this.selectionMode ===
|
|
150
|
+
if (this.selectionMode === 'range') {
|
|
156
151
|
// If no date is selected yet or both dates are already selected, start a new range
|
|
157
152
|
if (!this.selectedDate || (this.selectedDate && this.rangeEndDate)) {
|
|
158
153
|
this.selectedDate = date;
|
|
@@ -248,7 +243,7 @@ const createDatePicker = (config: DatePickerConfig = {}) => {
|
|
|
248
243
|
|
|
249
244
|
// Initialize with provided value if any
|
|
250
245
|
if (baseConfig.value) {
|
|
251
|
-
if (Array.isArray(baseConfig.value) && baseConfig.selectionMode ===
|
|
246
|
+
if (Array.isArray(baseConfig.value) && baseConfig.selectionMode === 'range') {
|
|
252
247
|
const start = parseDate(baseConfig.value[0]);
|
|
253
248
|
const end = parseDate(baseConfig.value[1]);
|
|
254
249
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// src/components/datepicker/index.ts
|
|
2
2
|
export { default } from './datepicker'
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
export type {
|
|
4
|
+
DatePickerConfig,
|
|
5
|
+
DatePickerComponent,
|
|
6
|
+
DatePickerVariant,
|
|
7
|
+
DatePickerView,
|
|
8
|
+
DatePickerSelectionMode
|
|
9
|
+
} from './types'
|
|
10
|
+
export {
|
|
11
|
+
DEFAULT_DATE_FORMAT
|
|
12
|
+
} from './types'
|