2022-05-05 13:57:30 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { useIntl, defineMessages } from 'react-intl';
|
|
|
|
|
|
|
|
import { HStack, Input } from 'soapbox/components/ui';
|
|
|
|
|
|
|
|
import IconPicker from './icon-picker';
|
|
|
|
|
2022-11-25 10:28:43 -08:00
|
|
|
import type { StreamfieldComponent } from 'soapbox/components/ui/streamfield/streamfield';
|
2022-05-05 13:57:30 -07:00
|
|
|
import type { PromoPanelItem } from 'soapbox/types/soapbox';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
icon: { id: 'soapbox_config.promo_panel.meta_fields.icon_placeholder', defaultMessage: 'Icon' },
|
|
|
|
label: { id: 'soapbox_config.promo_panel.meta_fields.label_placeholder', defaultMessage: 'Label' },
|
|
|
|
url: { id: 'soapbox_config.promo_panel.meta_fields.url_placeholder', defaultMessage: 'URL' },
|
|
|
|
});
|
|
|
|
|
|
|
|
const PromoPanelInput: StreamfieldComponent<PromoPanelItem> = ({ value, onChange }) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
const handleIconChange = (icon: any) => {
|
|
|
|
onChange(value.set('icon', icon.id));
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleChange = (key: 'text' | 'url'): React.ChangeEventHandler<HTMLInputElement> => {
|
|
|
|
return e => {
|
|
|
|
onChange(value.set(key, e.currentTarget.value));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-05-05 15:29:24 -07:00
|
|
|
<HStack space={2} alignItems='center' grow>
|
2022-05-05 13:57:30 -07:00
|
|
|
<IconPicker
|
|
|
|
value={value.icon}
|
|
|
|
onChange={handleIconChange}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Input
|
|
|
|
type='text'
|
2022-05-05 16:19:53 -07:00
|
|
|
outerClassName='w-full flex-grow'
|
2022-05-05 13:57:30 -07:00
|
|
|
placeholder={intl.formatMessage(messages.label)}
|
|
|
|
value={value.text}
|
|
|
|
onChange={handleChange('text')}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
type='text'
|
2022-05-05 16:19:53 -07:00
|
|
|
outerClassName='w-full flex-grow'
|
2022-05-05 13:57:30 -07:00
|
|
|
placeholder={intl.formatMessage(messages.url)}
|
|
|
|
value={value.url}
|
|
|
|
onChange={handleChange('url')}
|
|
|
|
/>
|
|
|
|
</HStack>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PromoPanelInput;
|