qat

Accordion, tree, disclosure

Accordion, Tree, Disclosure. They are copied into your app’s ui/ by qatjs add disclosure: the code is yours to edit.

Example

Baku within a day; other cities two to three days.

  • src
  • Cart.qx
  • Total.qx
  • README.md

Selected: cart

Orders placed before 2024 are archived.

Example.qx41 lines, 2 reactive namesOpen in the playground
import { Accordion, Disclosure, Tree } from './ui/disclosure/disclosure.qx'

const answers: Record<string, string> = {
  time: 'Baku within a day; other cities two to three days.',
  address: 'Until the order is handed to the courier.',
}
const files = [
  {
    id: 'src',
    label: 'src',
    children: [
      { id: 'cart', label: 'Cart.qx' },
      { id: 'total', label: 'Total.qx' },
    ],
  },
  { id: 'readme', label: 'README.md' },
]

export default function Example() {
  let file = state('cart')
  let opened = state(['src'])
  return (
    <div class="example-grid">
      <Accordion
        items={[
          { id: 'time', title: 'How long does delivery take?' },
          { id: 'address', title: 'Can I change the address?' },
        ]}
        open={['time']}
      >
        {(id) => <p>{answers[id]}</p>}
      </Accordion>
      <div>
        <Tree label="Files" items={files} bind:selected={file} bind:expanded={opened} />
        <p>Selected: {file}</p>
      </div>
    </div>
    <p>Orders placed before 2024 are archived.</p>
    <Disclosure>They are kept for seven years as the tax code requires, then deleted.</Disclosure>
  )
}
file stateopened state

Add it

shell1 line
npx qatjs add disclosure

Accordion

Sections that open and close: several at once, or one (`single`); `bind:open` (the open ids). As a custom element: <ui-accordion>.

Accordion: props
PropTypeAttribute
items{ id: string; title: QatNode }[]property only
openstring[]property only
singlebooleanyes
level2 | 3 | 4property only
Accordion: events
EventDetail
on:update:openCustomEvent<string[]>

Tree

A hierarchy: folders open and close, one item is selected; `bind:selected`, `bind:expanded`. As a custom element: <ui-tree>.

Tree: props
PropTypeAttribute
labelstringyes
itemsTreeNode[]property only
selectedstringyes
expandedstring[]property only
Tree: events
EventDetail
on:update:selectedCustomEvent<string>
on:update:expandedCustomEvent<string[]>

Disclosure

More of a paragraph, behind "Show more" (`more`) / "Show less" (`less`); `bind:open`. As a custom element: <ui-disclosure>.

Disclosure: props
PropTypeAttribute
morestringyes
lessstringyes
openbooleanyes
Disclosure: events
EventDetail
on:update:openCustomEvent<boolean>

Keys

KeyDoes
↑ ↓, Home, Endbetween headers (accordion), rows (tree)
→ ←open, close (tree)
Enter, Spacetoggle, select
typingjumps (tree)