Skip to content

Commit c9ac72d

Browse files
authored
feat: Replaced RadioGroup with Spectrum's (#2020) (#2021)
- Removed DH `RadioGroup` and `RadioItem` components - Re-exported Spectrum `RadioGroup` and `Radio` components - Updated references to use new version Here's diffs of what the components look like after migrating to Spectrum RadioGroup: **FilterSetManager** <img width="645" alt="image" src="https://github.com/deephaven/web-client-ui/assets/1900643/7640bf22-2fa4-41b1-ae24-7939660c0424"> **ChartBuilder** <img width="658" alt="image" src="https://github.com/deephaven/web-client-ui/assets/1900643/fe91065b-92a6-4beb-9d5c-e7b0acff4e11"> **TableCsvExporter** <img width="658" alt="image" src="https://github.com/deephaven/web-client-ui/assets/1900643/0dadcf86-3567-4d5c-a164-45c923f06585"> **Aggregations** <img width="656" alt="image" src="https://github.com/deephaven/web-client-ui/assets/1900643/b6e89a38-9df6-492a-94fd-4f5296d3d4f1"> BREAKING CHANGE: `RadioGroup` has been replaced by Spectrum `RadioGroup`. `RadioItem` has been replaced by Spectrum `Radio`
1 parent 99fc2f6 commit c9ac72d

46 files changed

