Skip to content

Commit a80518d

Browse files
authored
Merge pull request #121 from x0k/fix-120
[docs] Add a note about the explicit use of `extra` widgets (#120)
2 parents 79b3bfd + fb88145 commit a80518d

File tree

12 files changed

+124
-11
lines changed

12 files changed

+124
-11
lines changed

.changeset/curvy-buttons-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"docs2": patch
3+
---
4+
5+
Add a note about the explicit use of `extra` widgets (#120)

apps/docs2/src/content/docs/form/ui-schema.mdx

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export type UiSchemaRoot = UiSchemaDefinition & {
5757
```
5858
## Evaluation rules
5959

60-
Usually ui schema corresponds to the data structure described by json schema.
60+
Usually UI schema corresponds to the data structure described by json schema.
6161

6262
For example, with this JSON schema, the following UI schema would be correct:
6363

@@ -88,12 +88,12 @@ for the value of the `$ref` key, other fields will be ignored.
8888

8989
### Array
9090

91-
Instead of defining indices in the ui schema, the `items` keyword should be used
92-
to specify the ui schema for the elements of the array.
91+
Instead of defining indices in the UI schema, the `items` keyword should be used
92+
to specify the UI schema for the elements of the array.
9393

9494
For a fixed array `items` also can be an array.
9595
If you have additional items you should use `additionalItems` keyword
96-
to specify the ui schema for them.
96+
to specify the UI schema for them.
9797

9898
```
9999
{
@@ -104,24 +104,46 @@ to specify the ui schema for them.
104104

105105
### Object
106106

107-
You should use `additionalProperties` keyword to specify the ui schema for
107+
You should use `additionalProperties` keyword to specify the UI schema for
108108
additional properties.
109109

110-
You can use `additionalPropertyKeyInput` keyword to define an ui schema for
110+
You can use `additionalPropertyKeyInput` keyword to define an UI schema for
111111
the additional property key input field.
112112

113113
### oneOf/anyOf
114114

115-
You can define separate ui schemas for each `oneOf/anyOf` branch
116-
using the corresponding keyword in the ui schema.
117-
Otherwise the ui schema of the current field will be used.
115+
You can define separate UI schemas for each `oneOf/anyOf` branch
116+
using the corresponding keyword in the UI schema.
117+
Otherwise the UI schema of the current field will be used.
118118

119119
```
120120
{
121121
oneOf: [<uiSchema>, ...]
122122
}
123123
```
124124

125+
## UI components
126+
127+
Using the `ui:components` property, you can replace any
128+
[form component](../theme/#component-types) with a compatible one
129+
using the name of the connected component or
130+
the component itself directly.
131+
132+
Component `A` is compatible with component `B` if the properties and bindings
133+
of component `B` extend the properties and bindings of component `A`.
134+
135+
```ts
136+
export type CompatibleComponentType<T extends ComponentType> = {
137+
[C in ComponentType]: Expand<ComponentProps[T]> extends Expand<
138+
ComponentProps[C]
139+
>
140+
? ComponentBindings[T] extends ComponentBindings[C]
141+
? C
142+
: never
143+
: never;
144+
}[ComponentType];
145+
```
146+
125147
## UI options
126148

127149
The `UiOptions` type is an extensible set of components options. By default it

apps/docs2/src/content/docs/themes/_demo-schema.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ComponentDefinition, Schema, UiSchema } from "@sjsf/form";
33
import FilesField from "@sjsf/form/fields/extra-fields/files.svelte";
44
import { s } from "testing/demo";
55

6-
import { THEME_PACKAGES, type Theme } from '@/shared';
6+
import { THEME_PACKAGES, type Theme } from "@/shared";
77

88
const filesAsArrayField = cast(FilesField, {
99
value: {
@@ -14,9 +14,23 @@ const filesAsArrayField = cast(FilesField, {
1414
},
1515
}) satisfies ComponentDefinition<"arrayField">;
1616

17+
const WIDGET_USED_AS_DEFAULT_IN_FIELDS: Record<string, string[] | undefined> = {
18+
checkboxes: ["multiEnumField"],
19+
file: ["fileField", "filesField"],
20+
tags: ["tagsField"],
21+
};
22+
1723
export function createExtraImports(theme: Theme, widgets: string[]) {
1824
return widgets
19-
.map((w) => `import "${THEME_PACKAGES[theme]}/extra-widgets/${w}-include"`)
25+
.map((w) => {
26+
const line = `import "${THEME_PACKAGES[theme]}/extra-widgets/${w}-include"`;
27+
const fields = WIDGET_USED_AS_DEFAULT_IN_FIELDS[w];
28+
return fields
29+
? `// Used by default in the following fields: ${fields.join(
30+
", "
31+
)}\n${line}`
32+
: line;
33+
})
2034
.join("\n");
2135
}
2236

apps/docs2/src/content/docs/themes/basic.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ export const schemas = createSchemas(specs)
2525

2626
You can connect extra widgets using the following `include` imports:
2727

28+
:::note
29+
30+
For a widget to be applied, it must be explicitly specified in the
31+
[UI schema](../../form/ui-schema/#ui-components)
32+
or used in the field as the default widget.
33+
34+
:::
35+
2836
<Code lang='ts' code={createExtraImports("basic", extraWidgets)} />
2937

3038
## UI options

apps/docs2/src/content/docs/themes/daisyui.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ import daisyStyles from "@sjsf/daisyui-theme/styles.css?inline";
6666

6767
You can connect extra widgets using the following `include` imports:
6868

69+
:::note
70+
71+
For a widget to be applied, it must be explicitly specified in the
72+
[UI schema](../../form/ui-schema/#ui-components)
73+
or used in the field as the default widget.
74+
75+
:::
76+
6977
<Code lang='ts' code={createExtraImports("daisyui", extraWidgets)} />
7078

7179
## UI options

apps/docs2/src/content/docs/themes/daisyui5.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ You can connect extra widgets using the following `include` imports:
5050

5151
:::note
5252

53+
For a widget to be applied, it must be explicitly specified in the
54+
[UI schema](../../form/ui-schema/#ui-components)
55+
or used in the field as the default widget.
56+
57+
:::
58+
59+
:::caution
60+
5361
The following widgets `radio-buttons` and `filter-radio-buttons`,
5462
`cally-date-picker` and `pikaday-date-picker` replace each other -
5563
use one or import the replacement widget directly.

apps/docs2/src/content/docs/themes/flowbite.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ import flowbiteStyles from "@sjsf/flowbite-theme/styles.css?inline";
7070

7171
You can connect extra widgets using the following `include` imports:
7272

73+
:::note
74+
75+
For a widget to be applied, it must be explicitly specified in the
76+
[UI schema](../../form/ui-schema/#ui-components)
77+
or used in the field as the default widget.
78+
79+
:::
80+
7381
<Code lang='ts' code={createExtraImports("flowbite", extraWidgets)} />
7482

7583
## UI options

apps/docs2/src/content/docs/themes/flowbite3.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ Register the theme source path by adding a line like this to the `app.css` file.
5252

5353
You can connect extra widgets using the following `include` imports:
5454

55+
:::note
56+
57+
For a widget to be applied, it must be explicitly specified in the
58+
[UI schema](../../form/ui-schema/#ui-components)
59+
or used in the field as the default widget.
60+
61+
:::
62+
5563
<Code lang='ts' code={createExtraImports("flowbite3", extraWidgets)} />
5664

5765
## UI options

apps/docs2/src/content/docs/themes/shadcn.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ You can connect extra widgets using the following `include` imports:
9494

9595
:::note
9696

97+
For a widget to be applied, it must be explicitly specified in the
98+
[UI schema](../../form/ui-schema/#ui-components)
99+
or used in the field as the default widget.
100+
101+
:::
102+
103+
:::caution
104+
97105
The following widgets `combobox` and `select` replace each other -
98106
use one or import the replacement widget directly.
99107

apps/docs2/src/content/docs/themes/shadcn4.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ You can connect extra widgets using the following `include` imports:
7474

7575
:::note
7676

77+
For a widget to be applied, it must be explicitly specified in the
78+
[UI schema](../../form/ui-schema/#ui-components)
79+
or used in the field as the default widget.
80+
81+
:::
82+
83+
:::caution
84+
7785
The following widgets `combobox` and `select` replace each other -
7886
use one or import the replacement widget directly.
7987

0 commit comments

Comments
 (0)