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

Inheritance of Styles between different elements #51

Open
xypnox opened this issue Aug 5, 2023 · 0 comments
Open

Inheritance of Styles between different elements #51

xypnox opened this issue Aug 5, 2023 · 0 comments

Comments

@xypnox
Copy link

xypnox commented Aug 5, 2023

It is common to have a button that submits a form and a link that navigates to a different page have same or similar styles.

In these cases, the button would be a button element and link a a anchor tag. Which would have two definitions where the same set of styles are repeated.

Ex:

const Button = styled('button')`
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
  color: #000;
  background: #eee;
`

const Link = styled('a')`
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
  color: #000;
  background: #eee;

  text-decoration: none;
`

It becomes hard to manage such a codebase as for every similarly styled element the styles are repeated.

Is there a way to define styles such that they can be inherited inside each other? There are concepts such as Sass Mixins that help manage similar styles from one place and only inherit styles as needed.

One of the cool things could be:

const ButtonStyle = styled.mixin`
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
  color: #000;
  background: #eee;
`
const Button = styled('button')`
  ${ButtonStyle};
`
const Link = styled('a')`
  ${ButtonStyle};

  text-decoration: none;
`

Currently it can be done via just using a ``` string literal for static styles, but adding props etc to the mixin would help a long way.

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

1 participant