Skip to content

Commit

Permalink
adding toggle button, needs fix for reverse theme colors
Browse files Browse the repository at this point in the history
  • Loading branch information
jordantrouw committed Nov 23, 2024
1 parent 4397a3d commit ef7e749
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 120 deletions.
1 change: 0 additions & 1 deletion .depcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ ignores: [
"react-dom",
"remark-gfm",
"rimraf",
"storybook-dark-mode",
"webpack"
]
1 change: 0 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const config: StorybookConfig = {
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
// 'storybook-dark-mode',
],
framework: '@storybook/react-vite',
}
Expand Down
3 changes: 1 addition & 2 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Fustat:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@100;200;300;400;500;600;700&display=swap"
rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Outfit:[email protected]&display=swap" rel="stylesheet">
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { CssBaseline, ThemeProvider } from '@mui/material'
import { createTheme } from '@mui/material/styles'
import React from 'react'

import { InvertibleMuiThemeProvider } from '../InvertibleMuiThemeProvider/index.ts'
import { ThemeModeButtonGroup } from './ThemeModeButtonGroup.tsx'

export default {
title: 'Theme/ThemeModeButtonGroup',
component: ThemeModeButtonGroup,
parameters: { layout: 'fullscreen' },
}

const theme = createTheme({
palette: {
mode: 'light',
primary: { main: '#2c5ba8' },
secondary: { main: '#ffb300' },
},
})

const Template = () => (
<ThemeProvider theme={theme}>
<CssBaseline />
<InvertibleMuiThemeProvider>
<ThemeModeButtonGroup />
</InvertibleMuiThemeProvider>
</ThemeProvider>
)

export const Default = Template.bind({})
Default.args = {}
42 changes: 42 additions & 0 deletions packages/invertible-theme/src/Buttons/ThemeModeButtonGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Button, ButtonGroup, Chip, Stack,
} from '@mui/material'
import React from 'react'

import { useColorSchemeEx } from '../InvertibleMuiThemeProvider/index.ts'

