-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Fix discover, tsvb and Lens chart theming issues #69695
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2102674
fix: discover and tsvb theming issues
nickofthyme 18771dc
fix: broken jest tests
nickofthyme aff4e8a
test: fix charts theme tests based on changes
nickofthyme 189843c
fix: charts plugin theme readme spelling errors
nickofthyme 6207f94
fix: broken hook refactoring
nickofthyme d82c6b8
fix: tsvb border for bgColor with alpha values
nickofthyme 614bc5f
Merge branch 'master' into fix-chart-bg-color
nickofthyme 730c2e9
fix: add comment to style changes
nickofthyme 2c9cd0b
Merge branch 'master' into fix-chart-bg-color
nickofthyme cb726f3
Merge branch 'master' into fix-chart-bg-color
nickofthyme fb35a49
fix chart bgColor issues, update lens to use charts plugin
nickofthyme 135b43a
fix dependency issue
nickofthyme faece28
Update charts plugin parameters
nickofthyme fd7046f
Merge branch 'master' into fix-chart-bg-color
nickofthyme 21953cc
Merge branch 'master' into fix-chart-bg-color
nickofthyme f5fcbf3
fix type error with XYChart
nickofthyme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Theme Service | ||
|
||
The `theme` service offers utilities to interact with the kibana theme. EUI provides a light and dark theme object to supplement the Elastic-Charts `baseTheme`. However, every instance of a Chart would need to pass down the correct EUI theme depending on Kibana's light or dark mode. There are several ways you can use the `theme` service to get the correct shared `theme` and `baseTheme`. | ||
|
||
> The current theme (light or dark) of Kibana is typically taken into account for the functions below. | ||
|
||
## `chartsDefaultBaseTheme` | ||
|
||
Default `baseTheme` from `@elastic/charts` (i.e. light). | ||
|
||
## `chartsDefaultTheme` | ||
|
||
Default `theme` from `@elastic/eui` (i.e. light). | ||
|
||
## `useChartsTheme` and `useChartsBaseTheme` | ||
|
||
A **React hook** for simple fetching of the correct EUI `theme` and `baseTheme`. | ||
|
||
```js | ||
import { npStart } from 'ui/new_platform'; | ||
import { Chart, Settings } from '@elastic/charts'; | ||
|
||
export const YourComponent = () => ( | ||
<Chart> | ||
<Settings | ||
theme={npStart.plugins.charts.theme.useChartsTheme()} | ||
baseTheme={npStart.plugins.charts.theme.useChartsBaseTheme()} | ||
/> | ||
{/* ... */} | ||
</Chart> | ||
); | ||
``` | ||
|
||
## `chartsTheme$` and `chartsBaseTheme$` | ||
|
||
An **`Observable`** of the current charts `theme` and `baseTheme`. Use this implementation for more flexible updates to the chart theme without full page refreshes. | ||
|
||
```tsx | ||
import { npStart } from 'ui/new_platform'; | ||
import { EuiChartThemeType } from '@elastic/eui/src/themes/charts/themes'; | ||
import { Subscription, combineLatest } from 'rxjs'; | ||
import { Chart, Settings, Theme } from '@elastic/charts'; | ||
|
||
interface YourComponentProps {}; | ||
|
||
interface YourComponentState { | ||
chartsTheme: EuiChartThemeType['theme']; | ||
chartsBaseTheme: Theme; | ||
} | ||
|
||
export class YourComponent extends Component<YourComponentProps, YourComponentState> { | ||
private subscriptions: Subscription[] = []; | ||
|
||
public state = { | ||
chartsTheme: npStart.plugins.charts.theme.chartsDefaultTheme, | ||
chartsBaseTheme: npStart.plugins.charts.theme.chartsDefaultBaseTheme, | ||
}; | ||
|
||
componentDidMount() { | ||
this.subscription = combineLatest( | ||
npStart.plugins.charts.theme.chartsTheme$, | ||
npStart.plugins.charts.theme.chartsBaseTheme$ | ||
).subscribe(([chartsTheme, chartsBaseTheme]) => | ||
this.setState({ chartsTheme, chartsBaseTheme }) | ||
); | ||
} | ||
|
||
componentWillUnmount() { | ||
if (this.subscription) { | ||
this.subscription.unsubscribe(); | ||
} | ||
} | ||
|
||
public render() { | ||
const { chartsBaseTheme, chartsTheme } = this.state; | ||
|
||
return ( | ||
<Chart> | ||
<Settings | ||
theme={chartsTheme} | ||
baseTheme={chartsBaseTheme} | ||
/> | ||
{/* ... */} | ||
</Chart> | ||
); | ||
} | ||
} | ||
``` | ||
|
||
## Why have `theme` and `baseTheme`? | ||
|
||
The `theme` prop is a recursive partial `Theme` that overrides properties from the `baseTheme`. This allows changes to the `Theme` TS type in `@elastic/charts` without having to update the `@elastic/eui` themes for every `<Chart />`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It's irrelevant with this PR but I saw on L21 that there is a typo Funciton instead of Function and retrive instead of retrieve. Do you want to also correct it in this PR ?
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.
Fixed in d82c6b8