Skip to content

Commit e751828

Browse files
committed
feat: submit button custom text
Via widget API and form element prop./attr. See #7
1 parent 32f9f7d commit e751828

File tree

9 files changed

+26
-13
lines changed

9 files changed

+26
-13
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ I encourage you to contribute,
922922
like people did for the [React JSON Schema Form](https://github.com/rjsf-team/react-jsonschema-form) project.
923923
Core maintainers are working on the reference implementation, and community can add things of their interest.
924924

925-
If you want to enhance the lib. by supporting for more fields, it's quite easy!
925+
If you want to enhance the lib. by bringing support for more fields, it's quite easy!
926926
Just take a peek on the [Shoelace package](./packages/shoelace),
927927
which is the canonical implementation (meaning it's the most complete, API-wise).
928928
Then, you are welcome to make a pull request with new features, or bug fixes.

packages/carbon/src/widgets/submit.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import '@carbon/web-components/es/components/button/index.js';
77
export const submit: Widgets['submit'] = (options) => html`
88
<!-- -->
99
<div id=${options.id} class="theme-carbon widget-submit">
10-
<cds-button type="submit" isExpressive size="lg">Submit</cds-button>
10+
<cds-button type="submit" isExpressive size="lg"
11+
>${options.label ?? 'Submit'}</cds-button
12+
>
1113
</div>
1214
`;

packages/form/src/json-schema-form.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export class Jsf extends LitElement {
5252

5353
@property({ type: Boolean }) public submitButton = true;
5454

55+
@property({ type: String }) public submitButtonText = 'Submit';
56+
5557
@state() private _uiState: unknown = {};
5658

5759
protected _dig(
@@ -127,7 +129,7 @@ export class Jsf extends LitElement {
127129
// return flag('allOf');
128130
}
129131

130-
let nodeParsed = node;
132+
const nodeParsed = node;
131133

132134
// if (currentNode.allOf) {
133135
// node.allOf?.forEach((subSchema) => {
@@ -394,12 +396,15 @@ export class Jsf extends LitElement {
394396
}
395397

396398
#submit = () => {
397-
const options = { id: '__submit' };
399+
const options: Widgets['submit'] = {
400+
id: '__submit_button',
401+
label: this.submitButtonLabel,
402+
};
398403
const error = 'Missing submit widget.';
399404
return (
400405
this.widgets?.submit?.(options) ??
401406
// systemWidgets?.submit?.(options) ??
402-
this.widgets?.callout?.({ ...options, message: error }) ??
407+
this.widgets?.callout?.({ message: error }) ??
403408
error
404409
);
405410
};

packages/material/src/widgets/submit.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import '@material/web/button/filled-button.js';
77
export const submit: Widgets['submit'] = (options) => html`
88
<!-- -->
99
<div id=${options.id} class="theme-material widget-submit">
10-
<md-filled-button type="submit">Submit</md-filled-button>
10+
<md-filled-button type="submit"
11+
>${options.submitButtonText ?? 'Submit'}</md-filled-button
12+
>
1113
</div>
1214
`;

packages/shoelace/src/widgets/submit.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import '@shoelace-style/shoelace/dist/components/button/button.js';
77
export const submit: Widgets['submit'] = (options) => html`
88
<!-- -->
99
<div id=${options.id} class="theme-shoelace widget-submit">
10-
<sl-button type="submit" size="large">Submit</sl-button>
10+
<sl-button type="submit" size="large"
11+
>${options.label ?? 'Submit'}</sl-button
12+
>
1113
</div>
1214
`;

packages/spectrum/src/widgets/submit.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import '@spectrum-web-components/button/sp-button.js';
77
export const submit: Widgets['submit'] = (options) => html`
88
<!-- -->
99
<div id=${options.id} class="theme-spectrum widget-submit">
10-
<sp-button type="submit" size="large">Submit</sp-button>
10+
<sp-button type="submit" size="large"
11+
>${options.label ?? 'Submit'}</sp-button
12+
>
1113
</div>
1214
`;

packages/system/src/widgets/submit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import type { Widgets } from '@jsfe/types';
55
export const submit: Widgets['submit'] = (options) => html`
66
<!-- -->
77
<div id=${options.id} class="theme-system widget-submit">
8-
<button type="submit">Submit</button>
8+
<button type="submit">${options.label ?? 'Submit'}</button>
99
</div>
1010
`;

packages/types/src/widgets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,5 @@ export interface Widgets {
146146
type?: 'tip' | 'warning' | 'danger';
147147
}>;
148148

149-
submit?: Widget<undefined>;
149+
submit?: Widget<{ id?: string; label?: string }>;
150150
}

packages/wired/src/widgets/submit.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import 'wired-elements/lib/wired-button.js';
2+
13
import { html } from 'lit';
24

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

5-
import 'wired-elements/lib/wired-button.js';
6-
77
export const submit: Widgets['submit'] = (options) => html`
88
<!-- -->
99
<div id=${options.id} class="theme-wired widget-submit">
@@ -13,7 +13,7 @@ export const submit: Widgets['submit'] = (options) => html`
1313
@click=${(event: Event) =>
1414
// FIXME: !!!
1515
event.target?.dispatchEvent(new Event('submit', { bubbles: true }))}
16-
>Submit</wired-button
16+
>${options.label ?? 'Submit'}</wired-button
1717
>
1818
</div>
1919
`;

0 commit comments

Comments
 (0)