UNPKG

decap-cms-core

Version:

Decap CMS core application, see decap-cms package for the main distribution.

82 lines (69 loc) 2.16 kB
import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import React from 'react'; import styled from '@emotion/styled'; import { translate } from 'react-polyglot'; import { Link } from 'react-router-dom'; import { components, buttons, shadows } from 'decap-cms-ui-default'; const CollectionTopContainer = styled.div` ${components.cardTop}; margin-bottom: 22px; `; const CollectionTopRow = styled.div` display: flex; align-items: center; justify-content: space-between; `; const CollectionTopHeading = styled.h1` ${components.cardTopHeading}; `; const CollectionTopNewButton = styled(Link)` ${buttons.button}; ${shadows.dropDeep}; ${buttons.default}; ${buttons.gray}; padding: 0 30px; `; const CollectionTopDescription = styled.p` ${components.cardTopDescription}; margin-bottom: 0; `; function getCollectionProps(collection) { const collectionLabel = collection.get('label'); const collectionLabelSingular = collection.get('label_singular'); const collectionDescription = collection.get('description'); return { collectionLabel, collectionLabelSingular, collectionDescription, }; } function CollectionTop({ collection, newEntryUrl, t }) { const { collectionLabel, collectionLabelSingular, collectionDescription } = getCollectionProps( collection, t, ); return ( <CollectionTopContainer> <CollectionTopRow> <CollectionTopHeading>{collectionLabel}</CollectionTopHeading> {newEntryUrl ? ( <CollectionTopNewButton to={newEntryUrl}> {t('collection.collectionTop.newButton', { collectionLabel: collectionLabelSingular || collectionLabel, })} </CollectionTopNewButton> ) : null} </CollectionTopRow> {collectionDescription ? ( <CollectionTopDescription>{collectionDescription}</CollectionTopDescription> ) : null} </CollectionTopContainer> ); } CollectionTop.propTypes = { collection: ImmutablePropTypes.map.isRequired, newEntryUrl: PropTypes.string, t: PropTypes.func.isRequired, }; export default translate()(CollectionTop);