import React from 'react' import {styled, css} from 'styled-components' import {Box, Card, Grid, Text} from '@sanity/ui' import {WidgetContainer} from '../containers/WidgetContainer' import {DashboardConfig, LayoutConfig, DashboardWidget} from '../types' const media = { small: (...args: Parameters) => css` @media (min-width: ${({theme}) => theme.sanity.media[0]}px) { ${css(...args)} } `, medium: (...args: Parameters) => css` @media (min-width: ${({theme}) => theme.sanity.media[2]}px) { ${css(...args)} } `, } const Root = styled(Grid)` grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); & > div { overflow: hidden; } & > div[data-width='medium'] { ${media.small` grid-column: span 2; `} } & > div[data-width='large'] { ${media.small` grid-column: span 2; `} ${media.medium` grid-column: span 3; `} } & > div[data-width='full'] { ${media.small` grid-column: 1 / -1; `} } & > div[data-height='medium'] { ${media.small` grid-row: span 2; `} } & > div[data-height='large'] { ${media.small` grid-row: span 2; `} ${media.medium` grid-row: span 3; `} } & > div[data-height='full'] { ${media.medium` grid-row: 1 / -1; `} } ` export interface WidgetGroupProps { config: Partial } const NO_WIDGETS: DashboardWidget[] = [] const NO_LAYOUT: LayoutConfig = {} export function WidgetGroup(props: WidgetGroupProps) { const { config: {layout = NO_LAYOUT, widgets = NO_WIDGETS}, } = props return ( {widgets.length ? null : ( Add some widgets to populate this space. )} {widgets.map((widgetConfig, index) => { if (widgetConfig.type === '__experimental_group') { return } if (widgetConfig.component) { return } return {widgetConfig.name} is missing widget component })} ) }