Skip to content

Commit

Permalink
feat: add secondary color customization
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed May 31, 2022
1 parent e390016 commit 471cd93
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
29 changes: 27 additions & 2 deletions packages/widget-embedded/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const App = () => {
const [borderRadius, setBorderRadius] = useState(12);
const [borderRadiusSecondary, setBorderRadiusSecondary] = useState(6);
const [primary, setPrimaryColor] = useState('#3F49E1');
const [secondary, setSecondaryColor] = useState('#F5B5FF');
const [darkMode, setDarkMode] = useState(prefersDarkMode);
const [systemColor, setSystemColor] = useState(true);
const [theme, setTheme] = useState(() =>
Expand All @@ -82,6 +83,9 @@ const App = () => {
primary: {
main: '#3F49E1',
},
secondary: {
main: '#F5B5FF',
},
background: {
default:
(systemColor && prefersDarkMode) || darkMode ? '#000' : '#F4F5F6',
Expand Down Expand Up @@ -111,6 +115,9 @@ const App = () => {
primary: {
main: primary,
},
secondary: {
main: secondary,
},
},
shape: {
borderRadius,
Expand All @@ -129,6 +136,7 @@ const App = () => {
fontFamily,
prefersDarkMode,
primary,
secondary,
systemColor,
]);

Expand All @@ -140,6 +148,9 @@ const App = () => {
primary: {
main: primary,
},
secondary: {
main: secondary,
},
background: {
default:
(systemColor && prefersDarkMode) || darkMode ? '#000' : '#F4F5F6',
Expand All @@ -150,7 +161,7 @@ const App = () => {
if (systemColor) {
setDarkMode(systemColor && prefersDarkMode);
}
}, [darkMode, prefersDarkMode, primary, systemColor]);
}, [darkMode, prefersDarkMode, primary, secondary, systemColor]);

return (
<ThemeProvider theme={theme}>
Expand Down Expand Up @@ -251,12 +262,26 @@ const App = () => {
size="small"
InputProps={{
sx: {
width: 96,
width: 128,
},
}}
onChange={(event) => setPrimaryColor(event.target.value)}
/>
</Box>
<Box px={1}>
<TextField
value={secondary}
label="Secondary Color"
type="color"
size="small"
InputProps={{
sx: {
width: 128,
},
}}
onChange={(event) => setSecondaryColor(event.target.value)}
/>
</Box>
</FormGroup>
</FormControl>
</Box>
Expand Down
7 changes: 6 additions & 1 deletion packages/widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"private": true,
"sideEffects": false,
"module": "src/index.ts",
"scripts": {},
"scripts": {
"analyze": "source-map-explorer 'build/static/js/*.js'",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test"
},
"dependencies": {
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Avatar } from '@mui/material';
import { styled } from '@mui/material/styles';
import { alpha, styled } from '@mui/material/styles';
import { CardContainer, CardHeader } from '../Card';

export const Card = styled(CardContainer)(({ theme }) => ({
borderColor: theme.palette.mode === 'light' ? '#F7D4FF' : '#ee00ff47',
background: theme.palette.mode === 'light' ? '#FEF0FF' : '#ee00ff47',
borderColor: alpha(theme.palette.secondary.main, 0.48),
background: alpha(theme.palette.secondary.main, 0.2),
}));

export const RouteCard = styled(CardHeader)(({ theme }) => ({
Expand Down
17 changes: 16 additions & 1 deletion packages/widget/src/config/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const palette = {
},
secondary: {
main: '#F5B5FF',
light: lighten('#F5B5FF', 0.2),
light: lighten('#F5B5FF', 0.5),
dark: darken('#F5B5FF', 0.2),
},
success: {
Expand Down Expand Up @@ -82,6 +82,21 @@ export const createTheme = (mode: PaletteMode, theme: ThemeConfig = {}) =>
0.2,
),
},
secondary: {
main:
(theme.palette?.secondary as SimplePaletteColorOptions)?.main ??
palette.secondary.main,
light: lighten(
(theme.palette?.secondary as SimplePaletteColorOptions)?.main ??
palette.secondary.main,
0.5,
),
dark: darken(
(theme.palette?.secondary as SimplePaletteColorOptions)?.main ??
palette.secondary.main,
0.2,
),
},
...(mode === 'light'
? {
text: {
Expand Down

0 comments on commit 471cd93

Please sign in to comment.