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

Allow users to customize default variant placement #657

Merged
merged 1 commit into from
Feb 15, 2019

Conversation

adamwathan
Copy link
Member

This PR makes it possible for users to customize where the default (unaltered) variant for a utility is placed in the final CSS relative to other variants generated for that utility.

This is done by explicitly specifying default in the variant list if you want the default variant to be placed anywhere other than first in the list.

For example, this CSS:

@variants focus, default, hover {
  .order-2 {
    order: 2
  }
}

...will generate this output:

.focus\:order-2:focus {
  order: 2
}

.order-2 {
  order: 2
}

.hover\:order-2:hover {
  order: 2
}

If the default variant is not specified in the list, the default variant will be invisibly prepended to the variants list, ensuring that the default variant is always rendered first.

This feature is useful in situations where you want to create a custom variant that should still be overridable by a default variant when necessary, like outlined by @benface here:

#496 (comment)

@adamwathan adamwathan merged commit 3bea3a1 into master Feb 15, 2019
@codytooker
Copy link
Contributor

@xpromx

Or even

function ensureIncludesDefault(variants) {
  return [...new Set(['default', ...variants].reverse())].reverse()
}

@adamwathan adamwathan deleted the customize-default-variant-placement branch May 13, 2019 14:00
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

Successfully merging this pull request may close these issues.

3 participants