Skip to content

Commit

Permalink
[docs] Add widgets customization page
Browse files Browse the repository at this point in the history
  • Loading branch information
x0k committed Oct 11, 2024
1 parent e718abb commit 24d1dd5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-rings-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"docs": patch
---

Add widgets customization page
44 changes: 44 additions & 0 deletions apps/docs/src/content/docs/customization/widgets.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Custom widgets
sidebar:
order: 1
---

## Example

```typescript
import type { HTMLInputAttributes } from 'svelte/elements';

import type { Widget, WidgetCommonProps, Widgets, WidgetType } from '@sjsf/form';
import { theme } from '@sjsf/form/basic-theme';

import ToggleWidget from './toggle-widget.svelte';

declare module '@sjsf/form' {
export interface WidgetsAndProps<V> {
toggle: WidgetCommonProps<V, HTMLInputAttributes>;
}

export interface WidgetValue {
toggle: boolean;
}
}

// Creating new theme
const registry: { [T in WidgetType]: Widget<T> } = {
...,
toggle: ToggleWidget
};
// @ts-expect-error
export const widgets: Widgets = (type) => registry[type];


// Extension of existing theme
// @ts-expect-error
export const widgets: Widgets = (type, config) => {
if (type === "toggle") {
return ToggleWidget
}
return theme.widgets(type, config)
}
```

0 comments on commit 24d1dd5

Please sign in to comment.