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

Nested modifiers #30

Open
jpbelo opened this issue Jun 2, 2019 · 2 comments
Open

Nested modifiers #30

jpbelo opened this issue Jun 2, 2019 · 2 comments

Comments

@jpbelo
Copy link

jpbelo commented Jun 2, 2019

EXPECTED BEHAVIOR

Being able to write nested modifiers to reduce duplicated code.

const MODIFIER_CONFIG = {
  asButton: () => {
    css`
      border: 1px solid grey;
      padding: 10px 20px;
      font-size: 15px;
    `,
    primary: () => {
      css`
        background-color: red;
      `
    },
    secondary: () => {
      css`
        background-color: blue;
      `
    }
  },
  asText: () => {
    css`
      font-size: 12px;
    `,
    primary: ...
    secondary: ...
  },
};

<Component modifiers="asButton.secondary" />

ACTUAL BEHAVIOR

Have to either use multiple modifiers or duplicate the shared code.

@andrewtpoe
Copy link
Contributor

This is an interesting proposal, though I think I prefer smaller, more specific modifiers. When I've needed to share common styles in modifiers I typically extract them to a separate constant and add them to each style definition:

const withButtonStyles = css`/* ... */`;

const MODIFIER_CONFIG = {
  primary: () => css`
    ${withButtonStyles}
    /* ... */
  `,
  secondary: () => css`
    ${withButtonStyles}
    /* ... */
  `
};

More commonly, the base button styles are defined on the base component, and modifier styles should override what needs to be different:

const Button = styled.button`
  /* ...base button styles */
  ${applyStyleModifiers(MODIFIER_CONFIG)}

I don't consider needing to use multiple modifiers to be an issue as that is an extremely common use case.

I'm going to leave this issue open a little while longer to see if it gathers any interest.

@albertdugba
Copy link

Yes I also had similar problems, I agree with the author of this post, so I was experimenting with thus nice package where I wanted to create like a button component something similar to bootstrap i.e (primary,secondary,warning,danger,success) etc. It was not possible to use that approach. Would be very pleased if you guys can add that as a feature.

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

No branches or pull requests

3 participants