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

[CSS-in-JS] Starting simple usage docs #4558

Merged
merged 6 commits into from
Mar 3, 2021

Conversation

cchaos
Copy link
Contributor

@cchaos cchaos commented Feb 19, 2021

Some quick docs to get us started with defined examples to test.

Checklist

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4558/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4558/

@cchaos cchaos marked this pull request as ready for review March 2, 2021 21:50
@cchaos cchaos requested a review from thompsongl March 2, 2021 21:51
@cchaos
Copy link
Contributor Author

cchaos commented Mar 2, 2021

@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.

Comment on lines +18 to +22
// @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,
Copy link
Contributor Author

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.

Copy link
Contributor

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
}}>();

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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];
}

Copy link
Contributor Author

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.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4558/

Copy link
Contributor

@thompsongl thompsongl left a 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.

@cchaos cchaos merged commit 984cd48 into elastic:feature/css-in-js Mar 3, 2021
@cchaos cchaos deleted the feature/css-in-js_docs branch March 3, 2021 16:15
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

Successfully merging this pull request may close these issues.

3 participants