|
1 | 1 | import type { PageOutlineItem, TsSsgContext } from '@purestack/ts-common' |
2 | 2 | import { resolveTsSsgContext } from '@purestack/ts-common' |
3 | | -import { getSemanticToneClass, type SemanticTone } from '@purestack/ts-style' |
4 | | -import { type ComputedRef, computed, defineComponent, html } from 'regor' |
| 3 | +import type { SemanticTone } from '@purestack/ts-style' |
| 4 | +import { |
| 5 | + type ComputedRef, |
| 6 | + computed, |
| 7 | + defineComponent, |
| 8 | + html, |
| 9 | + type RefOrValue, |
| 10 | +} from 'regor' |
| 11 | +import { |
| 12 | + type ComponentVariant, |
| 13 | + type ComponentVariantMode, |
| 14 | + resolveComponentClasses, |
| 15 | +} from '../componentVariant' |
5 | 16 |
|
6 | 17 | export interface PageToc { |
7 | 18 | items?: PageOutlineItem[] |
8 | 19 | title?: string |
9 | | - tone?: SemanticTone |
10 | | - toneClass?: ComputedRef<string> |
| 20 | + tone?: RefOrValue<SemanticTone> |
| 21 | + variant?: RefOrValue<ComponentVariant> |
| 22 | + variantMode?: RefOrValue<ComponentVariantMode> |
| 23 | + classes?: ComputedRef<string> |
11 | 24 | } |
12 | 25 |
|
| 26 | +const DEFAULT_PAGE_TOC_VARIANT: ComponentVariant = 'flat' |
| 27 | +const DEFAULT_PAGE_TOC_VARIANT_MODE: ComponentVariantMode = 'stateless' |
| 28 | + |
13 | 29 | export interface PageTocItem extends PageOutlineItem { |
14 | 30 | href: string |
15 | 31 | children?: PageTocItem[] |
16 | 32 | } |
17 | 33 |
|
18 | 34 | const pageTocTemplate = html`<nav |
19 | | - class="page-toc tone-fill-flat tone-border-surface tone-text-surface" |
20 | | - :class="toneClass" |
| 35 | + class="page-toc" |
| 36 | + :class="classes" |
21 | 37 | aria-label="On this page" |
22 | 38 | > |
23 | 39 | <button |
@@ -115,13 +131,17 @@ function resolveTitle(props: PageToc) { |
115 | 131 |
|
116 | 132 | function definePageTocComponent() { |
117 | 133 | return defineComponent<PageToc>(pageTocTemplate, { |
118 | | - props: ['items', 'title', 'tone'], |
| 134 | + props: ['items', 'title', 'tone', 'variant', 'variantMode'], |
119 | 135 | context: (head) => { |
120 | 136 | const context = resolveTsSsgContext(head) |
121 | | - const tone = head.props.tone |
122 | 137 | return { |
123 | 138 | title: resolveTitle(head.props), |
124 | | - toneClass: computed(() => getSemanticToneClass(tone)), |
| 139 | + classes: computed(() => |
| 140 | + resolveComponentClasses(head.props, { |
| 141 | + defaultVariant: DEFAULT_PAGE_TOC_VARIANT, |
| 142 | + defaultVariantMode: DEFAULT_PAGE_TOC_VARIANT_MODE, |
| 143 | + }), |
| 144 | + ), |
125 | 145 | items: resolveItems(head.props, context), |
126 | 146 | } |
127 | 147 | }, |
|
0 commit comments