summaryrefslogtreecommitdiffstats
path: root/src/objects/_switch.scss
blob: e1f11329308ad332912c67ec4d1b3945a4425b1c (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
@use 'iro-sass/src/index' as iro;
@use '../functions' as fn;

@include iro.props-namespace('switch') {
    @include iro.props-store((
        --dims: (
            --width:           fn.global-dim(--size --350),
            --height:          fn.global-dim(--size --200),
            --label-gap:       fn.global-dim(--size --125),
            --border:          fn.global-dim(--border --medium),
            --pad-i:           fn.global-dim(--size --65),
            --pad-b:           fn.global-dim(--size --65),
            --rounding:        fn.global-dim(--rounding),
            --spacing-sibling: fn.global-dim(--size --300),

            --key-focus: (
                --border:        fn.global-dim(--key-focus --border),
                --border-offset: fn.global-dim(--key-focus --border-offset),
                --outline:       fn.global-dim(--key-focus --outline),
            ),
        ),
        --colors: (
            --track-bg:      fn.global-color(--border),
            --handle-border: fn.global-color(--text-mute-more),
            --handle-bg:     fn.global-color(--base --50),
    
            --hover: (
                --label:         fn.global-color(--heading),
                --handle-border: fn.global-color(--text-mute),
            ),
            --accent: (
                --handle-border: fn.global-color(--accent --900),
    
                --hover: (
                    --handle-border: fn.global-color(--accent --1000),
                ),
            ),
            --disabled: (
                --label:         fn.global-color(--text-disabled),
                --track-bg:      fn.global-color(--border),
                --handle-border: fn.global-color(--border-strong),
                --handle-bg:     fn.global-color(--base --50),
            ),
            --key-focus: (
                --label:   fn.global-color(--focus --text),
                --border:  fn.global-color(--focus --border),
                --outline: fn.global-color(--focus --outline),
            ),
        ),
    ));

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

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

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

                    &:checked {
                        @include iro.bem-sibling-elem('indicator') {
                            background-color: fn.color(--disabled --handle-border);

                            &::after {
                                border-color: fn.color(--disabled --handle-border);
                            }
                        }
                    }
                }
            }
        }
    }
}