verdnatura-chat/app/containers/UIKit/Actions.tsx

30 lines
848 B
TypeScript
Raw Normal View History

2020-02-11 14:01:35 +00:00
import React, { useState } from 'react';
import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit';
import Button from '../Button';
import I18n from '../../i18n';
interface IActions {
blockId: string;
appId: string;
elements: any[];
parser: any;
theme: string;
}
export const Actions = ({ blockId, appId, elements, parser, theme }: IActions) => {
2020-02-11 14:01:35 +00:00
const [showMoreVisible, setShowMoreVisible] = useState(() => elements.length > 5);
const renderedElements = showMoreVisible ? elements.slice(0, 5) : elements;
const Elements = () => renderedElements
.map((element: any) => parser.renderActions({ blockId, appId, ...element }, BLOCK_CONTEXT.ACTION, parser));
2020-02-11 14:01:35 +00:00
return (
<>
{/*@ts-ignore*/}
2020-02-11 14:01:35 +00:00
<Elements />
{showMoreVisible && (<Button theme={theme} title={I18n.t('Show_more')} onPress={() => setShowMoreVisible(false)} />)}
</>
);
};