Skip to content

Commit

Permalink
chore: example of optionTemplates
Browse files Browse the repository at this point in the history
  • Loading branch information
michel committed Dec 16, 2024
1 parent df3fd78 commit eb56b2f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/prefabs/structures/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {
OptionCategory,
OptionProducer,
PrefabComponentStyle,
OptionTemplates,
} from '@betty-blocks/component-sdk';

export interface Configuration {
options?: Record<string, OptionProducer>;
optionTemplates?: OptionTemplates;
adornmentIcon?: string;
label?: string;
inputLabel?: string;
Expand Down
16 changes: 14 additions & 2 deletions src/prefabs/structures/TextInput/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { component, PrefabReference } from '@betty-blocks/component-sdk';
import { updateOption } from '../../../utils';
import { Configuration } from '../Configuration';
import { options as defaults } from './options/index';
import {
options as defaults,
optionTemplates as optionTemplatesdefault,
} from './options/index';

export const TextInput = (
config: Configuration,
children: PrefabReference[] = [],
) => {
const options = { ...(config.options || defaults) };
const optionTemplates = {
...(config.optionTemplates || optionTemplatesdefault),
};
const ref = config.ref ? { ...config.ref } : undefined;

const categories = [
Expand Down Expand Up @@ -80,7 +86,13 @@ export const TextInput = (

return component(
'TextInput',
{ label: config.label, options, ref, optionCategories: categories },
{
label: config.label,
options,
optionTemplates,
ref,
optionCategories: categories,
},
children,
);
};
18 changes: 18 additions & 0 deletions src/prefabs/structures/TextInput/options/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
hideIf,
option,
optionTemplateOptions,
property,
showIf,
variable,
Expand Down Expand Up @@ -39,3 +40,20 @@ export const options = {
...styles,
...advanced,
};

export const optionTemplates = {
addChild: {
options: optionTemplateOptions({
property: property('Property', {
value: '',
showInReconfigure: true,
configuration: {
allowedKinds: ['TEXT', 'URL', 'IBAN', 'STRING'],
disabled: true,
condition: hideIf('property', 'EQ', ''),
showOnDrop: true,
},
}),
}),
},
};

0 comments on commit eb56b2f

Please sign in to comment.