forked from carbon-design-system/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_mixins.scss
151 lines (137 loc) · 3.91 KB
/
_mixins.scss
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
//
// Copyright IBM Corp. 2016, 2023
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//
@use 'sass:map';
@use 'vars' as *;
@use '../../config' as *;
@use '../../motion' as *;
@use '../../spacing' as *;
@use '../../theme' as *;
@use '../../type' as *;
@use '../../utilities/component-reset';
@use '../../utilities/convert';
@use '../../utilities/custom-property';
@use '../../utilities/layout';
@use 'tokens' as *;
$button-focus-color: custom-property.get-var('button-focus-color', $focus);
@mixin button-base {
// https://caniuse.com/mdn-css_types_length_lh
--temp-1lh: (
#{custom-property.get-var(
'body-compact-01-line-height',
map.get($body-compact-01, line-height)
)} * 1em
);
--temp-expressive-1lh: (
#{custom-property.get-var(
'body-compact-02-line-height',
map.get($body-compact-02, line-height)
)} * 1em
);
// -1px to compensate for border width
--temp-padding-block-max: calc(
(#{custom-property.get-var('layout-size-height-lg')} - var(--temp-1lh)) / 2 -
#{convert.to-rem(1px)}
);
@include component-reset.reset;
@include type-style('body-compact-01');
position: relative;
display: inline-flex;
flex-shrink: 0;
justify-content: space-between;
border-radius: $button-border-radius;
// Fix to remove added margins on buttons in safari (see #5155)
margin: 0;
cursor: pointer;
inline-size: max-content;
max-inline-size: convert.to-rem(320px);
min-block-size: layout.size('height');
outline: none;
// -1px to compensate for border width
padding-block: min(
calc((layout.size('height') - var(--temp-1lh)) / 2 - convert.to-rem(1px)),
var(--temp-padding-block-max)
);
padding-inline: calc(layout.density('padding-inline') - convert.to-rem(1px))
calc(
layout.density('padding-inline') * 3 + convert.to-rem(16px) - convert.to-rem(
1px
)
);
text-align: start;
text-decoration: none;
transition:
background $duration-fast-01 motion(entrance, productive),
box-shadow $duration-fast-01 motion(entrance, productive),
border-color $duration-fast-01 motion(entrance, productive),
outline $duration-fast-01 motion(entrance, productive);
vertical-align: top;
&:disabled,
&:hover:disabled,
&:focus:disabled,
&.#{$prefix}--btn--disabled,
&.#{$prefix}--btn--disabled:hover,
&.#{$prefix}--btn--disabled:focus {
border-color: $button-disabled;
background: $button-disabled;
box-shadow: none;
color: $text-on-color-disabled;
cursor: not-allowed;
}
.#{$prefix}--btn__icon {
position: absolute;
flex-shrink: 0;
block-size: convert.to-rem(16px);
inline-size: convert.to-rem(16px);
// -1px to compensate for border width
inset-block-start: min(
calc(
(layout.size('height') - convert.to-rem(16px)) / 2 - convert.to-rem(1px)
),
var(--temp-padding-block-max)
);
inset-inline-end: layout.density('padding-inline');
margin-block-start: convert.to-rem(1px);
}
}
/// Button variant styles
/// @access private
/// @group button
@mixin button-theme(
$bg-color,
$border-color,
$font-color,
$hover-bg-color,
$icon-color,
$active-color
) {
border-width: $button-outline-width;
border-style: solid;
border-color: $border-color;
background-color: $bg-color;
color: $font-color;
&:hover {
background-color: $hover-bg-color;
}
&:focus {
border-color: $button-focus-color;
box-shadow:
inset 0 0 0 $button-outline-width $button-focus-color,
inset 0 0 0 $button-border-width $background;
}
&:active {
background-color: $active-color;
}
.#{$prefix}--btn__icon,
.#{$prefix}--btn__icon path:not([data-icon-path]):not([fill='none']) {
fill: $icon-color;
}
}
@mixin button-padding-large {
align-items: baseline;
padding-block-start: $spacing-05;
padding-inline: $spacing-05 $spacing-10;
}