reaviz / reablocks

🧩 Component Library for React based on Tailwind. Maintained by @goodcodeus.
https://reablocks.dev
Apache License 2.0
131 stars 10 forks source link

Add ability to extend colors in component themes #211

Closed ghsteff closed 5 months ago

ghsteff commented 5 months ago

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

It's not easy to add colors to Buttons, Chips, etc. that aren't already included in the theme without ignoring ts

What is the new behavior?

You can add any color to multiple component themes and pass any color as a prop

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Here's an example of easily adding pink as a Chip color

const customTheme = extendComponentTheme<ChipTheme>(chipTheme, {
  base: `${chipTheme.base} rounded-full`,
  colors: {
    pink: {
      variants: {
        filled: `${chipTheme?.colors?.pink?.variants?.filled} text-panel-content bg-pink-500/10 border-pink-500`
      }
    }
  }
});

export const Simple = () => (
  <DeletableChip
    color="pink"
    theme={customTheme}
    onDelete={() => console.log('on delete')}
  >
    Deletable
  </DeletableChip>
);
image
netlify[bot] commented 5 months ago

Deploy Preview for reablocks-storybook ready!

Name Link
Latest commit ee858f900ecb48fd379355fcf3b30d57e1fe6d81
Latest deploy log https://app.netlify.com/sites/reablocks-storybook/deploys/664dff3df193d10008cd6fd4
Deploy Preview https://deploy-preview-211--reablocks-storybook.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.