[CSS-in-JS] Starting simple usage docs#4558
[CSS-in-JS] Starting simple usage docs#4558cchaos merged 6 commits intoelastic:feature/css-in-jsfrom
Conversation
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4558/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4558/ |
|
@thompsongl I'm thinking we should get these starter docs in sooner rather than later so that subsequent updates to the context will also update these examples showing how it changes. |
| // @ts-ignore Needs to be fixed in types | ||
| background: theme.colors.customColorPrimaryHighlight, | ||
| padding: theme.sizes.euiSizeXL, | ||
| // @ts-ignore Needs to be fixed in types | ||
| color: theme.colors.customColorPrimaryText, |
There was a problem hiding this comment.
I had to ignore these because TS complains that the custom keys don't exist.
There was a problem hiding this comment.
You need to tell useEuiTheme that the custom keys exist:
const [theme] = useEuiTheme<{colors: {
customColorPrimaryHighlight: string;
customColorPrimaryText: string
}}>();There was a problem hiding this comment.
Is there a way to do that on creation of the modifications instead of usage?
There was a problem hiding this comment.
Unfortunately, no. A given useEuiTheme doesn't/can't have enough knowledge about which provider it's accessing to be able to infer any extensions. This is mostly a limitation of how React context works.
If we want typed, autocomplete-ready theme variables for the base EUI theme, then we have to do this extra step to get extensions to work also.
There was a problem hiding this comment.
I'd imagine that if an app is planning on extending the theme and wants to use it in many places, they could create a wrapped hook to hide the details:
const useExtendedEuiTheme = () => {
const [theme, colorMode, modifications] = useEuiTheme<{colors: {
customColorPrimaryHighlight: string;
customColorPrimaryText: string
}}>();
return [theme, colorMode, modifications];
}There was a problem hiding this comment.
K, then I'm just going to leave the ts comments in for now to see if we can address a bit better.
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4558/ |
thompsongl
left a comment
There was a problem hiding this comment.
I'm good merging this in its current state and with the one change noted in my earlier comment.
Any alterations can happen in subsequent PRs to the feature branch as parts get added or refactored.
Some quick docs to get us started with defined examples to test.
Checklist