Skip to content

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

Merged
cchaos merged 6 commits into
elastic:feature/css-in-jsfrom
cchaos:feature/css-in-js_docs
Mar 3, 2021
Merged

cchaos merged 6 commits into
elastic:feature/css-in-jsfrom
cchaos:feature/css-in-js_docs

Conversation

@cchaos

@cchaos cchaos commented Feb 19, 2021 •

Copy link
Copy Markdown
Contributor

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

Checklist

@kibanamachine

Copy link
Copy Markdown
Contributor

@kibanamachine

Copy link
Copy Markdown
Contributor

@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

cchaos commented Mar 2, 2021

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

@thompsongl thompsongl left a comment

Copy link
Copy Markdown
Contributor

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