Skip to content

Commit

Permalink
feat: Replaced RadioGroup with Spectrum's (#2020) (#2021)
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
bmingles authored May 22, 2024
1 parent 99fc2f6 commit c9ac72d
Show file tree
Hide file tree
Showing 46 changed files with 118 additions and 298 deletions.
41 changes: 23 additions & 18 deletions packages/code-studio/src/styleguide/Inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
AutoResizeTextarea,
Checkbox,
ComboBox,
RadioItem,
Radio,
RadioGroup,
SearchInput,
TimeInput,
Expand Down Expand Up @@ -56,12 +56,9 @@ function Inputs(): React.ReactElement {
const [autoResizeTextareaValue, setAutoResizeTextareaValue] = useState(
'-DLiveTableMonitor.updateThreads=8 -DLiveTableMonitor.printDependencyInformation=false -Dassertion.heapDump=true -Drequire.heapDump=true -Dassertion.heapDump=true -Drequire.heapDump=true'
);
const handleRadioChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
setRadioValue(event.target.value);
},
[]
);
const handleRadioChange = useCallback((value: string) => {
setRadioValue(value);
}, []);

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

<div className="col">
<form>
<h5> Radios </h5>
<RadioGroup onChange={handleRadioChange} value={radioValue}>
<RadioItem value="1">Toggle this custom radio</RadioItem>
<RadioItem value="2">Or toggle this other custom radio</RadioItem>
<RadioItem value="3" disabled>
<h5 id="inputs-radios-heading">Radios</h5>
<RadioGroup
aria-labelledby="inputs-radios-heading"
onChange={handleRadioChange}
value={radioValue}
isInvalid={radioValue === '4'}
description="Select a radio item"
errorMessage={
radioValue === '4' ? 'Invalid radio selected' : undefined
}
>
<Radio value="1">Toggle this custom radio</Radio>
<Radio value="2">Or toggle this other custom radio</Radio>
<Radio value="3" isDisabled>
Disabled radio
</RadioItem>
<RadioItem value="4" isInvalid>
Invalid radio
</RadioItem>
{/* eslint-disable-next-line react/jsx-no-useless-fragment */}
<>{check4 && <RadioItem value="5">Extra radio item</RadioItem>}</>
</Radio>
<Radio value="4">Invalid radio</Radio>
<Radio isHidden={!check4} value="5">
Extra radio item
</Radio>
</RadioGroup>
</form>
<div className="form-group">
Expand Down
31 changes: 17 additions & 14 deletions packages/code-studio/src/styleguide/ListViews.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ChangeEvent, ReactNode, useCallback, useState } from 'react';
import React, { ReactNode, useCallback, useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import type { StyleProps } from '@react-types/shared';
import type { BoxAlignmentStyleProps, StyleProps } from '@react-types/shared';
import {
Grid,
Icon,
Expand All @@ -13,7 +13,7 @@ import {
Checkbox,
ListViewProps,
RadioGroup,
RadioItem,
Radio,
useSpectrumThemeProvider,
ListActionGroup,
} from '@deephaven/components';
Expand All @@ -35,7 +35,7 @@ function AccountIllustration(): JSX.Element {
);
}

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

const onDensityChange = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
setDensity(event.currentTarget.value as ListViewProps['density']);
},
[]
);
const onDensityChange = useCallback((value: string) => {
setDensity(value as ListViewProps['density']);
}, []);

const [showIcons, setShowIcons] = useState(true);
const [lastActionKey, setLastActionKey] = useState<ItemKey>('');
Expand All @@ -115,14 +112,20 @@ export function ListViews(): JSX.Element {
rows={`auto minmax(${singleChildExampleHeight}px, auto) 1fr auto 1fr`}
>
<LabeledFlexContainer
alignItems="center"
direction="row"
label="Density"
gridColumn="span 3"
>
<RadioGroup value={density} onChange={onDensityChange}>
<RadioItem value="compact">Compact</RadioItem>
<RadioItem value="regular">Regular</RadioItem>
<RadioItem value="spacious">Spacious</RadioItem>
<RadioGroup
aria-label="Density"
orientation="horizontal"
value={density}
onChange={onDensityChange}
>
<Radio value="compact">Compact</Radio>
<Radio value="regular">Regular</Radio>
<Radio value="spacious">Spacious</Radio>
</RadioGroup>
</LabeledFlexContainer>

Expand Down
35 changes: 1 addition & 34 deletions packages/code-studio/src/styleguide/SpectrumComparison.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/jsx-props-no-spreading */
/* eslint-disable react/style-prop-object */
import React, { Fragment, useCallback, useState } from 'react';
import React, { Fragment, useState } from 'react';
import {
ActionButton,
Button,
Expand All @@ -11,17 +11,13 @@ import {
Icon,
Item,
Picker,
Radio,
RadioGroup,
SpectrumButtonProps,
TextField,
} from '@adobe/react-spectrum';
import {
Button as BootstrapButtonOld,
Checkbox as CheckboxOld,
ComboBox as ComboBoxOld,
RadioGroup as RadioGroupOld,
RadioItem,
Select,
View,
Text,
Expand Down Expand Up @@ -51,14 +47,6 @@ const options = [

export function SpectrumComparison(): JSX.Element {
const [isChecked, setIsChecked] = useState(false);
const [radioValue, setRadioValue] = useState('1');

const handleRadioChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
setRadioValue(event.target.value);
},
[]
);

return (
<div
Expand Down Expand Up @@ -285,27 +273,6 @@ export function SpectrumComparison(): JSX.Element {
Disabled
</CheckboxOld>
<Checkbox isDisabled>Disabled</Checkbox>

<Flex direction="column">
<label>
Radio Group
<RadioGroupOld onChange={handleRadioChange} value={radioValue}>
<RadioItem value="1">One</RadioItem>
<RadioItem value="2">Two</RadioItem>
<RadioItem value="3">Three</RadioItem>
</RadioGroupOld>
</label>
</Flex>

<RadioGroup
label="Radio Group"
value={radioValue}
onChange={setRadioValue}
>
<Radio value="1">One</Radio>
<Radio value="2">Two</Radio>
<Radio value="3">Three</Radio>
</RadioGroup>
</Grid>
</View>
</Flex>
Expand Down
23 changes: 0 additions & 23 deletions packages/components/src/RadioGroup.test.tsx

This file was deleted.

57 changes: 0 additions & 57 deletions packages/components/src/RadioGroup.tsx

This file was deleted.

102 changes: 0 additions & 102 deletions packages/components/src/RadioItem.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export * from './navigation';
export { default as Option } from './Option';
export * from './popper';
export * from './modal';
export { default as RadioGroup } from './RadioGroup';
export { default as RadioItem } from './RadioItem';
export { default as RandomAreaPlotAnimation } from './RandomAreaPlotAnimation';
export * from './SearchableCombobox';
export { default as Select } from './Select';
Expand Down
Loading

0 comments on commit c9ac72d

Please sign in to comment.