forked from imixs/open-bpmn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a checkbox control for JsonForms
Issue imixs#196
- Loading branch information
Showing
5 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
open-bpmn.glsp-client/open-bpmn-properties/src/ImixsCheckboxGroup.tsx
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,119 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2022 Imixs Software Solutions GmbH and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { | ||
computeLabel, | ||
ControlProps, | ||
isDescriptionHidden, | ||
OwnPropsOfEnum | ||
} from '@jsonforms/core'; | ||
import { VanillaRendererProps } from '@jsonforms/vanilla-renderers'; | ||
import merge from 'lodash/merge'; | ||
import React, { useState } from 'react'; | ||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
export const ImixsCheckboxGroup = ({ | ||
classNames, | ||
id, | ||
label, | ||
options, | ||
required, | ||
description, | ||
errors, | ||
data, | ||
uischema, | ||
visible, | ||
config, | ||
enabled, | ||
path, | ||
handleChange | ||
}: ControlProps & VanillaRendererProps & OwnPropsOfEnum) => { | ||
const [isFocused, setFocus] = useState(false); | ||
const isValid = errors.length === 0; | ||
const appliedUiSchemaOptions = merge({}, config, uischema.options); | ||
const showDescription = !isDescriptionHidden( | ||
visible, | ||
description, | ||
isFocused, | ||
appliedUiSchemaOptions.showUnfocusedDescription | ||
); | ||
|
||
let groupStyle: { [x: string]: any } = {}; | ||
// compute flexDirection based on the optional option 'orientation=vertical|horizontal' | ||
groupStyle = { | ||
display: 'flex', | ||
flexDirection: ('vertical' === uischema!.options!.orientation) ? 'column' : 'row' | ||
}; | ||
|
||
// onChange={ev => handleChange(path, ev.currentTarget.value)} | ||
const handleCheckboxChange = (path,value) => { | ||
console.log('Hello Checkbox Click'); | ||
console.log('path='+path); | ||
console.log('value='+value); | ||
// add value only if not yed done | ||
if (!data.includes(value)) { | ||
data.push(value); | ||
} else { | ||
console.log('we unchcke it'); | ||
const ipos = data.indexOf(value); | ||
if (ipos !== -1) { | ||
data.splice(ipos, 1); | ||
} | ||
} | ||
// call main handler | ||
handleChange(path, data); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={'control imixs-checkbox-group'} | ||
hidden={!visible} | ||
onFocus={() => setFocus(true)} | ||
onBlur={() => setFocus(false)} | ||
> | ||
<label htmlFor={id} className={'imixs'}> | ||
{computeLabel( | ||
label, | ||
false, | ||
appliedUiSchemaOptions.hideRequiredAsterisk | ||
)} | ||
</label> | ||
<div style={groupStyle}> | ||
{options!.map(option => ( | ||
<div key={option.label}> | ||
<h4>{data.length}</h4> | ||
<input | ||
type='checkbox' | ||
value={option.value} | ||
id={option.value} | ||
name={id} | ||
checked={data.includes(option.value)} | ||
onChange={ev => handleCheckboxChange(path, ev.currentTarget.value)} | ||
disabled={!enabled} | ||
/> | ||
<label | ||
htmlFor={option.value} | ||
> | ||
{option.label} | ||
</label> | ||
</div> | ||
))} | ||
</div> | ||
<div className={'input-description'}> | ||
{!isValid ? errors : showDescription ? description : undefined} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
43 changes: 43 additions & 0 deletions
43
open-bpmn.glsp-client/open-bpmn-properties/src/ImixsCheckboxGroupControl.tsx
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,43 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2022 Imixs Software Solutions GmbH and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { | ||
and, | ||
ControlProps, | ||
isEnumControl, | ||
optionIs, RankedTester, rankWith | ||
} from '@jsonforms/core'; | ||
import { withJsonFormsEnumProps } from '@jsonforms/react'; | ||
import { VanillaRendererProps, withVanillaControlProps } from '@jsonforms/vanilla-renderers'; | ||
import React from 'react'; | ||
import { ImixsCheckboxGroup } from './ImixsCheckboxGroup'; | ||
|
||
/*********************** | ||
* This is a custom Checkbox renderer that allows vertical and horizontal orientation | ||
* <p> | ||
* In addition the renderer support label|value pairs separated by a | char. | ||
* | ||
*/ | ||
/* eslint-disable arrow-body-style */ | ||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
export const ImixsCheckboxGroupControl = (props: ControlProps & VanillaRendererProps) => { | ||
return <ImixsCheckboxGroup {...props} />; | ||
}; | ||
|
||
export const imixsCheckboxGroupControlTester: RankedTester = rankWith( | ||
3, | ||
and(isEnumControl, optionIs('format', 'checkbox-imixs')) | ||
); | ||
export default withVanillaControlProps(withJsonFormsEnumProps(ImixsCheckboxGroupControl)); |
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
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