2022-10-25 15:47:24 -07:00
|
|
|
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();
|
2022-10-25 15:47:24 -07:00
|
|
|
|
|
|
|
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'
|
2022-10-25 15:47:24 -07:00
|
|
|
palette={colors.primary}
|
|
|
|
onChange={updateColors('primary')}
|
2022-10-25 14:56:25 -07:00
|
|
|
/>
|
|
|
|
|
|
|
|
<PaletteListItem
|
|
|
|
label='Secondary'
|
2022-10-25 15:47:24 -07:00
|
|
|
palette={colors.secondary}
|
|
|
|
onChange={updateColors('secondary')}
|
2022-10-25 14:56:25 -07:00
|
|
|
/>
|
|
|
|
|
|
|
|
<PaletteListItem
|
|
|
|
label='Accent'
|
2022-10-25 15:47:24 -07:00
|
|
|
palette={colors.accent}
|
|
|
|
onChange={updateColors('accent')}
|
2022-10-25 14:56:25 -07:00
|
|
|
/>
|
|
|
|
|
|
|
|
<PaletteListItem
|
|
|
|
label='Gray'
|
2022-10-25 15:47:24 -07:00
|
|
|
palette={colors.gray}
|
|
|
|
onChange={updateColors('gray')}
|
2022-10-25 14:56:25 -07:00
|
|
|
/>
|
|
|
|
|
|
|
|
<PaletteListItem
|
|
|
|
label='Success'
|
2022-10-25 15:47:24 -07:00
|
|
|
palette={colors.success}
|
|
|
|
onChange={updateColors('success')}
|
2022-10-25 14:56:25 -07:00
|
|
|
/>
|
|
|
|
|
|
|
|
<PaletteListItem
|
|
|
|
label='Danger'
|
2022-10-25 15:47:24 -07:00
|
|
|
palette={colors.danger}
|
|
|
|
onChange={updateColors('danger')}
|
2022-10-25 14:56:25 -07:00
|
|
|
/>
|
|
|
|
</List>
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IPaletteListItem {
|
|
|
|
label: React.ReactNode,
|
|
|
|
palette: ColorGroup,
|
2022-10-25 15:47:24 -07:00
|
|
|
onChange: (palette: ColorGroup) => void,
|
2022-10-25 14:56:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Palette editor inside a ListItem. */
|
2022-10-25 15:47:24 -07:00
|
|
|
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>}>
|
2022-10-25 15:47:24 -07:00
|
|
|
<Palette palette={palette} onChange={onChange} />
|
2022-10-25 14:56:25 -07:00
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ThemeEditor;
|