-
Notifications
You must be signed in to change notification settings - Fork 14
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 colour and scheme picker
- Loading branch information
1 parent
6641204
commit 879baf1
Showing
10 changed files
with
172 additions
and
110 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,19 +1,73 @@ | ||
import {Group, Image} from '@coveord/plasma-mantine'; | ||
import { | ||
ActionIcon, | ||
ColorSwatch, | ||
Group, | ||
Image, | ||
useComputedColorScheme, | ||
useMantineColorScheme, | ||
} from '@coveord/plasma-mantine'; | ||
import {CheckSize16Px, MoonAndStarsSize32Px, SunSize32Px} from '@coveord/plasma-react-icons'; | ||
import {DefaultMantineColor, useMantineTheme} from '@mantine/core'; | ||
import {FunctionComponent} from 'react'; | ||
import githubLogo from './assets/github-mark.svg'; | ||
import plasmaLogo from './assets/plasma-logo.svg'; | ||
import StandaloneSearchBar from './search/StandaloneSearchBar'; | ||
import classes from './styles/TopBar.module.css'; | ||
import {useThemePicker} from './theme-picker/ThemePickerContext'; | ||
|
||
const TopBar = () => ( | ||
<Group justify="space-between" px="lg" py="xs" h="100%" wrap="nowrap" className={classes.topBar}> | ||
<div> | ||
<Image src={plasmaLogo} className="header-logo" height={80} fit="contain" alt="Plasma Design System" /> | ||
</div> | ||
<StandaloneSearchBar /> | ||
<a href="https://github.com/coveo/plasma#readme" aria-label="README" target="_blank"> | ||
<Image src={githubLogo} width={32} height={32} className={classes.githubImage} /> | ||
</a> | ||
<Group gap="sm"> | ||
<a href="https://github.com/coveo/plasma#readme" aria-label="README" target="_blank"> | ||
<Image src={githubLogo} width={32} height={32} className={classes.githubImage} /> | ||
</a> | ||
<ColorSchemePicker /> | ||
<PrimaryColorPicker /> | ||
</Group> | ||
</Group> | ||
); | ||
|
||
export default TopBar; | ||
|
||
const ColorSchemePicker = () => { | ||
const {setColorScheme} = useMantineColorScheme(); | ||
const computedColorScheme = useComputedColorScheme('light', {getInitialValueInEffect: true}); | ||
|
||
return ( | ||
<ActionIcon | ||
onClick={() => setColorScheme(computedColorScheme === 'light' ? 'dark' : 'light')} | ||
color="white" | ||
variant="subtle" | ||
size="xl" | ||
aria-label="Toggle color scheme" | ||
> | ||
{computedColorScheme === 'light' ? <MoonAndStarsSize32Px height={32} /> : <SunSize32Px height={32} />} | ||
</ActionIcon> | ||
); | ||
}; | ||
|
||
const PrimaryColorPicker = () => ( | ||
<Group gap="xs"> | ||
<ColorPickerSwatch color="blue" /> | ||
<ColorPickerSwatch color="violet" /> | ||
</Group> | ||
); | ||
|
||
const ColorPickerSwatch: FunctionComponent<{color: DefaultMantineColor}> = ({color}) => { | ||
const {setPrimaryColor} = useThemePicker(); | ||
const {primaryColor: currentColor} = useMantineTheme(); | ||
return ( | ||
<ColorSwatch | ||
size="32" | ||
component="button" | ||
color={`var(--mantine-color-${color}-filled`} | ||
onClick={() => setPrimaryColor(color)} | ||
> | ||
{currentColor === color ? <CheckSize16Px color="#fff" height={24} /> : null} | ||
</ColorSwatch> | ||
); | ||
}; |
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
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 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,9 @@ | ||
import {createSafeContext, type DefaultMantineColor} from '@coveord/plasma-mantine'; | ||
|
||
interface ThemePickerContextType { | ||
setPrimaryColor: (newColor: DefaultMantineColor) => void; | ||
} | ||
|
||
export const [ThemePickerProvider, useThemePicker] = createSafeContext<ThemePickerContextType>( | ||
'ThemePickerProvider component was not found in tree', | ||
); |