This repository has been archived by the owner on Oct 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
_c-button.scss
342 lines (261 loc) · 8.65 KB
/
_c-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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/* ============================================================================
@COMPONENTS -> BUTTON
========================================================================= */
/**
* Main button component with a bunch of modifiers plus an optional 'Grouping'
* option.
*
* The base component class and all of its modifiers:
*
.c-button
.c-button--secondary
.c-button--tiny
.c-button--small
.c-button--large
.c-button--huge
.c-button--full-bleed
*
* The 'Grouping' option base class and all of its modifiers:
*
.c-button-group
.c-button-group--vertical
*
* @markup
<button class="c-button [modifier(s)]">Button text</button>
*
* 'Grouping' option:
*
* N.B. grouping buttons requires that you remove the whitespace between the
* buttons so they're flush to each other, one way to do this is by inserting
* HTML comments between the buttons.
*
<div class="c-button-group">
<button class="c-button [modifier(s)]">Button text</button><!--
--><button class="c-button [modifier(s)]">Button text</button><!--
--><button class="c-button [modifier(s)]">Button text</button>
</div>
<div class="c-button-group c-button-group--vertical">
<button class="c-button c-button--full-bleed [modifier(s)]">Button text</button><!--
--><button class="c-button c-button--full-bleed [modifier(s)]">Button text</button><!--
--><button class="c-button c-button--full-bleed [modifier(s)]">Button text</button>
</div>
*
* @dependency
* This component is dependent on the Button object therefore it is
* `@extend`ed from this component.
*/
/**
* Settings.
*/
/**
* Toggle on/off certain styles and treatments.
*/
$c-button-apply-hover-styles: true !default;
$c-button-apply-border: false !default;
$c-button-apply-rounded-corners: true !default;
$c-button-apply-group: false !default;
$c-button-apply-group-rounded-corners: true !default;
/**
* Box sizing, here we set a variable assuming that `box-sizing: border-box;`
* is not set globally. If it has been previously been defined, the following
* variable will be overridden and will be set to `true`.
*/
$apply-friendly-box-model: false !default;
/**
* Colours.
*/
$c-button-background-color: $color-primary !default;
$c-button-background-color-secondary: $color-secondary !default;
$c-button-foreground-color: $color-white !default;
$c-button-foreground-color-secondary: $c-button-foreground-color !default;
/**
* Padding.
*/
$c-button-padding-base: $spacing-base !default;
$c-button-padding-tiny: $spacing-third !default;
$c-button-padding-small: $spacing-half !default;
$c-button-padding-large: $spacing-base-plus-half !default;
$c-button-padding-huge: $spacing-double !default;
/**
* Border.
*
* N.B. also includes the borders used in the 'Grouping' option.
*/
$c-button-border-thickness: 1 !default;
$c-button-border-style: solid !default;
$c-button-border-color:
darken($c-button-background-color, 10%) !default;
$c-button-border-color-secondary:
darken($c-button-background-color-secondary, 10%) !default;
/**
* Rounded corners.
*/
$c-button-rounded-corners-size: $border-radius !default;
/**
* Hover/focus styles, simple fade out effect via `opacity`
*/
$c-button-hover-opacity-strength: 0.7 !default;
$c-button-hover-transition-duration: 0.15s !default;
$c-button-hover-transition-timing-function: linear !default;
.c-button {
@extend %o-button;
text-align: center;
background-color: $c-button-background-color;
@include to-rem(padding, $c-button-padding-base / 2 $c-button-padding-base);
// Apply a border
@if $c-button-apply-border {
border: strip-unit($c-button-border-thickness) * 1px $c-button-border-style
$c-button-border-color;
}
// Apply rounded corners
@if $c-button-apply-rounded-corners {
// N.B. ugly hack in order to increase the specificity to override the
// removal of rounded corners that iOS applies set in Core -> Base ->
// Forms
html & {border-radius: strip-unit($c-button-rounded-corners-size) * 1px;}
}
// Foreground colour
&,
&:hover,
&:focus,
&:active {
color: $c-button-foreground-color;
}
// Apply hover/focus styles
@if $c-button-apply-hover-styles {
transition: opacity $c-button-hover-transition-duration
$c-button-hover-transition-timing-function;
&:hover,
&:focus {
opacity: $c-button-hover-opacity-strength;
}
}
}
/**
* Modifier: secondary colour.
*/
.c-button--secondary {
background-color: $c-button-background-color-secondary;
// Apply a border
@if $c-button-apply-border {
border-color: $c-button-border-color-secondary;
}
// Foreground colour
&,
&:hover,
&:focus,
&:active {
color: $c-button-foreground-color-secondary;
}
}
/**
* Modifier: tiny padding.
*/
.c-button--tiny {
@include to-rem(padding, $c-button-padding-tiny / 2 $c-button-padding-tiny);
}
/**
* Modifier: small padding.
*/
.c-button--small {
@include to-rem(padding, $c-button-padding-small / 2 $c-button-padding-small);
}
/**
* Modifier: large padding.
*/
.c-button--large {
@include to-rem(padding, $c-button-padding-large / 2 $c-button-padding-large);
}
/**
* Modifier: huge padding.
*/
.c-button--huge {
@include to-rem(padding, $c-button-padding-huge / 2 $c-button-padding-huge);
}
/**
* Modifier: full bleed.
*/
.c-button--full-bleed {
display: block;
width: 100%;
@if $apply-friendly-box-model == false {
// Remove paddings so that widths and paddings don't conflict however if
// you're applying a border then that *will* conflict with the width but
// Scally cannot help you in this case
padding-right: 0;
padding-left: 0;
}
}
/**
* Button group (optional).
*
* When you want to group a bunch of buttons side-by-side flush to each other
* i.e. with no gap between the buttons. To differentiate between the buttons
* a border is added.
*/
@if $c-button-apply-group {
.c-button-group {
.c-button {
@if $c-button-apply-border == false {
border: $c-button-border-thickness $c-button-border-style
$c-button-border-color;
}
// Turn off right borders so they don't double up, except for the last
// one
&:not(:last-child) {
border-right: 0;
}
// Turn off rounded corners if rounded corners are on by default as only
// the first and last buttons in the group need rounded corners
@if $c-button-apply-rounded-corners {
border-radius: 0;
}
// Round off the first and last buttons in the group
@if $c-button-apply-group-rounded-corners or
$c-button-apply-rounded-corners {
&:first-child {
border-top-left-radius: strip-unit($c-button-rounded-corners-size) * 1px;
border-bottom-left-radius: strip-unit($c-button-rounded-corners-size) * 1px;
}
&:last-child {
border-top-right-radius: strip-unit($c-button-rounded-corners-size) * 1px;
border-bottom-right-radius: strip-unit($c-button-rounded-corners-size) * 1px;
}
}
}
/**
* Modifier: vertically stacked button group.
*
* N.B. buttons within the vertically stacked version need to use the
* `button--full-bleed` modifier.
*/
&.c-button-group--vertical {
// This will shrink wrap the container to be as wide as the widest button
display: inline-block;
.c-button {
// Turn back on the right border that gets turned off by default
border-right: $c-button-border-thickness $c-button-border-style
$c-button-border-color;
// Turn off bottom borders so they don't double up, except for the last
// one
&:not(:last-child) {
border-bottom: 0;
}
// Round off the first and last buttons in the group
@if $c-button-apply-group-rounded-corners or
$c-button-apply-rounded-corners {
&:first-child {
border-bottom-left-radius: 0;
border-top-left-radius: strip-unit($c-button-rounded-corners-size) * 1px;
border-top-right-radius: strip-unit($c-button-rounded-corners-size) * 1px;
}
&:last-child {
border-top-right-radius: 0;
border-bottom-left-radius: strip-unit($c-button-rounded-corners-size) * 1px;
border-bottom-right-radius: strip-unit($c-button-rounded-corners-size) * 1px;
}
}
}
}
}
}