forked from elastic/eui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a ThemeSelector for optionally showing/changing content based o…
…n JS or Sass theming language
- Loading branch information
cchaos
committed
Sep 29, 2021
1 parent
dea0bd4
commit 963e589
Showing
6 changed files
with
153 additions
and
4 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
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 +1,2 @@ | ||
export { ThemeProvider, ThemeContext } from './theme_context'; | ||
export { LanguageSelector } from './language_selector'; |
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,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> | ||
); | ||
}; |
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