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

Styled component theme #14

Open
armandabric opened this issue Oct 5, 2017 · 1 comment
Open

Styled component theme #14

armandabric opened this issue Oct 5, 2017 · 1 comment

Comments

@armandabric
Copy link

armandabric commented Oct 5, 2017

In you application we use the styled-component theme to define the base colors and fonts of our application. In the same application we have multiple theme that is switched based on the current route.

To work with the css variable used by react-styled-select, I've use a work a dirty tricks:

import StylableSelect from 'react-styled-select';

const injectGlobalWithTheme = theme => {
    injectGlobal`
        :root {
            --styled-select-placeholder-color: grey;
            --styled-select-color: #555555;
            --styled-select-background-color: #ededed;
            --styled-select-border-width: 3px;
            --styled-select-border-radius: 4px;

            --styled-select-control-border-color: #ededed;
            --styled-select-control-focused-border-color: ${theme.accentColor};

            --styled-select-option-focused-background-color: ${theme.accentColor};

            --styled-select-menu-outer-background-color: ${theme.secondaryFontColor};
            --styled-select-menu-outer-border-color: #555555;
            --styled-select-menu-outer-border-radius: 4px;
            --styled-select-menu-outer-margin: 1px 0 0 0;
        }
    `;
};

export const Select = styled(StylableSelect)`
    ${({ theme }) => injectGlobalWithTheme(theme)}; // Here is the magic ✨

    min-width: 200px;
`;

Do not look at the variable names, I'm not up to date 😋

Did you have another way/idea to work with theme and CSS var ?

@armandabric armandabric changed the title Working with styled-component theme Styled component theme Oct 5, 2017
@agutoli
Copy link
Owner

agutoli commented Oct 8, 2017

Hi, @Spy-Seth. Good? So, I don't know if I like the idea about "styled themes", because this is a generic component, if I want to use glamorousjs or emotionjs in my project? I can not use styled-theme when I use emotionjs, right?

IMHO, we have to keep it more generic, without specifics tecnologies, I chose styled-components just in the development version, when this is compiled, the component is just a pure react component.

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

2 participants