Skip to content

Commit a24dc8c

Browse files
authored
feat: checkbox_group re-export (#2212)
Resolves #2211 Needed for changes in plugins PR: deephaven/deephaven-plugins#813
1 parent 86e16ee commit a24dc8c

9 files changed

Lines changed: 93 additions & 2 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react';
2+
import { CheckboxGroup, Flex, Text } from '@deephaven/components';
3+
// eslint-disable-next-line no-restricted-imports
4+
import { Checkbox } from '@adobe/react-spectrum';
5+
import SampleSection from './SampleSection';
6+
7+
export function CheckboxGroups(): JSX.Element {
8+
return (
9+
<SampleSection name="checkbox-groups">
10+
<h2 className="ui-title">Checkbox Groups</h2>
11+
<Flex gap="size-100" gridColumn="span 3" height="100%">
12+
<Flex direction="column">
13+
<Text>Single Child</Text>
14+
<CheckboxGroup aria-label="Single Child">
15+
<Checkbox value="Aaa">Aaa</Checkbox>
16+
</CheckboxGroup>
17+
</Flex>
18+
19+
<Flex direction="column">
20+
<Text>Multiple Children</Text>
21+
<CheckboxGroup aria-label="Multiple Children">
22+
<Checkbox value="Aaa">Aaa</Checkbox>
23+
<Checkbox value="Bbb">Bbb</Checkbox>
24+
<Checkbox value="Ccc">Ccc</Checkbox>
25+
</CheckboxGroup>
26+
</Flex>
27+
28+
<Flex direction="column">
29+
<Text>Mixed Children Types</Text>
30+
<CheckboxGroup aria-label="Mixed Children Types">
31+
{/* eslint-disable react/jsx-curly-brace-presence */}
32+
{'String 1'}
33+
{'String 2'}
34+
{444}
35+
{999}
36+
{true}
37+
{false}
38+
<Checkbox>Aaa</Checkbox>
39+
</CheckboxGroup>
40+
</Flex>
41+
</Flex>
42+
</SampleSection>
43+
);
44+
}
45+
46+
export default CheckboxGroups;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import Pickers from './Pickers';
4040
import ListViews from './ListViews';
4141
import ErrorViews from './ErrorViews';
4242
import XComponents from './XComponents';
43+
import CheckboxGroups from './CheckboxGroups';
4344

4445
const stickyProps = {
4546
position: 'sticky',
@@ -118,6 +119,7 @@ function StyleGuide(): React.ReactElement {
118119
<ItemListInputs />
119120
<DraggableLists />
120121
<TimeSliderInputs />
122+
<CheckboxGroups />
121123
<Dialog />
122124
<Modals />
123125
<ContextMenus />
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* eslint-disable react/no-array-index-key */
2+
import { isElementOfType } from '@deephaven/react-hooks';
3+
import React, { type ReactNode, useMemo } from 'react';
4+
import {
5+
Checkbox,
6+
CheckboxGroup as SpectrumCheckboxGroup,
7+
type SpectrumCheckboxGroupProps,
8+
} from '@adobe/react-spectrum';
9+
import { ensureArray } from '@deephaven/utils';
10+
11+
export type CheckboxGroupProps = {
12+
children: ReactNode;
13+
} & Omit<SpectrumCheckboxGroupProps, 'children'>;
14+
15+
/**
16+
* Augmented version of the Spectrum CheckboxGroup component that supports
17+
* primitive item children.
18+
*/
19+
export function CheckboxGroup({
20+
children,
21+
...props
22+
}: CheckboxGroupProps): JSX.Element {
23+
const wrappedChildren = useMemo(
24+
() =>
25+
ensureArray(children).map(child =>
26+
isElementOfType(child, Checkbox) ? (
27+
child
28+
) : (
29+
<Checkbox key={String(child)} value={String(child)}>
30+
{String(child)}
31+
</Checkbox>
32+
)
33+
),
34+
[children]
35+
);
36+
37+
return (
38+
// eslint-disable-next-line react/jsx-props-no-spreading
39+
<SpectrumCheckboxGroup {...props}>{wrappedChildren}</SpectrumCheckboxGroup>
40+
);
41+
}
42+
43+
export default CheckboxGroup;

packages/components/src/spectrum/forms.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
export {
22
Checkbox as SpectrumCheckbox,
33
type SpectrumCheckboxProps,
4-
CheckboxGroup,
5-
type SpectrumCheckboxGroupProps as CheckboxGroupProps,
64
Form,
75
type SpectrumFormProps as FormProps,
86
NumberField,

packages/components/src/spectrum/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export * from './picker';
2626
export * from './Heading';
2727
export * from './Text';
2828
export * from './View';
29+
export * from './CheckboxGroup';
2930

3031
/**
3132
* Custom DH spectrum utils

tests/styleguide.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const sampleSectionIds: string[] = [
4848
'sample-section-spectrum-forms',
4949
'sample-section-spectrum-overlays',
5050
'sample-section-spectrum-well',
51+
'sample-section-checkbox-groups',
5152
];
5253
const buttonSectionIds: string[] = [
5354
'sample-section-buttons-regular',
15.4 KB
Loading
26.5 KB
Loading
4.86 KB
Loading

0 commit comments

Comments
 (0)