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

Ability to choose a theme color from theme array of specific color range #38

Closed
yairEO opened this issue Jul 9, 2019 · 6 comments
Closed

Comments

@yairEO
Copy link

yairEO commented Jul 9, 2019

My theme code follows the standards:

Theme:

const baseColors = {
    grays: ['#9B9B9B', '#DEE2E5', '#EFF0F4', '#F7F8FA'],
    reds: ['#D30C2B', '#EF3920'],
    blues: ['#2C304C', '#1A395C', '#6782A4'],
}

const colors : {
	...baseColors,
	primary: baseColors.reds[0],
    secondary: baseColors.blues[1]
}

// ...more code...

export default {
    colors,
    fontSizes,
    fontWeights,
    shadows,
    space,
    radii,
}

I would like to access a specific "blue" color from xstyled:

Basic use-case:

import styled from '@xstyled/styled-components'

const MyComp = styled.div`
	background: grays[3]; // <- xStyled should parse this as: theme.colors.grays[3]
`

I cannot possibly give alias names to all my color, in reality I have many and naming them will be more confusing than accessing an Array index, since colors arrays are sorted by darker to lighter, and it's obvious to developers in the team which gray is lighter or darker by using an index, instead of creating alias names such as:

const colors : {
	...baseColors,
	primary: baseColors.reds[0],
    secondary: baseColors.blues[1],
    gray1: baseColors.grays[1],  // <- I don't want to make these only for xStyled
    gray2: baseColors.grays[2],
    gray3: baseColors.grays[3],
}
@yairEO yairEO changed the title Ability to choose a theme item from theme array Ability to choose a theme color from theme array of specific color range Jul 9, 2019
@gregberge
Copy link
Collaborator

Hello @yairEO, you have to use the "dot syntax":

background: grays.3;

@good-idea
Copy link

Just came here with the same question. I didn't see this in the docs -- I'd suggest adding it!

@gregberge
Copy link
Collaborator

Feel free to submit a PR to update the doc!

@yairEO
Copy link
Author

yairEO commented Aug 7, 2019

Not working 😞:

svg {
  fill: blues.4;
}

Working:

fill: ${({ theme }) => theme.colors.blues[4]};

@gregberge
Copy link
Collaborator

gregberge commented Aug 7, 2019

fill is not yet supported, we have to add it. Someone would like to try in a PR?

@gregberge
Copy link
Collaborator

See #45

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

3 participants