Skip to content

Commit

Permalink
feat: add color picker to developer panel in webapp
Browse files Browse the repository at this point in the history
  • Loading branch information
anfibiacreativa committed Nov 11, 2023
1 parent 0a04c2e commit 3910b3c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/webapp/src/components/SettingsStyles/SettingsStyles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.ms-style-picker {
display: grid;
margin-top: 10px;
grid-template-columns: repeat(4, 1fr);
}

.ms-style-picker > input,
.ms-style-picker > label {
margin-bottom: 10px;
margin-right: 10px;
}
57 changes: 57 additions & 0 deletions packages/webapp/src/components/SettingsStyles/SettingsStyles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useState } from 'react';
import './SettingsStyles.css';

type CustomStylesState = {
AccentHigh: string;
AccentLighter: string;
AccentContrast: string;
};

interface Props {
onChange: (newStyles: CustomStylesState) => void;
}

export const SettingsStyles = ({ onChange }: Props) => {
const defaultColors = ['#692b61', '#f6d5f2', '#5e3c7d'];

const [customStyles, setStyles] = useState<CustomStylesState>({
AccentHigh: defaultColors[0],
AccentLighter: defaultColors[1],
AccentContrast: defaultColors[2],
});

const handleInputChange = (key: keyof CustomStylesState, value: string) => {
setStyles((previousStyles) => ({
...previousStyles,
[key]: value,
}));
onChange({
...customStyles,
[key]: value,
});
};

return (
<>
<h3>Modify Styles</h3>
<div className="ms-style-picker">
{[
{ label: 'Accent High', name: 'AccentHigh', placeholder: 'Accent high' },
{ label: 'Accent Lighter', name: 'AccentLighter', placeholder: 'Accent lighter' },
{ label: 'Accent Contrast', name: 'AccentContrast', placeholder: 'Accent contrast' },
].map((input) => (
<React.Fragment key={input.name}>
<label htmlFor={`accent-${input.name.toLowerCase()}-picker`}>{input.label}</label>
<input
name={`accent-${input.name.toLowerCase()}-picker`}
type="color"
placeholder={input.placeholder}
value={customStyles[input.name as keyof CustomStylesState]}
onChange={(event) => handleInputChange(input.name as keyof CustomStylesState, event.target.value)}
/>
</React.Fragment>
))}
</div>
</>
);
};
1 change: 1 addition & 0 deletions packages/webapp/src/components/SettingsStyles/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SettingsStyles.jsx';

0 comments on commit 3910b3c

Please sign in to comment.