summaryrefslogtreecommitdiffstats
path: root/src/objects/_button.scss
blob: 3ef4813a5108f36976cdb87ca1cf0d2e92fd0dff (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
@use 'sass:list';
@use 'iro-sass/src/index' as iro;
@use '../functions' as fn;

$sizes:         'sm' 'lg' 'xl' !default;
$themes:        'accent' 'negative' !default;
$static-themes: 'black' 'white' !default;

@mixin theme($theme: ()) {
    &:link,
    &:visited,
    &:enabled {
        border-color:     transparent;
        background-color: fn.color(list.join($theme, --bg));
        color:            fn.color(list.join($theme, --label));
    }
    
    @include iro.bem-modifier('outline') {
        &:link,
        &:visited,
        &:enabled {
            border-color:     fn.color(list.join($theme, --outline-border));
            background-color: transparent;
            color:            fn.color(list.join($theme, --outline-label));
        }
    }

    &:link,
    &:visited,
    &:enabled {
        &:hover,
        &:focus-visible {
            border-color:     transparent;
            background-color: fn.color(list.join($theme, --hover --bg));
            color:            fn.color(list.join($theme, --hover --label));
        }

        &:active {
            border-color:     transparent;
            background-color: fn.color(list.join($theme, --active --bg));
            color:            fn.color(list.join($theme, --active --label));
        }
    }
}

@mixin static-theme($theme: ()) {
    border-color:     transparent;
    background-color: fn.color(list.join($theme, --disabled --bg));
    color:            fn.color(list.join($theme, --disabled --label));

    &::after {
        outline:    fn.color(list.join($theme, --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(list.join($theme, --key-focus --outline));
    }
    
    @include iro.bem-modifier('outline') {
        border-color:     fn.color(list.join($theme, --disabled --outline-border));
        background-color: transparent;
    }

    @include theme($theme);

    @include iro.bem-modifier('primary') {
        @include theme(list.join($theme, --primary));
    }
}

@include iro.props-namespace('button') {
    @include iro.props-store((
        --dims: (
            --line-height: 1.4,
            --pad-i:       fn.global-dim(--size --200),
            --pad-i-label: fn.global-dim(--size --75),
            --pad-b:       fn.global-dim(--size --65),
            --border:      fn.global-dim(--border --medium),
            --rounding:    10em,
            --font-size:   fn.global-dim(--font-size --100),

            --sm: (
                --pad-i:       fn.global-dim(--size --150),
                --pad-i-label: fn.global-dim(--size --50),
                --pad-b:       fn.global-dim(--size --25),
                --font-size:   fn.global-dim(--font-size --75),
            ),
            --lg: (
                --pad-i:       fn.global-dim(--size --250),
                --pad-i-label: fn.global-dim(--size --100),
                --pad-b:       fn.global-dim(--size --100),
                --font-size:   fn.global-dim(--font-size --150),
            ),
            --xl: (
                --pad-i:       fn.global-dim(--size --300),
                --pad-i-label: fn.global-dim(--size --150),
                --pad-b:       fn.global-dim(--size --150),
                --font-size:   fn.global-dim(--font-size --200),
            ),
            
            --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: (
            --bg:             fn.global-color(--border-mute),
            --label:          fn.global-color(--text),
            --outline-border: fn.global-color(--border),
            --outline-label:  fn.global-color(--text),

            --hover: (
                --bg:     fn.global-color(--border),
                --label:  fn.global-color(--heading),
            ),
            --active: (
                --bg:     fn.global-color(--border-strong),
                --label:  fn.global-color(--heading),
            ),
            --disabled: (
                --bg:             fn.global-color(--border-mute),
                --outline-border: fn.global-color(--border),
                --label:          fn.global-color(--text-disabled),
            ),
            --key-focus: (
                --label:   fn.global-color(--focus --text),
                --border:  fn.global-color(--focus --border),
                --outline: fn.global-color(--focus --outline),
            ),
            
            --primary: (
                --bg:             fn.global-color(--base --800),
                --label:          fn.global-color(--base --800-text),
                --outline-border: fn.global-color(--base --800),
                --outline-label:  fn.global-color(--text),

                --hover: (
                    --bg:     fn.global-color(--base --900),
                    --label:  fn.global-color(--base --900-text),
                ),
                --active: (
                    --bg:     fn.global-color(--base --900),
                    --label:  fn.global-color(--base --900-text),
                ),
            ),
        ),
    ));

    @each $theme in $themes {
        @include iro.props-store((
            --colors: (
                --#{$theme}: (
                    --bg:             fn.global-color(--#{$theme}-static --900),
                    --label:          fn.global-color(--#{$theme}-static --900-text),
                    --outline-border: fn.global-color(--#{$theme} --900),
                    --outline-label:  fn.global-color(--#{$theme} --1000),

                    --hover: (
                        --bg:     fn.global-color(--#{$theme}-static --1000),
                        --label:  fn.global-color(--#{$theme}-static --1000-text),
                    ),
                    --active: (
                        --bg:     fn.global-color(--#{$theme}-static --1100),
                        --label:  fn.global-color(--#{$theme}-static --1100-text),
                    ),
                ),
            ),
        ));
    }

    @each $theme in $static-themes {
        @include iro.props-store((
            --colors: (
                --static-#{$theme}: (
                    --bg:             fn.global-color(--#{$theme}-transparent --200),
                    --label:          fn.global-color(--#{$theme}-transparent --900),
                    --outline-border: fn.global-color(--#{$theme}-transparent --300),
                    --outline-label:  fn.global-color(--#{$theme}-transparent --900),

                    --hover: (
                        --bg:     fn.global-color(--#{$theme}-transparent --300),
                        --label:  fn.global-color(--#{$theme}-transparent --900),
                    ),
                    --active: (
                        --bg:     fn.global-color(--#{$theme}-transparent --400),
                        --label:  fn.global-color(--#{$theme}-transparent --900),
                    ),
                    --disabled: (
                        --bg:             fn.global-color(--#{$theme}-transparent --200),
                        --outline-border: fn.global-color(--#{$theme}-transparent --300),
                        --label:          fn.global-color(--#{$theme}-transparent --500),
                    ),
                    --key-focus: (
                        --bg:      fn.global-color(--#{$theme}-transparent --100),
                        --label:   fn.global-color(--#{$theme}-transparent --900),
                        --border:  fn.global-color(--#{$theme}-transparent --900),
                        --outline: fn.global-color(--#{$theme}-transparent --300),
                    ),

                    --primary: (
                        --bg:             fn.global-color(--#{$theme}-transparent --800),
                        --label:          fn.global-color(--#{$theme}-transparent --text),
                        --outline-border: fn.global-color(--#{$theme}-transparent --800),
                        --outline-label:  fn.global-color(--#{$theme}-transparent --900),
    
                        --hover: (
                            --bg:     fn.global-color(--#{$theme}-transparent --900),
                            --label:  fn.global-color(--#{$theme}-transparent --text),
                        ),
                        --active: (
                            --bg:     fn.global-color(--#{$theme}-transparent --900),
                            --label:  fn.global-color(--#{$theme}-transparent --text),
                        ),
                    ),
                ),
            ),
        ));
    }

    @include iro.bem-object(iro.props-namespace()) {
        display:          inline-block;
        position:         relative;
        padding-block:    fn.dim(--pad-b);
        padding-inline:   fn.dim(--pad-i);
        border:           fn.dim(--border) solid transparent;
        border-radius:    fn.dim(--rounding);
        border-color:     fn.color(--disabled --bg);
        background-color: fn.color(--disabled --bg);
        color:            fn.color(--disabled --label);
        font-size:        fn.dim(--font-size);
        font-weight:      500;
        line-height:      fn.dim(--line-height);
        text-align:       center;
        text-decoration:  none;

        &::after {
            content:        '';
            display:        none;
            position:       absolute;
            z-index:        1;
            inset:          calc(-1 * fn.dim(--border) - fn.dim(--key-focus --border-offset));
            border-radius:  calc(fn.dim(--rounding) + fn.dim(--key-focus --border-offset));
            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);
            pointer-events: none;
        }

        &:link,
        &:visited,
        &:enabled {
            &:focus-visible {
                &::after {
                    display: block;
                }
            }
        }

        @include iro.bem-elem('label') {
            margin-inline: fn.dim(--pad-i-label);
        }
    
        @include iro.bem-modifier('block') {
            display: block;
        }
    
        @include iro.bem-modifier('outline') {
            border-color:     fn.color(--disabled --outline-border);
            background-color: transparent;
        }

        @each $size in $sizes {
            @include iro.bem-modifier($size) {
                padding-block:  fn.dim(--#{$size} --pad-b);
                padding-inline: fn.dim(--#{$size} --pad-i);
                font-size:      fn.dim(--#{$size} --font-size);

                @include iro.bem-elem('label') {
                    margin-inline: fn.dim(--#{$size} --pad-i-label);
                }
            }
        }

        @include static-theme;
    
        @each $theme in $themes {
            @include iro.bem-modifier($theme) {
                @include theme(--#{$theme});
            }
        }
    
        @each $theme in $static-themes {
            @include iro.bem-modifier(static-#{$theme}) {
                @include static-theme(--static-#{$theme});
            }
        }
    
        @include iro.bem-modifier('round') {
            inline-size:    calc(1em * fn.dim(--line-height) + 2 * fn.dim(--pad-b));
            padding-inline: 0;
            border-radius:  100em;
        }
    }
}