Answer the question
In order to leave comments, you need to log in
What is the best way to handle associative arrays in SASS?
SASS has associative arrays (maps). The thing is certainly useful - it would be if it were not for the ugly syntax of using it: map-get($map, $key)
Who could have thought of such a thing, I don’t know. And okay, if I have a one-dimensional array. And if two-dimensional or God forbid three? Well, something like:
$button-color: (
primary: (
normal: (
background: #0088cc,
text: #ffffff,
),
hover: (
background: #0077b3,
text: #ffffff,
),
),
default: (
// ...
),
);
// wtf?
background-color: map-get(map-get(map-get($button-color, 'primary'), 'hover'), 'background');
$button-primary-normal-background: #0088cc;
$button-primary-normal-text: #ffffff;
$button-primary-hover-background: #0077b3;
$button-primary-hover-text: #ffffff;
// ...
Answer the question
In order to leave comments, you need to log in
It is good practice not to use all the features of the language (especially new ones) unnecessarily.
If a set of variables is enough, then you need to stop there, because your code will also need to be read by people, not just robots, so you should think about making a choice towards more maintainable code than towards more "optimized".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question