summaryrefslogtreecommitdiffstats
path: root/src/objects/_checkbox.scss
blob: 587321bc41e20e12a0c99fb70ec4e4e45ce3865e (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
230
231
232
233
234
235
236
237
238
239
@use 'iro-sass/src/index' as iro;

@include iro.props-namespace('checkbox') {
    @include iro.props-store((
        --dims: (
            --size:         iro.fn-px-to-rem(14px),
            --label-gap:    .6rem,
            --border-width: iro.props-get(--dims --border-width --medium, $global: true),
            --padding-x:    .3rem,
            --padding-y:    .3rem,
            --margin-right: iro.props-get(--dims --spacing --x --md, $global: true),
        ),
        --colors: (
            --box-border: iro.props-get(--colors --fg-hi, $global: true),
            --box-bg:     iro.props-get(--colors --bg-hi, $global: true),
    
            --hover: (
                --label:      iro.props-get(--colors --fg-lo, $global: true),
                --box-border: iro.props-get(--colors --fg, $global: true),
            ),
            --accent: (
                --box-border: iro.props-get(--colors --accent --primary, $global: true),
    
                --hover: (
                    --box-border: iro.props-get(--colors --accent --primary-lo, $global: true),
                ),
            ),
            --key-focus: (
                --label:      iro.props-get(--colors --focus --text, $global: true),
                --box-border: iro.props-get(--colors --focus --fill, $global: true),
                --shadow:     iro.props-get(--colors --focus --shadow, $global: true),
            ),
            --disabled: (
                --label:      iro.props-get(--colors --fg-hi3, $global: true),
                --box-border: iro.props-get(--colors --obj-lo, $global: true),
                --box-bg:     iro.props-get(--colors --bg-hi, $global: true),
            )
        ),
    ));

    @include iro.bem-object(iro.props-namespace()) {
        display:      inline-flex;
        position:     relative;
        align-items:  flex-start;
        margin-right: calc(-1 * #{iro.props-get(--dims --padding-x)} + #{iro.props-get(--dims --margin-right)});
        margin-left:  calc(-1 * #{iro.props-get(--dims --padding-x)});
        padding:      iro.props-get(--dims --padding-y) iro.props-get(--dims --padding-x); // sass-lint:disable-line shorthand-values
    
        @include iro.bem-elem('box') {
            display:          block;
            position:         relative;
            flex:             0 0 auto;
            width:            iro.props-get(--dims --size);
            height:           iro.props-get(--dims --size);
            margin-top:       calc(.5 * (#{$line-height * 1em} - #{iro.props-get(--dims --size)}));
            border-radius:    iro.props-get(--dims --border-width);
            background-color: iro.props-get(--colors --box-border);
    
            &::before,
            &::after {
                content:  '';
                display:  block;
                position: absolute;
            }
    
            &::before {
                z-index:          2;
                top:              iro.props-get(--dims --border-width);
                left:             iro.props-get(--dims --border-width);
                width:            calc(iro.props-get(--dims --size) - 2 * iro.props-get(--dims --border-width));
                height:           calc(iro.props-get(--dims --size) - 2 * iro.props-get(--dims --border-width));
                transition:       transform .2s ease;
                background-color: iro.props-get(--colors --box-bg);
            }
    
            &::after {
                z-index:       3;
                top:           calc(.5 * #{iro.props-get(--dims --size)} - 1px);
                left:          calc(1.5 * #{iro.props-get(--dims --border-width)});
                box-sizing:    border-box;
                width:         calc(iro.props-get(--dims --size) - 3 * iro.props-get(--dims --border-width));
                height:        0;
                transform:     scale(0);
                transition:    transform .2s ease;
                border-width:  0 2px 2px 0;
                border-style:  solid;
                border-radius: 2px;
                border-color:  iro.props-get(--colors --box-bg);
            }
        }
    
        @include iro.bem-elem('check-icon') {
            display:          block;
            position:         absolute;
            z-index:          2;
            top:              calc(1 * iro.props-get(--dims --border-width));
            left:             calc(1 * iro.props-get(--dims --border-width));
            width:            calc(100% - 2 * iro.props-get(--dims --border-width));
            height:           calc(100% - 2 * iro.props-get(--dims --border-width));
            transform:        scale(0);
            transform-origin: 40% 90%;
            transition:       transform .2s ease;
            stroke-width:     iro.fn-px-to-rem(3px);
            color:            iro.props-get(--colors --box-bg);
        }
    
        @include iro.bem-elem('label') {
            align-self:  baseline;
            margin-left: iro.props-get(--dims --label-gap);
        }
    
        @include iro.bem-elem('native') {
            position: absolute;
            top:      0;
            left:     0;
            width:    100%;
            height:   100%;
            margin:   0;
            padding:  0;
            overflow: hidden;
            opacity:  .0001;
    
            &:hover {
                @include iro.bem-sibling-elem('label') {
                    color: iro.props-get(--colors --hover --label);
                }
    
                @include iro.bem-sibling-elem('box') {
                    background-color: iro.props-get(--colors --hover --box-border);
                }
            }
    
            &: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: iro.props-get(--colors --disabled --label);
                }
    
                @include iro.bem-sibling-elem('box') {
                    background-color: iro.props-get(--colors --disabled --box-border);
    
                    &::before {
                        background-color: iro.props-get(--colors --disabled --box-bg);
                    }
                }
            }
    
            @include iro.bem-at-theme('keyboard') {
                &:focus {
                    @include iro.bem-sibling-elem('label') {
                        color: iro.props-get(--colors --key-focus --label);
                    }
    
                    @include iro.bem-sibling-elem('box') {
                        background-color: iro.props-get(--colors --key-focus --box-border);
                        box-shadow:       iro.props-get(--colors --key-focus --shadow);
                    }
                }
            }
        }
    
        @include iro.bem-modifier('accent') {
            @include iro.bem-elem('native') {
                &:checked {
                    @include iro.bem-sibling-elem('box') {
                        background-color: iro.props-get(--colors --accent --box-border);
                    }
        
                    &:hover {
                        @include iro.bem-sibling-elem('box') {
                            background-color: iro.props-get(--colors --accent --hover --box-border);
                        }
                    }
                }
    
                &:indeterminate {
                    @include iro.bem-sibling-elem('box') {
                        background-color: iro.props-get(--colors --accent --box-border);
                    }
        
                    &:hover {
                        @include iro.bem-sibling-elem('box') {
                            background-color: iro.props-get(--colors --accent --hover --box-border);
                        }
                    }
                }
    
                &:disabled {
                    @include iro.bem-sibling-elem('box') {
                        background-color: iro.props-get(--colors --disabled --box-border);
        
                        &::before {
                            background-color: iro.props-get(--colors --disabled --box-bg);
                        }
                    }

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