From 41a608481f90a1523d456f488ac10078b2541f30 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 25 Oct 2022 17:47:24 -0500 Subject: [PATCH] ThemeEditor: allow editing colors (sort of) --- .../theme-editor/components/color.tsx | 28 +++++++++++++ .../theme-editor/components/palette.tsx | 29 +++++++------- app/soapbox/features/theme-editor/index.tsx | 40 ++++++++++++++----- 3 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 app/soapbox/features/theme-editor/components/color.tsx diff --git a/app/soapbox/features/theme-editor/components/color.tsx b/app/soapbox/features/theme-editor/components/color.tsx new file mode 100644 index 000000000..1e2b6f3c1 --- /dev/null +++ b/app/soapbox/features/theme-editor/components/color.tsx @@ -0,0 +1,28 @@ +import React from 'react'; + +import ColorWithPicker from 'soapbox/features/soapbox_config/components/color-with-picker'; + +import type { ColorChangeHandler } from 'react-color'; + +interface IColor { + color: string, + onChange: (color: string) => void, +} + +/** Color input. */ +const Color: React.FC = ({ color, onChange }) => { + + const handleChange: ColorChangeHandler = (result) => { + onChange(result.hex); + }; + + return ( + + ); +}; + +export default Color; \ No newline at end of file diff --git a/app/soapbox/features/theme-editor/components/palette.tsx b/app/soapbox/features/theme-editor/components/palette.tsx index 4f89fa3ae..a8011790f 100644 --- a/app/soapbox/features/theme-editor/components/palette.tsx +++ b/app/soapbox/features/theme-editor/components/palette.tsx @@ -2,7 +2,8 @@ import React from 'react'; import compareId from 'soapbox/compare_id'; import { HStack } from 'soapbox/components/ui'; -import ColorWithPicker from 'soapbox/features/soapbox_config/components/color-with-picker'; + +import Color from './color'; interface ColorGroup { [tint: string]: string, @@ -10,27 +11,27 @@ interface ColorGroup { interface IPalette { palette: ColorGroup, + onChange: (palette: ColorGroup) => void, } /** Editable color palette. */ -const Palette: React.FC = ({ palette }) => { +const Palette: React.FC = ({ palette, onChange }) => { const tints = Object.keys(palette).sort(compareId); - const result = tints.map(tint => { - const hex = palette[tint]; - - return ( - {}} - /> - ); - }); + const handleChange = (tint: string) => { + return (color: string) => { + onChange({ + ...palette, + [tint]: color, + }); + }; + }; return ( - {result} + {tints.map(tint => ( + + ))} ); }; diff --git a/app/soapbox/features/theme-editor/index.tsx b/app/soapbox/features/theme-editor/index.tsx index 06a0a6496..ae83a975d 100644 --- a/app/soapbox/features/theme-editor/index.tsx +++ b/app/soapbox/features/theme-editor/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import List, { ListItem } from 'soapbox/components/list'; @@ -18,39 +18,58 @@ interface IThemeEditor { const ThemeEditor: React.FC = () => { const intl = useIntl(); const soapbox = useSoapboxConfig(); - const colors = soapbox.colors.toJS(); + + const [colors, setColors] = useState(soapbox.colors.toJS() as any); + + const updateColors = (key: string) => { + return (newColors: any) => { + setColors({ + ...colors, + [key]: { + ...colors[key], + ...newColors, + }, + }); + }; + }; return ( @@ -60,13 +79,14 @@ const ThemeEditor: React.FC = () => { interface IPaletteListItem { label: React.ReactNode, palette: ColorGroup, + onChange: (palette: ColorGroup) => void, } /** Palette editor inside a ListItem. */ -const PaletteListItem: React.FC = ({ label, palette }) => { +const PaletteListItem: React.FC = ({ label, palette, onChange }) => { return ( {label}}> - + ); };