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.
They are kept for seven years as the tax code requires, then deleted.
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 stateAdd it
npx qatjs add disclosureAccordion
Sections that open and close: several at once, or one (`single`); `bind:open` (the open ids). As a custom element: <ui-accordion>.
| Prop | Type | Attribute |
|---|---|---|
items | { id: string; title: QatNode }[] | property only |
open | string[] | property only |
single | boolean | yes |
level | 2 | 3 | 4 | property only |
| Event | Detail |
|---|---|
on:update:open | CustomEvent<string[]> |
Tree
A hierarchy: folders open and close, one item is selected; `bind:selected`, `bind:expanded`. As a custom element: <ui-tree>.
| Prop | Type | Attribute |
|---|---|---|
label | string | yes |
items | TreeNode[] | property only |
selected | string | yes |
expanded | string[] | property only |
| Event | Detail |
|---|---|
on:update:selected | CustomEvent<string> |
on:update:expanded | CustomEvent<string[]> |
Disclosure
More of a paragraph, behind "Show more" (`more`) / "Show less" (`less`); `bind:open`. As a custom element: <ui-disclosure>.
| Prop | Type | Attribute |
|---|---|---|
more | string | yes |
less | string | yes |
open | boolean | yes |
| Event | Detail |
|---|---|
on:update:open | CustomEvent<boolean> |
Keys
| Key | Does |
|---|---|
| ↑ ↓, Home, End | between headers (accordion), rows (tree) |
| → ← | open, close (tree) |
| Enter, Space | toggle, select |
| typing | jumps (tree) |