# All files / src/SuperSelect/presets pillPreset.tsx

45.45% Statements 10/22
0% Branches 0/10
0% Functions 0/4
47.61% Lines 10/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
    692x
    2x
    2x
    2x
    2x
    2x
    2x
    2x

    2x

    2x

     import { Check } from '@procore/core-icons'
    import React from 'react'
    import { Pill } from '../../Pill/Pill'
    import { PillSelectCheckedContainer } from '../../PillSelect/PillSelect.styles'
    import { Tooltip } from '../../Tooltip/Tooltip'
    import { OverflowObserver } from '../../_hooks/OverflowObserver'
    import { Label } from '../SuperSelect.components'
    import {
      PillSelectLabel,
      PillSelectLabelWrapper,
      PillSelectOptionWrapper,
      StyledLabel,
    } from '../SuperSelect.styles'
    import { SuperSelectConfig } from '../SuperSelect.types'
    import { useSuperSelectContext } from '../useSuperSelect'

    export const pillPreset: SuperSelectConfig = {
      components: {
        Label: React.forwardRef(({ hoverable }, ref) => {
          const ctx = useSuperSelectContext()

          return (
            <StyledLabel $hoverable={hoverable}>
              <PillSelectLabelWrapper>
                <OverflowObserver>
                  {({ isOverflowing, ref }) => {
                    return (
                      <Tooltip
                        trigger={isOverflowing ? 'hover' : 'none'}
                        overlay={ctx.state.selectedLabel}
                      >
                        {ctx.state.isEmpty() ? (
                          <Label ref={ref} hoverable={hoverable} />
                        ) : (
                          <PillSelectLabel
                            ref={ref}
                            color={(ctx.state.selectedOption as any)?.color}
                          >
                            {ctx.state.selectedLabel}
                          </PillSelectLabel>
                        )}
                      </Tooltip>
                    )
                  }}
                </OverflowObserver>
              </PillSelectLabelWrapper>
            </StyledLabel>
          )
        }),
        OptionLabel: ({ option }) => {
          const ctx = useSuperSelectContext()

          return (
            <PillSelectOptionWrapper>
              <Pill color={option.color}>{ctx.option.label(option)}</Pill>
              <PillSelectCheckedContainer>
                {ctx.option.isSelected(option) && <Check size="sm" />}
              </PillSelectCheckedContainer>
            </PillSelectOptionWrapper>
          )
        },
        MultiValue: ({ option }) => {
          const ctx = useSuperSelectContext()

          return <Pill color={option.color}>{ctx.option.label(option)}</Pill>
        },
      },
    }