Frontity Roadmap
Description
When themes get complex, users don’t want to copy the same color, font, margin… over and over again. Those settings should live in a theme settings configuration and must be easily accessible on the styled components.
- These theme settings should be in the Frontity state.
- Styled components should have access to all the state, not only these theme settings.
- These styled components should subscribe to changes in the state, just like any other connected component.
User Stories
As a theme developer
I want to use some sort of theme settings
so that I can reuse them in my styled components
Examples
export default {
state: {
theme: {
color: "red"
}
}
}
const Container = styled.div`
color: ${({ state }) => state.theme.color};
`;
Or any other state property:
const Container = styled.div`
color: ${({ state }) => state.router.link === "/" ? "red" : "green"};
`;
Possible solution
Integrate emotion-theming.
The problem with this approach is that the prop is hardcoded to theme
. If we want to give easy access to all the state, the syntax is weird:
const Container = styled.div`
color: ${({ theme }) => theme.state.router.link === "/" ? "red" : "green"};
`;
Also, it is not reactive to changes in state, as far as I know.
Allow the use of connect
We could use the same approach than with any other component: connect
:
let Container = styled.div`
color: ${({ state }) => state.router.link === "/" ? "red" : "green"};
`;
Container = connect(Container);
Right now it only works in the server. I’m not sure why. I guess it has something to do with styled components being forwarding refs, which I guess maybe work as normal components in the server.
Automatically connect styled
The same than the previous one, but done automatically when we re-export styled
in the frontity
package.
Workarounds
There are two ways to connect a styled component that work fine today.
Using the css
prop
const Container = ({ state, children }) => (
<div css={css`
color: ${state.router.link === "/" ? "red" : "green"};
`}>
{children}
</div>
);
export default connect(Container);
Using a connected parent
const Container = ({ state, children }) => (
<StyledContainer link={state.router.link}>{children}</StyledContainer>
);
const StyledContainer = styled.div`
color: ${({ link }) => link === "/" ? "red" : "green"};
`;
export default connect(Container);
So another possibility is to leave everything as it is today and simply promote one of these two solutions.