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 option for switch to take custom colors #426

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

apfister
Copy link

@apfister apfister commented Oct 29, 2020

Description

let the <Switch> take a color option to change the bg & border colors

Related Issue

n/a

Motivation and Context

I want moar colors!

How Has This Been Tested?

just cloned the repo locally, built the docs, and added a sample section in the docs

Screenshots (if appropriate):

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project. (i think??)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

@codylawson
Copy link
Contributor

@apfister In our Card component we allow custom colored bars similar to what you're doing here. One difference is that when the user provides a color name, like "green", we try to match the color to a variable in our theme palette. Do you think this is something we can incorporate in the case of Switch? Using browser named colors seems less useful than providing an easy method to use the theme variables.

@apfister
Copy link
Author

apfister commented Nov 6, 2020

@codylawson if i were trying to use the Switch component and i was providing "red" for the color, and "red" did not exist in the theme palette, i'm not sure i'd know why my Switch control isn't red. Isn't using well known color names more intuitive?

@codylawson
Copy link
Contributor

@apfister Hmm, I'm not sure how red or any common color names wouldn't exist as it's built into the default theme and there is a fallback provided to all components. I'm trying to picture a scenario where someone would prefer a browser defined named color over a theme color. Would you be satisfied with having a fallback to the browser named color if the name doesn't exist in the palette? If we're going to go with browser named colors then I think we should provide an example in the docs to show how to provide theme values from a react component.

@apfister
Copy link
Author

apfister commented Nov 6, 2020

@codylawson ok that makes sense. i was just worried that if i had no idea that the color param had to take in a name that existed in the theme palette, i would be stuck. Can you still put in the hex/rgb values if you wanted?

@codylawson
Copy link
Contributor

@apfister Yeah maybe something along the lines of:

background-color: `theme.palette[color] || color`;

So if the color doesn't exist as a property name on the theme then you would fallback to just using the string as is.

@apfister
Copy link
Author

apfister commented Nov 6, 2020

right on. so if i understand this correctly, if a user has setup a theme, this approach will try to follow that theme first and then fall back to just the browser name color, rgb, hex?

@codylawson
Copy link
Contributor

@apfister All calcite react components have a default theme so it won't matter if they didn't set it up. But yes, if the color string doesn't match any theme property names then it will just be passed to the browser as is.

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

Successfully merging this pull request may close these issues.

2 participants