-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Docs only] Adds a ThemeContext context to docs (#2857)
* Adds a ThemeContext context to docs Stores theme value in local store; Removes need for `with_theme`; Causes console errors by Charts * Changed method name * Fixing coloring of a11y badges on colors page * Fixing chart example * Removed themeIsLoading and console.log * Revert "Fixing coloring of a11y badges on colors page" This reverts commit 6a25012. * Removed remnants of theme from redux store Co-authored-by: Chandler Prall <[email protected]>
- Loading branch information
1 parent
7c11113
commit 1d9c510
Showing
23 changed files
with
145 additions
and
153 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
export { toggleTheme } from './theme_actions'; | ||
|
||
export { toggleLocale } from './locale_actions'; |
This file was deleted.
Oops, something went wrong.
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
77 changes: 23 additions & 54 deletions
77
src-docs/src/components/guide_theme_selector/guide_theme_selector.js
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 |
---|---|---|
@@ -1,59 +1,28 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import { ThemeContext } from '../with_theme'; | ||
import { EuiSelect, EuiFormRow } from '../../../../src/components'; | ||
import { EUI_THEMES } from '../../../../src/themes'; | ||
|
||
export class GuideThemeSelector extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.themeOptions = [ | ||
{ | ||
text: 'Light', | ||
value: 'light', | ||
}, | ||
{ | ||
text: 'Dark', | ||
value: 'dark', | ||
}, | ||
{ | ||
text: 'Amsterdam: Light', | ||
value: 'amsterdam-light', | ||
}, | ||
{ | ||
text: 'Amsterdam: Dark', | ||
value: 'amsterdam-dark', | ||
}, | ||
]; | ||
|
||
this.state = { | ||
value: this.themeOptions[0].value, | ||
}; | ||
} | ||
|
||
onChange = e => { | ||
this.setState({ | ||
value: e.target.value, | ||
}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<EuiFormRow label="Theme"> | ||
<EuiSelect | ||
options={this.themeOptions} | ||
value={this.props.selectedTheme} | ||
onChange={e => { | ||
this.props.onToggleTheme(e.target.value); | ||
}} | ||
aria-label="Switch the theme" | ||
/> | ||
</EuiFormRow> | ||
); | ||
} | ||
} | ||
export const GuideThemeSelector = () => { | ||
return ( | ||
<ThemeContext.Consumer> | ||
{context => <GuideThemeSelectorComponent context={context} />} | ||
</ThemeContext.Consumer> | ||
); | ||
}; | ||
|
||
GuideThemeSelector.propTypes = { | ||
onToggleTheme: PropTypes.func.isRequired, | ||
selectedTheme: PropTypes.string.isRequired, | ||
const GuideThemeSelectorComponent = ({ context }) => { | ||
return ( | ||
<EuiFormRow label="Theme"> | ||
<EuiSelect | ||
options={EUI_THEMES} | ||
value={context.theme} | ||
onChange={e => { | ||
context.changeTheme(e.target.value); | ||
}} | ||
aria-label="Switch the theme" | ||
/> | ||
</EuiFormRow> | ||
); | ||
}; |
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 was deleted.
Oops, something went wrong.
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 @@ | ||
export { ThemeProvider, ThemeContext } from './theme_context'; |
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,51 @@ | ||
import React from 'react'; | ||
import { EUI_THEMES, EUI_THEME } from '../../../../src/themes'; | ||
// @ts-ignore | ||
import { applyTheme } from '../../services'; | ||
|
||
const defaultState = { | ||
theme: EUI_THEMES[0].value, | ||
changeTheme: (themeValue: EUI_THEME['value']) => { | ||
applyTheme(themeValue); | ||
}, | ||
}; | ||
|
||
interface State { | ||
theme: EUI_THEME['value']; | ||
} | ||
|
||
export const ThemeContext = React.createContext(defaultState); | ||
|
||
export class ThemeProvider extends React.Component<object, State> { | ||
constructor(props: object) { | ||
super(props); | ||
|
||
const theme = localStorage.getItem('theme') || defaultState.theme; | ||
applyTheme(theme); | ||
|
||
this.state = { | ||
theme, | ||
}; | ||
} | ||
|
||
changeTheme = (themeValue: EUI_THEME['value']) => { | ||
this.setState({ theme: themeValue }, () => { | ||
localStorage.setItem('theme', themeValue); | ||
applyTheme(themeValue); | ||
}); | ||
}; | ||
|
||
render() { | ||
const { children } = this.props; | ||
const { theme } = this.state; | ||
return ( | ||
<ThemeContext.Provider | ||
value={{ | ||
theme, | ||
changeTheme: this.changeTheme, | ||
}}> | ||
{children} | ||
</ThemeContext.Provider> | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.