diff --git a/.changeset/add-table-of-contents-component.md b/.changeset/add-table-of-contents-component.md new file mode 100644 index 00000000..c8d2486f --- /dev/null +++ b/.changeset/add-table-of-contents-component.md @@ -0,0 +1,5 @@ +--- +"@ainsleydev/sveltekit-helper": patch +--- + +Add TableOfContents component with scrollspy and auto-discovery of headings via data attributes or CSS selector props diff --git a/.changeset/fix-slug-button-style-prop.md b/.changeset/fix-slug-button-style-prop.md new file mode 100644 index 00000000..151fc54a --- /dev/null +++ b/.changeset/fix-slug-button-style-prop.md @@ -0,0 +1,5 @@ +--- +"@ainsleydev/payload-helper": patch +--- + +Fix Slug field component build error by removing unsupported style prop from Payload Button diff --git a/packages/payload-helper/src/fields/Slug/Component.tsx b/packages/payload-helper/src/fields/Slug/Component.tsx index 550bde6b..de974cab 100644 --- a/packages/payload-helper/src/fields/Slug/Component.tsx +++ b/packages/payload-helper/src/fields/Slug/Component.tsx @@ -81,13 +81,11 @@ export const Component: React.FC = ({
- + + +
+export type TOCItem = { + label: string; + href: string; +}; + +export type TableOfContentsProps = { + /** + * Optional heading displayed above the TOC list. + */ + heading?: string; + /** + * Optional pre-generated items. If omitted, items are auto-discovered + * from the DOM using contentSelector + headingSelector on mount. + */ + items?: TOCItem[]; + /** + * Adds a left border to the TOC on tablet and above. + */ + displayBorder?: boolean; + /** + * CSS selector used to find the content element containing headings. + * Defaults to `[data-sidebar-content="true"]`. + */ + contentSelector?: string; + /** + * CSS selector for headings within the content element. + * Falls back to the `data-sidebar-selector` attribute on the content + * element, then `h2`. + * + * Priority: prop > data-sidebar-selector attribute > 'h2' + */ + headingSelector?: string; + /** + * Scroll offset in pixels applied to scrollspy detection. + * @default 80 + */ + scrollOffset?: number; +}; + + + + + + + + + + ``` + + @example + ```svelte + + + ``` + + @example + ```svelte + + + ``` +--> + +
+ {#if heading !== ''} +

+ {heading} +

+ {/if} + + {#each items as item, index (index)} +
  • + + {item.label} + +
  • + {/each} +
    +
    +
    + + diff --git a/packages/sveltekit-helper/src/components/index.ts b/packages/sveltekit-helper/src/components/index.ts index 305e3f68..4d10128a 100644 --- a/packages/sveltekit-helper/src/components/index.ts +++ b/packages/sveltekit-helper/src/components/index.ts @@ -1,6 +1,8 @@ export { default as Modal } from './Modal.svelte'; export { default as Sidebar } from './Sidebar.svelte'; export { default as Hamburger } from './Hamburger.svelte'; +export { default as TableOfContents } from './TableOfContents.svelte'; export { Alert, Notice } from './notifications'; export type { ModalProps, TransitionFn } from './Modal.svelte'; export type { AlertProps, AlertType, NoticeProps, NoticeType } from './notifications'; +export type { TableOfContentsProps, TOCItem } from './TableOfContents.svelte';