/
_ui-corners.scss
480 lines (440 loc) · 19.4 KB
/
_ui-corners.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
//-----------------------------------------------
// Variables
//-----------------------------------------------
$ui-corners-cache-buster: true !default;
// default widths
$ui-corners-corner-height: 10px !default;
$ui-corners-corner-width: 10px !default;
$ui-corners-side-width: 10px !default;
// defaults per corner
$ui-corners-corner-tl-height: $ui-corners-corner-height !default;
$ui-corners-corner-tl-width: $ui-corners-corner-width !default;
$ui-corners-corner-tr-height: $ui-corners-corner-height !default;
$ui-corners-corner-tr-width: $ui-corners-corner-width !default;
$ui-corners-corner-br-height: $ui-corners-corner-height !default;
$ui-corners-corner-br-width: $ui-corners-corner-width !default;
$ui-corners-corner-bl-height: $ui-corners-corner-height !default;
$ui-corners-corner-bl-width: $ui-corners-corner-width !default;
// defaults per side
$ui-corners-side-top-width: $ui-corners-side-width !default;
$ui-corners-side-bottom-width: $ui-corners-side-width !default;
$ui-corners-side-left-width: $ui-corners-side-width !default;
$ui-corners-side-right-width: $ui-corners-side-width !default;
//-----------------------------------------------
// Corner Border Width
// Adds padding to the corner container to simulate a border
// The second parameter allows for setting an inner padding in addition to the border
// @param list $width border-width list: [top] [right] [bottom] [left]
// @param list $padding (optional) padding list: [top] [right] [bottom] [left]
//-----------------------------------------------
@mixin corner-border-width ($border-width, $padding: false) {
@if $padding {
$border-width: corner-zip-widths($border-width, $padding);
}
&.ui-corners { padding: $border-width; }
}
//-----------------------------------------------
// Corner Zip Widths
// returns a list of the two lists added together
// @param list $a list of widths: [top] [right] [bottom] [left]
// @param list $b (optional) list of widths: [top] [right] [bottom] [left]
// @return list
//-----------------------------------------------
@function corner-zip-widths($a, $b: 0) {
$a-t: corner-nth($a, 1, 0);
$a-r: corner-nth($a, 2, $a-t);
$a-b: corner-nth($a, 3, $a-t);
$a-l: corner-nth($a, 4, $a-r);
$b-t: corner-nth($b, 1, 0);
$b-r: corner-nth($b, 2, $b-t);
$b-b: corner-nth($b, 3, $b-t);
$b-l: corner-nth($b, 4, $b-r);
$a-t: $a-t + $b-t;
$a-r: $a-r + $b-r;
$a-b: $a-b + $b-b;
$a-l: $a-l + $b-l;
@if $a-t == $a-b and $a-r == $a-l and $a-t == $a-r {
@return $a-t; // all equal
} @elseif $a-t == $a-b and $a-r == $a-l and $a-t != $a-r {
@return $a-t $a-r; // x and y different
} @elseif $a-t != $a-b and $a-r == $a-l {
@return $a-t $a-r $a-b; // y different
} @else {
@return $a-t $a-r $a-b $a-l;// all different
}
}
//-----------------------------------------------
// Corner Images
// @param list $tl [background-image] [width] [height] [background-position-x] [background-position-y] [left] [top] top-left corner
// @param list $t [background-image] [height] [background-position-x] [background-position-y] [left] [right] [top] top side
// @param list $tr [background-image] [width] [height] [background-position-x] [background-position-y] [right] [top] top-right corner
// @param list $r [background-image] [width] [background-position-x] [background-position-y] [right] [top] [bottom] right side
// @param list $br [background-image] [width] [height] [background-position-x] [background-position-y] [right] [bottom] bottom-right corner
// @param list $b [background-image] [height] [background-position-x] [background-position-y] [left] [right] [bottom] bottom side
// @param list $bl [background-image] [width] [height] [background-position-x] [background-position-y] [left] [bottom] bottom-left corner
// @param list $l [background-image] [width] [background-position-x] [background-position-y] [left] [top] [bottom] left side
//-----------------------------------------------
@mixin corner-images ($tl: auto, $t: auto, $tr: auto, $r: auto, $br: auto, $b: auto, $bl: auto, $l: auto) {
// corner images and dimensions
$tl-image: nth($tl, 1);
$tl-width: corner-var(corner-nth($tl, 2, auto) corner-image-width($tl-image) $ui-corners-corner-tl-width);
$tl-height: corner-var(corner-nth($tl, 3, auto) corner-image-height($tl-image) $ui-corners-corner-tl-height);
$tr-image: nth($tr, 1);
$tr-width: corner-var(corner-nth($tr, 2, auto) corner-image-width($tr-image) $ui-corners-corner-tr-width);
$tr-height: corner-var(corner-nth($tr, 3, auto) corner-image-height($tr-image) $ui-corners-corner-tr-height);
$br-image: nth($br, 1);
$br-width: corner-var(corner-nth($br, 2, auto) corner-image-width($br-image) $ui-corners-corner-br-width);
$br-height: corner-var(corner-nth($br, 3, auto) corner-image-height($br-image) $ui-corners-corner-br-height);
$bl-image: nth($bl, 1);
$bl-width: corner-var(corner-nth($bl, 2, auto) corner-image-width($bl-image) $ui-corners-corner-bl-width);
$bl-height: corner-var(corner-nth($bl, 3, auto) corner-image-height($bl-image) $ui-corners-corner-bl-height);
$t-image: nth($t, 1); $r-image: nth($r, 1); $b-image: nth($b, 1); $l-image: nth($l, 1);
// all backgrounds are the same
@if $tl-image != none and $tl-image == $t-image and $tl-image == $tr-image and $tl-image == $r-image
and $tl-image == $br-image and $tl-image == $b-image and $tl-image == $b-image and $tl-image == $l-image {
.ui-corners-corner, .ui-corners-side { background-image: image-url($tl-image, false, $ui-corners-cache-buster); }
$tl-image: none; $tr-image: none; $br-image: none; $bl-image: none;
$t-image: none; $r-image: none; $b-image: none; $l-image: none;
}
// normalize height and width
$width: false;
$height: false;
// check all width are the same
@if $tl-width == $tr-width and $tl-width == $br-width and $tl-width == $bl-width { $width: $tl-width; }
// check all heights are the same
@if $tl-height == $tr-height and $tl-height == $br-height and $tl-height == $bl-height { $height: $tl-height; }
// set the width and height with a generic class
@if ($width and $width != $ui-corners-corner-width) or ($height and $height != $ui-corners-corner-height)
or ($tl-image != none and $tl-image == $tr-image and $tl-image == $br-image and $tl-image == $bl-image) {
// when it matches default, fall back to generic corner class
.ui-corners-corner {
@if $width and $width != $ui-corners-corner-width { width: $width; }
@if $height and $height != $ui-corners-corner-height { height: $height; }
@if $tl-image != none and $tl-image == $tr-image and $tl-image == $br-image and $tl-image == $bl-image {
background-image: image-url($tl-image, false, $ui-corners-cache-buster);
$tl-image: none; $tr-image: none; $br-image: none; $bl-image: none;
}
}
}
// Top Left
@if $tl != auto {
.ui-corners-corner-tl {
@include corner-props(
$image: $tl-image,
$w: if($width, false, $tl-width),
$h: if($height, false, $tl-height),
$x: corner-nth($tl, 4, auto) false 0,
$y: corner-nth($tl, 5, auto) false 0,
$l: corner-nth($tl, 6, auto) false 0,
$t: corner-nth($tl, 7, auto) false 0
);
}
}
// Top Right
@if $tr != auto {
.ui-corners-corner-tr {
@include corner-props(
$image: $tr-image,
$w: if($width, false, $tr-width),
$h: if($height, false, $tr-height),
$x: corner-nth($tr, 4, auto) false 0,
$y: corner-nth($tr, 5, auto) false 0,
$r: corner-nth($tr, 6, auto) false 0,
$t: corner-nth($tr, 7, auto) false 0
);
}
}
// Bottom Right
@if $br != auto {
.ui-corners-corner-br {
@include corner-props(
$image: $br-image,
$w: if($width, false, $br-width),
$h: if($height, false, $br-height),
$x: corner-nth($br, 4, auto) false 0,
$y: corner-nth($br, 5, auto) false 0,
$r: corner-nth($br, 6, auto) false 0,
$b: corner-nth($br, 7, auto) false 0
);
}
}
// Bottom Left
@if $bl != auto {
.ui-corners-corner-bl {
@include corner-props(
$image: $bl-image,
$w: if($width, false, $bl-width),
$h: if($height, false, $bl-height),
$x: corner-nth($bl, 4, auto) false 0,
$y: corner-nth($bl, 5, auto) false 0,
$l: corner-nth($bl, 6, auto) false 0,
$b: corner-nth($bl, 7, auto) false 0
);
}
}
// Side left, right, top and bottom
$t-height: corner-var(corner-nth($t, 2, auto) $tl-height $ui-corners-side-left-width);
$t-left: corner-var(corner-nth($t, 6, auto) ($tl-width + corner-nth($tl, 6, 0)) $ui-corners-corner-width);
$t-right: corner-var(corner-nth($t, 7, auto) ($tr-width + corner-nth($tr, 6, 0)) $ui-corners-corner-width);
$b-height: corner-var(corner-nth($b, 2, auto) $bl-height $ui-corners-side-left-width);
$b-left: corner-var(corner-nth($b, 6, auto) ($bl-width + corner-nth($bl, 6, 0)) $ui-corners-corner-width);
$b-right: corner-var(corner-nth($b, 7, auto) ($br-width + corner-nth($br, 6, 0)) $ui-corners-corner-width);
$l-width: corner-var(corner-nth($l, 2, auto) $tl-width $ui-corners-side-left-width);
$l-top: corner-var(corner-nth($l, 6, auto) ($tl-height + corner-nth($tl, 7, 0)) $ui-corners-corner-height);
$l-bottom: corner-var(corner-nth($l, 7, auto) ($bl-height + corner-nth($bl, 7, 0)) $ui-corners-corner-height);
$r-width: corner-var(corner-nth($r, 2, auto) $tr-width $ui-corners-side-right-width);
$r-top: corner-var(corner-nth($r, 6, auto) ($tr-height + corner-nth($tr, 7, 0)) $ui-corners-corner-height);
$r-bottom: corner-var(corner-nth($r, 7, auto) ($br-height + corner-nth($br, 7, 0)) $ui-corners-corner-height);
// normalize left and right, top and bottom
$left: false;
$right: false;
$top: false;
$bottom: false;
$width: false;
$height: false;
// check all sides are the same
@if $t-left == $b-left { $left: $t-left; }
@if $t-right == $b-right { $right: $t-right; }
@if $t-height == $b-height { $height: $t-height; }
@if $l-top == $r-top { $top: $l-top; }
@if $l-bottom == $r-bottom { $bottom: $l-bottom; }
@if $l-width == $r-width { $width: $l-width; }
@if $t-image != none and $t-image == $r-image and $t-image == $b-image and $t-image == $l-image {
.ui-corners-side { background-image: image-url($t-image, false, $ui-corners-cache-buster); }
$t-image: none; $r-image: none; $b-image: none; $l-image: none;
}
// set the top and bottom sides with a generic class
@if ($left and $left != $ui-corners-corner-width) or ($right and $right != $ui-corners-corner-width)
or ($height and $height != $ui-corners-side-width) or ($t-image != none and $t-image == $b-image) {
// when it matches default, fall back to generic corner class
.ui-corners-side-top, .ui-corners-side-bottom {
@if $left and $left != $ui-corners-corner-width { left: $left; }
@if $right and $right != $ui-corners-corner-width { right: $right; }
@if $height and $height != $ui-corners-side-width { height: $height; }
@if $t-image != none and $t-image == $b-image { background-image: image-url($t-image, false, $ui-corners-cache-buster); $t-image: none; $b-image: none; }
}
}
// set the left and right sides with a generic class
@if ($top and $top != $ui-corners-corner-height) or ($bottom and $bottom != $ui-corners-corner-height)
or ($width and $width != $ui-corners-side-width) or ($l-image != none and $l-image == $r-image) {
// when it matches default, fall back to generic corner class
.ui-corners-side-left, .ui-corners-side-right {
@if $top and $top != $ui-corners-corner-height { top: $top; }
@if $bottom and $bottom != $ui-corners-corner-height { bottom: $bottom; }
@if $width and $width != $ui-corners-side-width { width: $width; }
@if $l-image != none and $l-image == $r-image { background-image: image-url($l-image, false, $ui-corners-cache-buster); $l-image: none; $r-image: none; }
}
}
// Top
@if $t != auto {
.ui-corners-side-top {
@include corner-props(
$image: $t-image,
$h: if($height, false, $t-height),
$x: corner-nth($t, 3, auto) false left,
$y: corner-nth($t, 4, auto) false top,
$l: if($left, false, $t-left),
$r: if($right, false, $t-right) + corner-nth($tr, 6, 0),
$t: corner-nth($t, 5, auto) false 0
);
}
}
// Bottom
@if $b != auto {
.ui-corners-side-bottom {
@include corner-props(
$image: $b-image,
$h: if($height, false, $b-height),
$x: corner-nth($b, 3, auto) false left,
$y: corner-nth($b, 4, auto) false bottom,
$l: if($left, false, $b-left),
$r: if($right, false, $b-right),
$b: corner-nth($b, 5, auto) false 0
);
}
}
// Left
@if $l != auto {
.ui-corners-side-left {
@include corner-props(
$image: $l-image,
$w: if($width, false, $l-width),
$x: corner-nth($l, 3, auto) false left,
$y: corner-nth($l, 4, auto) false top,
$l: corner-nth($l, 5, auto) false 0,
$t: if($top, false, $l-top),
$b: if($bottom, false, $l-bottom)
);
}
}
// Right
@if $r != auto {
.ui-corners-side-right {
@include corner-props(
$image: $r-image,
$w: if($width, false, $r-width),
$x: corner-nth($r, 3, auto) false right,
$y: corner-nth($r, 4, auto) false top,
$r: corner-nth($r, 5, auto) false 0,
$t: if($top, false, $r-top),
$b: if($bottom, false, $r-bottom)
);
}
}
}
//-----------------------------------------------
// Corner Props
// creates the porperties of corner or side
// @param image $image (optional)
// @param list $w (optional) [value] [auto] [default] element width.
// @param list $h (optional) [value] [auto] [default] element height.
// @param list $x (optional) [value] [auto] [default] background position x.
// @param list $y (optional) [value] [auto] [default] background position y.
// @param list $l (optional) [value] [auto] [default] position left.
// @param list $r (optional) [value] [auto] [default] position right.
// @param list $t (optional) [value] [auto] [default] position top.
// @param list $b (optional) [value] [auto] [default] position bottom.
//-----------------------------------------------
@mixin corner-props ($image: none, $w: false, $h: false, $x: false, $y: false, $l: false, $r: false, $t: false, $b: false) {
// each variable takes 3 values: passed auto default
$left: corner-var($l);
$right: corner-var($r);
$top: corner-var($t);
$bottom: corner-var($b);
$width: corner-var($w);
$height: corner-var($h);
@if $image != none { background-image: image-url($image, false, $ui-corners-cache-buster); }
@if $left != false { left: $left; }
@if $right != false { right: $right; }
@if $top != false { top: $top; }
@if $bottom != false { bottom: $bottom; }
@if $width != false { width: $width; }
@if $height != false { height: $height; }
$position-x: corner-var($x);
$position-y: corner-var($y);
@if $position-x != false or $position-y != false { background-position: if($position-x != false, $position-x, nth($x, 3)) if($position-y != false, $position-y, nth($x, 3)); }
}
//-----------------------------------------------
// Corner Nth
// returns the value of a list at an index or default value if the index is missing
// @param list $list value list
// @param int $n index within the lsit
// @param mixed $default default value if index does not exist
//-----------------------------------------------
@function corner-nth($list, $n, $default: false) {
$value: $default;
@if length($list) > $n - 1 { $value: nth($list, $n) }
@return $value;
}
//-----------------------------------------------
// Corner Image Width/Height
// returns the width of an image or default
// @param image $image
//-----------------------------------------------
@function corner-image-width($image) {
@if ($image == none) { @return default; }
@return image-width($image);
}
@function corner-image-height($image) {
@if ($image == none) { @return default; }
@return image-height($image);
}
//-----------------------------------------------
// Corner Vars
// returns the current value unless it is "auto" or "default" then those values are returned
// @param list $list list if values [current value] [value of auto] [value of default]
//-----------------------------------------------
@function corner-var($list) {
$val: nth($list, 1);
@if $val == auto { $val: nth($list, 2); }
@if $val == default { $val: nth($list, 3); }
@return $val;
}
//-----------------------------------------------
// Basic Styles (required)
//-----------------------------------------------
// corner wrapper
.ui-corners {
position: relative;
}
// the content of the wrapper
.ui-corners-content {
position: relative;
z-index: 1;
}
// all corners and sides
.ui-corners-corner, .ui-corners-side {
position: absolute;
z-index: 0;
}
//-----------------------------------------------
// Corners
//-----------------------------------------------
.ui-corners-corner {
height: $ui-corners-corner-height;
width: $ui-corners-corner-width;
background-repeat: no-repeat;
}
.ui-corners-corner-tl {
top: 0;
left: 0;
@if $ui-corners-corner-height != $ui-corners-corner-tl-height { height: $ui-corners-corner-tl-height; }
@if $ui-corners-corner-width != $ui-corners-corner-tl-width { width: $ui-corners-corner-tl-width; }
background-position: left top;
}
.ui-corners-corner-tr {
top: 0;
right: 0;
@if $ui-corners-corner-height != $ui-corners-corner-tr-height { height: $ui-corners-corner-tr-height; }
@if $ui-corners-corner-width != $ui-corners-corner-tr-width { width: $ui-corners-corner-tr-width; }
background-position: right top;
}
.ui-corners-corner-br {
bottom: 0;
right: 0;
@if $ui-corners-corner-height != $ui-corners-corner-br-height { height: $ui-corners-corner-br-height; }
@if $ui-corners-corner-width != $ui-corners-corner-br-width { width: $ui-corners-corner-br-width; }
background-position: right bottom;
}
.ui-corners-corner-bl {
bottom: 0;
left: 0;
@if $ui-corners-corner-height != $ui-corners-corner-bl-height { height: $ui-corners-corner-bl-height; }
@if $ui-corners-corner-width != $ui-corners-corner-bl-width { width: $ui-corners-corner-bl-width; }
background-position: left bottom;
}
//-----------------------------------------------
// Sides
//-----------------------------------------------
.ui-corners-side-top, .ui-corners-side-bottom {
left: $ui-corners-corner-width;
right: $ui-corners-corner-width;
height: $ui-corners-side-width;
background-repeat: repeat-x;
}
.ui-corners-side-left, .ui-corners-side-right {
top: $ui-corners-corner-height;
bottom: $ui-corners-corner-height;
width: $ui-corners-side-width;
background-repeat: repeat-y;
}
.ui-corners-side-top {
top: 0;
@if $ui-corners-side-width != $ui-corners-side-top-width { height: $ui-corners-side-top; }
background-position: left top;
}
.ui-corners-side-bottom {
bottom: 0;
@if $ui-corners-side-width != $ui-corners-side-bottom-width { height: $ui-corners-side-bottom; }
background-position: left bottom;
}
.ui-corners-side-left {
left: 0;
@if $ui-corners-side-width != $ui-corners-side-left-width { width: $ui-corners-side-left; }
background-position: left top;
}
.ui-corners-side-right {
right: 0;
@if $ui-corners-side-width != $ui-corners-side-right-width { width: $ui-corners-side-right; }
background-position: right top;
}