2021-09-13 20:41:05 +00:00
|
|
|
import React, { useState } from 'react';
|
2022-05-26 14:07:17 +00:00
|
|
|
import { BlockContext } from '@rocket.chat/ui-kit';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
import Button from '../Button';
|
|
|
|
import I18n from '../../i18n';
|
2022-03-16 19:07:49 +00:00
|
|
|
import { IActions } from './interfaces';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-03-29 20:06:50 +00:00
|
|
|
export const Actions = ({ blockId, appId, elements, parser }: IActions) => {
|
2022-03-16 19:07:49 +00:00
|
|
|
const [showMoreVisible, setShowMoreVisible] = useState(() => elements && elements.length > 5);
|
|
|
|
const renderedElements = showMoreVisible ? elements?.slice(0, 5) : elements;
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-03-16 19:07:49 +00:00
|
|
|
const Elements = () => (
|
2022-05-26 14:07:17 +00:00
|
|
|
<>{renderedElements?.map(element => parser?.renderActions({ blockId, appId, ...element }, BlockContext.ACTION, parser))}</>
|
2022-03-16 19:07:49 +00:00
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Elements />
|
2022-05-20 16:37:57 +00:00
|
|
|
{showMoreVisible && <Button title={I18n.t('Show_more')} onPress={() => setShowMoreVisible(false)} />}
|
2021-09-13 20:41:05 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|