mtrl 0.3.1 → 0.3.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/.env +15 -0
- package/CONTRIBUTING.md +62 -23
- package/DOCS.md +3 -3
- package/README.md +43 -20
- package/TESTING.md +128 -18
- package/dist/index.js +14865 -0
- package/git-user-stats.js +545 -0
- package/index.ts +9 -67
- package/package.json +8 -3
- package/src/components/badge/api.ts +15 -1
- package/src/components/badge/badge.ts +43 -4
- package/src/components/badge/config.ts +40 -8
- package/src/components/badge/index.ts +64 -3
- package/src/components/badge/types.ts +175 -33
- package/src/components/button/api.ts +63 -1
- package/src/components/button/button.ts +39 -3
- package/src/components/button/config.ts +21 -4
- package/src/components/button/index.ts +26 -1
- package/src/components/button/types.ts +7 -1
- package/src/components/card/api.ts +78 -9
- package/src/components/card/card.ts +58 -3
- package/src/components/card/config.ts +41 -11
- package/src/components/card/features.ts +39 -12
- package/src/components/card/index.ts +84 -19
- package/src/components/card/types.ts +218 -29
- package/src/components/carousel/carousel.ts +92 -28
- package/src/components/carousel/constants.ts +107 -21
- package/src/components/carousel/index.ts +31 -13
- package/src/components/checkbox/checkbox.ts +83 -16
- package/src/components/checkbox/index.ts +43 -1
- package/src/components/checkbox/types.ts +219 -32
- package/src/components/chips/api.ts +194 -0
- package/src/components/{chip → chips/chip}/api.ts +42 -2
- package/src/components/chips/chip/chip.ts +131 -0
- package/src/components/{chip → chips/chip}/config.ts +3 -3
- package/src/components/chips/chip/index.ts +3 -0
- package/src/components/chips/chips.md +481 -0
- package/src/components/chips/chips.ts +75 -0
- package/src/components/chips/config.ts +109 -0
- package/src/components/chips/constants.ts +61 -0
- package/src/components/chips/features/chip-items.ts +33 -0
- package/src/components/chips/features/container.ts +77 -0
- package/src/components/chips/features/controller.ts +448 -0
- package/src/components/chips/features/index.ts +5 -0
- package/src/components/chips/features/label.ts +108 -0
- package/src/components/chips/index.ts +11 -0
- package/src/components/chips/schema.ts +61 -0
- package/src/components/{chip → chips}/types.ts +203 -92
- package/src/components/dialog/dialog.ts +99 -16
- package/src/components/dialog/index.ts +97 -1
- package/src/components/dialog/types.ts +375 -69
- package/src/components/divider/config.ts +90 -6
- package/src/components/divider/divider.ts +32 -2
- package/src/components/divider/features.ts +26 -0
- package/src/components/divider/index.ts +30 -0
- package/src/components/divider/types.ts +86 -9
- package/src/components/extended-fab/api.ts +53 -1
- package/src/components/extended-fab/config.ts +29 -1
- package/src/components/extended-fab/extended-fab.ts +28 -0
- package/src/components/extended-fab/index.ts +36 -0
- package/src/components/extended-fab/types.ts +458 -13
- package/src/components/fab/api.ts +42 -2
- package/src/components/fab/config.ts +29 -1
- package/src/components/fab/fab.ts +16 -2
- package/src/components/fab/index.ts +35 -0
- package/src/components/fab/types.ts +374 -10
- package/src/components/list/api.ts +12 -2
- package/src/components/list/config.ts +21 -0
- package/src/components/list/features.ts +6 -0
- package/src/components/list/index.ts +56 -1
- package/src/components/list/list-item.ts +46 -2
- package/src/components/list/list.ts +73 -2
- package/src/components/list/types.ts +172 -0
- package/src/components/list/utils.ts +26 -2
- package/src/components/menu/api.ts +217 -20
- package/src/components/menu/config.ts +27 -0
- package/src/components/menu/features/visibility.ts +55 -6
- package/src/components/menu/index.ts +64 -0
- package/src/components/menu/menu-item.ts +46 -3
- package/src/components/menu/menu.ts +77 -1
- package/src/components/menu/types.ts +404 -39
- package/src/components/navigation/nav-item.ts +13 -2
- package/src/components/sheet/config.ts +1 -2
- package/src/components/sheet/features/gestures.ts +1 -1
- package/src/components/sheet/features/position.ts +1 -2
- package/src/components/sheet/features/state.ts +1 -1
- package/src/components/sheet/index.ts +10 -2
- package/src/components/sheet/sheet.ts +1 -2
- package/src/components/sheet/types.ts +29 -1
- package/src/components/slider/api.ts +1 -1
- package/src/components/slider/config.ts +1 -1
- package/src/components/slider/features/controller.ts +1 -1
- package/src/components/slider/features/handlers.ts +1 -1
- package/src/components/slider/features/states.ts +1 -1
- package/src/components/slider/index.ts +12 -5
- package/src/components/slider/schema.ts +1 -1
- package/src/components/slider/types.ts +31 -0
- package/src/components/tabs/tab-api.ts +1 -1
- package/src/components/tabs/types.ts +1 -1
- package/src/components/tooltip/api.ts +6 -2
- package/src/components/tooltip/config.ts +9 -28
- package/src/components/tooltip/index.ts +10 -1
- package/src/components/tooltip/types.ts +38 -3
- package/src/core/dom/create.ts +57 -51
- package/src/index.ts +129 -31
- package/src/styles/abstract/_mixins.scss +23 -9
- package/src/styles/abstract/_variables.scss +14 -4
- package/src/styles/components/_card.scss +1 -1
- package/src/styles/components/_chip.scss +323 -113
- package/src/styles/components/_tabs.scss +1 -1
- package/src/styles/themes/_autumn.scss +3 -0
- package/CLAUDE.md +0 -33
- package/src/components/checkbox/constants.ts +0 -37
- package/src/components/chip/chip-set.ts +0 -225
- package/src/components/chip/chip.ts +0 -118
- package/src/components/chip/constants.ts +0 -28
- package/src/components/chip/index.ts +0 -12
- package/src/components/list/constants.ts +0 -116
- package/src/components/sheet/constants.ts +0 -20
- package/src/components/slider/constants.ts +0 -32
- package/src/components/tooltip/constants.ts +0 -27
- package/test/components/badge.test.ts +0 -545
- package/test/components/bottom-app-bar.test.ts +0 -303
- package/test/components/button.test.ts +0 -233
- package/test/components/card.test.ts +0 -560
- package/test/components/carousel.test.ts +0 -951
- package/test/components/checkbox.test.ts +0 -462
- package/test/components/chip.test.ts +0 -692
- package/test/components/datepicker.test.ts +0 -1124
- package/test/components/dialog.test.ts +0 -990
- package/test/components/divider.test.ts +0 -412
- package/test/components/extended-fab.test.ts +0 -672
- package/test/components/fab.test.ts +0 -561
- package/test/components/list.test.ts +0 -365
- package/test/components/menu.test.ts +0 -718
- package/test/components/navigation.test.ts +0 -186
- package/test/components/progress.test.ts +0 -567
- package/test/components/radios.test.ts +0 -699
- package/test/components/search.test.ts +0 -1135
- package/test/components/segmented-button.test.ts +0 -732
- package/test/components/sheet.test.ts +0 -641
- package/test/components/slider.test.ts +0 -1220
- package/test/components/snackbar.test.ts +0 -461
- package/test/components/switch.test.ts +0 -452
- package/test/components/tabs.test.ts +0 -1369
- package/test/components/textfield.test.ts +0 -400
- package/test/components/timepicker.test.ts +0 -592
- package/test/components/tooltip.test.ts +0 -630
- package/test/components/top-app-bar.test.ts +0 -566
- package/test/core/dom.attributes.test.ts +0 -148
- package/test/core/dom.classes.test.ts +0 -152
- package/test/core/dom.events.test.ts +0 -243
- package/test/core/emitter.test.ts +0 -141
- package/test/core/ripple.test.ts +0 -99
- package/test/core/state.store.test.ts +0 -189
- package/test/core/utils.normalize.test.ts +0 -61
- package/test/core/utils.object.test.ts +0 -120
- package/test/setup.js +0 -371
- package/test/setup.ts +0 -451
- package/tsconfig.json +0 -22
- package/typedoc.json +0 -28
- package/typedoc.simple.json +0 -14
|
@@ -14,7 +14,7 @@ $container: '#{base.$prefix}-tabs';
|
|
|
14
14
|
display: flex;
|
|
15
15
|
flex-direction: column;
|
|
16
16
|
width: 100%;
|
|
17
|
-
background-color: t.color('surface'); // MD3: Surface color
|
|
17
|
+
// background-color: t.color('surface'); // MD3: Surface color
|
|
18
18
|
box-sizing: border-box;
|
|
19
19
|
|
|
20
20
|
// Basic container sizing
|
|
@@ -58,6 +58,9 @@
|
|
|
58
58
|
--#{$prefix}-sys-color-on-info: #003060;
|
|
59
59
|
--#{$prefix}-sys-color-on-info-rgb: 0, 48, 96;
|
|
60
60
|
|
|
61
|
+
// Include status colors for light theme
|
|
62
|
+
@include status-colors-light();
|
|
63
|
+
|
|
61
64
|
&[data-theme-mode="dark"] {
|
|
62
65
|
// Key colors
|
|
63
66
|
--#{$prefix}-sys-color-primary: #DDB995; // Softer brown
|
package/CLAUDE.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Build & Development Commands
|
|
6
|
-
- Build: `bun run build`
|
|
7
|
-
- Dev server: `bun run dev`
|
|
8
|
-
- Tests: `bun test`
|
|
9
|
-
- Single test: `bun test test/components/button.test.ts`
|
|
10
|
-
- Watch tests: `bun test --watch`
|
|
11
|
-
- Test with UI: `bun test --watch --ui`
|
|
12
|
-
- Test coverage: `bun test --coverage`
|
|
13
|
-
- Docs: `bun run docs` (uses TypeDoc)
|
|
14
|
-
|
|
15
|
-
## Code Conventions
|
|
16
|
-
- Factory pattern: Use `createComponent` naming for component creators
|
|
17
|
-
- Functional composition with pipe pattern
|
|
18
|
-
- Follow BEM-style CSS naming: `mtrl-component__element--modifier`
|
|
19
|
-
- Use TypeDoc-compatible comments for documentation
|
|
20
|
-
- Use TypeScript with strict typing where possible
|
|
21
|
-
- Error handling: Try/catch blocks for component creation
|
|
22
|
-
- Import order: core modules first, then utility functions, local imports last
|
|
23
|
-
- Components follow a standard structure in their directories (api.ts, config.ts, etc.)
|
|
24
|
-
- Use ES6+ features with full browser compatibility
|
|
25
|
-
|
|
26
|
-
## Test Conventions
|
|
27
|
-
- Tests live in `test/components/` with `.test.ts` extension
|
|
28
|
-
- Use JSDOM for DOM manipulation in tests
|
|
29
|
-
- Create mock implementations to avoid circular dependencies
|
|
30
|
-
- Test structure follows `describe/test` pattern
|
|
31
|
-
- Test component creation, options, events, and state changes
|
|
32
|
-
- Use `import type` to avoid circular dependencies in TypeScript tests
|
|
33
|
-
- Test directory structure mirrors src directory structure
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// src/components/checkbox/constants.ts
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Visual variants for checkbox
|
|
5
|
-
*/
|
|
6
|
-
export const CHECKBOX_VARIANTS = {
|
|
7
|
-
FILLED: 'filled',
|
|
8
|
-
OUTLINED: 'outlined'
|
|
9
|
-
} as const;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Label position options
|
|
13
|
-
*/
|
|
14
|
-
export const CHECKBOX_LABEL_POSITION = {
|
|
15
|
-
START: 'start',
|
|
16
|
-
END: 'end'
|
|
17
|
-
} as const;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Checkbox state classes
|
|
21
|
-
*/
|
|
22
|
-
export const CHECKBOX_STATES = {
|
|
23
|
-
CHECKED: 'checked',
|
|
24
|
-
INDETERMINATE: 'indeterminate',
|
|
25
|
-
DISABLED: 'disabled',
|
|
26
|
-
FOCUSED: 'focused'
|
|
27
|
-
} as const;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Checkbox element classes
|
|
31
|
-
*/
|
|
32
|
-
export const CHECKBOX_CLASSES = {
|
|
33
|
-
ROOT: 'checkbox',
|
|
34
|
-
INPUT: 'checkbox-input',
|
|
35
|
-
ICON: 'checkbox-icon',
|
|
36
|
-
LABEL: 'checkbox-label'
|
|
37
|
-
} as const;
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
// src/components/chip/chip-set.js
|
|
2
|
-
import { PREFIX } from '../../core/config'
|
|
3
|
-
import createChip from './chip'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates a chip set container for grouping related chips
|
|
7
|
-
* @param {Object} config - ChipSet configuration
|
|
8
|
-
* @param {Array} [config.chips=[]] - Array of chip configurations to initialize
|
|
9
|
-
* @param {boolean} [config.scrollable=false] - Whether the chip set is horizontally scrollable
|
|
10
|
-
* @param {boolean} [config.vertical=false] - Whether the chip set is vertically stacked
|
|
11
|
-
* @param {string} [config.class] - Additional CSS classes
|
|
12
|
-
* @param {string} [config.selector] - CSS selector for filtering behavior
|
|
13
|
-
* @param {boolean} [config.multiSelect=false] - Whether multiple chips can be selected simultaneously
|
|
14
|
-
* @param {Function} [config.onChange] - Callback function when chip selection changes
|
|
15
|
-
* @returns {Object} ChipSet component instance
|
|
16
|
-
*/
|
|
17
|
-
const createChipSet = (config = {}) => {
|
|
18
|
-
const {
|
|
19
|
-
chips = [],
|
|
20
|
-
scrollable = false,
|
|
21
|
-
vertical = false,
|
|
22
|
-
class: customClass,
|
|
23
|
-
selector = null,
|
|
24
|
-
multiSelect = false,
|
|
25
|
-
onChange = null
|
|
26
|
-
} = config
|
|
27
|
-
|
|
28
|
-
// Create container element
|
|
29
|
-
const element = document.createElement('div')
|
|
30
|
-
element.className = `${PREFIX}-chip-set`
|
|
31
|
-
|
|
32
|
-
if (customClass) {
|
|
33
|
-
element.classList.add(customClass)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (scrollable) {
|
|
37
|
-
element.classList.add(`${PREFIX}-chip-set--scrollable`)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (vertical) {
|
|
41
|
-
element.classList.add(`${PREFIX}-chip-set--vertical`)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Store chip instances
|
|
45
|
-
const chipInstances = []
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Updates chip selection states based on multiSelect configuration
|
|
49
|
-
* @param {Object} selectedChip - The chip that was clicked/selected
|
|
50
|
-
*/
|
|
51
|
-
const handleSelection = (selectedChip) => {
|
|
52
|
-
if (!multiSelect) {
|
|
53
|
-
// Single selection mode - deselect all other chips
|
|
54
|
-
chipInstances.forEach(chip => {
|
|
55
|
-
if (chip !== selectedChip && chip.isSelected()) {
|
|
56
|
-
chip.setSelected(false)
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Call onChange callback if provided
|
|
62
|
-
if (typeof onChange === 'function') {
|
|
63
|
-
const selectedChips = chipInstances.filter(chip => chip.isSelected())
|
|
64
|
-
onChange(selectedChips, selectedChip)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Adds a chip to the chip set
|
|
70
|
-
* @param {Object} chipConfig - Configuration for the chip
|
|
71
|
-
* @returns {Object} The created chip instance
|
|
72
|
-
*/
|
|
73
|
-
const addChip = (chipConfig) => {
|
|
74
|
-
const chipInstance = createChip({
|
|
75
|
-
...chipConfig,
|
|
76
|
-
onSelect: (chip) => {
|
|
77
|
-
handleSelection(chip)
|
|
78
|
-
if (chipConfig.onSelect) {
|
|
79
|
-
chipConfig.onSelect(chip)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
element.appendChild(chipInstance.element)
|
|
85
|
-
chipInstances.push(chipInstance)
|
|
86
|
-
|
|
87
|
-
// Add click handler to toggle selection
|
|
88
|
-
chipInstance.element.addEventListener('click', () => {
|
|
89
|
-
if (!chipInstance.element.getAttribute('aria-disabled') === 'true') {
|
|
90
|
-
chipInstance.toggleSelected()
|
|
91
|
-
handleSelection(chipInstance)
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
return chipInstance
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Initialize with provided chips
|
|
99
|
-
chips.forEach(chipConfig => addChip(chipConfig))
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
element,
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Adds a new chip to the chip set
|
|
106
|
-
* @param {Object} chipConfig - Configuration for the chip
|
|
107
|
-
* @returns {Object} The chip set instance for chaining
|
|
108
|
-
*/
|
|
109
|
-
addChip (chipConfig) {
|
|
110
|
-
addChip(chipConfig)
|
|
111
|
-
return this
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Removes a chip from the chip set
|
|
116
|
-
* @param {Object|number} chipOrIndex - Chip instance or index to remove
|
|
117
|
-
* @returns {Object} The chip set instance for chaining
|
|
118
|
-
*/
|
|
119
|
-
removeChip (chipOrIndex) {
|
|
120
|
-
const index = typeof chipOrIndex === 'number'
|
|
121
|
-
? chipOrIndex
|
|
122
|
-
: chipInstances.indexOf(chipOrIndex)
|
|
123
|
-
|
|
124
|
-
if (index >= 0 && index < chipInstances.length) {
|
|
125
|
-
const chip = chipInstances[index]
|
|
126
|
-
chip.destroy()
|
|
127
|
-
chipInstances.splice(index, 1)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return this
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Gets all chip instances in the set
|
|
135
|
-
* @returns {Array} Array of chip instances
|
|
136
|
-
*/
|
|
137
|
-
getChips () {
|
|
138
|
-
return [...chipInstances]
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Gets currently selected chips
|
|
143
|
-
* @returns {Array} Array of selected chip instances
|
|
144
|
-
*/
|
|
145
|
-
getSelectedChips () {
|
|
146
|
-
return chipInstances.filter(chip => chip.isSelected())
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Gets the values of selected chips
|
|
151
|
-
* @returns {Array} Array of selected chip values
|
|
152
|
-
*/
|
|
153
|
-
getSelectedValues () {
|
|
154
|
-
return this.getSelectedChips().map(chip => chip.getValue())
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Selects chips by their values
|
|
159
|
-
* @param {Array|string} values - Value or array of values to select
|
|
160
|
-
* @returns {Object} The chip set instance for chaining
|
|
161
|
-
*/
|
|
162
|
-
selectByValue (values) {
|
|
163
|
-
const valueArray = Array.isArray(values) ? values : [values]
|
|
164
|
-
|
|
165
|
-
chipInstances.forEach(chip => {
|
|
166
|
-
const shouldSelect = valueArray.includes(chip.getValue())
|
|
167
|
-
if (shouldSelect !== chip.isSelected()) {
|
|
168
|
-
chip.setSelected(shouldSelect)
|
|
169
|
-
}
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
return this
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Clears all selections
|
|
177
|
-
* @returns {Object} The chip set instance for chaining
|
|
178
|
-
*/
|
|
179
|
-
clearSelection () {
|
|
180
|
-
chipInstances.forEach(chip => {
|
|
181
|
-
chip.setSelected(false)
|
|
182
|
-
})
|
|
183
|
-
return this
|
|
184
|
-
},
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Sets the scrollable state of the chip set
|
|
188
|
-
* @param {boolean} isScrollable - Whether the chip set should be scrollable
|
|
189
|
-
* @returns {Object} The chip set instance for chaining
|
|
190
|
-
*/
|
|
191
|
-
setScrollable (isScrollable) {
|
|
192
|
-
if (isScrollable) {
|
|
193
|
-
element.classList.add(`${PREFIX}-chip-set--scrollable`)
|
|
194
|
-
} else {
|
|
195
|
-
element.classList.remove(`${PREFIX}-chip-set--scrollable`)
|
|
196
|
-
}
|
|
197
|
-
return this
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Sets the vertical layout state
|
|
202
|
-
* @param {boolean} isVertical - Whether the chip set should be vertically stacked
|
|
203
|
-
* @returns {Object} The chip set instance for chaining
|
|
204
|
-
*/
|
|
205
|
-
setVertical (isVertical) {
|
|
206
|
-
if (isVertical) {
|
|
207
|
-
element.classList.add(`${PREFIX}-chip-set--vertical`)
|
|
208
|
-
} else {
|
|
209
|
-
element.classList.remove(`${PREFIX}-chip-set--vertical`)
|
|
210
|
-
}
|
|
211
|
-
return this
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Destroys the chip set and all contained chips
|
|
216
|
-
*/
|
|
217
|
-
destroy () {
|
|
218
|
-
chipInstances.forEach(chip => chip.destroy())
|
|
219
|
-
chipInstances.length = 0
|
|
220
|
-
element.remove()
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export default createChipSet
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
// src/components/chip/chip.ts
|
|
2
|
-
import { PREFIX } from '../../core/config'
|
|
3
|
-
import { pipe } from '../../core/compose'
|
|
4
|
-
import { createBase, withElement } from '../../core/compose/component'
|
|
5
|
-
import {
|
|
6
|
-
withEvents,
|
|
7
|
-
withText,
|
|
8
|
-
withIcon,
|
|
9
|
-
withVariant,
|
|
10
|
-
withRipple,
|
|
11
|
-
withDisabled,
|
|
12
|
-
withLifecycle
|
|
13
|
-
} from '../../core/compose/features'
|
|
14
|
-
import { withAPI } from './api'
|
|
15
|
-
import { ChipConfig, ChipComponent } from './types'
|
|
16
|
-
import { createBaseConfig, getElementConfig, getApiConfig } from './config'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Creates a new Chip component
|
|
20
|
-
* @param {ChipConfig} config - Chip configuration
|
|
21
|
-
* @returns {ChipComponent} Chip component instance
|
|
22
|
-
*/
|
|
23
|
-
const createChip = (config: ChipConfig = {}): ChipComponent => {
|
|
24
|
-
const baseConfig = createBaseConfig(config)
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
// Create base component with core features
|
|
28
|
-
const chip = pipe(
|
|
29
|
-
createBase,
|
|
30
|
-
withEvents(),
|
|
31
|
-
withElement(getElementConfig(baseConfig)),
|
|
32
|
-
withVariant(baseConfig),
|
|
33
|
-
withDisabled(baseConfig),
|
|
34
|
-
withRipple(baseConfig),
|
|
35
|
-
withLifecycle()
|
|
36
|
-
)(baseConfig)
|
|
37
|
-
|
|
38
|
-
// Create a container for the chip content to ensure proper ordering
|
|
39
|
-
const contentContainer = document.createElement('div')
|
|
40
|
-
contentContainer.className = `${chip.getClass('chip')}-content`
|
|
41
|
-
contentContainer.style.display = 'flex'
|
|
42
|
-
contentContainer.style.alignItems = 'center'
|
|
43
|
-
contentContainer.style.justifyContent = 'center'
|
|
44
|
-
contentContainer.style.width = '100%'
|
|
45
|
-
chip.element.appendChild(contentContainer)
|
|
46
|
-
|
|
47
|
-
// Add leading icon if provided
|
|
48
|
-
if (config.leadingIcon || config.icon) {
|
|
49
|
-
const leadingIconElement = document.createElement('span')
|
|
50
|
-
leadingIconElement.className = `${chip.getClass('chip')}-leading-icon`
|
|
51
|
-
leadingIconElement.innerHTML = config.leadingIcon || config.icon || ''
|
|
52
|
-
contentContainer.appendChild(leadingIconElement)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Add text element if provided
|
|
56
|
-
if (config.text) {
|
|
57
|
-
const textElement = document.createElement('span')
|
|
58
|
-
textElement.className = `${chip.getClass('chip')}-text`
|
|
59
|
-
textElement.textContent = config.text
|
|
60
|
-
contentContainer.appendChild(textElement)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Add trailing icon if provided
|
|
64
|
-
if (config.trailingIcon) {
|
|
65
|
-
const trailingIconElement = document.createElement('span')
|
|
66
|
-
trailingIconElement.className = `${chip.getClass('chip')}-trailing-icon`
|
|
67
|
-
trailingIconElement.innerHTML = config.trailingIcon
|
|
68
|
-
|
|
69
|
-
// Add click handler for trailing icon
|
|
70
|
-
if (config.onTrailingIconClick) {
|
|
71
|
-
trailingIconElement.addEventListener('click', (e) => {
|
|
72
|
-
e.stopPropagation() // Prevent chip click event
|
|
73
|
-
config.onTrailingIconClick(chip as unknown as ChipComponent)
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
contentContainer.appendChild(trailingIconElement)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Add selected class if needed
|
|
81
|
-
if (config.selected) {
|
|
82
|
-
chip.element.classList.add(`${chip.getClass('chip')}--selected`)
|
|
83
|
-
chip.element.setAttribute('aria-selected', 'true')
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Add API methods to the component
|
|
87
|
-
const enhancedChip = withAPI(getApiConfig(chip))(chip)
|
|
88
|
-
|
|
89
|
-
// Add click handler for selection toggle
|
|
90
|
-
if (config.variant === 'filter' ||
|
|
91
|
-
config.variant === 'assist' ||
|
|
92
|
-
config.selectable) {
|
|
93
|
-
|
|
94
|
-
chip.element.addEventListener('click', () => {
|
|
95
|
-
if (enhancedChip.isDisabled()) return
|
|
96
|
-
|
|
97
|
-
enhancedChip.toggleSelected()
|
|
98
|
-
|
|
99
|
-
// Call onChange callback if provided
|
|
100
|
-
if (config.onChange) {
|
|
101
|
-
config.onChange(enhancedChip as unknown as ChipComponent)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Call onSelect callback if provided
|
|
105
|
-
if (config.onSelect) {
|
|
106
|
-
config.onSelect(enhancedChip as unknown as ChipComponent)
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return enhancedChip as unknown as ChipComponent
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.error('Chip creation error:', error)
|
|
114
|
-
throw new Error(`Failed to create chip: ${(error as Error).message}`)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export default createChip
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// src/components/chip/constants.js
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Available variants for the Chip component
|
|
5
|
-
* @enum {string}
|
|
6
|
-
*/
|
|
7
|
-
export const CHIP_VARIANTS = {
|
|
8
|
-
/** Standard filled chip with solid background */
|
|
9
|
-
FILLED: 'filled',
|
|
10
|
-
|
|
11
|
-
/** Outlined chip with transparent background and border */
|
|
12
|
-
OUTLINED: 'outlined',
|
|
13
|
-
|
|
14
|
-
/** Elevated chip with shadow */
|
|
15
|
-
ELEVATED: 'elevated',
|
|
16
|
-
|
|
17
|
-
/** Assist chip for suggesting actions */
|
|
18
|
-
ASSIST: 'assist',
|
|
19
|
-
|
|
20
|
-
/** Filter chip for filtering content */
|
|
21
|
-
FILTER: 'filter',
|
|
22
|
-
|
|
23
|
-
/** Input chip for representing user input */
|
|
24
|
-
INPUT: 'input',
|
|
25
|
-
|
|
26
|
-
/** Suggestion chip for presenting options */
|
|
27
|
-
SUGGESTION: 'suggestion'
|
|
28
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/components/chip/index.ts
|
|
2
|
-
export { default } from './chip'
|
|
3
|
-
export { default as createChipSet } from './chip-set'
|
|
4
|
-
export type {
|
|
5
|
-
ChipConfig,
|
|
6
|
-
ChipComponent,
|
|
7
|
-
ChipVariant
|
|
8
|
-
} from './types'
|
|
9
|
-
export type {
|
|
10
|
-
ChipSetConfig,
|
|
11
|
-
ChipSetComponent
|
|
12
|
-
} from './chip-set'
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
// src/components/list/constants.ts
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* List types/variants
|
|
5
|
-
*/
|
|
6
|
-
export const LIST_TYPES = {
|
|
7
|
-
DEFAULT: 'default', // Standard list
|
|
8
|
-
SINGLE_SELECT: 'single', // Single selection list
|
|
9
|
-
MULTI_SELECT: 'multi', // Multiple selection list
|
|
10
|
-
RADIO: 'radio' // Radio button list
|
|
11
|
-
} as const;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* List layout variants
|
|
15
|
-
*/
|
|
16
|
-
export const LIST_LAYOUTS = {
|
|
17
|
-
HORIZONTAL: 'horizontal', // Default horizontal layout
|
|
18
|
-
VERTICAL: 'vertical' // Items with more content stacked vertically
|
|
19
|
-
} as const;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* List item layouts
|
|
23
|
-
*/
|
|
24
|
-
export const LIST_ITEM_LAYOUTS = {
|
|
25
|
-
HORIZONTAL: 'horizontal', // Default horizontal layout
|
|
26
|
-
VERTICAL: 'vertical' // Stacked layout with vertical alignment
|
|
27
|
-
} as const;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* List element class names
|
|
31
|
-
*/
|
|
32
|
-
export const LIST_CLASSES = {
|
|
33
|
-
ROOT: 'list',
|
|
34
|
-
GROUP: 'list-group',
|
|
35
|
-
GROUP_TITLE: 'list-group-title',
|
|
36
|
-
DIVIDER: 'list-divider',
|
|
37
|
-
SECTION: 'list-section',
|
|
38
|
-
SECTION_TITLE: 'list-section-title',
|
|
39
|
-
ITEM: 'list-item',
|
|
40
|
-
ITEM_CONTENT: 'list-item-content',
|
|
41
|
-
ITEM_LEADING: 'list-item-leading',
|
|
42
|
-
ITEM_TEXT: 'list-item-text',
|
|
43
|
-
ITEM_OVERLINE: 'list-item-overline',
|
|
44
|
-
ITEM_HEADLINE: 'list-item-headline',
|
|
45
|
-
ITEM_SUPPORTING: 'list-item-supporting',
|
|
46
|
-
ITEM_META: 'list-item-meta',
|
|
47
|
-
ITEM_TRAILING: 'list-item-trailing'
|
|
48
|
-
} as const;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* List validation schema
|
|
52
|
-
*/
|
|
53
|
-
export const LIST_SCHEMA = {
|
|
54
|
-
type: 'object',
|
|
55
|
-
properties: {
|
|
56
|
-
type: {
|
|
57
|
-
type: 'string',
|
|
58
|
-
enum: Object.values(LIST_TYPES),
|
|
59
|
-
default: LIST_TYPES.DEFAULT
|
|
60
|
-
},
|
|
61
|
-
layout: {
|
|
62
|
-
type: 'string',
|
|
63
|
-
enum: Object.values(LIST_LAYOUTS),
|
|
64
|
-
default: LIST_LAYOUTS.HORIZONTAL
|
|
65
|
-
},
|
|
66
|
-
items: {
|
|
67
|
-
type: 'array',
|
|
68
|
-
items: {
|
|
69
|
-
type: 'object'
|
|
70
|
-
},
|
|
71
|
-
default: []
|
|
72
|
-
},
|
|
73
|
-
groups: {
|
|
74
|
-
type: 'array',
|
|
75
|
-
items: {
|
|
76
|
-
type: 'object',
|
|
77
|
-
properties: {
|
|
78
|
-
id: { type: 'string', required: true },
|
|
79
|
-
title: { type: 'string' },
|
|
80
|
-
items: { type: 'array' }
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
optional: true
|
|
84
|
-
},
|
|
85
|
-
sections: {
|
|
86
|
-
type: 'array',
|
|
87
|
-
items: {
|
|
88
|
-
type: 'object',
|
|
89
|
-
properties: {
|
|
90
|
-
id: { type: 'string', required: true },
|
|
91
|
-
title: { type: 'string', required: true },
|
|
92
|
-
items: { type: 'array', required: true }
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
optional: true
|
|
96
|
-
},
|
|
97
|
-
disabled: {
|
|
98
|
-
type: 'boolean',
|
|
99
|
-
default: false
|
|
100
|
-
},
|
|
101
|
-
class: {
|
|
102
|
-
type: 'string',
|
|
103
|
-
optional: true
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} as const;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* List item states
|
|
110
|
-
*/
|
|
111
|
-
export const LIST_ITEM_STATES = {
|
|
112
|
-
SELECTED: 'selected',
|
|
113
|
-
DISABLED: 'disabled',
|
|
114
|
-
FOCUSED: 'focused',
|
|
115
|
-
HOVERED: 'hovered'
|
|
116
|
-
} as const;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// src/components/sheet/constants.ts
|
|
2
|
-
export const SHEET_VARIANTS = {
|
|
3
|
-
STANDARD: 'standard',
|
|
4
|
-
MODAL: 'modal',
|
|
5
|
-
EXPANDED: 'expanded'
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const SHEET_POSITIONS = {
|
|
9
|
-
BOTTOM: 'bottom',
|
|
10
|
-
TOP: 'top',
|
|
11
|
-
LEFT: 'left',
|
|
12
|
-
RIGHT: 'right'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const SHEET_EVENTS = {
|
|
16
|
-
OPEN: 'open',
|
|
17
|
-
CLOSE: 'close',
|
|
18
|
-
DRAG_START: 'dragstart',
|
|
19
|
-
DRAG_END: 'dragend'
|
|
20
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// src/components/slider/constants.ts
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Available slider color variants
|
|
5
|
-
*/
|
|
6
|
-
export const SLIDER_COLORS = {
|
|
7
|
-
PRIMARY: 'primary',
|
|
8
|
-
SECONDARY: 'secondary',
|
|
9
|
-
TERTIARY: 'tertiary',
|
|
10
|
-
ERROR: 'error'
|
|
11
|
-
} as const;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Available slider size variants
|
|
15
|
-
*/
|
|
16
|
-
export const SLIDER_SIZES = {
|
|
17
|
-
SMALL: 'small',
|
|
18
|
-
MEDIUM: 'medium',
|
|
19
|
-
LARGE: 'large'
|
|
20
|
-
} as const;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Available slider events
|
|
24
|
-
*/
|
|
25
|
-
export const SLIDER_EVENTS = {
|
|
26
|
-
CHANGE: 'change',
|
|
27
|
-
INPUT: 'input',
|
|
28
|
-
FOCUS: 'focus',
|
|
29
|
-
BLUR: 'blur',
|
|
30
|
-
START: 'start',
|
|
31
|
-
END: 'end'
|
|
32
|
-
} as const;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// src/components/tooltip/constants.ts
|
|
2
|
-
|
|
3
|
-
export const TOOLTIP_POSITIONS = {
|
|
4
|
-
TOP: 'top',
|
|
5
|
-
RIGHT: 'right',
|
|
6
|
-
BOTTOM: 'bottom',
|
|
7
|
-
LEFT: 'left',
|
|
8
|
-
TOP_START: 'top-start',
|
|
9
|
-
TOP_END: 'top-end',
|
|
10
|
-
RIGHT_START: 'right-start',
|
|
11
|
-
RIGHT_END: 'right-end',
|
|
12
|
-
BOTTOM_START: 'bottom-start',
|
|
13
|
-
BOTTOM_END: 'bottom-end',
|
|
14
|
-
LEFT_START: 'left-start',
|
|
15
|
-
LEFT_END: 'left-end'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const TOOLTIP_VARIANTS = {
|
|
19
|
-
DEFAULT: 'default',
|
|
20
|
-
RICH: 'rich',
|
|
21
|
-
PLAIN: 'plain'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const DEFAULT_SHOW_DELAY = 300
|
|
25
|
-
export const DEFAULT_HIDE_DELAY = 100
|
|
26
|
-
export const DEFAULT_OFFSET = 8
|
|
27
|
-
export const DEFAULT_ARROW_SIZE = 8
|