UNPKG

6.25 kBSCSSView Raw
1// Foundation for Sites by ZURB
2// foundation.zurb.com
3// Licensed under MIT Open Source
4
5////
6/// @group button-group
7////
8
9/// Margin for button groups.
10/// @type Number
11$buttongroup-margin: 1rem !default;
12
13/// Margin between buttons in a button group.
14/// @type Number
15$buttongroup-spacing: 1px !default;
16
17/// Selector for the buttons inside a button group.
18/// @type String
19$buttongroup-child-selector: '.button' !default;
20
21/// Maximum number of buttons that can be in an even-width button group.
22/// @type Number
23$buttongroup-expand-max: 6 !default;
24
25/// Determines if $button-radius is applied to each button or the button group as a whole. Use $global-radius in _settings.scss to change radius.
26/// @type Boolean
27$buttongroup-radius-on-each: true !default;
28
29/// Add styles for a button group container.
30/// @param {String} $child-selector [$buttongroup-child-selector] - Selector for the buttons inside a button group.
31/// @param {Number} $spacing [$buttongroup-spacing] - Spacing between buttons in a button group.
32@mixin button-group(
33 $child-selector: $buttongroup-child-selector,
34 $spacing: $buttongroup-spacing
35) {
36 @include clearfix;
37 margin-bottom: $buttongroup-margin;
38
39 @if $global-flexbox {
40 display: flex;
41 flex-wrap: nowrap;
42 align-items: stretch;
43 }
44 @else {
45 font-size: 0;
46 }
47
48 #{$child-selector} {
49 margin: 0;
50 margin-#{$global-right}: $spacing;
51 margin-bottom: $spacing;
52 font-size: map-get($button-sizes, default);
53
54 @if $global-flexbox {
55 flex: 0 0 auto;
56 }
57
58 &:last-child {
59 margin-#{$global-right}: 0;
60 }
61
62 @if not $buttongroup-radius-on-each {
63 border-radius: 0;
64
65 &:first-child {
66 border-top-#{$global-left}-radius: $button-radius;
67 border-bottom-#{$global-left}-radius: $button-radius;
68 }
69
70 &:last-child {
71 border-top-#{$global-right}-radius: $button-radius;
72 border-bottom-#{$global-right}-radius: $button-radius;
73 }
74 }
75
76 }
77}
78
79/// Creates a full-width button group, making each button equal width.
80/// @param {String} $selector [$buttongroup-child-selector] - Selector for the buttons inside a button group.
81/// @param {Number} $spacing [$buttongroup-spacing] - Spacing between buttons in a button group.
82@mixin button-group-expand(
83 $selector: $buttongroup-child-selector,
84 $spacing: $buttongroup-spacing,
85 $count: null
86) {
87 @if not $global-flexbox {
88 margin-#{$global-right}: -$spacing;
89
90 &::before,
91 &::after {
92 display: none;
93 }
94 }
95
96 #{$selector} {
97 @if $global-flexbox {
98 flex: 1 1 0px; // sass-lint:disable-line zero-unit
99 }
100 @else {
101 // One child
102 &:first-child:last-child {
103 width: 100%
104 }
105
106 // Two or more childreen
107 @for $i from 2 through $buttongroup-expand-max {
108 &:first-child:nth-last-child(#{$i}) {
109 &, &:first-child:nth-last-child(#{$i}) ~ #{$selector} {
110 display: inline-block;
111 width: calc(#{percentage(1 / $i)} - #{$spacing});
112 margin-#{$global-right}: $spacing;
113
114 &:last-child {
115 margin-#{$global-right}: $spacing * -$buttongroup-expand-max;
116 }
117 }
118 }
119 }
120 }
121 }
122}
123
124/// Stacks the buttons in a button group.
125/// @param {String} $selector [$buttongroup-child-selector] - Selector for the buttons inside the button group.
126@mixin button-group-stack(
127 $selector: $buttongroup-child-selector
128) {
129 @if $global-flexbox {
130 flex-wrap: wrap;
131 }
132
133 #{$selector} {
134 @if $global-flexbox {
135 flex: 0 0 100%;
136 }
137 @else {
138 width: 100%;
139 }
140
141 &:last-child {
142 margin-bottom: 0;
143 }
144
145
146 @if not $buttongroup-radius-on-each {
147 border-radius: 0;
148
149 &:first-child{
150 border-top-#{$global-left}-radius: $global-radius;
151 border-top-#{$global-right}-radius: $global-radius;
152 }
153
154 &:last-child {
155 margin-bottom: 0;
156 border-bottom-#{$global-left}-radius: $global-radius;
157 border-bottom-#{$global-right}-radius: $global-radius;
158 }
159 }
160
161 }
162}
163
164/// Un-stacks the buttons in a button group.
165/// @param {String} $selector [$buttongroup-child-selector] - Selector for the buttons inside the button group.
166@mixin button-group-unstack(
167 $selector: $buttongroup-child-selector
168) {
169 #{$selector} {
170 @if $global-flexbox {
171 flex: 1 1 0px; // sass-lint:disable-line zero-unit
172 }
173 @else {
174 width: auto;
175 }
176 margin-bottom: 0;
177
178 @if not $buttongroup-radius-on-each {
179 &:first-child {
180 border-top-#{$global-left}-radius: $global-radius;
181 border-top-#{$global-right}-radius: 0;
182 border-bottom-#{$global-left}-radius: $global-radius;
183 }
184
185 &:last-child {
186 border-top-#{$global-right}-radius: $global-radius;
187 border-bottom-#{$global-right}-radius: $global-radius;
188 border-bottom-#{$global-left}-radius: 0;
189 }
190 }
191
192 }
193}
194
195@mixin foundation-button-group {
196 .button-group {
197 @include button-group;
198
199 // Sizes
200 @each $size, $value in map-remove($button-sizes, default) {
201 &.#{$size} #{$buttongroup-child-selector} {
202 font-size: $value;
203 }
204 }
205
206 // Even-width Group
207 &.expanded { @include button-group-expand; }
208
209 // Colors
210 @each $name, $color in $foundation-palette {
211 @if $button-fill != hollow {
212 &.#{$name} #{$buttongroup-child-selector} {
213 @include button-style($color, auto, auto);
214 }
215 }
216 @else {
217 &.#{$name} #{$buttongroup-child-selector} {
218 @include button-hollow;
219 @include button-hollow-style($color);
220 }
221 }
222 }
223
224 &.stacked,
225 &.stacked-for-small,
226 &.stacked-for-medium {
227 @include button-group-stack;
228 }
229
230 &.stacked-for-small {
231 @include breakpoint(medium) {
232 @include button-group-unstack;
233 }
234 }
235
236 &.stacked-for-medium {
237 @include breakpoint(large) {
238 @include button-group-unstack;
239 }
240 }
241
242 &.stacked-for-small.expanded { // sass-lint:disable-line force-element-nesting
243 @include breakpoint(small only) {
244 display: block;
245
246 #{$buttongroup-child-selector} {
247 display: block;
248 margin-#{$global-right}: 0;
249 }
250 }
251 }
252 }
253}