Luca Reghellin
Luca Reghellin

Reputation: 8103

Dynamic output of sass maps?

say this (sass maps):

$small:(
  side-spacing: 14px
);

$medium-aux:(
  side-spacing: 28px
);

$large:(
  side-spacing: 38px
);

Is there a way to build a 'function' that outputs the above, receiving the values? Like (fake):

build_spacings(14px, 28px, 38px);

They asked me why this is not a duplicate question: I'm speaking specifically of sass maps, and not necessarilly global ones.

Upvotes: 1

Views: 54

Answers (1)

Andrew Myers
Andrew Myers

Reputation: 2786

You can set those global variables if you use the !global keyword.

Here is working code that will generate the maps in your question:

@mixin build_spacings ($s, $m, $l) {
  $small: (
    side-spacing: $s
  ) !global;

  $medium-aux: (
    side-spacing: $m
  ) !global;

  $large: (
    side-spacing: $l
  ) !global;
}

@include build_spacings(14px, 28px, 38px);

You can see it working at SassMeister.

Upvotes: 1

Related Questions