Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sass map dynamic keys

Tags:

sass

sass-maps

Is it possible to use variables as keys to define a map?

Example code

$types: (
        'INPUT': 1,
        'SELECT': 2,
        'BUTTON': 3,
);

$colors: (
        $types['INPUT'] : #f44336,
        $types['SELECT']: #2196f3,
        $types['BUTTON']: #9c27b0,
);
like image 533
unloco Avatar asked Dec 05 '25 22:12

unloco


1 Answers

I found out how to do it

@function type($key) {
  @return map-get($types, $key);
}

$colors: (
        type('INPUT'): #f44336,
        type('SELECT'): #2196f3,
        type('BUTTON'): #9c27b0,
}
like image 72
unloco Avatar answered Dec 10 '25 13:12

unloco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!