-
Notifications
You must be signed in to change notification settings - Fork 31
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
AkshatJawne
merged 10 commits into
deephaven:main
from
AkshatJawne:checkbox_group_re_export
Sep 25, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2202c9c
feat: checkbox_group re-export
AkshatJawne a30b515
adjust PR comments
AkshatJawne 764d23f
add changes based on review
AkshatJawne 99abc1d
modify according to review
AkshatJawne 64f50bd
make changes based on PR
AkshatJawne c2114da
modify based off PR comments
AkshatJawne c63a8d9
Merge branch 'main' into checkbox_group_re_export
AkshatJawne d23335c
fix imports
AkshatJawne e96149d
update styleguide e2e
AkshatJawne 983f35e
add snapshots
AkshatJawne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+15.4 KB
tests/styleguide.spec.ts-snapshots/checkbox-groups-chromium-linux.png
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the styleguide, I think there's a bug with handling of
true
/false
There's probably a stringify that needs to happen somewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I wrap my children in wrappedChildren, I pass in
String(child)
into the checkbox, which seems to work for the other primitives. Is there any other way I can stringify?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue here is that
React.Children.map
convertstrue
/false
to null.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might try
ensureArray
from @deephaven/utils insteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you may still need React.Children.map to deal withkey
props, but you'll need to convert booleans to strings before passing into it.