-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [#52] Implement the preview of a selectboxes component
When manual values are available, they are rendered as is and their default value is taken into account. When the variable data source is specified, a single option is rendered to at least inform the form builder of the expression being used. In the future, we can possibly provide a 'variable' box so that they can try out the preview with a realistic form variable state.
- Loading branch information
1 parent
0d82260
commit 96eb381
Showing
2 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {SelectboxesComponentSchema} from '@open-formulieren/types'; | ||
import {useIntl} from 'react-intl'; | ||
|
||
import {SelectBoxes} from '@/components/formio'; | ||
|
||
import {ComponentPreviewProps} from '../types'; | ||
import {checkIsManualOptions} from './helpers'; | ||
|
||
/** | ||
* Show a formio selectboxes component preview. | ||
* | ||
* NOTE: for the time being, this is rendered in the default Formio bootstrap style, | ||
* however at some point this should use the components of | ||
* @open-formulieren/formio-renderer instead for a more accurate preview. | ||
*/ | ||
const Preview: React.FC<ComponentPreviewProps<SelectboxesComponentSchema>> = ({component}) => { | ||
const intl = useIntl(); | ||
const {key, label, description, tooltip, validate} = component; | ||
const {required = false} = validate || {}; | ||
const isManualOptions = checkIsManualOptions(component); | ||
const options = isManualOptions | ||
? component.values || [] | ||
: [ | ||
{ | ||
value: 'itemsExpression', | ||
label: intl.formatMessage( | ||
{ | ||
description: 'Selectboxes dummy option for itemsExpression', | ||
defaultMessage: 'Options from expression: <code>{expression}</code>', | ||
}, | ||
{ | ||
expression: JSON.stringify(component.openForms.itemsExpression), | ||
code: chunks => <code>{chunks}</code>, | ||
} | ||
), | ||
}, | ||
]; | ||
return ( | ||
<SelectBoxes | ||
name={key} | ||
options={options} | ||
label={label} | ||
tooltip={tooltip} | ||
required={required} | ||
description={description} | ||
/> | ||
); | ||
}; | ||
|
||
export default Preview; |