-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_space.scss
More file actions
114 lines (103 loc) · 2.48 KB
/
_space.scss
File metadata and controls
114 lines (103 loc) · 2.48 KB
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
/**
* Space style generation
* Custom properties and styles with configuration.
*/
/**
* Requires
*/
@use "sass:list";
@use "sass:map";
@use "sass:meta";
@use 'abstract';
@use 'mixins';
@use 'media';
/**
* Component css class
* @protected
* @type {string} css class
*/
$class: 'ui-space' !default;
/**
* Component property prefix
* @protected
* @type {string} property name
*/
$props: 'ui-space-' !default;
/**
* Config defaults
* @private
* @type {map}
*/
$-config: (
sizes: null,
properties: (
margin,
padding,
),
);
/**
* Update component config options
* @public
* @param {map} $sizes - Map of size options
* @param {list} $properties - List of property options
* @output {void} - Only sets config options
*/
@mixin config($config) {
$-config: abstract.config($config, $-config, true, false, 'ui-space.config::') !global;
}
/**
* Generate required custom properties
* @public
* @param {null|map} $extend - Extend properties for output only
* @output Adds components custom properties in current scope
*/
@mixin properties($extend: null) {
$compiled: abstract.merge-optional(map.get($-config, 'sizes'), $extend);
$render: ();
@each $name, $sizes in $compiled {
$value: abstract.spacing($sizes...);
$render: map.set($render, $name, $value);
}
@include mixins.properties($render, $props, '_at_', 'ui-space.properties::');
}
/**
* Get size variable name
* @public
* @param {string} $name - Size reference
* @output Returns a css var declaration
*/
@function get($name) {
@return var(--#{$props}#{$name});
}
/**
* Generate spacing styles
* @public
* @output Outputs configured spacing styles in given context
*/
@mixin styles() {
// Must have at least one defined style
$-sizes: map.get($-config, 'sizes');
@if meta.type-of($-sizes) != map {
@error 'You must define at least one spacing size using the config mixin';
}
// Must have at least one property style
$-properties: map.get($-config, 'properties');
@if meta.type-of($-properties) != list {
@error 'You must define at least one spacing property using the config mixin';
}
@if list.length($-properties) < 1 {
@error 'You must define at least one spacing property using the config mixin';
}
// Render utility classes
.#{$class} {
@each $prop in $-properties {
&--#{abstract.str-initials($prop)} {
@each $name, $size in $-sizes {
&-#{$name} {
#{$prop}: var(--#{$props}#{$name});
}
}
}
}
}
}