|
| 1 | +import { defineComponent, html } from 'regor' |
| 2 | +import { TocPlayground } from './playground' |
| 3 | + |
| 4 | +export interface TocPlaygroundControls { |
| 5 | + playground: TocPlayground |
| 6 | +} |
| 7 | + |
| 8 | +const controlsTemplate = html`<Panel variant="surface" bodyClass="p-4" data-toc-ignore> |
| 9 | + <Flex direction="column" class="gap-4"> |
| 10 | + <FormInputField |
| 11 | + :id="playground.prefix + '-title'" |
| 12 | + label="Heading text" |
| 13 | + :model="playground.title"/> |
| 14 | + <Flex wrap="true" class="gap-2"> |
| 15 | + <Btn @click="playground.add" data-toc-action="add" tone="accent" |
| 16 | + >Add section</Btn> |
| 17 | + <Btn |
| 18 | + @click="playground.rename" |
| 19 | + :disabled="!playground.hasSections" |
| 20 | + data-toc-action="rename" |
| 21 | + variant="surface" |
| 22 | + >Rename last</Btn> |
| 23 | + <Btn |
| 24 | + @click="playground.reorder" |
| 25 | + :disabled="playground.sections.length < 2" |
| 26 | + data-toc-action="reorder" |
| 27 | + variant="surface" |
| 28 | + >Move last to first</Btn> |
| 29 | + <Btn |
| 30 | + @click="playground.toggleExcluded" |
| 31 | + :disabled="!playground.hasSections" |
| 32 | + data-toc-action="exclude" |
| 33 | + variant="surface" |
| 34 | + >{{ playground.lastExcluded ? 'Include last' : 'Exclude last' }}</Btn> |
| 35 | + <Btn |
| 36 | + @click="playground.remove" |
| 37 | + :disabled="!playground.hasSections" |
| 38 | + data-toc-action="remove" |
| 39 | + variant="surface" |
| 40 | + >Remove last</Btn> |
| 41 | + <Btn |
| 42 | + @click="playground.clear" |
| 43 | + :disabled="!playground.hasSections" |
| 44 | + data-toc-action="clear" |
| 45 | + variant="subtle" |
| 46 | + >Clear sections</Btn> |
| 47 | + </Flex> |
| 48 | + <Flex wrap="true" align="center" class="gap-3"> |
| 49 | + <FormCheck |
| 50 | + :id="playground.prefix + '-automatic'" |
| 51 | + label="Refresh after every change" |
| 52 | + :checked="playground.automatic" |
| 53 | + data-toc-auto-refresh/> |
| 54 | + <Btn |
| 55 | + @click="playground.refresh" |
| 56 | + data-toc-action="refresh" |
| 57 | + variant="outlineFill" |
| 58 | + >Refresh TOC</Btn> |
| 59 | + </Flex> |
| 60 | + <p |
| 61 | + class="text-muted fs-sm m-0" |
| 62 | + role="status" |
| 63 | + aria-live="polite" |
| 64 | + aria-atomic="true" |
| 65 | + data-toc-status |
| 66 | + > |
| 67 | + {{ playground.status }} |
| 68 | + </p> |
| 69 | + </Flex> |
| 70 | +</Panel>` |
| 71 | + |
| 72 | +export function defineTocPlaygroundControls() { |
| 73 | + return defineComponent<TocPlaygroundControls>(controlsTemplate, { |
| 74 | + context: (head) => ({ playground: head.requireContext(TocPlayground) }), |
| 75 | + }) |
| 76 | +} |
0 commit comments