summaryrefslogtreecommitdiffstats
path: root/src/objects/_radio.scss
blob: c6e5a60dfd9915291bf532e042126cb61686e43e (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
@use 'sass:meta';
@use 'iro-sass/src/iro-sass' as iro;
@use 'iro-sass/src/props';
@use '../props' as *;
@use '../core.vars' as core;

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

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

    @include iro.bem-object('radio') {
        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 iro.bem-elem('circle') {
            display:            inline-block;
            flex:               0 0 auto;
            inline-size:        props.get(vars.$diameter);
            block-size:         props.get(vars.$diameter);
            margin-block-start: calc(.5em * props.get(core.$font--standard--line-height) - .5 * props.get(vars.$diameter) - props.get(vars.$key-focus--border-offset));
            vertical-align:     top;
            background-color:   props.get(vars.$circle-border-color);
            background-clip:    padding-box;
            border:             props.get(vars.$key-focus--border-offset) solid transparent;
            border-radius:      2em;
    
            &::after {
                position:           relative;
                inset-block-start:  props.get(vars.$border-width);
                inset-inline-start: props.get(vars.$border-width);
                display:            block;
                inline-size:        calc(props.get(vars.$diameter) - 2 * props.get(vars.$border-width));
                block-size:         calc(props.get(vars.$diameter) - 2 * props.get(vars.$border-width));
                content:            '';
                background-color:   props.get(vars.$circle-bg-color);
                border-radius:      props.get(vars.$diameter);
                transition:         transform .2s ease;
            }
        }
    
        @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('circle') {
                    background-color: props.get(vars.$hover--circle-border-color);
                }
            }
    
            &:checked {
                @include iro.bem-sibling-elem('circle') {
                    &::after {
                        transform: scale(.44);
                    }
                }
            }
    
            &:disabled {
                @include iro.bem-sibling-elem('label') {
                    color: props.get(vars.$disabled--label-color);
                }
    
                @include iro.bem-sibling-elem('circle') {
                    background-color: props.get(vars.$disabled--circle-border-color);
    
                    &::after {
                        background-color: props.get(vars.$disabled--circle-bg-color);
                    }
                }
            }

            &:focus-visible {
                @include iro.bem-sibling-elem('label') {
                    color: props.get(vars.$key-focus--label-color);
                }

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