-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1892 from adevinta/combobox-disclosure
feat(combobox): combobox disclosure button
- Loading branch information
Showing
7 changed files
with
255 additions
and
159 deletions.
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
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,57 @@ | ||
/* eslint-disable complexity */ | ||
import { Icon } from '@spark-ui/icon' | ||
import { IconButton } from '@spark-ui/icon-button' | ||
import { ArrowHorizontalDown } from '@spark-ui/icons/dist/icons/ArrowHorizontalDown' | ||
import { useMergeRefs } from '@spark-ui/use-merge-refs' | ||
import { ComponentProps, forwardRef, type Ref } from 'react' | ||
|
||
import { useComboboxContext } from './ComboboxContext' | ||
|
||
interface DisclosureProps extends Omit<ComponentProps<typeof IconButton>, 'aria-label'> { | ||
className?: string | ||
closedLabel: string | ||
openedLabel: string | ||
} | ||
|
||
export const Disclosure = forwardRef( | ||
( | ||
{ | ||
className, | ||
closedLabel, | ||
openedLabel, | ||
intent = 'neutral', | ||
design = 'ghost', | ||
size = 'sm', | ||
...props | ||
}: DisclosureProps, | ||
forwardedRef: Ref<HTMLButtonElement> | ||
) => { | ||
const { getToggleButtonProps } = useComboboxContext() | ||
|
||
const { ref: downshiftRef, ...downshiftDisclosureProps } = getToggleButtonProps() | ||
const isOpen = downshiftDisclosureProps['aria-expanded'] | ||
|
||
const ref = useMergeRefs(forwardedRef, downshiftRef) | ||
|
||
return ( | ||
<IconButton | ||
ref={ref} | ||
className={className} | ||
intent={intent} | ||
design={design} | ||
size={size} | ||
{...downshiftDisclosureProps} | ||
{...props} | ||
aria-label={isOpen ? openedLabel : closedLabel} | ||
> | ||
<Icon> | ||
<Icon className="shrink-0" size="sm"> | ||
<ArrowHorizontalDown /> | ||
</Icon> | ||
</Icon> | ||
</IconButton> | ||
) | ||
} | ||
) | ||
|
||
Disclosure.displayName = 'Combobox.Disclosure' |
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
Oops, something went wrong.