# All files / src/Sidebar Sidebar.tsx

44.68% Statements 21/47
0% Branches 0/2
0% Functions 0/8
56.75% Lines 21/37

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
    1601x
    1x
    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

     import React from 'react'
    import { H2 } from '../Semantic'
    import { addSubcomponents } from '../_utils/addSubcomponents'
    import {
      AnchorAttributes,
      DivAttributes,
      HeadingAttributes,
      LiAttributes,
      OlAttributes,
      Props,
    } from '../_utils/types'
    import {
      StyledSidebar,
      StyledSidebarButton,
      StyledSidebarDivider,
      StyledSidebarHeader,
      StyledSidebarHeaderAction,
      StyledSidebarMenu,
      StyledSidebarMenuItem,
    } from './Sidebar.styles'

    interface SidebarMenuItemProps extends Props {
      /**
       * @since 10.19.0
       */
      active?: boolean
    }

    export const Sidebar_ = React.forwardRef<HTMLDivElement, DivAttributes & Props>(
      function Sidebar({ children, ...props }, ref) {
        return (
          <StyledSidebar ref={ref} {...props}>
            {children}
          </StyledSidebar>
        )
      }
    )

    export const Divider = React.forwardRef<HTMLDivElement, DivAttributes & Props>(
      function Divider({ children, ...props }, ref) {
        return <StyledSidebarDivider {...props} ref={ref} />
      }
    )

    export const Button = React.forwardRef<HTMLDivElement, DivAttributes & Props>(
      function Button({ children, ...props }, ref) {
        return (
          <StyledSidebarButton {...props} ref={ref}>
            {children}
          </StyledSidebarButton>
        )
      }
    )

    export const Header = React.forwardRef<HTMLDivElement, DivAttributes & Props>(
      function Header({ children, ...props }, ref) {
        return (
          <StyledSidebarHeader {...props} ref={ref}>
            {children}
          </StyledSidebarHeader>
        )
      }
    )

    export const HeaderLabel = React.forwardRef<
      HTMLHeadingElement,
      HeadingAttributes & Props
    >(function HeaderLabel({ children, ...props }, ref) {
      return (
        <H2 {...props} ref={ref}>
          {children}
        </H2>
      )
    })

    export const HeaderAction = React.forwardRef<
      HTMLAnchorElement,
      AnchorAttributes & Props
    >(function HeaderAction({ children, ...props }, ref) {
      return (
        <StyledSidebarHeaderAction {...props} ref={ref}>
          {children}
        </StyledSidebarHeaderAction>
      )
    })

    export const Menu = React.forwardRef<HTMLOListElement, OlAttributes & Props>(
      function Menu({ children, ...props }, ref) {
        return (
          <StyledSidebarMenu {...props} ref={ref}>
            {children}
          </StyledSidebarMenu>
        )
      }
    )

    export const MenuItem = React.forwardRef<
      HTMLLIElement,
      LiAttributes & SidebarMenuItemProps
    >(function MenuItem({ active = false, children, ...props }, ref) {
      return (
        <StyledSidebarMenuItem {...props} $active={active} ref={ref}>
          {children}
        </StyledSidebarMenuItem>
      )
    })

    Sidebar_.displayName = 'Sidebar'

    Divider.displayName = 'Sidebar.Divider'

    Button.displayName = 'Sidebar.Button'

    Header.displayName = 'Sidebar.Header'

    HeaderLabel.displayName = 'Sidebar.HeaderLabel'

    HeaderAction.displayName = 'Sidebar.HeaderAction'

    Menu.displayName = 'Sidebar.Menu'

    MenuItem.displayName = 'Sidebar.MenuItem'

    /**
     * @deprecated
     * This design has been removed from the system.  The sidebar concepts are incoportated into other components. Instead you may want one of the following:
     * - `Panel`
     * - `Page.Aside` for layout location
     * - `Title`
     * - `Button`, `ButtonLink`, `Link` placed in a `Title.Actions` or `Panel.HeaderActions`
     * - `Menu`
     */
    /** @deprecatedSince 10.19.0 */
    export const Sidebar = addSubcomponents(
      {
        /** @deprecated Visual dividers are a parent of Panel.Section */
        /** @deprecatedSince 10.19.0 */
        Divider,
        /** @deprecated Try block prop on a Button */
        /** @deprecatedSince 10.19.0 */
        Button,
        /** @deprecated Try Title */
        /** @deprecatedSince 10.19.0 */
        Header,
        /** @deprecated Try Title and Title.Text or Panel componenls } */
        /** @deprecatedSince 10.19.0 */
        HeaderLabel,
        /** @deprecated Try Title.Actions or Panel.HeaderActions */
        /** @deprecatedSince 10.19.0 */
        HeaderAction,
        /** @deprecated See Menu component */
        /** @deprecatedSince 10.19.0 */
        Menu,
        /** @deprecated See Menu component */
        /** @deprecatedSince 10.19.0 */
        MenuItem,
      },
      Sidebar_
    )