Streamfield: i18n

This commit is contained in:
Alex Gleason 2022-05-02 22:05:43 -05:00
parent 96401006ff
commit 89b612e6bf
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import { useIntl, defineMessages } from 'react-intl';
import Button from '../button/button'; import Button from '../button/button';
import HStack from '../hstack/hstack'; import HStack from '../hstack/hstack';
@ -6,6 +7,11 @@ import IconButton from '../icon-button/icon-button';
import Stack from '../stack/stack'; import Stack from '../stack/stack';
import Text from '../text/text'; import Text from '../text/text';
const messages = defineMessages({
add: { id: 'streamfield.add', defaultMessage: 'Add' },
remove: { id: 'streamfield.remove', defaultMessage: 'Remove' },
});
interface IStreamfield { interface IStreamfield {
/** Array of values for the streamfield. */ /** Array of values for the streamfield. */
values: any[], values: any[],
@ -36,6 +42,7 @@ const Streamfield: React.FC<IStreamfield> = ({
component: Component, component: Component,
maxItems = Infinity, maxItems = Infinity,
}) => { }) => {
const intl = useIntl();
const handleChange = (i: number) => { const handleChange = (i: number) => {
return (value: any) => { return (value: any) => {
@ -62,6 +69,7 @@ const Streamfield: React.FC<IStreamfield> = ({
className='bg-transparent text-gray-400 hover:text-gray-600' className='bg-transparent text-gray-400 hover:text-gray-600'
src={require('@tabler/icons/icons/x.svg')} src={require('@tabler/icons/icons/x.svg')}
onClick={() => onRemoveItem(i)} onClick={() => onRemoveItem(i)}
title={intl.formatMessage(messages.remove)}
/> />
)} )}
</HStack> </HStack>
@ -76,7 +84,7 @@ const Streamfield: React.FC<IStreamfield> = ({
theme='ghost' theme='ghost'
block block
> >
Add {intl.formatMessage(messages.add)}
</Button> </Button>
)} )}
</Stack> </Stack>