Skip to content
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: Replaced RadioGroup with Spectrum's (#2020) #2021

Merged
merged 13 commits into from
May 22, 2024
36 changes: 19 additions & 17 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,23 @@ 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}
>
<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>
</Radio>
<Radio value="4" UNSAFE_className="is-invalid">
bmingles marked this conversation as resolved.
Show resolved Hide resolved
Invalid radio
</RadioItem>
{/* eslint-disable-next-line react/jsx-no-useless-fragment */}
<>{check4 && <RadioItem value="5">Extra radio item</RadioItem>}</>
</Radio>
<Radio isHidden={!check4} value="5">
Extra radio item
</Radio>
</RadioGroup>
</form>
<div className="form-group">
Expand Down
25 changes: 13 additions & 12 deletions packages/code-studio/src/styleguide/ListViews.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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 {
Expand All @@ -13,7 +13,7 @@ import {
Checkbox,
ListViewProps,
RadioGroup,
RadioItem,
Radio,
useSpectrumThemeProvider,
ListActionGroup,
} from '@deephaven/components';
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 Down Expand Up @@ -119,10 +116,14 @@ export function ListViews(): JSX.Element {
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"
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 @@ -38,8 +38,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
4 changes: 2 additions & 2 deletions packages/components/src/spectrum/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export {
type SpectrumFormProps as FormProps,
NumberField,
type SpectrumNumberFieldProps as NumberFieldProps,
// Radio - re-export once we re-export RadioGroup
// RadioGroup - we need to replace references to our DH `RadioGroup` before we can re-export
Radio,
RadioGroup,
RangeSlider,
type SpectrumRangeSliderProps as RangeSliderProps,
Slider,
Expand Down
Loading
Loading