mtrl 0.2.2 → 0.2.3
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/.typedocignore +11 -0
- package/DOCS.md +153 -0
- package/index.ts +18 -3
- package/package.json +7 -2
- package/src/components/badge/_styles.scss +174 -0
- package/src/components/badge/api.ts +292 -0
- package/src/components/badge/badge.ts +52 -0
- package/src/components/badge/config.ts +68 -0
- package/src/components/badge/constants.ts +30 -0
- package/src/components/badge/features.ts +185 -0
- package/src/components/badge/index.ts +4 -0
- package/src/components/badge/types.ts +105 -0
- package/src/components/button/types.ts +174 -29
- package/src/components/carousel/_styles.scss +645 -0
- package/src/components/carousel/api.ts +147 -0
- package/src/components/carousel/carousel.ts +178 -0
- package/src/components/carousel/config.ts +91 -0
- package/src/components/carousel/constants.ts +95 -0
- package/src/components/carousel/features/drag.ts +388 -0
- package/src/components/carousel/features/index.ts +8 -0
- package/src/components/carousel/features/slides.ts +682 -0
- package/src/components/carousel/index.ts +38 -0
- package/src/components/carousel/types.ts +327 -0
- package/src/components/dialog/_styles.scss +213 -0
- package/src/components/dialog/api.ts +283 -0
- package/src/components/dialog/config.ts +113 -0
- package/src/components/dialog/constants.ts +32 -0
- package/src/components/dialog/dialog.ts +56 -0
- package/src/components/dialog/features.ts +713 -0
- package/src/components/dialog/index.ts +15 -0
- package/src/components/dialog/types.ts +221 -0
- package/src/components/progress/_styles.scss +13 -1
- package/src/components/progress/api.ts +2 -2
- package/src/components/progress/progress.ts +2 -2
- package/src/components/progress/types.ts +3 -0
- package/src/components/radios/_styles.scss +232 -0
- package/src/components/radios/api.ts +100 -0
- package/src/components/radios/config.ts +60 -0
- package/src/components/radios/constants.ts +28 -0
- package/src/components/radios/index.ts +4 -0
- package/src/components/radios/radio.ts +269 -0
- package/src/components/radios/radios.ts +42 -0
- package/src/components/radios/types.ts +232 -0
- package/src/components/sheet/_styles.scss +236 -0
- package/src/components/sheet/api.ts +96 -0
- package/src/components/sheet/config.ts +66 -0
- package/src/components/sheet/constants.ts +20 -0
- package/src/components/sheet/features/content.ts +51 -0
- package/src/components/sheet/features/gestures.ts +177 -0
- package/src/components/sheet/features/index.ts +6 -0
- package/src/components/sheet/features/position.ts +42 -0
- package/src/components/sheet/features/state.ts +116 -0
- package/src/components/sheet/features/title.ts +86 -0
- package/src/components/sheet/index.ts +4 -0
- package/src/components/sheet/sheet.ts +57 -0
- package/src/components/sheet/types.ts +266 -0
- package/src/components/slider/_styles.scss +518 -0
- package/src/components/slider/api.ts +336 -0
- package/src/components/slider/config.ts +145 -0
- package/src/components/slider/constants.ts +28 -0
- package/src/components/slider/features/appearance.ts +140 -0
- package/src/components/slider/features/disabled.ts +43 -0
- package/src/components/slider/features/events.ts +164 -0
- package/src/components/slider/features/index.ts +5 -0
- package/src/components/slider/features/interactions.ts +256 -0
- package/src/components/slider/features/keyboard.ts +114 -0
- package/src/components/slider/features/slider.ts +336 -0
- package/src/components/slider/features/structure.ts +264 -0
- package/src/components/slider/features/ui.ts +518 -0
- package/src/components/slider/index.ts +9 -0
- package/src/components/slider/slider.ts +58 -0
- package/src/components/slider/types.ts +166 -0
- package/src/components/tabs/_styles.scss +224 -0
- package/src/components/tabs/api.ts +443 -0
- package/src/components/tabs/config.ts +80 -0
- package/src/components/tabs/constants.ts +12 -0
- package/src/components/tabs/index.ts +4 -0
- package/src/components/tabs/tabs.ts +52 -0
- package/src/components/tabs/types.ts +247 -0
- package/src/components/textfield/_styles.scss +97 -4
- package/src/components/tooltip/_styles.scss +241 -0
- package/src/components/tooltip/api.ts +411 -0
- package/src/components/tooltip/config.ts +78 -0
- package/src/components/tooltip/constants.ts +27 -0
- package/src/components/tooltip/index.ts +4 -0
- package/src/components/tooltip/tooltip.ts +60 -0
- package/src/components/tooltip/types.ts +178 -0
- package/src/index.ts +9 -1
- package/src/styles/abstract/_variables.scss +24 -12
- package/tsconfig.json +22 -0
- package/typedoc.json +28 -0
- package/typedoc.simple.json +14 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/components/radios/config.ts
|
|
2
|
+
import {
|
|
3
|
+
createComponentConfig,
|
|
4
|
+
createElementConfig,
|
|
5
|
+
BaseComponentConfig
|
|
6
|
+
} from '../../core/config/component-config';
|
|
7
|
+
import { RadiosConfig } from './types';
|
|
8
|
+
import { RADIO_DIRECTIONS, RADIO_SIZES } from './constants';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Default configuration for the Radios component
|
|
12
|
+
*/
|
|
13
|
+
export const defaultConfig: RadiosConfig = {
|
|
14
|
+
name: '',
|
|
15
|
+
direction: RADIO_DIRECTIONS.VERTICAL,
|
|
16
|
+
size: RADIO_SIZES.MEDIUM,
|
|
17
|
+
disabled: false,
|
|
18
|
+
ripple: true,
|
|
19
|
+
options: []
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates the base configuration for Radios component
|
|
24
|
+
* @param {RadiosConfig} config - User provided configuration
|
|
25
|
+
* @returns {RadiosConfig} Complete configuration with defaults applied
|
|
26
|
+
*/
|
|
27
|
+
export const createBaseConfig = (config: RadiosConfig): RadiosConfig =>
|
|
28
|
+
createComponentConfig(defaultConfig, config, 'radios') as RadiosConfig;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Generates element configuration for the Radios container
|
|
32
|
+
* @param {RadiosConfig} config - Radios configuration
|
|
33
|
+
* @returns {Object} Element configuration object for withElement
|
|
34
|
+
*/
|
|
35
|
+
export const getElementConfig = (config: RadiosConfig) => {
|
|
36
|
+
return createElementConfig(config, {
|
|
37
|
+
tag: 'div',
|
|
38
|
+
attrs: {
|
|
39
|
+
role: 'radiogroup'
|
|
40
|
+
},
|
|
41
|
+
className: config.class
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates API configuration for the Radios component
|
|
47
|
+
* @param {Object} comp - Component with disabled and lifecycle features
|
|
48
|
+
* @returns {Object} API configuration object
|
|
49
|
+
*/
|
|
50
|
+
export const getApiConfig = (comp) => ({
|
|
51
|
+
disabled: {
|
|
52
|
+
enable: () => comp.disabled.enable(),
|
|
53
|
+
disable: () => comp.disabled.disable()
|
|
54
|
+
},
|
|
55
|
+
lifecycle: {
|
|
56
|
+
destroy: () => comp.lifecycle.destroy()
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export default defaultConfig;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/components/radios/constants.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Radio states for styling and behavior
|
|
5
|
+
*/
|
|
6
|
+
export const RADIO_STATES = {
|
|
7
|
+
CHECKED: 'checked',
|
|
8
|
+
UNCHECKED: 'unchecked',
|
|
9
|
+
DISABLED: 'disabled',
|
|
10
|
+
FOCUSED: 'focused'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Radio sizes
|
|
15
|
+
*/
|
|
16
|
+
export const RADIO_SIZES = {
|
|
17
|
+
SMALL: 'small',
|
|
18
|
+
MEDIUM: 'medium',
|
|
19
|
+
LARGE: 'large'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Radio layout directions
|
|
24
|
+
*/
|
|
25
|
+
export const RADIO_DIRECTIONS = {
|
|
26
|
+
VERTICAL: 'vertical',
|
|
27
|
+
HORIZONTAL: 'horizontal'
|
|
28
|
+
};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// src/components/radios/radio.ts
|
|
2
|
+
import { RadiosConfig, RadioOptionConfig, RadioItem } from './types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a feature that adds radio functionality to a component
|
|
6
|
+
* @param {RadiosConfig} config - Configuration with radio options
|
|
7
|
+
* @returns {Function} Higher-order function that adds radio to component
|
|
8
|
+
*/
|
|
9
|
+
export const withRadio = (config: RadiosConfig) => (component) => {
|
|
10
|
+
const radios: RadioItem[] = [];
|
|
11
|
+
const radiosClass = component.getClass('radios');
|
|
12
|
+
let selectedValue = config.value || '';
|
|
13
|
+
|
|
14
|
+
// Add direction class
|
|
15
|
+
component.element.classList.add(
|
|
16
|
+
`${radiosClass}--${config.direction || 'vertical'}`
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// Add size class
|
|
20
|
+
component.element.classList.add(
|
|
21
|
+
`${radiosClass}--${config.size || 'medium'}`
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Setup disabled state if needed
|
|
25
|
+
if (config.disabled) {
|
|
26
|
+
component.element.classList.add(`${radiosClass}--disabled`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a radio item DOM structure
|
|
31
|
+
* @param {RadioOptionConfig} option - Radio option configuration
|
|
32
|
+
* @returns {RadioItem} Radio item object
|
|
33
|
+
*/
|
|
34
|
+
const createRadioItem = (option: RadioOptionConfig): RadioItem => {
|
|
35
|
+
// Create container
|
|
36
|
+
const radioContainer = document.createElement('div');
|
|
37
|
+
radioContainer.classList.add(`${radiosClass}-item`);
|
|
38
|
+
|
|
39
|
+
// Create input
|
|
40
|
+
const input = document.createElement('input');
|
|
41
|
+
input.type = 'radio';
|
|
42
|
+
input.name = config.name;
|
|
43
|
+
input.value = option.value;
|
|
44
|
+
input.classList.add(`${radiosClass}-input`);
|
|
45
|
+
|
|
46
|
+
// Set checked state if value matches
|
|
47
|
+
if (selectedValue === option.value) {
|
|
48
|
+
input.checked = true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Set disabled state if needed
|
|
52
|
+
if (config.disabled || option.disabled) {
|
|
53
|
+
input.disabled = true;
|
|
54
|
+
radioContainer.classList.add(`${radiosClass}-item--disabled`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Create label
|
|
58
|
+
const label = document.createElement('label');
|
|
59
|
+
label.classList.add(`${radiosClass}-label`);
|
|
60
|
+
|
|
61
|
+
// Create a container for the radio visual
|
|
62
|
+
const radioControl = document.createElement('span');
|
|
63
|
+
radioControl.classList.add(`${radiosClass}-control`);
|
|
64
|
+
|
|
65
|
+
// Create the radio circle
|
|
66
|
+
const radioCircle = document.createElement('span');
|
|
67
|
+
radioCircle.classList.add(`${radiosClass}-circle`);
|
|
68
|
+
|
|
69
|
+
// Add ripple container if ripple is enabled
|
|
70
|
+
if (config.ripple !== false) {
|
|
71
|
+
const rippleContainer = document.createElement('span');
|
|
72
|
+
rippleContainer.classList.add(`${radiosClass}-ripple`);
|
|
73
|
+
radioControl.appendChild(rippleContainer);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Add circle to control
|
|
77
|
+
radioControl.appendChild(radioCircle);
|
|
78
|
+
|
|
79
|
+
// Create text span
|
|
80
|
+
const textSpan = document.createElement('span');
|
|
81
|
+
textSpan.classList.add(`${radiosClass}-text`);
|
|
82
|
+
textSpan.textContent = option.label;
|
|
83
|
+
|
|
84
|
+
// Set label position
|
|
85
|
+
if (option.labelBefore) {
|
|
86
|
+
label.classList.add(`${radiosClass}-label--before`);
|
|
87
|
+
label.appendChild(textSpan);
|
|
88
|
+
label.appendChild(radioControl);
|
|
89
|
+
} else {
|
|
90
|
+
label.appendChild(radioControl);
|
|
91
|
+
label.appendChild(textSpan);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Setup ID for label-input connection
|
|
95
|
+
const inputId = `${radiosClass}-${option.value}-${Math.random().toString(36).substring(2, 9)}`;
|
|
96
|
+
input.id = inputId;
|
|
97
|
+
label.htmlFor = inputId;
|
|
98
|
+
|
|
99
|
+
// Add elements to container
|
|
100
|
+
radioContainer.appendChild(input);
|
|
101
|
+
radioContainer.appendChild(label);
|
|
102
|
+
|
|
103
|
+
// Add change event listener
|
|
104
|
+
const handleChange = (e) => {
|
|
105
|
+
if (input.checked) {
|
|
106
|
+
selectedValue = option.value;
|
|
107
|
+
|
|
108
|
+
// Update other radio inputs
|
|
109
|
+
radios.forEach(radio => {
|
|
110
|
+
if (radio.input !== input) {
|
|
111
|
+
radio.input.checked = false;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Emit change event
|
|
116
|
+
component.events.emit('change', {
|
|
117
|
+
value: option.value,
|
|
118
|
+
originalEvent: e,
|
|
119
|
+
option
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
input.addEventListener('change', handleChange);
|
|
125
|
+
|
|
126
|
+
// Return radio item
|
|
127
|
+
return {
|
|
128
|
+
element: radioContainer,
|
|
129
|
+
input,
|
|
130
|
+
label,
|
|
131
|
+
config: option,
|
|
132
|
+
destroy: () => {
|
|
133
|
+
input.removeEventListener('change', handleChange);
|
|
134
|
+
if (radioContainer.parentNode) {
|
|
135
|
+
radioContainer.parentNode.removeChild(radioContainer);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Adds a radio option to the radios component
|
|
143
|
+
* @param {RadioOptionConfig} option - Radio option configuration
|
|
144
|
+
* @returns {Component} The component for chaining
|
|
145
|
+
*/
|
|
146
|
+
const addOption = (option: RadioOptionConfig) => {
|
|
147
|
+
// Create radio item
|
|
148
|
+
const radioItem = createRadioItem(option);
|
|
149
|
+
|
|
150
|
+
// Add to DOM
|
|
151
|
+
component.element.appendChild(radioItem.element);
|
|
152
|
+
|
|
153
|
+
// Add to radios array
|
|
154
|
+
radios.push(radioItem);
|
|
155
|
+
|
|
156
|
+
return component;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Removes a radio option from the radios component
|
|
161
|
+
* @param {string} value - Value of the radio to remove
|
|
162
|
+
* @returns {Component} The component for chaining
|
|
163
|
+
*/
|
|
164
|
+
const removeOption = (value: string) => {
|
|
165
|
+
const index = radios.findIndex(radio => radio.config.value === value);
|
|
166
|
+
|
|
167
|
+
if (index !== -1) {
|
|
168
|
+
// Get radio item
|
|
169
|
+
const radioItem = radios[index];
|
|
170
|
+
|
|
171
|
+
// Remove from DOM and cleanup
|
|
172
|
+
radioItem.destroy();
|
|
173
|
+
|
|
174
|
+
// Remove from array
|
|
175
|
+
radios.splice(index, 1);
|
|
176
|
+
|
|
177
|
+
// If we removed the selected value, reset the selection
|
|
178
|
+
if (selectedValue === value) {
|
|
179
|
+
selectedValue = '';
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return component;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Initialize radios from config
|
|
187
|
+
if (config.options && Array.isArray(config.options)) {
|
|
188
|
+
config.options.forEach(option => addOption(option));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Return enhanced component
|
|
192
|
+
return {
|
|
193
|
+
...component,
|
|
194
|
+
radios,
|
|
195
|
+
|
|
196
|
+
getValue: () => selectedValue,
|
|
197
|
+
|
|
198
|
+
setValue: (value: string) => {
|
|
199
|
+
selectedValue = value;
|
|
200
|
+
|
|
201
|
+
radios.forEach(radio => {
|
|
202
|
+
radio.input.checked = radio.config.value === value;
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return component;
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
getSelected: () => {
|
|
209
|
+
const selected = radios.find(radio => radio.config.value === selectedValue);
|
|
210
|
+
return selected ? selected.config : null;
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
addOption,
|
|
214
|
+
removeOption,
|
|
215
|
+
|
|
216
|
+
enable: () => {
|
|
217
|
+
component.element.classList.remove(`${radiosClass}--disabled`);
|
|
218
|
+
|
|
219
|
+
radios.forEach(radio => {
|
|
220
|
+
radio.input.disabled = radio.config.disabled || false;
|
|
221
|
+
if (!radio.config.disabled) {
|
|
222
|
+
radio.element.classList.remove(`${radiosClass}-item--disabled`);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
return component;
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
disable: () => {
|
|
230
|
+
component.element.classList.add(`${radiosClass}--disabled`);
|
|
231
|
+
|
|
232
|
+
radios.forEach(radio => {
|
|
233
|
+
radio.input.disabled = true;
|
|
234
|
+
radio.element.classList.add(`${radiosClass}-item--disabled`);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
return component;
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
enableOption: (value: string) => {
|
|
241
|
+
const radio = radios.find(r => r.config.value === value);
|
|
242
|
+
|
|
243
|
+
if (radio) {
|
|
244
|
+
radio.config.disabled = false;
|
|
245
|
+
radio.input.disabled = component.element.classList.contains(`${radiosClass}--disabled`);
|
|
246
|
+
|
|
247
|
+
if (!radio.input.disabled) {
|
|
248
|
+
radio.element.classList.remove(`${radiosClass}-item--disabled`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return component;
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
disableOption: (value: string) => {
|
|
256
|
+
const radio = radios.find(r => r.config.value === value);
|
|
257
|
+
|
|
258
|
+
if (radio) {
|
|
259
|
+
radio.config.disabled = true;
|
|
260
|
+
radio.input.disabled = true;
|
|
261
|
+
radio.element.classList.add(`${radiosClass}-item--disabled`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return component;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
export default withRadio;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/components/radios/radios.ts
|
|
2
|
+
import { PREFIX } from '../../core/config';
|
|
3
|
+
import { pipe } from '../../core/compose';
|
|
4
|
+
import { createBase, withElement } from '../../core/compose/component';
|
|
5
|
+
import { withEvents, withDisabled, withLifecycle } from '../../core/compose/features';
|
|
6
|
+
import { withRadio } from './radio';
|
|
7
|
+
import { withAPI } from './api';
|
|
8
|
+
import { RadiosConfig, RadiosComponent } from './types';
|
|
9
|
+
import { createBaseConfig, getElementConfig, getApiConfig } from './config';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new Radios component
|
|
13
|
+
* @param {RadiosConfig} config - Radios configuration object
|
|
14
|
+
* @returns {RadiosComponent} Radios component instance
|
|
15
|
+
*/
|
|
16
|
+
const createRadios = (config: RadiosConfig): RadiosComponent => {
|
|
17
|
+
// Ensure name is provided
|
|
18
|
+
if (!config.name) {
|
|
19
|
+
config.name = `radios-${Math.random().toString(36).substring(2, 9)}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const baseConfig = createBaseConfig(config);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const radios = pipe(
|
|
26
|
+
createBase,
|
|
27
|
+
withEvents(),
|
|
28
|
+
withElement(getElementConfig(baseConfig)),
|
|
29
|
+
withRadio(baseConfig),
|
|
30
|
+
withDisabled(baseConfig),
|
|
31
|
+
withLifecycle(),
|
|
32
|
+
comp => withAPI(getApiConfig(comp))(comp)
|
|
33
|
+
)(baseConfig);
|
|
34
|
+
|
|
35
|
+
return radios as RadiosComponent;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error('Radios creation error:', error);
|
|
38
|
+
throw new Error(`Failed to create radios component: ${(error as Error).message}`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default createRadios;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// src/components/radios/types.ts
|
|
2
|
+
import { RADIO_SIZES, RADIO_DIRECTIONS } from './constants';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for a radio option in the Radios component
|
|
6
|
+
* @category Components
|
|
7
|
+
*/
|
|
8
|
+
export interface RadioOptionConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Radio input value attribute
|
|
11
|
+
* @example 'option1'
|
|
12
|
+
*/
|
|
13
|
+
value: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Radio label text content
|
|
17
|
+
* @example 'Option 1'
|
|
18
|
+
*/
|
|
19
|
+
label: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Whether the radio is initially disabled
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Whether to position the label before the radio
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
labelBefore?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Configuration interface for the Radios component
|
|
36
|
+
* @category Components
|
|
37
|
+
*/
|
|
38
|
+
export interface RadiosConfig {
|
|
39
|
+
/**
|
|
40
|
+
* Radio input name attribute used for grouping radios
|
|
41
|
+
* @example 'options'
|
|
42
|
+
*/
|
|
43
|
+
name: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Array of radio option configurations
|
|
47
|
+
*/
|
|
48
|
+
options?: RadioOptionConfig[];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Initial selected value
|
|
52
|
+
*/
|
|
53
|
+
value?: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether the entire group is initially disabled
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
disabled?: boolean;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Group layout direction
|
|
63
|
+
* @default 'vertical'
|
|
64
|
+
*/
|
|
65
|
+
direction?: keyof typeof RADIO_DIRECTIONS | string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Radio size
|
|
69
|
+
* @default 'medium'
|
|
70
|
+
*/
|
|
71
|
+
size?: keyof typeof RADIO_SIZES | string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Whether to enable ripple effect
|
|
75
|
+
* @default true
|
|
76
|
+
*/
|
|
77
|
+
ripple?: boolean;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Additional CSS classes to add to the radios component
|
|
81
|
+
*/
|
|
82
|
+
class?: string;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Component prefix for class names
|
|
86
|
+
* @default 'mtrl'
|
|
87
|
+
*/
|
|
88
|
+
prefix?: string;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Component name used in class generation
|
|
92
|
+
*/
|
|
93
|
+
componentName?: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Ripple effect configuration
|
|
97
|
+
*/
|
|
98
|
+
rippleConfig?: {
|
|
99
|
+
/** Duration of the ripple animation in milliseconds */
|
|
100
|
+
duration?: number;
|
|
101
|
+
/** Timing function for the ripple animation */
|
|
102
|
+
timing?: string;
|
|
103
|
+
/** Opacity values for ripple start and end [start, end] */
|
|
104
|
+
opacity?: [string, string];
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Interface for a single radio in the Radios component
|
|
110
|
+
* @category Components
|
|
111
|
+
*/
|
|
112
|
+
export interface RadioItem {
|
|
113
|
+
/** The radio container element */
|
|
114
|
+
element: HTMLElement;
|
|
115
|
+
|
|
116
|
+
/** The actual radio input element */
|
|
117
|
+
input: HTMLInputElement;
|
|
118
|
+
|
|
119
|
+
/** The label element */
|
|
120
|
+
label: HTMLLabelElement;
|
|
121
|
+
|
|
122
|
+
/** The radio option configuration */
|
|
123
|
+
config: RadioOptionConfig;
|
|
124
|
+
|
|
125
|
+
/** Destroys the radio and removes event listeners */
|
|
126
|
+
destroy: () => void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Radios component interface
|
|
131
|
+
* @category Components
|
|
132
|
+
*/
|
|
133
|
+
export interface RadiosComponent {
|
|
134
|
+
/** The radios container DOM element */
|
|
135
|
+
element: HTMLElement;
|
|
136
|
+
|
|
137
|
+
/** Array of radio items in the group */
|
|
138
|
+
radios: RadioItem[];
|
|
139
|
+
|
|
140
|
+
/** API for managing component lifecycle */
|
|
141
|
+
lifecycle: {
|
|
142
|
+
/** Destroys the component and cleans up resources */
|
|
143
|
+
destroy: () => void;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Gets a class name with the component's prefix
|
|
148
|
+
* @param name - Base class name
|
|
149
|
+
* @returns Prefixed class name
|
|
150
|
+
*/
|
|
151
|
+
getClass: (name: string) => string;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Gets the radios component name
|
|
155
|
+
* @returns Selected radio value or empty string if none selected
|
|
156
|
+
*/
|
|
157
|
+
getValue: () => string;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Sets the radios component value (selects a radio)
|
|
161
|
+
* @param value - Value to select
|
|
162
|
+
* @returns The radios component for chaining
|
|
163
|
+
*/
|
|
164
|
+
setValue: (value: string) => RadiosComponent;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Gets the selected radio option's configuration
|
|
168
|
+
* @returns The selected radio option config or null
|
|
169
|
+
*/
|
|
170
|
+
getSelected: () => RadioOptionConfig | null;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Adds a radio option to the radios component
|
|
174
|
+
* @param option - Radio option configuration
|
|
175
|
+
* @returns The radios component for chaining
|
|
176
|
+
*/
|
|
177
|
+
addOption: (option: RadioOptionConfig) => RadiosComponent;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Removes a radio option from the radios component
|
|
181
|
+
* @param value - Value of the radio to remove
|
|
182
|
+
* @returns The radios component for chaining
|
|
183
|
+
*/
|
|
184
|
+
removeOption: (value: string) => RadiosComponent;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Enables the radios component
|
|
188
|
+
* @returns The radios component for chaining
|
|
189
|
+
*/
|
|
190
|
+
enable: () => RadiosComponent;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Disables the radios component
|
|
194
|
+
* @returns The radios component for chaining
|
|
195
|
+
*/
|
|
196
|
+
disable: () => RadiosComponent;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Enables a specific radio option
|
|
200
|
+
* @param value - Value of the radio to enable
|
|
201
|
+
* @returns The radios component for chaining
|
|
202
|
+
*/
|
|
203
|
+
enableOption: (value: string) => RadiosComponent;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Disables a specific radio option
|
|
207
|
+
* @param value - Value of the radio to disable
|
|
208
|
+
* @returns The radios component for chaining
|
|
209
|
+
*/
|
|
210
|
+
disableOption: (value: string) => RadiosComponent;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Destroys the radios component and all radio items
|
|
214
|
+
*/
|
|
215
|
+
destroy: () => void;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Adds an event listener to the radios component
|
|
219
|
+
* @param event - Event name ('change')
|
|
220
|
+
* @param handler - Event handler function
|
|
221
|
+
* @returns The radios component for chaining
|
|
222
|
+
*/
|
|
223
|
+
on: (event: string, handler: Function) => RadiosComponent;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Removes an event listener from the radios component
|
|
227
|
+
* @param event - Event name
|
|
228
|
+
* @param handler - Event handler function
|
|
229
|
+
* @returns The radios component for chaining
|
|
230
|
+
*/
|
|
231
|
+
off: (event: string, handler: Function) => RadiosComponent;
|
|
232
|
+
}
|