mirror of
https://github.com/strapi/strapi.git
synced 2025-08-10 17:58:07 +00:00
73 lines
2.0 KiB
JavaScript
73 lines
2.0 KiB
JavaScript
/*
|
|
* NOTE:
|
|
* This component should be put in the strapi-helper-plugin
|
|
* at some point so the other packages can benefits from the updates
|
|
*
|
|
*
|
|
*/
|
|
|
|
import React, { Fragment } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { FormattedMessage } from 'react-intl';
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
import { HeaderModalTitle } from 'strapi-helper-plugin';
|
|
import ModalSection from '../ModalSection';
|
|
import Text from '../Text';
|
|
import BackButton from './BackButton';
|
|
import Wrapper from './Wrapper';
|
|
|
|
const ModalHeader = ({ goBack, headerBreadcrumbs, withBackButton, HeaderComponent }) => {
|
|
const translatedHeaders = headerBreadcrumbs
|
|
? headerBreadcrumbs.map(headerTrad => ({
|
|
key: headerTrad,
|
|
element: <FormattedMessage id={headerTrad} />,
|
|
}))
|
|
: null;
|
|
|
|
const handleClick = () => {
|
|
goBack('backButton');
|
|
};
|
|
|
|
return (
|
|
<Wrapper>
|
|
<ModalSection>
|
|
<HeaderModalTitle>
|
|
{withBackButton && <BackButton onClick={handleClick} type="button" />}
|
|
{HeaderComponent && <HeaderComponent />}
|
|
{translatedHeaders &&
|
|
translatedHeaders.map(({ key, element }, index) => {
|
|
const shouldDisplayChevron = index < translatedHeaders.length - 1;
|
|
|
|
return (
|
|
<Fragment key={key}>
|
|
{element}
|
|
{shouldDisplayChevron && (
|
|
<Text as="span" fontSize="xs" color="#919bae">
|
|
<FontAwesomeIcon icon="chevron-right" style={{ margin: '0 10px' }} />
|
|
</Text>
|
|
)}
|
|
</Fragment>
|
|
);
|
|
})}
|
|
</HeaderModalTitle>
|
|
</ModalSection>
|
|
</Wrapper>
|
|
);
|
|
};
|
|
|
|
ModalHeader.defaultProps = {
|
|
goBack: () => {},
|
|
headerBreadcrumbs: [],
|
|
withBackButton: false,
|
|
HeaderComponent: null,
|
|
};
|
|
|
|
ModalHeader.propTypes = {
|
|
goBack: PropTypes.func,
|
|
headerBreadcrumbs: PropTypes.array,
|
|
withBackButton: PropTypes.bool,
|
|
HeaderComponent: PropTypes.elementType,
|
|
};
|
|
|
|
export default ModalHeader;
|