bigbuffet-rw/app/soapbox/features/theme-editor/index.tsx

94 lines
2.2 KiB
TypeScript
Raw Normal View History

import React, { useState } from 'react';
2022-10-25 14:56:25 -07:00
import { defineMessages, useIntl } from 'react-intl';
import List, { ListItem } from 'soapbox/components/list';
import { Column } from 'soapbox/components/ui';
import { useSoapboxConfig } from 'soapbox/hooks';
import Palette, { ColorGroup } from './components/palette';
const messages = defineMessages({
title: { id: 'admin.theme.title', defaultMessage: 'Theme' },
});
interface IThemeEditor {
}
/** UI for editing Tailwind theme colors. */
const ThemeEditor: React.FC<IThemeEditor> = () => {
const intl = useIntl();
const soapbox = useSoapboxConfig();
const [colors, setColors] = useState(soapbox.colors.toJS() as any);
const updateColors = (key: string) => {
return (newColors: any) => {
setColors({
...colors,
[key]: {
...colors[key],
...newColors,
},
});
};
};
2022-10-25 14:56:25 -07:00
return (
<Column label={intl.formatMessage(messages.title)}>
<List>
<PaletteListItem
label='Primary'
palette={colors.primary}
onChange={updateColors('primary')}
2022-10-25 14:56:25 -07:00
/>
<PaletteListItem
label='Secondary'
palette={colors.secondary}
onChange={updateColors('secondary')}
2022-10-25 14:56:25 -07:00
/>
<PaletteListItem
label='Accent'
palette={colors.accent}
onChange={updateColors('accent')}
2022-10-25 14:56:25 -07:00
/>
<PaletteListItem
label='Gray'
palette={colors.gray}
onChange={updateColors('gray')}
2022-10-25 14:56:25 -07:00
/>
<PaletteListItem
label='Success'
palette={colors.success}
onChange={updateColors('success')}
2022-10-25 14:56:25 -07:00
/>
<PaletteListItem
label='Danger'
palette={colors.danger}
onChange={updateColors('danger')}
2022-10-25 14:56:25 -07:00
/>
</List>
</Column>
);
};
interface IPaletteListItem {
label: React.ReactNode,
palette: ColorGroup,
onChange: (palette: ColorGroup) => void,
2022-10-25 14:56:25 -07:00
}
/** Palette editor inside a ListItem. */
const PaletteListItem: React.FC<IPaletteListItem> = ({ label, palette, onChange }) => {
2022-10-25 14:56:25 -07:00
return (
<ListItem label={<div className='w-20'>{label}</div>}>
<Palette palette={palette} onChange={onChange} />
2022-10-25 14:56:25 -07:00
</ListItem>
);
};
export default ThemeEditor;