unloco
unloco

Reputation: 7330

Sass map dynamic keys

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,
);

Upvotes: 3

Views: 578

Answers (1)

unloco
unloco

Reputation: 7330

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,
}

Upvotes: 3

Related Questions