Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add custom widget handler for object #13

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

pgoforth
Copy link

@pgoforth pgoforth commented Sep 18, 2024

This provides the ability to add a custom widget handler for objects, avoiding the need for polymorphism in the object widget.

schema.json:

{
    "title": "Extra Fields",
    "description": "An explanation of the fields below. This new container is an atonomous widget, that can have it's own styles, yet contain form fields...like a modal that displays a terms of service.",
    "properties": {
        "agree": {
            "title": "I agree",
            "description": "Checking this box indicates you agree to our terms of service.",
            "type": "boolean"
        }
    }
}

uiSchema.json:

{
    "ui:widget": "dialog",
    "agree": {
        "ui:widget": "checkbox"
    }
}

Then you assign the custom handler when you are extending your form:

form.ts:

import { Jsf } from '@jsfe/form';
import { dialog } from './dialog';

export class JsfSystem extends Jsf {
    public widgets = {
        // standard widgets
        dialog,
    };
}

dialog.ts:

import { nothing, html } from 'lit';

import type { Widgets } from '@jsfe/types';

export const object: Widgets['object'] = (options) => html`
    <div
        role="dialog"
        id=${options.id}
        part="object"
    >
        ${options.label ? html`<h2>${options.label}</h2>` : ``}
        <!-- -->
        ${options.helpText
            ? html`<p>${options.helpText}</p>`
            : nothing}
        <!--  -->
        ${options.children}
    </div>
`;

@pgoforth pgoforth force-pushed the feat/custom_object_widget branch from 2fc826c to 31ba78b Compare September 30, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant