summaryrefslogtreecommitdiffstats
path: root/src/_functions.scss
blob: 94254134d856e9cca10c871761e0bb97f13001e5 (plain) (blame)
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
@use 'iro-sass/src/index' as iro;

@function color($key, $tree: 'colors', $default: null, $global: false) {
    @return iro.props-get(join(--colors, $key), $tree, $default, $global);
}

@function global-color($key, $tree: 'colors', $default: null, $global: true) {
    @return color($key, $tree, $default, $global);
}

@function foreign-color($foreign-key, $key, $tree: 'colors', $default: null, $global: true) {
    @return iro.props-get(join($foreign-key --colors, $key), $tree, $default, $global);
}

@function dim($key, $tree: 'dims', $default: null, $global: false) {
    @return iro.props-get(join(--dims, $key), $tree, $default, $global);
}

@function global-dim($key, $tree: 'dims', $default: null, $global: true) {
    @return dim($key, $tree, $default, $global);
}

@function foreign-dim($foreign-key, $key, $tree: 'dims', $default: null, $global: true) {
    @return iro.props-get(join($foreign-key --dims, $key), $tree, $default, $global);
}

@function font-prop($data, $overrides, $key, $prop) {
    @if (map-has-key($overrides, $prop)) {
        @return map-get($overrides, $prop);
    } @else if (map-has-key($data, $prop)) {
        @return global-dim(--font $key $prop);
    }
    @return null;
}

@function set-font($key, $overrides: ()) {
    $font: iro.props-get-static(join(--dims --font, $key), 'dims', $global: true);

    $map: (
        font-family:             font-prop($font, $overrides, $key, --family),
        font-size:               font-prop($font, $overrides, $key, --size),
        font-weight:             font-prop($font, $overrides, $key, --weight),
        font-style:              font-prop($font, $overrides, $key, --style),
        line-height:             font-prop($font, $overrides, $key, --line-height),
        text-transform:          font-prop($font, $overrides, $key, --transform),
        letter-spacing:          font-prop($font, $overrides, $key, --spacing),
        font-variant-alternates: font-prop($font, $overrides, $key, --variant-alternates),
    );

    @return $map;
}

@mixin set-font($basis, $values: ()) {
    $values: set-font($basis, $values);

    @each $prop, $value in $values {
        @if $value != null {
            #{$prop}: $value;
        }
    }
}