# All files / src/EmptyState EmptyState.demo.stories.tsx

77.27% Statements 17/22
25% Branches 2/8
100% Functions 2/2
75% Lines 15/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    921x
    1x
    1x
    1x
    1x

    1x

    1x

    1x

    1x

    1x
    2x
    1x

    1x

    1x

    1x

     import React from 'react'
    import { Button } from '../Button/Button'
    import { Ipsum } from '../_storyHelpers_/constants'
    import imageSrc from './assets/default.stories.png'
    import { EmptyState } from './EmptyState'

    export default {
      component: EmptyState,
      title: 'Demos/EmptyState',
      parameters: {
        chromatic: { disableSnapshot: true },
      },
    }

    const emptyStates = {
      noItems: 'No Items',
      imageChild: 'Image Child',
      noItemsNoPermissions: 'No Items, No Create Permissions',
      noResults: 'No Results',
      recycleBin: 'Recycle Bin',
    } as const

    function EmptyStateStatus(props: { status: string }) {
      switch (props.status) {
        case emptyStates.noItems:
          return <EmptyState.NoItems />
        case emptyStates.imageChild:
          return (
            <EmptyState.Image>
              <img src={imageSrc} />
            </EmptyState.Image>
          )
        case emptyStates.noItemsNoPermissions:
          return <EmptyState.NoItemsWithoutCreatePermissions />
        case emptyStates.noResults:
          return <EmptyState.NoResults />
        case emptyStates.recycleBin:
          return <EmptyState.RecycleBin />
        default:
          return null
      }
    }

    export const Demo = ({ ...props }): any => {
      const { content, status } = props
      const text = content > 0 ? Ipsum(content) : ''

      return (
        <EmptyState {...props}>
          <EmptyStateStatus status={status} />
          <EmptyState.Title>Empty State Title</EmptyState.Title>
          <EmptyState.Description>{text}</EmptyState.Description>
          <EmptyState.Actions>
            <Button>Action Button</Button>
          </EmptyState.Actions>
        </EmptyState>
      )
    }

    Demo.args = {
      content: 10,
      compact: false,
      status: emptyStates.noItems,
    }

    Demo.argTypes = {
      content: {
        control: {
          type: 'range',
          min: 0,
          max: 1000,
          step: 5,
        },
      },
      compact: {
        control: 'boolean',
      },
      status: {
        mapping: emptyStates,
        options: Object.keys(emptyStates),
        control: {
          type: 'select',
          labels: {
            ...emptyStates,
          },
        },
      },
      onClick: {
        action: 'onClick',
      },
    }