-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat:Add RadioGroup custom component #8
Open
najeebkp
wants to merge
1
commit into
conductor-sdk:main
Choose a base branch
from
najeebkp:radiogroup_component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+12,554
−7,844
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
894 changes: 894 additions & 0 deletions
894
react/human-task-material-renderers/.yarn/releases/yarn-4.3.0.cjs
Large diffs are not rendered by default.
Oops, something went wrong.
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,3 @@ | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-4.3.0.cjs |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think we need this change |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
{ | ||
"name": "@io-orkes/human-task-material-renderers-react", | ||
"version": "v0.0.0", | ||
"private": false, | ||
"license": "Apache-2.0", | ||
"homepage": "https://orkes.io", | ||
"repository": { | ||
|
@@ -86,5 +85,6 @@ | |
], | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
87 changes: 87 additions & 0 deletions
87
react/human-task-material-renderers/src/components/custom/RadioGroup/RadioGroup.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,87 @@ | ||
/* | ||
* Copyright 2024 Conductor Authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import React from "react"; | ||
import { | ||
FormControlLabel, | ||
RadioGroup as RadioGroupMUI, | ||
Radio, | ||
} from "@mui/material"; | ||
|
||
export interface RadioGroupProps { | ||
id?: string; | ||
label?: string; | ||
value?: string; | ||
default?: string; | ||
required?: boolean; | ||
readonly?: boolean; | ||
path: string; | ||
options: string[]; | ||
handleChange?: (path: string, value: string) => void; | ||
} | ||
|
||
const RadioGroup: React.FC<RadioGroupProps> = ({ | ||
id, | ||
value, | ||
label, | ||
default: defaultValue, | ||
required, | ||
readonly, | ||
path, | ||
options, | ||
handleChange, | ||
}) => { | ||
return ( | ||
<FormControlLabel | ||
id={id} | ||
labelPlacement="top" | ||
required={required} | ||
control={ | ||
<RadioGroupMUI | ||
row | ||
aria-labelledby="human-radio-group" | ||
name="activeRadioGroup" | ||
value={value ? value : defaultValue} | ||
onChange={(e) => handleChange?.(path, e.target.value)} | ||
> | ||
{options.map((item, index) => ( | ||
<FormControlLabel | ||
key={index} | ||
value={item} | ||
control={<Radio />} | ||
label={item} | ||
disabled={readonly} | ||
/> | ||
))} | ||
</RadioGroupMUI> | ||
} | ||
label={label} | ||
sx={{ | ||
alignItems: "baseline", | ||
marginLeft: 0, | ||
"& .MuiFormControlLabel-label": { | ||
color: "rgba(0, 0, 0, 0.6)", | ||
fontWeight: 400, | ||
fontSize: "1rem", | ||
}, | ||
"& .MuiFormControlLabel-root .MuiFormControlLabel-label": { | ||
fontWeight: 400, | ||
fontSize: "1rem", | ||
color: "#1A1E23", | ||
}, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default RadioGroup; |
52 changes: 52 additions & 0 deletions
52
react/human-task-material-renderers/src/components/custom/RadioGroup/RadioGroupControl.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,52 @@ | ||
/* | ||
* Copyright 2024 Conductor Authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { ControlProps } from "@jsonforms/core"; | ||
import { withJsonFormsControlProps } from "@jsonforms/react"; | ||
import RadioGroup, { RadioGroupProps } from "./RadioGroup"; | ||
import _omit from "lodash/omit"; | ||
|
||
type RadioGroupOptions = RadioGroupProps & { | ||
assignDefaultRadioValue: boolean; | ||
}; | ||
|
||
const RadioGroupControl = ({ | ||
data, | ||
id, | ||
label, | ||
handleChange, | ||
path, | ||
uischema, | ||
enabled, | ||
...rest | ||
}: ControlProps) => { | ||
const restProps: Partial<RadioGroupProps> = _omit( | ||
uischema?.options as RadioGroupOptions, | ||
["assignDefaultRadioValue"] | ||
); | ||
const options = rest?.schema?.enum ?? []; | ||
return ( | ||
<RadioGroup | ||
value={data} | ||
id={id} | ||
label={label} | ||
path={path} | ||
handleChange={handleChange} | ||
readonly={!enabled} | ||
options={options} | ||
{...restProps} | ||
/> | ||
); | ||
}; | ||
|
||
export default withJsonFormsControlProps(RadioGroupControl); |
16 changes: 16 additions & 0 deletions
16
react/human-task-material-renderers/src/components/custom/RadioGroup/RadioGroupTester.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,16 @@ | ||
/* | ||
* Copyright 2024 Conductor Authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { rankWith, optionIs } from "@jsonforms/core"; | ||
|
||
export default rankWith(21, optionIs("format", "radio")); |
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
36 changes: 36 additions & 0 deletions
36
react/human-task-material-renderers/src/stories/components/RadioGroup.stories.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,36 @@ | ||
/* | ||
* Copyright 2024 Conductor Authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import RadioGroupComponent, { | ||
RadioGroupProps, | ||
} from "components/custom/RadioGroup/RadioGroup"; | ||
|
||
export default { | ||
title: "RadioGroup", | ||
component: RadioGroupComponent, | ||
tags: ["autodocs"], | ||
args: {}, | ||
argTypes: {}, | ||
} as Meta<RadioGroupProps>; | ||
|
||
type Story = StoryObj<typeof RadioGroupComponent>; | ||
|
||
export const Primary: Story = { | ||
args: { | ||
label: "Radio control", | ||
default: "", | ||
value: "radio1", | ||
options: ["radio1", "radio2"], | ||
}, | ||
}; |
72 changes: 72 additions & 0 deletions
72
react/human-task-material-renderers/src/stories/components/RadioGroupControl.stories.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,72 @@ | ||
/* | ||
* Copyright 2024 Conductor Authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import type { Meta } from "@storybook/react"; | ||
import { ControlProps } from "@jsonforms/core"; | ||
import { JsonForms } from "@jsonforms/react"; | ||
import { | ||
materialCells, | ||
materialRenderers, | ||
} from "@jsonforms/material-renderers"; | ||
|
||
import { RadioGroupControl, RadioGroupTester } from "components/custom"; | ||
|
||
const renderers = [ | ||
...materialRenderers, | ||
{ tester: RadioGroupTester, renderer: RadioGroupControl }, | ||
]; | ||
|
||
const schema = { | ||
properties: { | ||
radio_control: { | ||
type: "string", | ||
enum: ["option1", "option2"], | ||
}, | ||
}, | ||
}; | ||
|
||
const uiSchema = { | ||
type: "VerticalLayout", | ||
elements: [ | ||
{ | ||
type: "Control", | ||
scope: "#/properties/radio_control", | ||
options: { | ||
format: "radio", | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export const Control = (args: ControlProps) => { | ||
return ( | ||
<JsonForms | ||
schema={schema} | ||
uischema={uiSchema} | ||
renderers={renderers} | ||
cells={materialCells} | ||
data={args.data} | ||
readonly={false} | ||
/> | ||
); | ||
}; | ||
|
||
export default { | ||
title: "RadioGroup JSON form control", | ||
component: Control, | ||
tags: ["autodocs"], | ||
args: { | ||
data: {}, | ||
}, | ||
argTypes: {}, | ||
} as Meta<ControlProps>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we need this