-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(website): add theme switcher and theme switching (#82)
* feat(website): add website theme switcher * chore(node): lock down the node version for build tools * fix: pr feedback * fix(screen reader only): fix typings for the as prop * fix(screen-reader-only): swap back to a default span * fix: adjust the site header to accomodate the theme switcher
- Loading branch information
Showing
15 changed files
with
293 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v10.16 | ||
v10.16 |
7 changes: 6 additions & 1 deletion
7
packages/paste-core/utilities/screen-reader-only/src/index.tsx
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,13 +1,79 @@ | ||
import * as React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import {themeGet} from 'styled-system'; | ||
import {useUID} from 'react-uid'; | ||
import {ScreenReaderOnly} from '@twilio-paste/screen-reader-only'; | ||
import {Box} from '@twilio-paste/box'; | ||
import {Themes, ThemesType} from '../constants'; | ||
import {useActiveSiteTheme} from '../context/ActiveSiteThemeContext'; | ||
|
||
interface ThemeSwitcherProps { | ||
children?: React.ReactElement; | ||
} | ||
|
||
const StyledThemeSwitcherLabel = styled.label<{}>(props => ({ | ||
cursor: 'pointer', | ||
display: 'inline-block', | ||
padding: `${themeGet('space.space20')(props)} ${themeGet('space.space40')(props)}`, | ||
'&:hover': { | ||
textDecoration: 'underline', | ||
}, | ||
})); | ||
|
||
const StyledThemeSwitcherRadio = styled.input<{}>(props => ({ | ||
opacity: 0, | ||
position: 'absolute', | ||
[`&:focus + ${StyledThemeSwitcherLabel}`]: { | ||
boxShadow: themeGet('shadows.shadowFocus')(props), | ||
textDecoration: 'underline', | ||
}, | ||
[`&:checked + ${StyledThemeSwitcherLabel}`]: { | ||
backgroundColor: themeGet('backgroundColors.colorBackgroundPrimary')(props), | ||
borderRadius: themeGet('radii.borderRadius10')(props), | ||
color: themeGet('textColors.colorTextInverse')(props), | ||
}, | ||
})); | ||
|
||
export const ThemeSwitcher: React.FC<ThemeSwitcherProps> = () => { | ||
const {theme, updateActiveSiteTheme} = useActiveSiteTheme(); | ||
|
||
const handleChange: React.ChangeEventHandler<HTMLInputElement> = event => { | ||
updateActiveSiteTheme(event.currentTarget.value as ThemesType); | ||
}; | ||
|
||
const consoleID = useUID(); | ||
const sendGridID = useUID(); | ||
|
||
return ( | ||
<div> | ||
<ScreenReaderOnly>Theme Switcher Placeholder</ScreenReaderOnly> | ||
</div> | ||
<Box | ||
as="form" | ||
borderColor="colorBorderLight" | ||
borderRadius="borderRadius20" | ||
borderStyle="solid" | ||
borderWidth="borderWidth10" | ||
padding="space10" | ||
> | ||
<Box as="fieldset" borderWidth="borderWidth0" padding="space0" margin="space0"> | ||
<ScreenReaderOnly as="legend">Change the site theme</ScreenReaderOnly> | ||
<StyledThemeSwitcherRadio | ||
checked={theme === Themes.CONSOLE} | ||
id={consoleID} | ||
name="sitetheme" | ||
onChange={handleChange} | ||
type="radio" | ||
value={Themes.CONSOLE} | ||
/> | ||
<StyledThemeSwitcherLabel htmlFor={consoleID}>Console</StyledThemeSwitcherLabel> | ||
<StyledThemeSwitcherRadio | ||
checked={theme === Themes.SENDGRID} | ||
id={sendGridID} | ||
name="sitetheme" | ||
onChange={handleChange} | ||
type="radio" | ||
value={Themes.SENDGRID} | ||
/> | ||
<StyledThemeSwitcherLabel htmlFor={sendGridID}>SendGrid</StyledThemeSwitcherLabel> | ||
</Box> | ||
</Box> | ||
); | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
packages/paste-website/src/components/site-wrapper/constants.ts
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,2 +1,2 @@ | ||
export const SIDEBAR_WIDTH = '240px'; | ||
export const HEADER_HEIGHT = '64px'; | ||
export const HEADER_HEIGHT = '70px'; |
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.
a3b400d
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.
Successfully aliased the URL https://paste-933km2qx3.now.sh to the following aliases: