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.
Issue imixs#196
- Loading branch information
Showing
4 changed files
with
170 additions
and
24 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
open-bpmn.glsp-client/open-bpmn-properties/src/ImixsRadioGroup.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,99 @@ | ||
/******************************************************************************** | ||
* 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'; | ||
|
||
export const ImixsRadioGroup = ({ | ||
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' | ||
}; | ||
|
||
return ( | ||
<div | ||
className={'control imixs-radio-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}> | ||
<input | ||
type='radio' | ||
value={option.value} | ||
id={option.value} | ||
name={id} | ||
checked={data === option.value} | ||
onChange={ev => handleChange(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/ImixsRadioGroupControl.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 { ImixsRadioGroup } from './ImixsRadioGroup'; | ||
|
||
/*********************** | ||
* This is a custom radiobutton 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 ImixsRadioGroupControl = (props: ControlProps & VanillaRendererProps) => { | ||
return <ImixsRadioGroup {...props} />; | ||
}; | ||
|
||
export const imixsRadioGroupControlTester: RankedTester = rankWith( | ||
3, | ||
and(isEnumControl, optionIs('format', 'radio-imixs')) | ||
); | ||
export default withVanillaControlProps(withJsonFormsEnumProps(ImixsRadioGroupControl)); |
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