-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add widgets customization page
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"docs": patch | ||
--- | ||
|
||
Add widgets customization page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
``` |