11import { CodeEditor , Language } from '@patternfly/react-code-editor' ;
2- import { Dropdown , DropdownItem , MenuToggle , MenuToggleElement , Switch } from '@patternfly/react-core' ;
2+ import {
3+ Checkbox ,
4+ Dropdown ,
5+ DropdownItem ,
6+ Flex ,
7+ FlexItem ,
8+ MenuToggle ,
9+ MenuToggleElement ,
10+ Switch
11+ } from '@patternfly/react-core' ;
312import { getSchemaType , WidgetProps } from '@rjsf/utils' ;
413import classNames from 'classnames' ;
514import * as _ from 'lodash' ;
615import * as React from 'react' ;
716import { useTranslation } from 'react-i18next' ;
817import { useTheme } from '../../../utils/theme-hook' ;
918import { JSON_SCHEMA_NUMBER_TYPES } from './const' ;
19+ import { AtomicFieldTemplate } from './templates' ;
1020
1121export const TextWidget : React . FC < WidgetProps > = props => {
1222 const { disabled = false , id, onBlur, onChange, onFocus, readonly = false , schema = { } , value = '' } = props ;
@@ -148,6 +158,52 @@ export const JSONWidget: React.FC<WidgetProps> = props => {
148158 ) ;
149159} ;
150160
161+ export const ArrayCheckboxesWidget : React . FC < WidgetProps > = props => {
162+ const { schema, value, id, onBlur, onChange, onFocus } = props ;
163+
164+ const errFunc = ( ) => console . error ( 'Function not implemented.' ) ;
165+
166+ return (
167+ // since schema type is 'array' and widget is 'checkboxes', we use AtomicFieldTemplate
168+ // to render the field and values all at once without the add/remove buttons
169+ < AtomicFieldTemplate
170+ onKeyChange = { ( ) => errFunc }
171+ onDropPropertyClick = { ( ) => errFunc }
172+ { ...{
173+ ...props ,
174+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
175+ style : props . style as React . StyleHTMLAttributes < any > | undefined ,
176+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
177+ description : ( schema . items as any ) ?. description || props . description ,
178+ readonly : props . readonly === true ,
179+ disabled : props . disabled === true
180+ } }
181+ >
182+ < Flex direction = { { default : 'row' } } onBlur = { ( ) => onBlur ( id , value ) } onFocus = { ( ) => onFocus ( id , value ) } >
183+ {
184+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
185+ ( schema . items as any ) . enum . map ( ( option : string , index : number ) => (
186+ < FlexItem key = { `${ id } -${ index } ` } >
187+ < Checkbox
188+ id = { `${ id } -${ index } ` }
189+ label = { option }
190+ isChecked = { _ . isNil ( value ) ? false : value . includes ( option ) }
191+ onClick = { ( ) =>
192+ onChange (
193+ value . includes ( option ) ? value . filter ( ( v : string ) => v !== option ) : [ ...value , option ] ,
194+ undefined ,
195+ id
196+ )
197+ }
198+ />
199+ </ FlexItem >
200+ ) )
201+ }
202+ </ Flex >
203+ </ AtomicFieldTemplate >
204+ ) ;
205+ } ;
206+
151207export default {
152208 BaseInput : TextWidget ,
153209 CheckboxWidget : SwitchWidget , // force using switch everywhere for consistency
@@ -158,5 +214,6 @@ export default {
158214 TextWidget,
159215 int32 : NumberWidget ,
160216 int64 : NumberWidget ,
161- map : JSONWidget
217+ map : JSONWidget ,
218+ arrayCheckboxes : ArrayCheckboxesWidget
162219} ;
0 commit comments