// Copyright 2017-2019 @polkadot/react-components authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. import React from 'react'; import styled from 'styled-components'; import Collection, { CollectionProps as Props, CollectionState as State, collectionStyles } from './Collection'; import translate from './translate'; class CardGrid extends Collection { public static getDerivedStateFromProps (props: Props): State { const state = super.getDerivedStateFromProps(props); return { ...state, showHeader: !state.isEmpty || !!props.headerText }; } protected renderEmpty (): React.ReactNode { const { buttons, emptyText, headerText, t } = this.props; if (headerText) { return super.renderEmpty(); } return (

{emptyText || t('No items')}

{buttons && (
{buttons}
)}
); } public renderCollection (): React.ReactNode { const { children } = this.props; return (
{children}
); } } export default translate( styled(CardGrid as React.ComponentClass)` ${collectionStyles} .ui--CardGrid-grid { display: flex; flex-wrap: wrap; > .ui--CardGrid-spacer { flex: 1 1; margin: 0.25rem; padding: 0 1.5rem; } } .ui--CardGrid-lowercase { text-transform: lowercase; } .ui--Card, .ui--CardGrid-spacer { flex: 1 1; min-width: 40rem; max-width: 71rem; } .ui--CardGrid-empty { display: flex; justify-content: center; align-items: center; flex-direction: column; margin: 6rem 0; > h2 { margin-bottom: 2rem; } } `);