summaryrefslogtreecommitdiffstats
path: root/src/objects/_checkbox.scss
blob: 78a9b1f6016e3eff39c11bb888051511f6c68e71 (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
223
224
225
226
227
228
229
@use 'sass:meta';
@use 'iro-sass/src/iro-sass' as iro;
@use 'iro-sass/src/props';
@use '../core.vars' as core;

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

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

    @include iro.bem-object('checkbox') {
        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-b) - props.get(vars.$key-focus--border-offset));

        @include iro.bem-elem('box') {
            position:           relative;
            display:            inline-block;
            flex:               0 0 auto;
            inline-size:        props.get(vars.$size);
            block-size:         props.get(vars.$size);
            margin-block-start: calc(.5em * props.get(core.$font--standard--line-height) - .5 * props.get(vars.$size) - props.get(vars.$key-focus--border-offset));
            vertical-align:     top;
            background-color:   props.get(vars.$box-border-color);
            background-clip:    padding-box;
            border:             props.get(vars.$key-focus--border-offset) solid transparent;
            border-radius:      calc(props.get(vars.$border-width) + props.get(vars.$key-focus--border-offset));
    
            &::before,
            &::after {
                position: absolute;
                display:  block;
                content:  '';
            }
    
            &::before {
                inset-block-start:  props.get(vars.$border-width);
                inset-inline-start: props.get(vars.$border-width);
                z-index:            2;
                inline-size:        calc(props.get(vars.$size) - 2 * props.get(vars.$border-width));
                block-size:         calc(props.get(vars.$size) - 2 * props.get(vars.$border-width));
                background-color:   props.get(vars.$box-bg-color);
                transition:         transform .2s ease;
            }
    
            &::after {
                inset-block-start:   calc(.5 * props.get(vars.$size) - 1px);
                inset-inline-start:  calc(1.5 * props.get(vars.$border-width));
                z-index:             3;
                box-sizing:          border-box;
                inline-size:         calc(props.get(vars.$size) - 3 * props.get(vars.$border-width));
                block-size:          0;
                border-color:        props.get(vars.$box-bg-color);
                border-style:        solid;
                border-radius:       2px;
                transition:          transform .2s ease;
                transform:           scale(0);
                border-block-width:  0 2px;
                border-inline-width: 0 2px;
            }
        }
    
        @include iro.bem-elem('check-icon') {
            position:           absolute;
            inset-block-start:  calc(1 * props.get(vars.$border-width));
            inset-inline-start: calc(1 * props.get(vars.$border-width));
            z-index:            2;
            display:            block;
            inline-size:        calc(100% - 2 * props.get(vars.$border-width));
            block-size:         calc(100% - 2 * props.get(vars.$border-width));
            margin:             0;
            color:              props.get(vars.$box-bg-color);
            stroke-width:       iro.fn-px-to-rem(3px);
            transition:         transform .2s ease;
            transform:          scale(0);
            transform-origin:   40% 90%;
        }
    
        @include iro.bem-elem('label') {
            margin-inline-start: calc(props.get(vars.$label-gap) - props.get(vars.$key-focus--border-offset));
        }
    
        @include iro.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 iro.bem-sibling-elem('label') {
                    color: props.get(vars.$hover--label-color);
                }
    
                @include iro.bem-sibling-elem('box') {
                    background-color: props.get(vars.$hover--box-border-color);
                }
            }
    
            &:checked {
                @include iro.bem-sibling-elem('box') {
                    &::before {
                        transform: scale(0);
                    }
    
                    @include iro.bem-elem('check-icon') {
                        transform: scale(1);
                    }
                }
            }
    
            &:indeterminate {
                @include iro.bem-sibling-elem('box') {
                    &::before {
                        transform: scale(0);
                    }
    
                    &::after {
                        transform: scale(1);
                    }
    
                    @include iro.bem-elem('check-icon') {
                        transform: scale(0);
                    }
                }
            }
    
            &:disabled {
                @include iro.bem-sibling-elem('label') {
                    color: props.get(vars.$disabled--label-color);
                }
    
                @include iro.bem-sibling-elem('box') {
                    background-color: props.get(vars.$disabled--box-border-color);
    
                    &::before {
                        background-color: props.get(vars.$disabled--box-bg-color);
                    }
                }
            }
    
            &:focus-visible {
                @include iro.bem-sibling-elem('label') {
                    color: props.get(vars.$key-focus--label-color);
                }

                @include iro.bem-sibling-elem('box') {
                    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 iro.bem-modifier('standalone') {
            @include iro.bem-elem('box') {
                margin-block-start: 0;
            }
        }
    
        @include iro.bem-modifier('accent') {
            @include iro.bem-elem('native') {
                &:checked {
                    @include iro.bem-sibling-elem('box') {
                        background-color: props.get(vars.$accent--box-border-color);
                    }
        
                    &:hover,
                    &:focus-visible {
                        @include iro.bem-sibling-elem('box') {
                            background-color: props.get(vars.$accent--hover--box-border-color);
                        }
                    }
                }
    
                &:indeterminate {
                    @include iro.bem-sibling-elem('box') {
                        background-color: props.get(vars.$accent--box-border-color);
                    }
        
                    &:hover,
                    &:focus-visible {
                        @include iro.bem-sibling-elem('box') {
                            background-color: props.get(vars.$accent--hover--box-border-color);
                        }
                    }
                }
    
                &:disabled {
                    @include iro.bem-sibling-elem('box') {
                        background-color: props.get(vars.$disabled--box-border-color);
        
                        &::before {
                            background-color: props.get(vars.$disabled--box-bg-color);
                        }
                    }

                    &:checked {
                        @include iro.bem-sibling-elem('box') {
                            background-color: props.get(vars.$disabled--box-border-color);
                        }
                    }
        
                    &:indeterminate {
                        @include iro.bem-sibling-elem('box') {
                            background-color: props.get(vars.$disabled--box-border-color);
                        }
                    }
                }
            }
        }
    }
}