export const ThemeModeButtonGroup: React.FC = () => {
const {
darkMode, lightMode, systemMode, mode, setMode,
} = useColorSchemeEx()

return (
<Stack direction="column" gap={2} alignItems="start">
<Stack direction="row" gap={2}>
Current Mode:
{' '}
<Chip label={mode} />
</Stack>
<ButtonGroup>
<Button
variant={darkMode ? 'contained' : 'outlined'}
onClick={() => setMode('dark')}
>
Dark Mode
</Button>
<Button
variant={lightMode ? 'contained' : 'outlined'}
onClick={() => setMode('light')}
>
Light Mode
</Button>
<Button
variant={systemMode ? 'contained' : 'outlined'}
onClick={() => setMode('system')}
>
System
</Button>
</ButtonGroup>
</Stack>
)
}
1 change: 1 addition & 0 deletions packages/invertible-theme/src/Buttons/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './DarkModeIconButton.tsx'
export * from './ThemeModeButtonGroup.tsx'
5 changes: 2 additions & 3 deletions packages/theme/src/ColorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import {
import React from 'react'

export interface ColorCardProps extends BoxProps {
color: string
colorName: string
subtype?: string
}

export const ColorCard: React.FC<ColorCardProps> = ({
color, colorName, subtype, ...props
colorName, subtype, ...props
}) => {
return (
<Box
Expand All @@ -30,7 +29,7 @@ export const ColorCard: React.FC<ColorCardProps> = ({
</Typography>
</Box>
<Typography alignSelf="flex-end" variant="caption">
{color}
{colorName}
</Typography>
</Box>
)
Expand Down
12 changes: 8 additions & 4 deletions packages/theme/src/ColorShowcase.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box } from '@mui/material'
import { Box, Stack } from '@mui/material'
import type { Meta, StoryFn } from '@storybook/react'
import { ThemeModeButtonGroup } from '@xylabs/react-invertible-theme'
import React from 'react'

import { ColorShowcase } from './ColorShowcase.tsx'
Expand All @@ -12,9 +13,12 @@ const StorybookEntry = {
} as Meta<typeof ColorShowcase>

const Template: StoryFn<typeof ColorShowcase> = () => (
<Box display="flex" height="100vh" width="100vw">
<ColorShowcase></ColorShowcase>
</Box>
<Stack display="flex" flexDirection="column" gap={2} alignItems="stretch" height="100vh" width="100vw">
<Box alignSelf="center">
<ThemeModeButtonGroup />
</Box>
<ColorShowcase />
</Stack>
)

const Default = Template.bind({})
Expand Down
58 changes: 42 additions & 16 deletions packages/theme/src/ColorShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,72 @@ import {
Box,
useTheme,
} from '@mui/material'
import { DarkModeIconButtonForColorScheme } from '@xylabs/react-invertible-theme'
import React from 'react'

import { ColorCard } from './ColorCard.tsx'
import { PaletteColorCard } from './PaletteColorCard.tsx'

export const ColorShowcase: React.FC = () => {
const theme = useTheme()

return (
<Box display="flex" flexDirection="column" flex="1 1 0px">
<DarkModeIconButtonForColorScheme defaultLightModeColor="default" />
<Box display="flex" flex="1 1 0px" flexDirection="row" justifyContent="stretch">
<ColorCard
bgcolor={theme.palette.background.default}
color={theme.palette.background.default as string}
style={{ background: theme.palette.background.gradient }}
color={theme.palette.background.gradient}
colorName="Background"
subtype="default"
subtype="Gradient"
/>
<ColorCard
bgcolor={theme.palette.background.paper}
color={theme.palette.background.paper as string}
bgcolor={theme.palette.text.primary}
color={theme.palette.background.default}
colorName="Background"
subtype="paper"
subtype="Default"
/>
<ColorCard
bgcolor={theme.palette.background.gradient}
color={theme.palette.background.gradient as string}
colorName="Gradient"
bgcolor={theme.palette.text.primary}
color={theme.palette.background.paper}
colorName="Background"
subtype="Paper"
/>
</Box>
<Box display="flex" flex="1 1 0px" flexDirection="row" justifyContent="stretch">
<PaletteColorCard color={theme.palette.primary} colorName="Primary" subtype="main" />
<PaletteColorCard color={theme.palette.secondary} colorName="Secondary" subtype="main" />
<ColorCard
color={theme.palette.primary.contrastText}
bgcolor={theme.palette.primary.main}
colorName="Primary"
/>
<ColorCard
color={theme.palette.secondary.contrastText}
bgcolor={theme.palette.secondary.main}
colorName="Secondary"
/>
<Box display="flex" flex="1 1 0px" flexDirection="column">
<Box display="flex" flex="1 1 0px" flexDirection="row">
<PaletteColorCard color={theme.palette.info} colorName="Info" subtype="main" />
<PaletteColorCard color={theme.palette.success} colorName="Success" subtype="main" />
<ColorCard
color={theme.palette.info.contrastText}
bgcolor={theme.palette.info.main}
colorName="Info"
/>
<ColorCard
color={theme.palette.success.contrastText}
bgcolor={theme.palette.success.main}
colorName="Success"
/>
</Box>
<Box display="flex" flex="1 1 0px" flexDirection="row">
<PaletteColorCard color={theme.palette.warning} colorName="Warning" subtype="main" />
<PaletteColorCard color={theme.palette.error} colorName="Error" subtype="main" />
<ColorCard
color={theme.palette.warning.contrastText}
bgcolor={theme.palette.warning.main}
colorName="Warning"
/>
<ColorCard
color={theme.palette.error.contrastText}
bgcolor={theme.palette.error.main}
colorName="Error"
/>
</Box>
</Box>
</Box>
Expand Down
29 changes: 0 additions & 29 deletions packages/theme/src/PaletteColorCard.stories.tsx

This file was deleted.

37 changes: 0 additions & 37 deletions packages/theme/src/PaletteColorCard.tsx

This file was deleted.

Loading

0 comments on commit ef7e749

Please sign in to comment.