Skip to content

Commit

Permalink
feat: checkbox_group re-export (deephaven#2212)
Browse files Browse the repository at this point in the history
Resolves deephaven#2211

Needed for changes in plugins PR:
deephaven/deephaven-plugins#813
  • Loading branch information
AkshatJawne authored and mofojed committed Jan 7, 2025
1 parent cc67bce commit a20fa1d
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 2 deletions.
46 changes: 46 additions & 0 deletions packages/code-studio/src/styleguide/CheckboxGroups.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import { CheckboxGroup, Flex, Text } from '@deephaven/components';
// eslint-disable-next-line no-restricted-imports
import { Checkbox } from '@adobe/react-spectrum';
import SampleSection from './SampleSection';

export function CheckboxGroups(): JSX.Element {
return (
<SampleSection name="checkbox-groups">
<h2 className="ui-title">Checkbox Groups</h2>
<Flex gap="size-100" gridColumn="span 3" height="100%">
<Flex direction="column">
<Text>Single Child</Text>
<CheckboxGroup aria-label="Single Child">
<Checkbox value="Aaa">Aaa</Checkbox>
</CheckboxGroup>
</Flex>

<Flex direction="column">
<Text>Multiple Children</Text>
<CheckboxGroup aria-label="Multiple Children">
<Checkbox value="Aaa">Aaa</Checkbox>
<Checkbox value="Bbb">Bbb</Checkbox>
<Checkbox value="Ccc">Ccc</Checkbox>
</CheckboxGroup>
</Flex>

<Flex direction="column">
<Text>Mixed Children Types</Text>
<CheckboxGroup aria-label="Mixed Children Types">
{/* eslint-disable react/jsx-curly-brace-presence */}
{'String 1'}
{'String 2'}
{444}
{999}
{true}
{false}
<Checkbox>Aaa</Checkbox>
</CheckboxGroup>
</Flex>
</Flex>
</SampleSection>
);
}

export default CheckboxGroups;
2 changes: 2 additions & 0 deletions packages/code-studio/src/styleguide/StyleGuide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import SpectrumComparison from './SpectrumComparison';
import Pickers from './Pickers';
import ListViews from './ListViews';
import ErrorViews from './ErrorViews';
import CheckboxGroups from './CheckboxGroups';

const stickyProps = {
position: 'sticky',
Expand Down Expand Up @@ -117,6 +118,7 @@ function StyleGuide(): React.ReactElement {
<ItemListInputs />
<DraggableLists />
<TimeSliderInputs />
<CheckboxGroups />
<Dialog />
<Modals />
<ContextMenus />
Expand Down
43 changes: 43 additions & 0 deletions packages/components/src/spectrum/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable react/no-array-index-key */
import { isElementOfType } from '@deephaven/react-hooks';
import React, { type ReactNode, useMemo } from 'react';
import {
Checkbox,
CheckboxGroup as SpectrumCheckboxGroup,
type SpectrumCheckboxGroupProps,
} from '@adobe/react-spectrum';
import { ensureArray } from '@deephaven/utils';

export type CheckboxGroupProps = {
children: ReactNode;
} & Omit<SpectrumCheckboxGroupProps, 'children'>;

/**
* Augmented version of the Spectrum CheckboxGroup component that supports
* primitive item children.
*/
export function CheckboxGroup({
children,
...props
}: CheckboxGroupProps): JSX.Element {
const wrappedChildren = useMemo(
() =>
ensureArray(children).map(child =>
isElementOfType(child, Checkbox) ? (
child
) : (
<Checkbox key={String(child)} value={String(child)}>
{String(child)}
</Checkbox>
)
),
[children]
);

return (
// eslint-disable-next-line react/jsx-props-no-spreading
<SpectrumCheckboxGroup {...props}>{wrappedChildren}</SpectrumCheckboxGroup>
);
}

export default CheckboxGroup;
2 changes: 0 additions & 2 deletions packages/components/src/spectrum/forms.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export {
Checkbox as SpectrumCheckbox,
type SpectrumCheckboxProps,
CheckboxGroup,
type SpectrumCheckboxGroupProps as CheckboxGroupProps,
Form,
type SpectrumFormProps as FormProps,
NumberField,
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/spectrum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export * from './picker';
export * from './Heading';
export * from './Text';
export * from './View';
export * from './CheckboxGroup';

/**
* Custom DH spectrum utils
Expand Down
1 change: 1 addition & 0 deletions tests/styleguide.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const sampleSectionIds: string[] = [
'sample-section-spectrum-overlays',
'sample-section-spectrum-well',
'sample-section-error-views',
'sample-section-checkbox-groups',
];
const buttonSectionIds: string[] = [
'sample-section-buttons-regular',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a20fa1d

Please sign in to comment.