Skip to content

Commit 906a44e

Browse files
committed
fix: allow group name and fix onclick label
1 parent cb4d2bd commit 906a44e

File tree

11 files changed

+105
-20
lines changed

11 files changed

+105
-20
lines changed

packages/pluggableWidgets/checkbox-radio-selection-web/src/CheckboxRadioSelection.editorConfig.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function getIconPreview(isMultiSelect: boolean): ContainerProps {
147147
export function getPreview(values: CheckboxRadioSelectionPreviewProps, isDarkMode: boolean): StructurePreviewProps {
148148
const palette = structurePreviewPalette[isDarkMode ? "dark" : "light"];
149149
const structurePreviewChildren: StructurePreviewProps[] = [];
150-
// let readOnly = values.readOnly;
150+
let readOnly = values.readOnly;
151151

152152
// Handle custom content dropzones when enabled
153153
if (values.optionsSourceCustomContentType !== "no") {
@@ -165,6 +165,10 @@ export function getPreview(values: CheckboxRadioSelectionPreviewProps, isDarkMod
165165
dropzone.hideDataSourceHeaderIf(false)
166166
)(values.optionsSourceDatabaseCustomContent)
167167
);
168+
169+
if (values.databaseAttributeString.length === 0) {
170+
readOnly = values.customEditability === "never";
171+
}
168172
} else if (values.source === "static") {
169173
values.optionsSourceStaticDataSource.forEach(value => {
170174
structurePreviewChildren.push(
@@ -196,7 +200,8 @@ export function getPreview(values: CheckboxRadioSelectionPreviewProps, isDarkMod
196200
return container()(
197201
rowLayout({
198202
columnSize: "grow",
199-
backgroundColor: palette.background.container
203+
borderRadius: 2,
204+
backgroundColor: readOnly ? palette.background.containerDisabled : palette.background.container
200205
})(
201206
getIconPreview(isMultiSelect),
202207
container()(container({ padding: 3 })(), text()(getCustomCaption(values)))
@@ -210,7 +215,8 @@ export function getPreview(values: CheckboxRadioSelectionPreviewProps, isDarkMod
210215
columnSize: "grow",
211216
borders: true,
212217
borderWidth: 1,
213-
borderRadius: 2
218+
borderRadius: 2,
219+
backgroundColor: readOnly ? palette.background.containerDisabled : palette.background.container
214220
})(container({ grow: 1, padding: 4 })(...structurePreviewChildren))
215221
);
216222
}

packages/pluggableWidgets/checkbox-radio-selection-web/src/CheckboxRadioSelection.editorPreview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "./helpers/Database/Preview/DatabasePreviewSelector";
1212
import { AssociationPreviewSelector } from "./helpers/Association/Preview/AssociationPreviewSelector";
1313
import "./ui/CheckboxRadioSelection.scss";
14+
import "./ui/CheckboxRadioSelectionPreview.scss";
1415
import { CheckboxSelection } from "./components/CheckboxSelection/CheckboxSelection";
1516

1617
export const preview = (props: CheckboxRadioSelectionPreviewProps): ReactElement => {
@@ -20,7 +21,8 @@ export const preview = (props: CheckboxRadioSelectionPreviewProps): ReactElement
2021
inputId: id,
2122
labelId: `${id}-label`,
2223
readOnlyStyle: props.readOnlyStyle,
23-
ariaRequired: dynamic(false)
24+
ariaRequired: dynamic(false),
25+
groupName: dynamic(`${id}-group`)
2426
};
2527

2628
// eslint-disable-next-line react-hooks/rules-of-hooks
Loading

packages/pluggableWidgets/checkbox-radio-selection-web/src/CheckboxRadioSelection.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default function CheckboxRadioSelection(props: CheckboxRadioSelectionCont
1717
inputId: props.id,
1818
labelId: `${props.id}-label`,
1919
readOnlyStyle: props.readOnlyStyle,
20-
ariaRequired: props.ariaRequired
20+
ariaRequired: props.ariaRequired,
21+
groupName: props.groupName
2122
};
2223

2324
return (

packages/pluggableWidgets/checkbox-radio-selection-web/src/CheckboxRadioSelection.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
</property>
229229
<property key="readOnlyStyle" type="enumeration" defaultValue="text">
230230
<caption>Read-only style</caption>
231-
<description>How the combo box will appear in read-only mode.</description>
231+
<description>How the checkbox radio selection will appear in read-only mode.</description>
232232
<enumerationValues>
233233
<enumerationValue key="bordered">Control</enumerationValue>
234234
<enumerationValue key="text">Content only</enumerationValue>
@@ -255,6 +255,11 @@
255255
<description />
256256
<returnType type="Boolean" />
257257
</property>
258+
<property key="groupName" type="expression" required="false">
259+
<caption>Group name</caption>
260+
<description />
261+
<returnType type="String" />
262+
</property>
258263
</propertyGroup>
259264
</propertyGroup>
260265
</properties>

packages/pluggableWidgets/checkbox-radio-selection-web/src/components/CheckboxSelection/CheckboxSelection.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from "classnames";
2-
import { ReactElement, createElement } from "react";
2+
import { ReactElement, createElement, MouseEvent } from "react";
33
import { SelectionBaseProps, MultiSelector } from "../../helpers/types";
44
import { CaptionContent } from "../CaptionContent";
55

@@ -8,11 +8,13 @@ export function CheckboxSelection({
88
tabIndex = 0,
99
inputId,
1010
ariaRequired,
11-
readOnlyStyle
11+
readOnlyStyle,
12+
groupName
1213
}: SelectionBaseProps<MultiSelector>): ReactElement {
1314
const options = selector.getOptions();
1415
const currentIds = selector.currentId || [];
1516
const isReadOnly = selector.readOnly;
17+
const name = groupName?.value ?? inputId;
1618

1719
const handleChange = (optionId: string, checked: boolean): void => {
1820
if (!isReadOnly) {
@@ -37,7 +39,6 @@ export function CheckboxSelection({
3739
{options.map((optionId, index) => {
3840
const isSelected = currentIds.includes(optionId);
3941
const checkboxId = `${inputId}-checkbox-${index}`;
40-
const name = selector.caption.get(optionId);
4142

4243
return (
4344
<div
@@ -49,14 +50,24 @@ export function CheckboxSelection({
4950
<input
5051
type="checkbox"
5152
id={checkboxId}
52-
name={name && name.length > 0 ? name : inputId}
53+
name={name}
5354
value={optionId}
5455
checked={isSelected}
5556
disabled={isReadOnly}
5657
tabIndex={tabIndex}
5758
onChange={e => handleChange(optionId, e.target.checked)}
5859
/>
59-
<CaptionContent htmlFor={checkboxId}>{selector.caption.render(optionId)}</CaptionContent>
60+
<CaptionContent
61+
onClick={(e: MouseEvent<HTMLDivElement>) => {
62+
e.preventDefault();
63+
e.stopPropagation();
64+
e.nativeEvent.stopImmediatePropagation();
65+
handleChange(optionId, !isSelected);
66+
}}
67+
htmlFor={checkboxId}
68+
>
69+
{selector.caption.render(optionId)}
70+
</CaptionContent>
6071
</div>
6172
);
6273
})}

packages/pluggableWidgets/checkbox-radio-selection-web/src/components/RadioSelection/RadioSelection.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from "classnames";
2-
import { ReactElement, createElement } from "react";
2+
import { ChangeEvent, ReactElement, createElement, MouseEvent } from "react";
33
import { SelectionBaseProps, SingleSelector } from "../../helpers/types";
44
import { CaptionContent } from "../CaptionContent";
55

@@ -8,15 +8,18 @@ export function RadioSelection({
88
tabIndex = 0,
99
inputId,
1010
ariaRequired,
11-
readOnlyStyle
11+
readOnlyStyle,
12+
groupName
1213
}: SelectionBaseProps<SingleSelector>): ReactElement {
1314
const options = selector.options.getAll();
1415
const currentId = selector.currentId;
1516
const isReadOnly = selector.readOnly;
17+
const name = groupName?.value ?? inputId;
1618

17-
const handleChange = (optionId: string): void => {
19+
const handleChange = (e: ChangeEvent<HTMLInputElement>): void => {
20+
const selectedItem = e.target.value;
1821
if (!isReadOnly) {
19-
selector.setValue(optionId);
22+
selector.setValue(selectedItem);
2023
}
2124
};
2225

@@ -36,8 +39,6 @@ export function RadioSelection({
3639
{options.map((optionId, index) => {
3740
const isSelected = currentId === optionId;
3841
const radioId = `${inputId}-radio-${index}`;
39-
const name = selector.caption.get(optionId);
40-
4142
return (
4243
<div
4344
key={optionId}
@@ -48,14 +49,26 @@ export function RadioSelection({
4849
<input
4950
type="radio"
5051
id={radioId}
51-
name={name && name.length > 0 ? name : inputId}
52+
name={name}
5253
value={optionId}
5354
checked={isSelected}
5455
disabled={isReadOnly}
5556
tabIndex={tabIndex}
56-
onChange={() => handleChange(optionId)}
57+
onChange={handleChange}
5758
/>
58-
<CaptionContent htmlFor={radioId}>{selector.caption.render(optionId)}</CaptionContent>
59+
<CaptionContent
60+
onClick={(e: MouseEvent<HTMLDivElement>) => {
61+
e.preventDefault();
62+
e.stopPropagation();
63+
e.nativeEvent.stopImmediatePropagation();
64+
if (!isReadOnly) {
65+
selector.setValue(optionId);
66+
}
67+
}}
68+
htmlFor={radioId}
69+
>
70+
{selector.caption.render(optionId)}
71+
</CaptionContent>
5972
</div>
6073
);
6174
})}

packages/pluggableWidgets/checkbox-radio-selection-web/src/helpers/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ export interface SelectionBaseProps<Selector> {
8383
selector: Selector;
8484
tabIndex: number;
8585
ariaRequired: DynamicValue<boolean>;
86+
groupName: DynamicValue<string> | undefined;
8687
}

packages/pluggableWidgets/checkbox-radio-selection-web/src/ui/CheckboxRadioSelection.scss

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,32 @@
22
.widget-checkbox-radio-selection {
33
display: block;
44
position: relative;
5+
6+
&-readonly {
7+
&.widget-checkbox-radio-selection-readonly-text {
8+
.widget-checkbox-radio-selection-radio-item {
9+
display: none;
10+
11+
&.widget-checkbox-radio-selection-radio-item-selected {
12+
display: block;
13+
14+
input {
15+
display: none;
16+
}
17+
}
18+
}
19+
}
20+
}
21+
22+
label {
23+
font-weight: inherit;
24+
}
25+
26+
input[type="radio"],
27+
input[type="checkbox"] {
28+
& + label {
29+
cursor: pointer;
30+
margin-left: var(--spacing-small, 8px);
31+
}
32+
}
533
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Checkbox Radio Selection Widget Styles
2+
.widget-checkbox-radio-selection.widget-checkbox-radio-selection-editor-preview {
3+
.widget-checkbox-radio-selection-readonly {
4+
&.widget-checkbox-radio-selection-readonly-text {
5+
.widget-checkbox-radio-selection-radio-item {
6+
display: block;
7+
8+
&.widget-checkbox-radio-selection-radio-item {
9+
input {
10+
display: none;
11+
}
12+
}
13+
}
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)