summaryrefslogtreecommitdiffstats
path: root/src/objects/_switch.scss
blob: 8612d31161a18ec472b3b4f29fb8dce95a2f45f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
@use 'sass:meta';
@use 'iro-sass/src/bem';
@use 'iro-sass/src/props';
@use '../props' as *;
@use '../core.vars' as core;

@forward 'switch.vars';
@use 'switch.vars' as vars;

@mixin styles {
    @include materialize-at-root(meta.module-variables('vars'));

    @include bem.object('switch') {
        position:       relative;
        display:        inline-block;
        padding-block:  props.get(vars.$pad-b);
        padding-inline: props.get(vars.$pad-i);
        margin-inline:
            calc(-1 * props.get(vars.$pad-i) - props.get(vars.$key-focus--border-offset))
            calc(props.get(vars.$spacing-sibling) - props.get(vars.$pad-i) - props.get(vars.$key-focus--border-offset));
    
        @include bem.elem('indicator') {
            display:            inline-block;
            flex:               0 0 auto;
            inline-size:        props.get(vars.$inline-size);
            block-size:         props.get(vars.$block-size);
            margin-block-start: calc(.5em * props.get(core.$font--standard--line-height) - .5 * props.get(vars.$block-size) - props.get(vars.$key-focus--border-offset));
            vertical-align:     top;
            background-color:   props.get(vars.$track-bg-color);
            background-clip:    padding-box;
            border:             props.get(vars.$key-focus--border-offset) solid transparent;
            border-radius:      2em;
            transition:         background-color .2s ease;
    
            &::after {
                display:          block;
                inline-size:      calc(props.get(vars.$block-size) - 2 * props.get(vars.$border-width));
                block-size:       calc(props.get(vars.$block-size) - 2 * props.get(vars.$border-width));
                content:          '';
                background-color: props.get(vars.$handle-bg-color);
                border:           props.get(vars.$border-width) solid props.get(vars.$handle-border-color);
                border-radius:    props.get(vars.$inline-size);
                transition:       transform .2s ease;
            }
        }
    
        @include bem.elem('label') {
            margin-inline-start: props.get(vars.$label-gap);
        }
    
        @include bem.elem('native') {
            position:           absolute;
            inset-block-start:  0;
            inset-inline-start: 0;
            z-index:            -1;
            inline-size:        100%;
            block-size:         100%;
            padding:            0;
            margin:             0;
            overflow:           hidden;
            appearance:         none;
            border-radius:      props.get(vars.$rounding);
    
            &:hover,
            &:focus-visible {
                @include bem.sibling-elem('label') {
                    color: props.get(vars.$hover--label-color);
                }
    
                @include bem.sibling-elem('indicator') {
                    &::after {
                        border-color: props.get(vars.$hover--handle-border-color);
                    }
                }
            }
    
            &:checked {
                @include bem.sibling-elem('indicator') {
                    background-color: props.get(vars.$handle-border-color);
    
                    &::after {
                        border-color: props.get(vars.$handle-border-color);
                        transform:    translate(calc(props.get(vars.$inline-size) - props.get(vars.$block-size) + .5px), 0);
                    }
                }
    
                &:hover,
                &:focus-visible {
                    @include bem.sibling-elem('indicator') {
                        background-color: props.get(vars.$hover--handle-border-color);

                        &::after {
                            border-color: props.get(vars.$hover--handle-border-color);
                        }
                    }
                }
            }
    
            &:disabled {
                @include bem.sibling-elem('label') {
                    color: props.get(vars.$disabled--label-color);
                }
    
                @include bem.sibling-elem('indicator') {
                    background-color: props.get(vars.$disabled--track-bg-color);
    
                    &::after {
                        background-color: props.get(vars.$disabled--handle-bg-color);
                        border-color:     props.get(vars.$disabled--handle-border-color);
                    }
                }
    
                &:checked {
                    @include bem.sibling-elem('indicator') {
                        background-color: props.get(vars.$disabled--handle-border-color);
    
                        &::after {
                            border-color: props.get(vars.$disabled--handle-border-color);
                        }
                    }
                }
            }
    
            &:focus-visible {
                @include bem.sibling-elem('label') {
                    color: props.get(vars.$key-focus--label-color);
                }

                @include bem.sibling-elem('indicator') {
                    outline:    props.get(vars.$key-focus--border-color) solid props.get(vars.$key-focus--border-width);
                    box-shadow:
                        0 
                        0
                        0
                        calc(props.get(vars.$key-focus--border-width) + props.get(vars.$key-focus--outline-width))
                        props.get(vars.$key-focus--outline-color);
                }
            }
        }
    
        @include bem.modifier('standalone') {
            @include bem.elem('indicator') {
                margin-block-start: 0;
            }
        }
    
        @include bem.modifier('accent') {
            @include bem.elem('native') {
                &:checked {
                    @include bem.sibling-elem('indicator') {
                        background-color: props.get(vars.$accent--handle-border-color);
        
                        &::after {
                            border-color: props.get(vars.$accent--handle-border-color);
                        }
                    }
        
                    &:hover,
                    &:focus-visible {
                        @include bem.sibling-elem('indicator') {
                            background-color: props.get(vars.$accent--hover--handle-border-color);
    
                            &::after {
                                border-color: props.get(vars.$accent--hover--handle-border-color);
                            }
                        }
                    }
                }
        
                &:disabled {
                    @include bem.sibling-elem('label') {
                        color: props.get(vars.$disabled--label-color);
                    }

                    &:checked {
                        @include bem.sibling-elem('indicator') {
                            background-color: props.get(vars.$disabled--handle-border-color);

                            &::after {
                                border-color: props.get(vars.$disabled--handle-border-color);
                            }
                        }
                    }
                }
            }
        }
    }
}