# All files / src/DetailPage DetailPage.tsx

100% Statements 36/36
50% Branches 1/2
100% Functions 7/7
100% Lines 32/32

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
    1652x
    2x
    2x

    2x
    2x
    2x

    2x
    2x

    2x

    2x
    3x
    3x

    2x

    1x

    2x

    1x

    1x

    2x
    2x
    2x

    2x

    1x

    2x

    1x

    2x

    1x

    2x
    2x
    2x
    2x
    2x

    2x

     import React from 'react'
    import { Grid } from '../Grid/Grid'
    import { Page } from '../PageLayout/PageLayout'
    import {
      PageComponentProps,
      PageFooterProps,
    } from '../PageLayout/PageLayout.types'
    import { Section, SectionProvider } from '../Section/Section'
    import { H1 } from '../Semantic/Semantic'
    import { addSubcomponents } from '../_utils/addSubcomponents'
    import { Props } from '../_utils/types'
    import { gridConfig } from './DetailPage.constants'
    import {
      StyledDetailPageBody,
      StyledDetailPageCard,
      StyledDetailPageFooter,
      StyledDetailPageFooterActions,
      StyledDetailPageFooterContent,
      StyledDetailPageFooterNotation,
    } from './DetailPage.styles'
    import { DetailPageProps, DetailPageWidth } from './DetailPage.types'

    export const DetailPageViewContext = React.createContext<{
      width: DetailPageWidth
    }>({
      width: 'md',
    })

    const DetailPage_ = React.forwardRef<HTMLDivElement, DetailPageProps>(
      function DetailPage_({ width = 'md', children, ...props }, ref) {
        return (
          <DetailPageViewContext.Provider value={{ width }}>
            <Page ref={ref} {...props}>
              {children}
            </Page>
          </DetailPageViewContext.Provider>
        )
      }
    )

    export const Heading = React.forwardRef<HTMLDivElement, Props>(function Heading(
      props,
      ref
    ) {
      return <H1 ref={ref} {...props} />
    })

    export const Body = React.forwardRef<HTMLDivElement, PageComponentProps>(
      function Body(props, ref) {
        const { width } = React.useContext(DetailPageViewContext)

        return (
          <Page.Body>
            <Grid.Row>
              <Grid.Col
                colWidth={gridConfig[width].width}
                colStart={gridConfig[width].offset}
              >
                <StyledDetailPageBody ref={ref} {...props} />
              </Grid.Col>
            </Grid.Row>
          </Page.Body>
        )
      }
    )

    export const Footer = React.forwardRef<HTMLDivElement, PageFooterProps>(
      function Footer({ children, ...props }, ref) {
        return (
          <StyledDetailPageFooter ref={ref} {...props}>
            <StyledDetailPageFooterContent>
              {children}
            </StyledDetailPageFooterContent>
          </StyledDetailPageFooter>
        )
      }
    )

    export const FooterNotation = React.forwardRef<HTMLDivElement, Props>(
      function FooterNotation(props, ref) {
        return <StyledDetailPageFooterNotation ref={ref} {...props} />
      }
    )

    export const FooterActions = React.forwardRef<HTMLDivElement, Props>(
      function Actions(props, ref) {
        return <StyledDetailPageFooterActions ref={ref} {...props} />
      }
    )

    export const Card = React.forwardRef<HTMLDivElement, Props>(function Card(
      props,
      ref
    ) {
      return (
        <SectionProvider>
          <StyledDetailPageCard ref={ref} {...props} />
        </SectionProvider>
      )
    })

    DetailPage_.displayName = 'DetailPage'
    Heading.displayName = 'DetailPage.Heading'
    Body.displayName = 'DetailPage.Body'
    Footer.displayName = 'DetailPage.Footer'
    Card.displayName = 'DetailPage.Card'

    /**

     A detail page is used when an object is selected from a list page. The layout
     can adhere to varying predefined widths depending on use case.

      - DetailPage
        - DetailPage.Main
          - DetailPage.Header
            - DetailPage.Breadcrumbs
              - Breadcrumbs
            - DetailPage.Banner
              - Banner
            - DetailPage.Title
              - Title or H1
            - DetailPage.Tabs
              - Tabs
          - DetailPage.Body
            - DetailPage.Title
            - DetailPage.Banner
            - DetailPage.Card
              - DetailPage.Banner
              - DetailPage.Section
                - DetailPage.Section
              - DetailPage.Section
          - DetailPage.Footer
            - DetailPage.FooterNotation
            - DetailPage.FooterActions
              - Button
        - DetailPage.Aside
          - Panel

     @since 10.19.0

     @see [Storybook](https://procore.github.io/core/core-react/latest/?path=/story/demos-detailpage--edit)

     @see [Design Guidelines](https://design.procore.com/detail)

     */
    export const DetailPage = addSubcomponents(
      {
        Main: Page.Main,
        Header: Page.Header,
        Breadcrumbs: Page.Breadcrumbs,
        Card,
        Banner: Page.Banner,
        Title: Page.Title,
        Heading,
        Tabs: Page.Tabs,
        Footer,
        FooterActions,
        FooterNotation,
        Section,
        Body,
        Aside: Page.Aside,
      },
      DetailPage_
    )