-
Notifications
You must be signed in to change notification settings - Fork 11
/
_button.scss
258 lines (221 loc) · 6.92 KB
/
_button.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
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
// Foundation for Sites by ZURB
// foundation.zurb.com
// Licensed under MIT Open Source
////
/// @group button
////
/// Padding inside buttons.
/// @type List
$button-padding: 0.85em 1em !default;
/// Margin around buttons.
/// @type List
$button-margin: 0 0 $global-margin 0 !default;
/// Default fill for buttons. Can either be `solid` or `hollow`.
/// @type Keyword
$button-fill: solid !default;
/// Default background color for buttons.
/// @type Color
$button-background: $primary-color !default;
/// Background color on hover for buttons.
/// @type Color
$button-background-hover: scale-color($button-background, $lightness: -15%) !default;
/// Font color for buttons.
/// @type List
$button-color: $white !default;
/// Font color for buttons, if the background is light.
/// @type List
$button-color-alt: $black !default;
/// Border radius for buttons, defaulted to global-radius.
/// @type Number
$button-radius: $global-radius !default;
/// Sizes for buttons.
/// @type Map
$button-sizes: (
tiny: 0.6rem,
small: 0.75rem,
default: 0.9rem,
large: 1.25rem,
) !default;
/// opacity for a disabled button.
/// @type List
$button-opacity-disabled: 0.25 !default;
// Internal: flip from margin-right to margin-left for defaults
@if $global-text-direction == 'rtl' {
$button-margin: 0 0 $global-margin $global-margin !default;
}
// TODO: Document button-base() mixin
@mixin button-base {
@include disable-mouse-outline;
display: inline-block;
text-align: center;
line-height: 1;
cursor: pointer;
-webkit-appearance: none;
transition: background-color 0.25s ease-out, color 0.25s ease-out;
vertical-align: middle;
border: 1px solid transparent;
border-radius: $button-radius;
padding: $button-padding;
margin: $button-margin;
font-size: map-get($button-sizes, default);
}
/// Expands a button to make it full-width.
/// @param {Boolean} $expand [true] - Set to `true` to enable the expand behavior. Set to `false` to reverse this behavior.
@mixin button-expand($expand: true) {
@if $expand {
display: block;
width: 100%;
margin-left: 0;
margin-right: 0;
}
@else {
display: inline-block;
width: auto;
margin: $button-margin;
}
}
/// Sets the visual style of a button.
/// @param {Color} $background [$button-background] - Background color of the button.
/// @param {Color} $background-hover [$button-background-hover] - Background color of the button on hover. Set to `auto` to have the mixin automatically generate a hover color.
/// @param {Color} $color [$button-color] - Text color of the button. Set to `auto` to automatically generate a color based on the background color.
@mixin button-style(
$background: $button-background,
$background-hover: $button-background-hover,
$color: $button-color
) {
@if $color == auto {
$color: foreground($background);
}
@if $background-hover == auto {
$background-hover: scale-color($background, $lightness: -20%);
}
background-color: $background;
color: $color;
&:hover, &:focus {
background-color: $background-hover;
color: $color;
}
}
/// Removes background fill on hover and focus for hollow buttons.
@mixin button-hollow {
&,
&:hover, &:focus {
background-color: transparent;
}
}
@mixin button-hollow-style($color: $primary-color) {
$color-hover: scale-color($color, $lightness: -50%);
border: 1px solid $color;
color: $color;
&:hover, &:focus {
border-color: $color-hover;
color: $color-hover;
}
}
/// Adds disabled styles to a button by fading the element, reseting the cursor, and disabling pointer events.
@mixin button-disabled {
opacity: $button-opacity-disabled;
cursor: not-allowed;
pointer-events: none;
}
/// Adds a dropdown arrow to a button.
/// @param {Number} $size [0.4em] - Size of the arrow. We recommend using an `em` value so the triangle scales when used inside different sizes of buttons.
/// @param {Color} $color [white] - Color of the arrow.
/// @param {Number} $offset [$button-padding] - Distance between the arrow and the text of the button. Defaults to whatever the right padding of a button is.
@mixin button-dropdown(
$size: 0.4em,
$color: $white,
$offset: get-side($button-padding, right)
) {
&::after {
@include css-triangle($size, $color, down);
position: relative;
top: 0.4em; // Aligns the arrow with the text of the button
float: #{$global-right};
margin-#{$global-left}: get-side($button-padding, right);
display: inline-block;
}
}
/// Adds all styles for a button. For more granular control over styles, use the individual button mixins.
/// @param {Boolean} $expand [false] - Set to `true` to make the button full-width.
/// @param {Color} $background [$button-background] - Background color of the button.
/// @param {Color} $background-hover [$button-background-hover] - Background color of the button on hover. Set to `auto` to have the mixin automatically generate a hover color.
/// @param {Color} $color [$button-color] - Text color of the button. Set to `auto` to automatically generate a color based on the background color.
/// @param {Keyword} $style [solid] - Set to `hollow` to create a hollow button. The color defined in `$background` will be used as the primary color of the button.
@mixin button(
$expand: false,
$background: $button-background,
$background-hover: $button-background-hover,
$color: $button-color,
$style: $button-fill
) {
@include button-base;
@if $style == solid {
@include button-style($background, $background-hover, $color);
}
@else if $style == hollow {
@include button-hollow;
@include button-hollow-style($background);
}
@if $expand {
@include button-expand;
}
}
@mixin foundation-button {
.button {
@include button;
// Sizes
@each $size, $value in map-remove($button-sizes, default) {
&.#{$size} { font-size: $value; }
}
&.expanded { @include button-expand; }
// Colors
@each $name, $color in $foundation-palette {
@if $button-fill != hollow {
&.#{$name} {
@include button-style($color, auto);
}
}
@else {
&.#{$name} {
@include button-hollow-style($color);
}
&.#{$name}.dropdown::after {
border-top-color: $color;
}
}
}
// Hollow style
@if $button-fill != hollow {
&.hollow {
@include button-hollow;
@include button-hollow-style;
@each $name, $color in $foundation-palette {
&.#{$name} {
@include button-hollow-style($color);
}
}
}
}
// Disabled style
&.disabled,
&[disabled] {
@include button-disabled;
}
// Dropdown arrow
&.dropdown {
@include button-dropdown;
@if $button-fill == hollow {
&::after {
border-top-color: $button-background;
}
}
}
// Button with dropdown arrow only
&.arrow-only::after {
margin-#{$global-left}: 0;
float: none;
top: -0.1em;
}
}
}