1e0845f4b9
* Add tsconfig.json for common * Prefer `const` over `let` over `var` * Kill dead code * Fix some trivial Typescript issues * Turn on Typescript linting in common except for no-explicit-any * Correctly specify tsconfig dir name in functions eslintrc * Give react children explicit types * Add explicit types to removeUndefinedProps * Create StripeSession type * Give event in Dropdown an explicit type * Revert "Give event in Dropdown an explicit type" This reverts commit80604310f2
. * Give bids in NewBidTable an explicit type * Cast results of removeUndefinedProps when neccessary * Fix type of JoinSpans * Revert "Cast results of removeUndefinedProps when neccessary" This reverts commit5541617bc8
. * Revert "Add explicit types to removeUndefinedProps" This reverts commitccf8ffb0b5
. * Give React children types everywhere * Give event a type * Give event correct type * Lint * Standardize React import Co-authored-by: Marshall Polaris <marshall@pol.rs>
34 lines
635 B
TypeScript
34 lines
635 B
TypeScript
import { ReactNode } from 'react'
|
|
|
|
export const JoinSpans = (props: {
|
|
children: ReactNode[]
|
|
separator?: ReactNode
|
|
}) => {
|
|
const { separator } = props
|
|
const children = props.children.filter((x) => !!x)
|
|
|
|
if (children.length === 0) return <></>
|
|
if (children.length === 1) return <>{children[0]}</>
|
|
if (children.length === 2)
|
|
return (
|
|
<>
|
|
{children[0]} and {children[1]}
|
|
</>
|
|
)
|
|
|
|
const head = children.slice(0, -1).map((child) => (
|
|
<>
|
|
{child}
|
|
{separator || ','}{' '}
|
|
</>
|
|
))
|
|
|
|
const tail = children[children.length - 1]
|
|
|
|
return (
|
|
<>
|
|
{head}and {tail}
|
|
</>
|
|
)
|
|
}
|