mtrl 0.0.0
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/LICENSE +21 -0
- package/README.md +251 -0
- package/index.js +10 -0
- package/package.json +17 -0
- package/src/components/button/api.js +54 -0
- package/src/components/button/button.js +81 -0
- package/src/components/button/config.js +8 -0
- package/src/components/button/constants.js +63 -0
- package/src/components/button/index.js +2 -0
- package/src/components/button/styles.scss +231 -0
- package/src/components/checkbox/api.js +45 -0
- package/src/components/checkbox/checkbox.js +95 -0
- package/src/components/checkbox/constants.js +88 -0
- package/src/components/checkbox/index.js +2 -0
- package/src/components/checkbox/styles.scss +183 -0
- package/src/components/container/api.js +42 -0
- package/src/components/container/container.js +45 -0
- package/src/components/container/index.js +2 -0
- package/src/components/container/styles.scss +59 -0
- package/src/components/list/constants.js +89 -0
- package/src/components/list/index.js +2 -0
- package/src/components/list/list-item.js +147 -0
- package/src/components/list/list.js +267 -0
- package/src/components/list/styles/_list-item.scss +142 -0
- package/src/components/list/styles/_list.scss +89 -0
- package/src/components/list/styles/_variables.scss +13 -0
- package/src/components/list/styles.scss +19 -0
- package/src/components/navigation/api.js +43 -0
- package/src/components/navigation/constants.js +235 -0
- package/src/components/navigation/features/items.js +192 -0
- package/src/components/navigation/index.js +2 -0
- package/src/components/navigation/nav-item.js +137 -0
- package/src/components/navigation/navigation.js +55 -0
- package/src/components/navigation/styles/_bar.scss +51 -0
- package/src/components/navigation/styles/_base.scss +129 -0
- package/src/components/navigation/styles/_drawer.scss +169 -0
- package/src/components/navigation/styles/_rail.scss +65 -0
- package/src/components/navigation/styles.scss +6 -0
- package/src/components/snackbar/api.js +125 -0
- package/src/components/snackbar/constants.js +41 -0
- package/src/components/snackbar/features.js +69 -0
- package/src/components/snackbar/index.js +2 -0
- package/src/components/snackbar/position.js +63 -0
- package/src/components/snackbar/queue.js +74 -0
- package/src/components/snackbar/snackbar.js +70 -0
- package/src/components/snackbar/styles.scss +182 -0
- package/src/components/switch/api.js +44 -0
- package/src/components/switch/constants.js +80 -0
- package/src/components/switch/index.js +2 -0
- package/src/components/switch/styles.scss +172 -0
- package/src/components/switch/switch.js +71 -0
- package/src/components/textfield/api.js +49 -0
- package/src/components/textfield/constants.js +81 -0
- package/src/components/textfield/index.js +2 -0
- package/src/components/textfield/styles/base.scss +107 -0
- package/src/components/textfield/styles/filled.scss +58 -0
- package/src/components/textfield/styles/outlined.scss +66 -0
- package/src/components/textfield/styles.scss +6 -0
- package/src/components/textfield/textfield.js +68 -0
- package/src/core/build/constants.js +51 -0
- package/src/core/build/icon.js +78 -0
- package/src/core/build/ripple.js +92 -0
- package/src/core/build/text.js +54 -0
- package/src/core/collection/adapters/base.js +26 -0
- package/src/core/collection/adapters/mongodb.js +232 -0
- package/src/core/collection/adapters/route.js +201 -0
- package/src/core/collection/collection.js +259 -0
- package/src/core/collection/list-manager.js +157 -0
- package/src/core/compose/base.js +8 -0
- package/src/core/compose/component.js +225 -0
- package/src/core/compose/features/checkable.js +114 -0
- package/src/core/compose/features/disabled.js +25 -0
- package/src/core/compose/features/events.js +48 -0
- package/src/core/compose/features/icon.js +33 -0
- package/src/core/compose/features/index.js +20 -0
- package/src/core/compose/features/input.js +92 -0
- package/src/core/compose/features/lifecycle.js +69 -0
- package/src/core/compose/features/position.js +60 -0
- package/src/core/compose/features/ripple.js +32 -0
- package/src/core/compose/features/size.js +9 -0
- package/src/core/compose/features/style.js +12 -0
- package/src/core/compose/features/text.js +17 -0
- package/src/core/compose/features/textinput.js +118 -0
- package/src/core/compose/features/textlabel.js +28 -0
- package/src/core/compose/features/track.js +49 -0
- package/src/core/compose/features/variant.js +9 -0
- package/src/core/compose/features/withEvents.js +67 -0
- package/src/core/compose/index.js +16 -0
- package/src/core/compose/pipe.js +69 -0
- package/src/core/config.js +140 -0
- package/src/core/dom/attributes.js +33 -0
- package/src/core/dom/classes.js +70 -0
- package/src/core/dom/create.js +133 -0
- package/src/core/dom/events.js +175 -0
- package/src/core/dom/index.js +5 -0
- package/src/core/dom/utils.js +22 -0
- package/src/core/index.js +23 -0
- package/src/core/layout/index.js +93 -0
- package/src/core/state/disabled.js +14 -0
- package/src/core/state/emitter.js +63 -0
- package/src/core/state/events.js +29 -0
- package/src/core/state/index.js +6 -0
- package/src/core/state/lifecycle.js +64 -0
- package/src/core/state/store.js +112 -0
- package/src/core/utils/index.js +39 -0
- package/src/core/utils/mobile.js +74 -0
- package/src/core/utils/object.js +22 -0
- package/src/core/utils/validate.js +37 -0
- package/src/index.js +11 -0
- package/src/styles/abstract/_base.scss +2 -0
- package/src/styles/abstract/_config.scss +28 -0
- package/src/styles/abstract/_functions.scss +124 -0
- package/src/styles/abstract/_mixins.scss +261 -0
- package/src/styles/abstract/_variables.scss +158 -0
- package/src/styles/main.scss +78 -0
- package/src/styles/themes/_base-theme.scss +49 -0
- package/src/styles/themes/_baseline.scss +90 -0
- package/src/styles/themes/_forest.scss +71 -0
- package/src/styles/themes/_index.scss +6 -0
- package/src/styles/themes/_ocean.scss +71 -0
- package/src/styles/themes/_sunset.scss +55 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// src/components/snackbar/styles.scss
|
|
2
|
+
@use 'sass:map';
|
|
3
|
+
@use '../../styles/abstract/mixins' as m;
|
|
4
|
+
@use '../../styles/abstract/variables' as v;
|
|
5
|
+
|
|
6
|
+
.#{v.$prefix}-snackbar {
|
|
7
|
+
// Base styles following modern minimal design
|
|
8
|
+
@include m.typography('body-medium');
|
|
9
|
+
position: fixed;
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
justify-content: space-between;
|
|
13
|
+
min-width: 280px;
|
|
14
|
+
max-width: 480px;
|
|
15
|
+
padding: 12px 16px;
|
|
16
|
+
gap: 12px;
|
|
17
|
+
|
|
18
|
+
// Updated colors and appearance
|
|
19
|
+
background-color: rgba(32, 33, 36, 0.9);
|
|
20
|
+
color: rgb(255, 255, 255);
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
backdrop-filter: blur(8px);
|
|
23
|
+
|
|
24
|
+
// Animation setup - separated properties for better transitions
|
|
25
|
+
opacity: 0;
|
|
26
|
+
transform: translateY(20px);
|
|
27
|
+
transition:
|
|
28
|
+
opacity 200ms cubic-bezier(0.4, 0, 0.2, 1),
|
|
29
|
+
transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
30
|
+
|
|
31
|
+
z-index: var(--mtrl-sys-z-index-snackbar);
|
|
32
|
+
pointer-events: none;
|
|
33
|
+
will-change: transform, opacity;
|
|
34
|
+
|
|
35
|
+
// Message text styles
|
|
36
|
+
&-text {
|
|
37
|
+
@include m.truncate(1);
|
|
38
|
+
flex: 1;
|
|
39
|
+
font-size: 14px;
|
|
40
|
+
line-height: 20px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Action button styles
|
|
44
|
+
&-action {
|
|
45
|
+
@include m.typography('label-large');
|
|
46
|
+
padding: 8px 12px;
|
|
47
|
+
margin: -8px -12px;
|
|
48
|
+
color: rgb(138, 180, 248);
|
|
49
|
+
background: none;
|
|
50
|
+
border: none;
|
|
51
|
+
border-radius: 4px;
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
font-weight: 500;
|
|
54
|
+
font-size: 14px;
|
|
55
|
+
text-transform: capitalize;
|
|
56
|
+
white-space: nowrap;
|
|
57
|
+
transition: background-color 150ms ease;
|
|
58
|
+
|
|
59
|
+
&:hover {
|
|
60
|
+
background-color: rgba(138, 180, 248, 0.08);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&:focus-visible {
|
|
64
|
+
outline: 2px solid rgb(138, 180, 248);
|
|
65
|
+
outline-offset: 0px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
&:active {
|
|
69
|
+
background-color: rgba(138, 180, 248, 0.12);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Positioning variants with corrected transforms
|
|
74
|
+
&--start {
|
|
75
|
+
bottom: 24px;
|
|
76
|
+
left: 24px;
|
|
77
|
+
transform: translateY(20px);
|
|
78
|
+
|
|
79
|
+
@include m.rtl {
|
|
80
|
+
left: auto;
|
|
81
|
+
right: 24px;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@include m.breakpoint-down('sm') {
|
|
85
|
+
left: 16px;
|
|
86
|
+
bottom: 16px;
|
|
87
|
+
|
|
88
|
+
@include m.rtl {
|
|
89
|
+
left: auto;
|
|
90
|
+
right: 16px;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&--center {
|
|
96
|
+
bottom: 24px;
|
|
97
|
+
left: 50%;
|
|
98
|
+
transform: translate(-50%, 20px);
|
|
99
|
+
|
|
100
|
+
@include m.breakpoint-down('sm') {
|
|
101
|
+
bottom: 16px;
|
|
102
|
+
width: calc(100% - 32px);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
&--end {
|
|
107
|
+
bottom: 24px;
|
|
108
|
+
right: 24px;
|
|
109
|
+
transform: translateY(20px);
|
|
110
|
+
|
|
111
|
+
@include m.rtl {
|
|
112
|
+
right: auto;
|
|
113
|
+
left: 24px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@include m.breakpoint-down('sm') {
|
|
117
|
+
right: 16px;
|
|
118
|
+
bottom: 16px;
|
|
119
|
+
|
|
120
|
+
@include m.rtl {
|
|
121
|
+
right: auto;
|
|
122
|
+
left: 16px;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Visible state with corrected transforms
|
|
128
|
+
&--visible {
|
|
129
|
+
opacity: 1;
|
|
130
|
+
pointer-events: auto;
|
|
131
|
+
|
|
132
|
+
&.#{v.$prefix}-snackbar--start,
|
|
133
|
+
&.#{v.$prefix}-snackbar--end {
|
|
134
|
+
transform: translateY(0);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
&.#{v.$prefix}-snackbar--center {
|
|
138
|
+
transform: translate(-50%, 0);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Multiple line variant
|
|
143
|
+
&--multiline {
|
|
144
|
+
padding-top: 14px;
|
|
145
|
+
padding-bottom: 14px;
|
|
146
|
+
|
|
147
|
+
.#{v.$prefix}-snackbar-text {
|
|
148
|
+
@include m.truncate(2);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Accessibility
|
|
153
|
+
@include m.reduced-motion {
|
|
154
|
+
transition: none;
|
|
155
|
+
transform: none;
|
|
156
|
+
|
|
157
|
+
&--visible {
|
|
158
|
+
transform: none;
|
|
159
|
+
|
|
160
|
+
&.#{v.$prefix}-snackbar--center {
|
|
161
|
+
transform: translateX(-50%);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@include m.high-contrast {
|
|
167
|
+
outline: 2px solid currentColor;
|
|
168
|
+
background-color: black;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Mobile optimizations
|
|
172
|
+
@include m.breakpoint-down('sm') {
|
|
173
|
+
min-width: auto;
|
|
174
|
+
max-width: none;
|
|
175
|
+
margin: 0 16px;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Print styles
|
|
179
|
+
@include m.print {
|
|
180
|
+
display: none;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/components/switch/api.js
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Enhances switch component with API methods
|
|
5
|
+
* @param {Object} options - API configuration
|
|
6
|
+
* @param {Object} options.disabled - Disabled state handlers
|
|
7
|
+
* @param {Object} options.lifecycle - Lifecycle handlers
|
|
8
|
+
* @param {Object} options.checkable - Checked state handlers
|
|
9
|
+
*/
|
|
10
|
+
export const withAPI = ({ disabled, lifecycle, checkable }) => (component) => ({
|
|
11
|
+
...component,
|
|
12
|
+
element: component.element,
|
|
13
|
+
|
|
14
|
+
// Value management
|
|
15
|
+
getValue: component.getValue,
|
|
16
|
+
setValue (value) {
|
|
17
|
+
component.setValue(value)
|
|
18
|
+
return this
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
// State management
|
|
22
|
+
check: checkable.check,
|
|
23
|
+
uncheck: checkable.uncheck,
|
|
24
|
+
toggle: checkable.toggle,
|
|
25
|
+
isChecked: checkable.isChecked,
|
|
26
|
+
|
|
27
|
+
// Label management
|
|
28
|
+
setLabel (text) {
|
|
29
|
+
component.text?.setText(text)
|
|
30
|
+
return this
|
|
31
|
+
},
|
|
32
|
+
getLabel () {
|
|
33
|
+
return component.text?.getText() || ''
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
// Event handling
|
|
37
|
+
on: component.on,
|
|
38
|
+
off: component.off,
|
|
39
|
+
|
|
40
|
+
// State management
|
|
41
|
+
enable: disabled.enable,
|
|
42
|
+
disable: disabled.disable,
|
|
43
|
+
destroy: lifecycle.destroy
|
|
44
|
+
})
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/components/switch/constants.js
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Label position options
|
|
5
|
+
*/
|
|
6
|
+
export const SWITCH_LABEL_POSITION = {
|
|
7
|
+
START: 'start',
|
|
8
|
+
END: 'end'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Validation schema for switch configuration
|
|
13
|
+
*/
|
|
14
|
+
export const SWITCH_SCHEMA = {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
name: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
optional: true
|
|
20
|
+
},
|
|
21
|
+
checked: {
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
optional: true
|
|
24
|
+
},
|
|
25
|
+
required: {
|
|
26
|
+
type: 'boolean',
|
|
27
|
+
optional: true
|
|
28
|
+
},
|
|
29
|
+
disabled: {
|
|
30
|
+
type: 'boolean',
|
|
31
|
+
optional: true
|
|
32
|
+
},
|
|
33
|
+
value: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
optional: true
|
|
36
|
+
},
|
|
37
|
+
label: {
|
|
38
|
+
type: 'string',
|
|
39
|
+
optional: true
|
|
40
|
+
},
|
|
41
|
+
labelPosition: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
enum: Object.values(SWITCH_LABEL_POSITION),
|
|
44
|
+
optional: true
|
|
45
|
+
},
|
|
46
|
+
icon: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
optional: true
|
|
49
|
+
},
|
|
50
|
+
ariaLabel: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
optional: true
|
|
53
|
+
},
|
|
54
|
+
class: {
|
|
55
|
+
type: 'string',
|
|
56
|
+
optional: true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Switch state classes
|
|
63
|
+
*/
|
|
64
|
+
export const SWITCH_STATES = {
|
|
65
|
+
CHECKED: 'checked',
|
|
66
|
+
DISABLED: 'disabled',
|
|
67
|
+
FOCUSED: 'focused'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Switch element classes
|
|
72
|
+
*/
|
|
73
|
+
export const SWITCH_CLASSES = {
|
|
74
|
+
ROOT: 'switch',
|
|
75
|
+
INPUT: 'switch-input',
|
|
76
|
+
TRACK: 'switch-track',
|
|
77
|
+
THUMB: 'thumb',
|
|
78
|
+
THUMB_ICON: 'thumb-icon',
|
|
79
|
+
LABEL: 'switch-label'
|
|
80
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// src/components/switch/styles.scss
|
|
2
|
+
@use 'sass:map';
|
|
3
|
+
@use '../../styles/abstract/config' as c;
|
|
4
|
+
|
|
5
|
+
.#{c.$prefix}-switch {
|
|
6
|
+
display: inline-flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
position: relative;
|
|
9
|
+
min-height: 32px;
|
|
10
|
+
padding: 4px 0;
|
|
11
|
+
user-select: none;
|
|
12
|
+
|
|
13
|
+
&-input {
|
|
14
|
+
position: absolute;
|
|
15
|
+
opacity: 0;
|
|
16
|
+
width: 100%;
|
|
17
|
+
height: 100%;
|
|
18
|
+
margin: 0;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
z-index: 1;
|
|
21
|
+
|
|
22
|
+
&:disabled {
|
|
23
|
+
cursor: not-allowed;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// New focus style that's more visible
|
|
27
|
+
&:focus-visible ~ .#{c.$prefix}-switch-track {
|
|
28
|
+
outline: 2px solid var(--mtrl-sys-color-primary);
|
|
29
|
+
outline-offset: 2px;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&-track {
|
|
34
|
+
position: relative;
|
|
35
|
+
min-width: 52px;
|
|
36
|
+
height: 32px;
|
|
37
|
+
border-radius: 16px;
|
|
38
|
+
background-color: var(--mtrl-sys-color-surface-container-highest);
|
|
39
|
+
border: 2px solid var(--mtrl-sys-color-outline);
|
|
40
|
+
transition: background-color map.get(c.$motion, 'duration-short4') map.get(c.$motion, 'easing-standard'),
|
|
41
|
+
border-color map.get(c.$motion, 'duration-short4') map.get(c.$motion, 'easing-standard'),
|
|
42
|
+
outline map.get(c.$motion, 'duration-short4') map.get(c.$motion, 'easing-standard');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&-thumb {
|
|
46
|
+
position: absolute;
|
|
47
|
+
top: 6px;
|
|
48
|
+
left: 6px;
|
|
49
|
+
width: 16px;
|
|
50
|
+
height: 16px;
|
|
51
|
+
border-radius: 50%;
|
|
52
|
+
background-color: var(--mtrl-sys-color-outline);
|
|
53
|
+
transform: translateX(0);
|
|
54
|
+
transition: all map.get(c.$motion, 'duration-short4') map.get(c.$motion, 'easing-emphasized');
|
|
55
|
+
display: flex;
|
|
56
|
+
align-items: center;
|
|
57
|
+
justify-content: center;
|
|
58
|
+
|
|
59
|
+
&-icon {
|
|
60
|
+
display: flex;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: center;
|
|
63
|
+
opacity: 0;
|
|
64
|
+
transform: scale(0);
|
|
65
|
+
transition: all map.get(c.$motion, 'duration-short4') map.get(c.$motion, 'easing-emphasized');
|
|
66
|
+
color: var(--mtrl-sys-color-primary);
|
|
67
|
+
|
|
68
|
+
svg {
|
|
69
|
+
width: 14px;
|
|
70
|
+
height: 14px;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&-label {
|
|
76
|
+
@include c.typography('body-large');
|
|
77
|
+
margin-left: 12px;
|
|
78
|
+
color: var(--mtrl-sys-color-on-surface);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Label position variants
|
|
82
|
+
&--label-start {
|
|
83
|
+
flex-direction: row-reverse;
|
|
84
|
+
|
|
85
|
+
.#{c.$prefix}-switch-label {
|
|
86
|
+
margin-left: 0;
|
|
87
|
+
margin-right: 12px;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
&--label-end {
|
|
92
|
+
flex-direction: row;
|
|
93
|
+
|
|
94
|
+
.#{c.$prefix}-switch-label {
|
|
95
|
+
margin-left: 12px;
|
|
96
|
+
margin-right: 0;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@include c.rtl {
|
|
101
|
+
&--label-start {
|
|
102
|
+
.#{c.$prefix}-switch-label {
|
|
103
|
+
margin-left: 12px;
|
|
104
|
+
margin-right: 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
&--label-end {
|
|
109
|
+
.#{c.$prefix}-switch-label {
|
|
110
|
+
margin-left: 0;
|
|
111
|
+
margin-right: 12px;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// States
|
|
117
|
+
&--checked {
|
|
118
|
+
.#{c.$prefix}-switch-track {
|
|
119
|
+
background-color: var(--mtrl-sys-color-primary);
|
|
120
|
+
border-color: var(--mtrl-sys-color-primary);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.#{c.$prefix}-switch-thumb {
|
|
124
|
+
background-color: var(--mtrl-sys-color-on-primary);
|
|
125
|
+
transform: translateX(20px);
|
|
126
|
+
width: 24px;
|
|
127
|
+
height: 24px;
|
|
128
|
+
top: 2px;
|
|
129
|
+
left: 2px;
|
|
130
|
+
|
|
131
|
+
&-icon {
|
|
132
|
+
opacity: 1;
|
|
133
|
+
transform: scale(1);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
&--disabled {
|
|
139
|
+
opacity: .5;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Hover effects
|
|
143
|
+
&:not(&--disabled) {
|
|
144
|
+
.#{c.$prefix}-switch-input:hover + .#{c.$prefix}-switch-track {
|
|
145
|
+
&::before {
|
|
146
|
+
content: '';
|
|
147
|
+
position: absolute;
|
|
148
|
+
top: -8px;
|
|
149
|
+
left: -8px;
|
|
150
|
+
right: -8px;
|
|
151
|
+
bottom: -8px;
|
|
152
|
+
background-color: var(--mtrl-sys-color-on-surface);
|
|
153
|
+
opacity: 0.08;
|
|
154
|
+
border-radius: 20px;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@include c.reduced-motion {
|
|
160
|
+
.#{c.$prefix}-switch-track,
|
|
161
|
+
.#{c.$prefix}-switch-thumb,
|
|
162
|
+
.#{c.$prefix}-switch-thumb-icon {
|
|
163
|
+
transition: none;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@include c.high-contrast {
|
|
168
|
+
.#{c.$prefix}-switch-track {
|
|
169
|
+
border-width: 2px;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/components/switch/switch.js
|
|
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
|
+
withTextLabel,
|
|
8
|
+
withDisabled,
|
|
9
|
+
withLifecycle,
|
|
10
|
+
withInput,
|
|
11
|
+
withTrack,
|
|
12
|
+
withCheckable
|
|
13
|
+
} from '../../core/compose/features'
|
|
14
|
+
import { withAPI } from './api'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Adds label position handling to switch
|
|
18
|
+
*/
|
|
19
|
+
const withLabelPosition = (config) => (component) => {
|
|
20
|
+
if (!config.label) return component
|
|
21
|
+
|
|
22
|
+
const position = config.labelPosition || 'end'
|
|
23
|
+
component.element.classList.add(`${PREFIX}-switch--label-${position}`)
|
|
24
|
+
|
|
25
|
+
return component
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new Switch component
|
|
30
|
+
* @param {Object} config - Switch configuration
|
|
31
|
+
* @param {string} [config.name] - Input name
|
|
32
|
+
* @param {boolean} [config.checked] - Initial checked state
|
|
33
|
+
* @param {boolean} [config.required] - Is input required
|
|
34
|
+
* @param {boolean} [config.disabled] - Is switch disabled
|
|
35
|
+
* @param {string} [config.value] - Input value
|
|
36
|
+
* @param {string} [config.label] - Label text
|
|
37
|
+
* @param {string} [config.labelPosition='end'] - Label position (start/end)
|
|
38
|
+
* @param {string} [config.class] - Additional CSS classes
|
|
39
|
+
*/
|
|
40
|
+
const createSwitch = (config = {}) => {
|
|
41
|
+
const baseConfig = {
|
|
42
|
+
...config,
|
|
43
|
+
componentName: 'switch',
|
|
44
|
+
prefix: PREFIX
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return pipe(
|
|
48
|
+
createBase,
|
|
49
|
+
withEvents(), // Move events first to ensure system is available
|
|
50
|
+
withElement({
|
|
51
|
+
tag: 'div',
|
|
52
|
+
componentName: 'switch',
|
|
53
|
+
className: config.class,
|
|
54
|
+
interactive: true
|
|
55
|
+
}),
|
|
56
|
+
withInput(baseConfig),
|
|
57
|
+
withTrack(baseConfig),
|
|
58
|
+
withTextLabel(baseConfig),
|
|
59
|
+
withLabelPosition(baseConfig),
|
|
60
|
+
withCheckable(baseConfig),
|
|
61
|
+
withDisabled(),
|
|
62
|
+
withLifecycle(),
|
|
63
|
+
comp => withAPI({
|
|
64
|
+
disabled: comp.disabled,
|
|
65
|
+
lifecycle: comp.lifecycle,
|
|
66
|
+
checkable: comp.checkable
|
|
67
|
+
})(comp)
|
|
68
|
+
)(baseConfig)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default createSwitch
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/components/textfield/api.js
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Enhances textfield component with API methods
|
|
5
|
+
* @param {Object} options - API configuration
|
|
6
|
+
* @param {Object} options.disabled - Disabled state handlers
|
|
7
|
+
* @param {Object} options.lifecycle - Lifecycle handlers
|
|
8
|
+
*/
|
|
9
|
+
export const withAPI = ({ disabled, lifecycle }) => (component) => ({
|
|
10
|
+
...component,
|
|
11
|
+
// Core element reference
|
|
12
|
+
element: component.element,
|
|
13
|
+
|
|
14
|
+
// Value management
|
|
15
|
+
getValue: () => component.getValue(),
|
|
16
|
+
setValue (value) {
|
|
17
|
+
component.setValue(value)
|
|
18
|
+
return this
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
// Attributes API
|
|
22
|
+
setAttribute (name, value) {
|
|
23
|
+
component.setAttribute(name, value)
|
|
24
|
+
return this
|
|
25
|
+
},
|
|
26
|
+
getAttribute: component.getAttribute,
|
|
27
|
+
removeAttribute (name) {
|
|
28
|
+
component.removeAttribute(name)
|
|
29
|
+
return this
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
// Label management
|
|
33
|
+
setLabel (text) {
|
|
34
|
+
component.label?.setText(text)
|
|
35
|
+
return this
|
|
36
|
+
},
|
|
37
|
+
getLabel () {
|
|
38
|
+
return component.label?.getText() || ''
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
// Event handling
|
|
42
|
+
on: component.on,
|
|
43
|
+
off: component.off,
|
|
44
|
+
|
|
45
|
+
// State management
|
|
46
|
+
enable: disabled.enable,
|
|
47
|
+
disable: disabled.disable,
|
|
48
|
+
destroy: lifecycle.destroy
|
|
49
|
+
})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// src/components/textfield/constants.js
|
|
2
|
+
|
|
3
|
+
export const TEXTFIELD_VARIANTS = {
|
|
4
|
+
FILLED: 'filled',
|
|
5
|
+
OUTLINED: 'outlined'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const TEXTFIELD_SIZES = {
|
|
9
|
+
SMALL: 'small',
|
|
10
|
+
MEDIUM: 'medium',
|
|
11
|
+
LARGE: 'large'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const TEXTFIELD_TYPES = {
|
|
15
|
+
TEXT: 'text',
|
|
16
|
+
PASSWORD: 'password',
|
|
17
|
+
EMAIL: 'email',
|
|
18
|
+
NUMBER: 'number',
|
|
19
|
+
TEL: 'tel',
|
|
20
|
+
URL: 'url',
|
|
21
|
+
SEARCH: 'search',
|
|
22
|
+
MULTILINE: 'multiline'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const TEXTFIELD_SCHEMA = {
|
|
26
|
+
type: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
enum: Object.values(TEXTFIELD_TYPES),
|
|
29
|
+
required: false
|
|
30
|
+
},
|
|
31
|
+
variant: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
enum: Object.values(TEXTFIELD_VARIANTS),
|
|
34
|
+
required: false
|
|
35
|
+
},
|
|
36
|
+
size: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
enum: Object.values(TEXTFIELD_SIZES),
|
|
39
|
+
required: false
|
|
40
|
+
},
|
|
41
|
+
name: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
required: false
|
|
44
|
+
},
|
|
45
|
+
label: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
required: false
|
|
48
|
+
},
|
|
49
|
+
placeholder: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
required: false
|
|
52
|
+
},
|
|
53
|
+
value: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
required: false
|
|
56
|
+
},
|
|
57
|
+
required: {
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
required: false
|
|
60
|
+
},
|
|
61
|
+
disabled: {
|
|
62
|
+
type: 'boolean',
|
|
63
|
+
required: false
|
|
64
|
+
},
|
|
65
|
+
maxLength: {
|
|
66
|
+
type: 'number',
|
|
67
|
+
required: false
|
|
68
|
+
},
|
|
69
|
+
pattern: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
required: false
|
|
72
|
+
},
|
|
73
|
+
autocomplete: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
required: false
|
|
76
|
+
},
|
|
77
|
+
class: {
|
|
78
|
+
type: 'string',
|
|
79
|
+
required: false
|
|
80
|
+
}
|
|
81
|
+
}
|