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

Add support for boolean values for theme.variants #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

likethemammal
Copy link

@likethemammal likethemammal commented Dec 27, 2019

Because the docs dont explicitly say otherwise, I assumed that boolean values would work as keys in the values object passed to theme.variants(). After some debugging and looking through the source I realized this wasnt possible because of a conditional that checked if the value's key was truthy.

These changes explicitly check if the value's key is undefined, which allows props passed to the styled Component to be boolean values.

Example usage:

theme.variants('someMode', 'hasSomeProp', {
  [true]: {
    light: 'some value',
    dark: 'some darker value',
  },
  [false]: {
    light: 'some other value',
    dark: 'some other darker value',
  }
})

@likethemammal likethemammal changed the title Add support for boolean values Add support for boolean values for theme.variants Dec 30, 2019
@matthew-dean
Copy link

I came here looking for the same thing. I don't think that would work because an object's keys, by definition, can only be a string, number, or symbol. So I feel like this is a side-effect of checking for values using key names.

Instead, IMO this should allow a custom function, like:

theme.variants('someMode', 'hasSomeProp', val => {
  if (val === true) {
    return {
      light: 'some value',
      dark: 'some darker value',
    }
  }
  return {
    light: 'some other value',
    dark: 'some other darker value',
  }
})

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