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

95.12% Statements 39/41
50% Branches 7/14
62.5% Functions 5/8
96.96% Lines 32/33

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
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    2191x
    1x
    1x
    1x
    1x
    1x
    1x

    1x

    1x
    1x
    1x
    1x
    1x

    1x
    4x
    1x
    1x

    1x

    1x
    1x

    1x

    1x

    3x

    1x

    6x
    1x
    1x
    1x

    1x

    10x

    1x

    1x
     import { Info, Upload, Wifi, WifiOff, Wrench } from '@procore/core-icons/dist'
    import React from 'react'
    import { Button } from '../Button/Button'
    import { FlexList } from '../FlexList/FlexList'
    import { UL } from '../Semantic/Semantic'
    import { exampleText, Ipsum } from '../_storyHelpers_/constants'
    import {
      ActionBanner,
      Banner,
      ErrorBanner,
      InfoBanner,
      UNSAFE_MiniBanner,
    } from './Banner'
    import { BannerIconProps, BannerVariant } from './Banner.types'

    interface BannerDemoProps {
      bodyContent: number
      icon: BannerIconProps
      titleContent: number
      variant: BannerVariant
      onClickBannerDismiss: React.ComponentProps<typeof Banner.Dismiss>['onClick']
      expandableContentMaxHeight: number
      expandableContentLines: number
    }

    export default {
      component: Banner,
      title: 'Demos/Banner',
      parameters: {
        options: {
          showPanel: true,
        },
        chromatic: { disableSnapshot: true },

        a11y: {
          config: {
            rules: [{ id: 'button-name', enabled: false }],
          },
        },
      },
    }

    function noop() {}

    const WifiOffIcon = <WifiOff size="lg" />
    const UploadIcon = <Upload size="lg" />
    const WrenchIcon = <Wrench size="lg" />
    const WifiIcon = <Wifi size="lg" />
    const icons = { WifiOffIcon, UploadIcon, WrenchIcon, WifiIcon }

    export const Demo = ({ ...props }: BannerDemoProps) => {
      let { icon, titleContent, bodyContent, onClickBannerDismiss } = props
      const title = titleContent > 0 ? Ipsum(titleContent) : ''
      const body = bodyContent > 0 ? Ipsum(bodyContent) : ''

      return (
        <Banner {...props}>
          {icon && <Banner.Icon icon={icon} />}
          <Banner.Content>
            <Banner.Title>{title}</Banner.Title>
            <Banner.Body>{body}</Banner.Body>
          </Banner.Content>

          <Banner.Action>
            <Button onClick={noop}>{exampleText.default}</Button>
          </Banner.Action>

          <Banner.Dismiss onClick={onClickBannerDismiss} />
        </Banner>
      )
    }

    export const DemoPresets = ({
      ...props
    }: Pick<BannerDemoProps, 'bodyContent' | 'variant'>) => {
      const presets = [ErrorBanner, ActionBanner, InfoBanner]

      return (
        <FlexList direction="column">
          {presets.map((BannerComponent) => {
            return (
              <BannerComponent key={BannerComponent.displayName}>
                <Banner.Content>
                  <Banner.Title>{Ipsum(64)}</Banner.Title>
                  <Banner.Body>{Ipsum(128)}</Banner.Body>
                </Banner.Content>
              </BannerComponent>
            )
          })}
          <UNSAFE_MiniBanner style={{ width: '633px' }}>
            <Banner.Icon icon={<Info size="sm" />} />
            <Banner.Content>
              FPO <b>Drawing Log Subscribers</b> will be notified any time changes
              are made to the Drawings, including Revisions and published Markup.
              Read our support page to <a href="#">learn more.</a>
            </Banner.Content>
          </UNSAFE_MiniBanner>
        </FlexList>
      )
    }

    export const DemoExpandableContent = ({ ...props }: BannerDemoProps) => {
      let {
        titleContent,
        bodyContent,
        expandableContentLines,
        onClickBannerDismiss,
        icon,
        expandableContentMaxHeight,
      } = props
      const title = titleContent > 0 ? Ipsum(titleContent) : ''
      const body = bodyContent > 0 ? Ipsum(bodyContent) : ''
      const [isExpanded, setExpanded] = React.useState(true)

      return (
        <Banner {...props}>
          {icon && <Banner.Icon icon={icon} />}
          <Banner.Content>
            <Banner.Title>{title}</Banner.Title>
            <Banner.Body>{body}</Banner.Body>
          </Banner.Content>

          <Banner.Action>
            <Button onClick={() => setExpanded((prev) => !prev)}>
              {`${isExpanded ? 'Hide' : 'Show'} Details`}
            </Button>
          </Banner.Action>

          <Banner.Dismiss onClick={onClickBannerDismiss} />

          <Banner.ExpandableContent
            expanded={isExpanded}
            expandableContentMaxHeight={expandableContentMaxHeight}
          >
            <UL>
              {Array.from(Array(expandableContentLines)).map((_, i) => {
                return (
                  <li key={`${i}_${expandableContentMaxHeight}`}>
                    value ({i + 1}).jpg
                  </li>
                )
              })}
            </UL>
          </Banner.ExpandableContent>
        </Banner>
      )
    }

    Demo.argTypes = {
      variant: {
        defaultValue: 'action',
        control: {
          type: 'select',
          options: [
            'action',
            'error',
            'info',
            'success',
            'UNSAFE_attention_emphasized',
          ],
        },
      },
      bodyContent: {
        defaultValue: 30,
        control: {
          type: 'range',
          min: 0,
          max: 1000,
          step: 10,
        },
      },
      titleContent: {
        defaultValue: 10,
        control: {
          type: 'range',
          min: 0,
          max: 1000,
          step: 10,
        },
      },
      expandableContentLines: {
        defaultValue: 10,
        control: {
          type: 'range',
          min: 0,
          max: 50,
          step: 5,
        },
      },
      icon: {
        defaultValue: '',
        options: Object.keys(icons),
        mapping: icons,
        control: {
          type: 'select',
          labels: {
            UploadIcon: 'upload',
            WifiIcon: 'wifi',
            WifiOffIcon: 'wifioff',
            WrenchIcon: 'wrench',
          },
        },
      },
      onClickBannerDismiss: {
        action: 'onClickBannerDismiss',
      },
      expandableContentMaxHeight: {
        defaultValue: 120,
        control: {
          type: 'range',
          min: 0,
          max: 700,
          step: 10,
        },
      },
    }

    DemoExpandableContent.argTypes = { ...Demo.argTypes }