UNPKG

7.51 kBSCSSView Raw
1// Foundation for Sites by ZURB
2// foundation.zurb.com
3// Licensed under MIT Open Source
4
5// sass-lint:disable force-element-nesting, no-qualifying-elements
6
7////
8/// @group table
9////
10
11/// Default color for table background.
12/// @type Color
13$table-background: $white !default;
14
15/// Default scale for darkening the striped table rows and the table border.
16/// @type Number
17$table-color-scale: 5% !default;
18
19/// Default style for table border.
20/// @type List
21$table-border: 1px solid smart-scale($table-background, $table-color-scale) !default;
22
23/// Default padding for table.
24/// @type Number
25$table-padding: rem-calc(8 10 10) !default;
26
27/// Default scale for darkening the table rows on hover.
28/// @type Number
29$table-hover-scale: 2% !default;
30
31/// Default color of standard rows on hover.
32/// @type List
33$table-row-hover: darken($table-background, $table-hover-scale) !default;
34
35/// Default color of striped rows on hover.
36/// @type List
37$table-row-stripe-hover: darken($table-background, $table-color-scale + $table-hover-scale) !default;
38
39/// If `true`, tables are striped by default and an .unstriped class is created. If `false`, a .striped class is created.
40/// @type Boolean
41$table-is-striped: true !default;
42
43/// Default background color for striped rows.
44/// @type Color
45$table-striped-background: smart-scale($table-background, $table-color-scale) !default;
46
47/// Default value for showing the stripe on rows of the tables, excluding the header and footer. If even, the even rows will have a background color. If odd, the odd rows will have a background color. If empty, or any other value, the table rows will have no striping.
48/// @type Keyword
49$table-stripe: even !default;
50
51/// Default color for header background.
52/// @type Color
53$table-head-background: smart-scale($table-background, $table-color-scale / 2) !default;
54
55/// Default color of header rows on hover.
56/// @type List
57$table-head-row-hover: darken($table-head-background, $table-hover-scale) !default;
58
59/// Default color for footer background.
60/// @type Color
61$table-foot-background: smart-scale($table-background, $table-color-scale) !default;
62
63/// Default color of footer rows on hover.
64/// @type List
65$table-foot-row-hover: darken($table-foot-background, $table-hover-scale) !default;
66
67/// Default font color for header.
68/// @type Color
69$table-head-font-color: $body-font-color !default;
70
71/// Default font color for footer.
72/// @type Color
73$table-foot-font-color: $body-font-color !default;
74
75/// Default value for showing the header when using stacked tables.
76/// @type Boolean
77$show-header-for-stacked: false !default;
78
79/// Breakpoint at which stacked table switches from mobile to desktop view.
80/// @type Breakpoint
81$table-stack-breakpoint: medium !default;
82
83@mixin -zf-table-stripe($stripe: $table-stripe) {
84 tr {
85 // If stripe is set to even, darken the even rows.
86 @if $stripe == even {
87 &:nth-child(even) {
88 border-bottom: 0;
89 background-color: $table-striped-background;
90 }
91 }
92
93 // If stripe is set to odd, darken the odd rows.
94 @else if $stripe == odd {
95 &:nth-child(odd) {
96 background-color: $table-striped-background;
97 }
98 }
99 }
100}
101
102@mixin -zf-table-unstripe() {
103 tr {
104 border-bottom: 0;
105 border-bottom: $table-border;
106 background-color: $table-background;
107 }
108}
109
110@mixin -zf-table-children-styles($stripe: $table-stripe, $is-striped: $table-is-striped) {
111 thead,
112 tbody,
113 tfoot {
114 border: $table-border;
115 background-color: $table-background;
116 }
117
118 // Caption
119 caption {
120 padding: $table-padding;
121 font-weight: $global-weight-bold;
122 }
123
124 // Table head
125 thead {
126 background: $table-head-background;
127 color: $table-head-font-color;
128 }
129
130 // Table foot
131 tfoot {
132 background: $table-foot-background;
133 color: $table-foot-font-color;
134 }
135
136 // Table head and foot
137 thead,
138 tfoot {
139 // Rows within head and foot
140 tr {
141 background: transparent;
142 }
143
144 // Cells within head and foot
145 th,
146 td {
147 padding: $table-padding;
148 font-weight: $global-weight-bold;
149 text-align: #{$global-left};
150 }
151 }
152
153 // Table rows
154 tbody {
155 th,
156 td {
157 padding: $table-padding;
158 }
159 }
160
161 // If tables are striped
162 @if $is-striped == true {
163 tbody {
164 @include -zf-table-stripe($stripe);
165 }
166
167 &.unstriped {
168 tbody {
169 @include -zf-table-unstripe();
170 background-color: $table-background;
171 }
172 }
173 }
174
175 // If tables are not striped
176 @else if $is-striped == false {
177 tbody {
178 @include -zf-table-unstripe();
179 }
180
181 &.striped {
182 tbody {
183 @include -zf-table-stripe($stripe);
184 }
185 }
186 }
187}
188
189/// Adds the general styles for tables.
190/// @param {Keyword} $stripe [$table-stripe] - Uses keywords even, odd, or none to darken rows of the table. The default value is even.
191@mixin table(
192 $stripe: $table-stripe,
193 $nest: false
194) {
195 border-collapse: collapse;
196 width: 100%;
197 margin-bottom: $global-margin;
198 border-radius: $global-radius;
199
200 @if $nest {
201 @include -zf-table-children-styles($stripe);
202 }
203 @else {
204 @at-root {
205 @include -zf-table-children-styles($stripe);
206 }
207 }
208}
209
210/// Adds the ability to horizontally scroll the table when the content overflows horizontally.
211@mixin table-scroll {
212 display: block;
213 width: 100%;
214 overflow-x: auto;
215}
216
217/// Slightly darkens the table rows on hover.
218@mixin table-hover {
219 thead tr {
220 //Darkens the table header rows on hover.
221 &:hover {
222 background-color: $table-head-row-hover;
223 }
224 }
225
226 tfoot tr {
227 //Darkens the table footer rows on hover.
228 &:hover {
229 background-color: $table-foot-row-hover;
230 }
231 }
232
233 tbody tr {
234 //Darkens the non-striped table rows on hover.
235 &:hover {
236 background-color: $table-row-hover;
237 }
238 }
239
240 @if $table-is-striped == true {
241 // Darkens the even striped table rows.
242 @if($table-stripe == even) {
243 &:not(.unstriped) tr:nth-of-type(even):hover {
244 background-color: $table-row-stripe-hover;
245 }
246 }
247
248 // Darkens the odd striped table rows.
249 @elseif($table-stripe == odd) {
250 &:not(.unstriped) tr:nth-of-type(odd):hover {
251 background-color: $table-row-stripe-hover;
252 }
253 }
254 }
255
256 @else if $table-is-striped == false {
257 // Darkens the even striped table rows.
258 @if($table-stripe == even) {
259 &.striped tr:nth-of-type(even):hover {
260 background-color: $table-row-stripe-hover;
261 }
262 }
263
264 // Darkens the odd striped table rows.
265 @elseif($table-stripe == odd) {
266 &.striped tr:nth-of-type(odd):hover {
267 background-color: $table-row-stripe-hover;
268 }
269 }
270 }
271}
272
273/// Adds styles for a stacked table. Useful for small-screen layouts.
274/// @param {Boolean} $header [$show-header-for-stacked] - Show the first th of header when stacked.
275@mixin table-stack($header: $show-header-for-stacked) {
276 @if $header {
277 thead {
278 th {
279 display: block;
280 }
281 }
282 }
283 @else {
284 thead {
285 display: none;
286 }
287 }
288
289 tfoot {
290 display: none;
291 }
292
293 tr,
294 th,
295 td {
296 display: block;
297 }
298
299 td {
300 border-top: 0;
301 }
302}
303
304@mixin foundation-table($nest: false) {
305 table {
306 @include table($nest: $nest);
307 }
308
309 table.stack {
310 @include breakpoint($table-stack-breakpoint down) {
311 @include table-stack;
312 }
313 }
314
315 table.scroll {
316 @include table-scroll;
317 }
318
319 table.hover {
320 @include table-hover;
321 }
322
323 .table-scroll {
324 overflow-x: auto;
325
326 table {
327 width: auto;
328 }
329 }
330}