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

Split playground live options to reduce undesirable whitespace in layout #3719

Merged
merged 1 commit into from
Jun 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 44 additions & 24 deletions packages/playground/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,32 @@ const HeaderButton: React.FC<
function HeaderButtons({ playGroundFormRef }: { playGroundFormRef: React.MutableRefObject<any> }) {
return (
<>
<HeaderButton
title='Click me to submit the form programmatically.'
onClick={() => playGroundFormRef.current.submit()}
>
Prog. Submit
</HeaderButton>{' '}
<HeaderButton
title='Click me to validate the form programmatically.'
onClick={() => playGroundFormRef.current.validateForm()}
>
Prog. Validate
</HeaderButton>{' '}
<HeaderButton
title='Click me to reset the form programmatically.'
onClick={() => playGroundFormRef.current.reset()}
>
Prog. Reset
</HeaderButton>
<label className='control-label'>Programmatic</label>
<div className='btn-group'>
<HeaderButton
title='Click me to submit the form programmatically.'
onClick={() => playGroundFormRef.current.submit()}
>
Submit
</HeaderButton>
<HeaderButton
title='Click me to validate the form programmatically.'
onClick={() => playGroundFormRef.current.validateForm()}
>
Validate
</HeaderButton>
<HeaderButton
title='Click me to reset the form programmatically.'
onClick={() => playGroundFormRef.current.reset()}
>
Reset
</HeaderButton>
</div>
</>
);
}

const liveSettingsSchema: RJSFSchema = {
const liveSettingsBooleanSchema: RJSFSchema = {
type: 'object',
properties: {
liveValidate: { type: 'boolean', title: 'Live validation' },
Expand All @@ -59,6 +62,12 @@ const liveSettingsSchema: RJSFSchema = {
noValidate: { type: 'boolean', title: 'Disable validation' },
noHtml5Validate: { type: 'boolean', title: 'Disable HTML 5 validation' },
focusOnFirstError: { type: 'boolean', title: 'Focus on 1st Error' },
},
};

const liveSettingsSelectSchema: RJSFSchema = {
type: 'object',
properties: {
showErrorList: {
type: 'string',
default: 'top',
Expand Down Expand Up @@ -115,7 +124,7 @@ const liveSettingsSchema: RJSFSchema = {
},
};

const liveSettingsUiSchema: UiSchema = {
const liveSettingsSelectUiSchema: UiSchema = {
experimental_defaultFormStateBehavior: {
'ui:options': {
label: false,
Expand Down Expand Up @@ -188,7 +197,7 @@ export default function Header({

const handleSetLiveSettings = useCallback(
({ formData }: IChangeEvent) => {
setLiveSettings(formData);
setLiveSettings((previousLiveSettings) => ({ ...previousLiveSettings, ...formData }));
},
[setLiveSettings]
);
Expand Down Expand Up @@ -220,17 +229,28 @@ export default function Header({
<div className='page-header'>
<h1>react-jsonschema-form</h1>
<div className='row'>
<div className='col-sm-6'>
<div className='col-sm-4'>
<Selector onSelected={load} />
</div>
<div className='col-sm-2'>
<Form
idPrefix='rjsf_options'
schema={liveSettingsSchema}
schema={liveSettingsBooleanSchema}
formData={liveSettings}
validator={localValidator}
onChange={handleSetLiveSettings}
>
<div />
</Form>
</div>
<div className='col-sm-2'>
<Form
idPrefix='rjsf_options'
schema={liveSettingsSelectSchema}
formData={liveSettings}
validator={localValidator}
onChange={handleSetLiveSettings}
uiSchema={liveSettingsUiSchema}
uiSchema={liveSettingsSelectUiSchema}
>
<div />
</Form>
Expand Down