Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixin : default value for variable arguments feature #810

Closed
Nabellaleen opened this issue Jun 21, 2013 · 3 comments
Closed

Mixin : default value for variable arguments feature #810

Nabellaleen opened this issue Jun 21, 2013 · 3 comments

Comments

@Nabellaleen
Copy link

Actually, it's possible to have a default value for a mixin arguments

@mixin sexy-font($font-family: sans-serif) {
  font-family: $font-family;
}

or a variable arguments (that you must fill in)

@mixin sexy-font($font-family...) {
  font-family: $font-family;
}

But it's not possible to have a default value for a variable arguments, to not be forced to fill it

@mixin sexy-font($font-family: sans-serif...) {
  font-family: $font-family;
}
// or
@mixin sexy-font($font-family...: sans-serif) {
  font-family: $font-family;
}

What do you think ?

@Frexuz
Copy link

Frexuz commented Jun 26, 2013

+1

@Snugug
Copy link

Snugug commented Jun 26, 2013

You can do this currently the same way you define input defaults in JavaScript; with a check:

@mixin my-font($font-family...) {
  @if length($font-family) == 0 {
    $font-family: sans-serif;
  }

  font-family: $font-family;
}

Or, with Sass's if function:

@mixin my-font($font-family...) {
  $font-family: if(length($font-family) == 0, sans-serif, $font-family);

  font-family: $font-family;
}

@chriseppstein
Copy link

👍 That's how we expected it to be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants