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

Q: Exposing props to allow for easier UI abstraction #348

Open
StuartMorris0 opened this issue Jan 22, 2022 · 2 comments
Open

Q: Exposing props to allow for easier UI abstraction #348

StuartMorris0 opened this issue Jan 22, 2022 · 2 comments

Comments

@StuartMorris0
Copy link

StuartMorris0 commented Jan 22, 2022

💬 Questions and Help

Firstly, the project looks awesome, having come from a heavily styled-components and styled-system background.

My first question, is around how you might expose props for creating UI components. Often with projects, we tend to abstract the UI components such as Button, Input and so on, into more reusable components with strict Typescript interfaces.

In essence, we would take something like this....

<x.button
      type="button"
      color="white"
      transition
      bg={{ _: 'emerald-500', hover: 'emerald-800' }}
    >

Into it's own Button component and expose props such as variant which may then further style the component.

This removes the requirement to always pass a bunch of reused props every time the primary button is needed. It also removes the @xstyled... calls from all pages and into less components, should the need to change arise.

Previously with styled-system we used to generate/build prop types (interfaces) so that we could further expose those props should we wish. For the above example, we might want to expose bg but everything else be behind the scenes. What would be the recommended approach for this?

Furthermore, is there any documentation around creating variants? I read that some of the variants part was deprecated as it was confusing. But interested to learn more around what approach might be best. In the above example, just creating variants for buttons that are predefined by the actual Button component, rather than exposing x.button everywhere.

Thanks!

@jguddas
Copy link
Contributor

jguddas commented Apr 15, 2022

I'm a big fan of having a utility that behaves similarly to styled(MyComponent) from styled-components.

interface ButtonProps {
  children: React.ReactNode;
}

const Button = styled<ButtonProps>(x.button, {
  type: 'button',
  color: 'white',
  transition: true
  bg: { _: 'emerald-500', hover: 'emerald-800' }
})``;

const DangerButton = styled<ButtonProps>(Button, {
  bg: { _: 'red-500', hover: 'red-800' }
})``;

ps.: You can already use this pattern with defaultProps or .attrs.

@felubra
Copy link

felubra commented Apr 16, 2022

@StuartMorris0 maybe the approach in #224 could help you.

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

4 participants