Lines changed: 118 additions & 298 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/code-studio/src/styleguide/Inputs.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
AutoResizeTextarea,
66
Checkbox,
77
ComboBox,
8-
RadioItem,
8+
Radio,
99
RadioGroup,
1010
SearchInput,
1111
TimeInput,
@@ -56,12 +56,9 @@ function Inputs(): React.ReactElement {
5656
const [autoResizeTextareaValue, setAutoResizeTextareaValue] = useState(
5757
'-DLiveTableMonitor.updateThreads=8 -DLiveTableMonitor.printDependencyInformation=false -Dassertion.heapDump=true -Drequire.heapDump=true -Dassertion.heapDump=true -Drequire.heapDump=true'
5858
);
59-
const handleRadioChange = useCallback(
60-
(event: React.ChangeEvent<HTMLInputElement>) => {
61-
setRadioValue(event.target.value);
62-
},
63-
[]
64-
);
59+
const handleRadioChange = useCallback((value: string) => {
60+
setRadioValue(value);
61+
}, []);
6562

6663
const handleToggleClick = useCallback(() => {
6764
setOn(!on);
@@ -186,18 +183,26 @@ function Inputs(): React.ReactElement {
186183

187184
<div className="col">
188185
<form>
189-
<h5> Radios </h5>
190-
<RadioGroup onChange={handleRadioChange} value={radioValue}>
191-
<RadioItem value="1">Toggle this custom radio</RadioItem>
192-
<RadioItem value="2">Or toggle this other custom radio</RadioItem>
193-
<RadioItem value="3" disabled>
186+
<h5 id="inputs-radios-heading">Radios</h5>
187+
<RadioGroup
188+
aria-labelledby="inputs-radios-heading"
189+
onChange={handleRadioChange}
190+
value={radioValue}
191+
isInvalid={radioValue === '4'}
192+
description="Select a radio item"
193+
errorMessage={
194+
radioValue === '4' ? 'Invalid radio selected' : undefined
195+
}
196+
>
197+
<Radio value="1">Toggle this custom radio</Radio>
198+
<Radio value="2">Or toggle this other custom radio</Radio>
199+
<Radio value="3" isDisabled>
194200
Disabled radio
195-
</RadioItem>
196-
<RadioItem value="4" isInvalid>
197-
Invalid radio
198-
</RadioItem>
199-
{/* eslint-disable-next-line react/jsx-no-useless-fragment */}
200-
<>{check4 && <RadioItem value="5">Extra radio item</RadioItem>}</>
201+
</Radio>
202+
<Radio value="4">Invalid radio</Radio>
203+
<Radio isHidden={!check4} value="5">
204+
Extra radio item
205+
</Radio>
201206
</RadioGroup>
202207
</form>
203208
<div className="form-group">

packages/code-studio/src/styleguide/ListViews.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { ChangeEvent, ReactNode, useCallback, useState } from 'react';
1+
import React, { ReactNode, useCallback, useState } from 'react';
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3-
import type { StyleProps } from '@react-types/shared';
3+
import type { BoxAlignmentStyleProps, StyleProps } from '@react-types/shared';
44
import {
55
Grid,
66
Icon,
@@ -13,7 +13,7 @@ import {
1313
Checkbox,
1414
ListViewProps,
1515
RadioGroup,
16-
RadioItem,
16+
Radio,
1717
useSpectrumThemeProvider,
1818
ListActionGroup,
1919
} from '@deephaven/components';
@@ -35,7 +35,7 @@ function AccountIllustration(): JSX.Element {
3535
);
3636
}
3737

38-
interface LabeledProps extends StyleProps {
38+
interface LabeledProps extends BoxAlignmentStyleProps, StyleProps {
3939
label: string;
4040
direction?: 'row' | 'column';
4141
children: ReactNode;
@@ -83,12 +83,9 @@ export function ListViews(): JSX.Element {
8383
2 + // listview border
8484
LIST_VIEW_ROW_HEIGHTS[density ?? 'compact'][scale];
8585

86-
const onDensityChange = useCallback(
87-
(event: ChangeEvent<HTMLInputElement>) => {
88-
setDensity(event.currentTarget.value as ListViewProps['density']);
89-
},
90-
[]
91-
);
86+
const onDensityChange = useCallback((value: string) => {
87+
setDensity(value as ListViewProps['density']);
88+
}, []);
9289

9390
const [showIcons, setShowIcons] = useState(true);
9491
const [lastActionKey, setLastActionKey] = useState<ItemKey>('');
@@ -115,14 +112,20 @@ export function ListViews(): JSX.Element {
115112
rows={`auto minmax(${singleChildExampleHeight}px, auto) 1fr auto 1fr`}
116113
>
117114
<LabeledFlexContainer
115+
alignItems="center"
118116
direction="row"
119117
label="Density"
120118
gridColumn="span 3"
121119
>
122-
<RadioGroup value={density} onChange={onDensityChange}>
123-
<RadioItem value="compact">Compact</RadioItem>
124-
<RadioItem value="regular">Regular</RadioItem>
125-
<RadioItem value="spacious">Spacious</RadioItem>
120+
<RadioGroup
121+
aria-label="Density"
122+
orientation="horizontal"
123+
value={density}
124+
onChange={onDensityChange}
125+
>
126+
<Radio value="compact">Compact</Radio>
127+
<Radio value="regular">Regular</Radio>
128+
<Radio value="spacious">Spacious</Radio>
126129
</RadioGroup>
127130
</LabeledFlexContainer>
128131

packages/code-studio/src/styleguide/SpectrumComparison.tsx

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable react/jsx-props-no-spreading */
22
/* eslint-disable react/style-prop-object */
3-
import React, { Fragment, useCallback, useState } from 'react';
3+
import React, { Fragment, useState } from 'react';
44
import {
55
ActionButton,
66
Button,
@@ -11,17 +11,13 @@ import {
1111
Icon,
1212
Item,
1313
Picker,
14-
Radio,
15-
RadioGroup,
1614
SpectrumButtonProps,
1715
TextField,
1816
} from '@adobe/react-spectrum';
1917
import {
2018
Button as BootstrapButtonOld,
2119
Checkbox as CheckboxOld,
2220
ComboBox as ComboBoxOld,
23-
RadioGroup as RadioGroupOld,
24-
RadioItem,
2521
Select,
2622
View,
2723
Text,
@@ -51,14 +47,6 @@ const options = [
5147

5248
export function SpectrumComparison(): JSX.Element {
5349
const [isChecked, setIsChecked] = useState(false);
54-
const [radioValue, setRadioValue] = useState('1');
55-
56-
const handleRadioChange = useCallback(
57-
(event: React.ChangeEvent<HTMLInputElement>) => {
58-
setRadioValue(event.target.value);
59-
},
60-
[]
61-
);
6250

6351
return (
6452
<div
@@ -285,27 +273,6 @@ export function SpectrumComparison(): JSX.Element {
285273
Disabled
286274
</CheckboxOld>
287275
<Checkbox isDisabled>Disabled</Checkbox>
288-
289-
<Flex direction="column">
290-
<label>
291-
Radio Group
292-
<RadioGroupOld onChange={handleRadioChange} value={radioValue}>
293-
<RadioItem value="1">One</RadioItem>
294-
<RadioItem value="2">Two</RadioItem>
295-
<RadioItem value="3">Three</RadioItem>
296-
</RadioGroupOld>
297-
</label>
298-
</Flex>
299-
300-
<RadioGroup
301-
label="Radio Group"
302-
value={radioValue}
303-
onChange={setRadioValue}
304-
>
305-
<Radio value="1">One</Radio>
306-
<Radio value="2">Two</Radio>
307-
<Radio value="3">Three</Radio>
308-
</RadioGroup>
309276
</Grid>
310277
</View>
311278
</Flex>

packages/components/src/RadioGroup.test.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/components/src/RadioGroup.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

packages/components/src/RadioItem.tsx

Lines changed: 0 additions & 102 deletions
This file was deleted.

packages/components/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ export * from './navigation';
3737
export { default as Option } from './Option';
3838
export * from './popper';
3939
export * from './modal';
40-
export { default as RadioGroup } from './RadioGroup';
41-
export { default as RadioItem } from './RadioItem';
4240
export { default as RandomAreaPlotAnimation } from './RandomAreaPlotAnimation';
4341
export * from './SearchableCombobox';
4442
export { default as Select } from './Select';

0 commit comments

Comments
 (0)