-
Notifications
You must be signed in to change notification settings - Fork 842
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
[CSS-in-JS] Starting simple usage docs #4558
[CSS-in-JS] Starting simple usage docs #4558
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to ignore these because TS complains that the custom keys don't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to do that on creation of the modifications instead of usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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