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

70.37% Statements 19/27
100% Branches 0/0
55.55% Functions 5/9
61.9% Lines 13/21

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
    1111x

    1x
    1x
    1x

    1x

    2x
    2x

    1x

    1x

    3x

    3x

    3x

    3x

     import { VisuallyHidden } from '@react-aria/visually-hidden'
    import { Meta } from '@storybook/react/types-6-0'
    import React from 'react'
    import { StoryGrid } from '../_storyHelpers_/components/StoryGrid'
    import { Tabs } from './Tabs'

    export default {
      component: Tabs,
      title: 'Demos/Tabs',
      args: {
        dark: false,
        tab1: 'Emails',
        tab2: 'Related Items',
        tab3: 'Pending Approval',
      },
      argTypes: {
        onClick: {
          action: 'onClick Tab',
        },
        onPress: {
          action: 'onPress Tab',
        },
      },
    } as Meta

    export const Demo = ({ onClick, onPress, ...props }: any) => {
      const [active, setActive] = React.useState(2)

      const tabTitles = [props.tab1, props.tab2, props.tab3]

      return (
        <>
          <StoryGrid columns={1}>
            <h2 id="basic">
              Basic <VisuallyHidden>Demo</VisuallyHidden>
            </h2>
            <Tabs {...props} aria-labelledby="basic">
              {Array.from(Array(3).keys()).map((i) => (
                <Tabs.Tab
                  key={i}
                  active={i === active}
                  onClick={(e: any) => {
                    setActive(i)
                    onClick(e)
                  }}
                >
                  <Tabs.Link>{tabTitles[i]}</Tabs.Link>
                </Tabs.Tab>
              ))}
            </Tabs>
            <h2 id="button">
              Button <VisuallyHidden>Demo</VisuallyHidden>
            </h2>
            <Tabs {...props} aria-labelledby="button">
              {Array.from(Array(3).keys()).map((i) => (
                <Tabs.Tab
                  key={i}
                  active={i === active}
                  onPress={(e: any) => {
                    setActive(i)
                    onPress(e)
                  }}
                  role="button"
                >
                  <Tabs.Link>{tabTitles[i]}</Tabs.Link>
                </Tabs.Tab>
              ))}
            </Tabs>
            <h2 id="link">
              Link <VisuallyHidden>Demo</VisuallyHidden>
            </h2>
            <Tabs {...props} aria-labelledby="link">
              {Array.from(Array(3).keys()).map((i) => (
                <Tabs.Tab
                  key={i}
                  active={i === active}
                  onPress={(e: any) => {
                    setActive(i)
                    onPress(e)
                  }}
                  role="link"
                  href="#"
                >
                  <Tabs.Link>{tabTitles[i]}</Tabs.Link>
                </Tabs.Tab>
              ))}
            </Tabs>
            <h2 id="anchor">
              Anchors Wrap <VisuallyHidden>Demo</VisuallyHidden>
            </h2>
            <Tabs {...props} aria-labelledby="anchor">
              {Array.from(Array(3).keys()).map((i) => (
                <Tabs.Tab
                  key={i}
                  active={i === active}
                  onClick={(e: any) => {
                    setActive(i)
                    onClick(e)
                  }}
                >
                  <a href="##">
                    <Tabs.Link>{tabTitles[i]}</Tabs.Link>
                  </a>
                </Tabs.Tab>
              ))}
            </Tabs>
          </StoryGrid>
        </>
      )
    }