-
Notifications
You must be signed in to change notification settings - Fork 834
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
[Docs] Add ThemeLanguages and new Breakpoints page #5227
Changes from 10 commits
963e589
f3eccfb
4e66fbc
082a756
2db22a4
fcb1b1c
b6e52f6
11cb672
c386f09
db817b5
f4dd077
57f4d4e
884cb28
be6754e
9273b2b
b8e3bf0
352c9f7
1f10e95
58a6f14
6385c6d
e136566
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { ThemeProvider, ThemeContext } from './theme_context'; | ||
export { LanguageSelector } from './language_selector'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { useContext, useState } from 'react'; | ||
|
||
import { | ||
EuiButtonGroup, | ||
EuiIcon, | ||
EuiLink, | ||
EuiText, | ||
EuiTourStep, | ||
} from '../../../../src/components'; | ||
|
||
import { | ||
ThemeContext, | ||
theme_languages, | ||
THEME_LANGUAGES, | ||
} from './theme_context'; | ||
|
||
const NOTIF_STORAGE_KEY = 'js_vs_sass_notification'; | ||
|
||
export const LanguageSelector = ({ | ||
onChange, | ||
}: { | ||
onChange?: (id: string) => void; | ||
}) => { | ||
const themeContext = useContext(ThemeContext); | ||
const toggleIdSelected = themeContext.themeLanguage; | ||
const onLanguageChange = (optionId: string) => { | ||
themeContext.changeThemeLanguage(optionId as THEME_LANGUAGES['id']); | ||
onChange?.(optionId); | ||
setTourIsOpen(false); | ||
localStorage.setItem(NOTIF_STORAGE_KEY, 'dismissed'); | ||
}; | ||
|
||
const [isTourOpen, setTourIsOpen] = useState( | ||
localStorage.getItem(NOTIF_STORAGE_KEY) !== 'dismissed' | ||
); | ||
|
||
const onTourDismiss = () => { | ||
setTourIsOpen(false); | ||
localStorage.setItem(NOTIF_STORAGE_KEY, 'dismissed'); | ||
}; | ||
|
||
return ( | ||
// @ts-ignore Fixes for tour in another PR | ||
<EuiTourStep | ||
content={ | ||
<EuiText style={{ maxWidth: 320 }}> | ||
<p>Select your preferred styling language with this toggle button.</p> | ||
</EuiText> | ||
} | ||
isStepOpen={isTourOpen} | ||
onFinish={onTourDismiss} | ||
step={1} | ||
stepsTotal={1} | ||
title={ | ||
<> | ||
<EuiIcon type="bell" size="s" /> Theming update | ||
</> | ||
} | ||
footerAction={<EuiLink onClick={onTourDismiss}>Got it!</EuiLink>} | ||
> | ||
<EuiButtonGroup | ||
buttonSize="m" | ||
color="accent" | ||
legend="Language selector" | ||
options={theme_languages} | ||
idSelected={toggleIdSelected} | ||
onChange={(id) => onLanguageChange(id)} | ||
/> | ||
</EuiTourStep> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,17 +6,43 @@ import { EuiThemeProvider } from '../../../../src/services'; | |
import { EuiThemeAmsterdam } from '../../../../src/themes/eui-amsterdam/theme'; | ||
import { EuiThemeDefault } from '../../../../src/themes/eui/theme'; | ||
|
||
export const STYLE_STORAGE_KEY = 'js_vs_sass_preference'; | ||
|
||
export type THEME_LANGUAGES = { | ||
id: 'language--js' | 'language--sass'; | ||
label: string; | ||
title: string; | ||
}; | ||
|
||
export const theme_languages: THEME_LANGUAGES[] = [ | ||
{ | ||
id: 'language--js', | ||
label: 'JS', | ||
title: 'Language selector: CSS-in-JS', | ||
}, | ||
{ | ||
id: 'language--sass', | ||
label: 'Sass', | ||
title: 'Language selector: Sass', | ||
}, | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The labels for these button are up for debate. Mainly that I couldn't think of anything better than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No strong opinions in here personally, the only thing I can even remotely think of is changing the label to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same thought, but also unsure if it's better |
||
|
||
const THEME_NAMES = EUI_THEMES.map(({ value }) => value); | ||
const THEME_LANGS = theme_languages.map(({ id }) => id); | ||
|
||
const defaultState = { | ||
theme: THEME_NAMES[2], | ||
themeLanguage: THEME_LANGS[0], | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
changeThemeLanguage: (language: THEME_LANGUAGES['id']) => {}, | ||
theme: THEME_NAMES[0], | ||
changeTheme: (themeValue: EUI_THEME['value']) => { | ||
applyTheme(themeValue); | ||
}, | ||
}; | ||
|
||
interface State { | ||
theme: EUI_THEME['value']; | ||
themeLanguage: THEME_LANGUAGES['id']; | ||
} | ||
|
||
export const ThemeContext = React.createContext(defaultState); | ||
|
@@ -25,12 +51,19 @@ export class ThemeProvider extends React.Component<object, State> { | |
constructor(props: object) { | ||
super(props); | ||
|
||
let themeLanguage = localStorage.getItem( | ||
STYLE_STORAGE_KEY | ||
) as THEME_LANGUAGES['id']; | ||
if (!themeLanguage || !THEME_LANGS.includes(themeLanguage)) | ||
themeLanguage = defaultState.themeLanguage; | ||
|
||
let theme = localStorage.getItem('theme'); | ||
if (!theme || !THEME_NAMES.includes(theme)) theme = defaultState.theme; | ||
applyTheme(theme); | ||
|
||
this.state = { | ||
theme, | ||
themeLanguage, | ||
}; | ||
} | ||
|
||
|
@@ -41,14 +74,22 @@ export class ThemeProvider extends React.Component<object, State> { | |
}); | ||
}; | ||
|
||
changeThemeLanguage = (language: THEME_LANGUAGES['id']) => { | ||
this.setState({ themeLanguage: language }, () => { | ||
localStorage.setItem(STYLE_STORAGE_KEY, language); | ||
}); | ||
}; | ||
|
||
render() { | ||
const { children } = this.props; | ||
const { theme } = this.state; | ||
const { theme, themeLanguage } = this.state; | ||
return ( | ||
<ThemeContext.Provider | ||
value={{ | ||
theme, | ||
themeLanguage, | ||
changeTheme: this.changeTheme, | ||
changeThemeLanguage: this.changeThemeLanguage, | ||
}} | ||
> | ||
<EuiThemeProvider | ||
|
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.
Ooh thanks for fixing this! The axe-devtools complaint about our sticky top bar always bugged me :) @1Copenut, do you have any extra suggestions for this region/label, or does this look good to you?
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.
I like this
role="region"
addition. It frames that control bar nicely. What do you think about spelling out the name like "EUI Documentation theme and apps" ? Users who benefit the most from aria labels may not think of this in terms of a bar, but more of what it allows them to do or learn about EUI.