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

Provide typing for theme, when an interpolation function is passed to css prop on EUI components #8123

Closed
eokoneyo opened this issue Nov 8, 2024 · 1 comment
Labels
answered Issues answered by the EUI team - auto-closes open issues in 7 days if no follow-up response question

Comments

@eokoneyo
Copy link
Contributor

eokoneyo commented Nov 8, 2024

Describe the bug

Currently EUI exposes the css prop on it's components to support extending styling on it's components, however when a function is passed the theme value is not typed. for instance the following;

 <EuiContextMenuItem
    icon="trash"
    css={({ euiTheme }) => ({ color: euiTheme.colors.danger })}
 >
  delete
</EuiContextMenuItem>

has euiTheme typed as any, which results in folks either typing it as any or ignoring with a ts comment directive, this can however be circumvented by extending the theme value within emotion (see here) to provide the correct type and improve developer experience.

Impact and severity
This is mostly a developer experience ask, especially that Shared UX is undertaking an initiative to nudge folks to adopt emotion over SCSS within Kibana

Environment and versions

  • EUI version: 97.3.1

Expected behavior
Using interpolation function with the css prop should have euiTheme properly typed.

Minimum reproducible sandbox
Please refer to https://codesandbox.io/p/sandbox/qvjvhk

Screenshots
Image

@eokoneyo eokoneyo added bug ⚠️ needs validation For bugs that need confirmation as to whether they're reproducible labels Nov 8, 2024
@cee-chen cee-chen added question and removed bug ⚠️ needs validation For bugs that need confirmation as to whether they're reproducible labels Nov 13, 2024
@cee-chen
Copy link
Member

cee-chen commented Nov 13, 2024

Hi Eyo - this is not an issue that EUI can fix, it's a required implementation of Emotion (see https://emotion.sh/docs/typescript#define-a-theme).

You will need to add an emotion.d.ts file in your Kibana plugin for the parameter in css functions to be properly typed as EUI's theme. See the osquery plugin for an example of their tsconfig setup.

I've added a specific section/question for this in our Emotion FAQ thread - feel free to refer other devs to it in the future.

@cee-chen cee-chen added the answered Issues answered by the EUI team - auto-closes open issues in 7 days if no follow-up response label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered Issues answered by the EUI team - auto-closes open issues in 7 days if no follow-up response question
Projects
None yet
Development

No branches or pull requests

2 participants