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: checkbox_group re-export #2212

Merged
merged 10 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/components/src/spectrum/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
Checkbox,
CheckboxGroup as SpectrumCheckboxGroup,
SpectrumCheckboxGroupProps,
} from '@adobe/react-spectrum';
import React, { useMemo } from 'react';

/**
* Augmented version of the Spectrum CheckboxGroup component that supports
* primitive item children.
*/
export function CheckboxGroup({
children,
...props
}: SpectrumCheckboxGroupProps): JSX.Element {
const wrappedChildren = useMemo(
() =>
React.Children.map(children, child => {
if (typeof child === 'function') {
return child;
}
return <Checkbox>{child}</Checkbox>;
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
}),
[children]
);

return (
<SpectrumCheckboxGroup
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
// eslint-disable-next-line react/no-children-prop
children={wrappedChildren}
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved
/>
);
}

CheckboxGroup.displayName = 'CheckboxGroup';
AkshatJawne marked this conversation as resolved.
Show resolved Hide resolved

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
Loading