Skip to content

The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.

2.0 KB
Raw Blame
// The one fold-out: a quiet line with a chevron that opens what most people don't need ("Show default models", "More
// voices", "How to get a key"). Native <details>, so it works with the keyboard and find-in-page. The chevron points
// right while closed and down while open. `FoldOutButton` is the same line for an opener that adds something instead
// of showing it (a second greeting). Styles in fold-out.css.
import type { ReactNode } from 'react'
import { cx, Icon } from './kit.tsx'
import './fold-out.css'

type Props = {
  /** The line's words; `openSummary`: its words while open ("Hide default models"). */
  summary: ReactNode
  openSummary?: ReactNode
  /** Controlled: open now. Leave out to let the fold-out keep its own state (`defaultOpen` to start open). */
  open?: boolean
  defaultOpen?: boolean
  onToggle?: (open: boolean) => void
  /** The summary's tooltip. */
  title?: string
  id?: string
  className?: string
  children: ReactNode
}

export function FoldOut({ summary, openSummary, open, defaultOpen, onToggle, title, id, className, children }: Props) {
  return (
    <details
      id={id}
      className={cx('k-fold', className)}
      open={open ?? defaultOpen}
      onToggle={e => onToggle?.(e.currentTarget.open)}
    >
      <summary title={title}>
        <Icon name="down" size={14} className="k-fold-chevron" />
        <span className="k-fold-closed">{summary}</span>
        {openSummary && <span className="k-fold-open">{openSummary}</span>}
      </summary>
      <div className="k-fold-body">{children}</div>
    </details>
  )
}

/** The fold-out's line as a button: it adds or opens something in place (a second greeting). */
export function FoldOutButton({
  onClick,
  title,
  children,
}: {
  onClick: () => void
  title?: string
  children: ReactNode
}) {
  return (
    <button type="button" className="k-fold-button" title={title} onClick={onClick}>
      <Icon name="down" size={14} className="k-fold-chevron" />
      {children}
    </button>
  )
}