summaryrefslogtreecommitdiffstats
path: root/src/objects/_radio.scss
blob: fd821d32d3e7c8aa11c728bf65418857f0613c54 (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
@use 'iro-sass/src/index' as iro;
@use '../functions' as fn;

@include iro.props-namespace('radio') {
    @include iro.props-store((
        --dims: (
            --diameter:     iro.fn-px-to-rem(15px),
            --label-gap:    .6rem,
            --border-width: fn.dim(--border-width --medium, $global: true),
            --padding-x:    .3rem,
            --padding-y:    .3rem,
            --margin-right: fn.dim(--spacing --x --md, $global: true),
        ),
    ), 'dims');

    @include iro.props-store((
        --colors: (
            --circle-border: fn.color(--fg-hi, $global: true),
            --circle-bg:     fn.color(--bg-hi, $global: true),
    
            --hover: (
                --label:         fn.color(--fg-lo, $global: true),
                --circle-border: fn.color(--fg, $global: true),
            ),
            --accent: (
                --circle-border: fn.color(--accent --primary, $global: true),
    
                --hover: (
                    --circle-border: fn.color(--accent --primary-lo, $global: true),
                ),
            ),
            --key-focus: (
                --label:         fn.color(--focus --text, $global: true),
                --circle-border: fn.color(--focus --fill, $global: true),
                --shadow:        fn.color(--focus --shadow, $global: true),
            ),
            --disabled: (
                --label:         fn.color(--fg-hi3, $global: true),
                --circle-border: fn.color(--obj-lo, $global: true),
                --circle-bg:     fn.color(--bg-hi, $global: true),
            )
        ),
    ), 'colors');

    @include iro.bem-object(iro.props-namespace()) {
        display:      inline-flex;
        position:     relative;
        align-items:  flex-start;
        margin-right: calc(-1 * fn.dim(--padding-x) + fn.dim(--margin-right));
        margin-left:  calc(-1 * fn.dim(--padding-x));
        padding:      fn.dim(--padding-y) fn.dim(--padding-x);
    
        @include iro.bem-elem('circle') {
            display:          block;
            position:         relative;
            box-sizing:       border-box;
            flex:             0 0 auto;
            width:            fn.dim(--diameter);
            height:           fn.dim(--diameter);
            margin-top:       calc(.5 * (#{$line-height * 1em} - #{fn.dim(--diameter)}));
            border-radius:    2em;
            background-color: fn.color(--circle-border);
    
            &::after {
                content:          '';
                display:          block;
                position:         absolute;
                z-index:          10;
                top:              50%;
                left:             fn.dim(--border-width);
                width:            calc(fn.dim(--diameter) - 2 * fn.dim(--border-width));
                height:           calc(fn.dim(--diameter) - 2 * fn.dim(--border-width));
                transform:        translateY(-50%);
                transition:       transform .2s ease;
                border-radius:    fn.dim(--diameter);
                background-color: fn.color(--circle-bg);
            }
        }
    
        @include iro.bem-elem('label') {
            align-self:  baseline;
            margin-left: fn.dim(--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: fn.color(--hover --label);
                }
    
                @include iro.bem-sibling-elem('circle') {
                    background-color: fn.color(--hover --circle-border);
                }
            }
    
            &:checked {
                @include iro.bem-sibling-elem('circle') {
                    &::after {
                        transform: translateY(-50%) scale(.44);
                    }
                }
            }
    
            &:disabled {
                @include iro.bem-sibling-elem('label') {
                    color: fn.color(--disabled --label);
                }
    
                @include iro.bem-sibling-elem('circle') {
                    background-color: fn.color(--disabled --circle-border);
    
                    &::after {
                        background-color: fn.color(--disabled --circle-bg);
                    }
                }
            }
    
            @include iro.bem-at-theme('keyboard') {
                &:focus {
                    @include iro.bem-sibling-elem('label') {
                        color: fn.color(--key-focus --label);
                    }
    
                    @include iro.bem-sibling-elem('circle') {
                        background-color: fn.color(--key-focus --circle-border);
                        box-shadow:       fn.color(--key-focus --shadow);
                    }
                }
            }
        }
    
        @include iro.bem-modifier('accent') {
            @include iro.bem-elem('native') {
                &:checked {
                    @include iro.bem-sibling-elem('circle') {
                        background-color: fn.color(--accent --circle-border);
                    }
        
                    &:hover {
                        @include iro.bem-sibling-elem('circle') {
                            background-color: fn.color(--accent --hover --circle-border);
                        }
                    }
                }
    
                &:disabled {
                    @include iro.bem-sibling-elem('circle') {
                        background-color: fn.color(--disabled --circle-border);
        
                        &::after {
                            background-color: fn.color(--disabled --circle-bg);
                        }
                    }
        
                    &:checked {
                        @include iro.bem-sibling-elem('circle') {
                            background-color: fn.color(--disabled --circle-border);
                        }
                    }
                }
            }
        }
    }
}