Skip to content

Commit

Permalink
Change prop style for dropdowns
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeldking committed Aug 21, 2021
1 parent c8462d8 commit 4506046
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
30 changes: 10 additions & 20 deletions src/dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import React, {
} from 'react';
import { DropdownButton, DropdownButtonProps } from './DropdownButton';
import { DropdownMenu } from './DropdownMenu';
import { DropdownTrigger } from './DropdownTrigger';
import { DropdownTrigger, DropdownTriggerProps } from './DropdownTrigger';
import { useResizeObserver } from '@react-aria/utils';
import { Placement, FocusableRefValue } from '../types';
import { FocusableRefValue } from '../types';
import { useUnwrapDOMRef } from '../utils';

export type DropdownProps = {
Expand All @@ -22,26 +22,20 @@ export type DropdownProps = {
*/
children: ReactNode;
/**
* the placement of the dropdown menu
* @default "bottom left"
* the dropdown trigger props
*/
menuPlacement?: Placement;
triggerProps?: Omit<DropdownTriggerProps, 'children'>;
/**
* before text or icon for the button
* the dropdown button props
*/
buttonAddonBefore?: DropdownButtonProps['addonBefore'];
/**
* additional styles for the button
*/
buttonStyle?: CSSProperties;
buttonProps?: DropdownButtonProps;
};

export function Dropdown({
menu,
children,
menuPlacement = 'bottom left',
buttonAddonBefore,
buttonStyle,
triggerProps = { placement: 'bottom left' },
buttonProps,
}: DropdownProps) {
let triggerRef = useRef<FocusableRefValue<HTMLButtonElement>>(null);
let unwrappedTriggerRef = useUnwrapDOMRef(triggerRef);
Expand All @@ -67,12 +61,8 @@ export function Dropdown({
};

return (
<DropdownTrigger placement={menuPlacement}>
<DropdownButton
ref={triggerRef}
addonBefore={buttonAddonBefore}
style={buttonStyle}
>
<DropdownTrigger {...triggerProps}>
<DropdownButton ref={triggerRef} {...buttonProps}>
{children}
</DropdownButton>
<DropdownMenu style={menuStyle}>{menu}</DropdownMenu>
Expand Down
6 changes: 3 additions & 3 deletions stories/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Menu = () => (
<ListItem>hello</ListItem>
</List>
);

export const Gallery = () => (
<Provider>
<ul
Expand All @@ -48,7 +49,7 @@ export const Gallery = () => (
<Dropdown menu={<Menu />}>Click Me</Dropdown>
</li>
<li>
<Dropdown menu={<Menu />} buttonAddonBefore="Dataset A">
<Dropdown menu={<Menu />} buttonProps={{ addonBefore: 'Dataset A' }}>
Click Me
</Dropdown>
</li>
Expand All @@ -62,8 +63,7 @@ export const Gallery = () => (
</ListItem>
</List>
}
buttonAddonBefore="Dataset A"
buttonStyle={{ maxWidth: 250 }}
buttonProps={{ addonBefore: 'Dataset A', style: { maxWidth: 250 } }}
>
Really really really really really really really long text
</Dropdown>
Expand Down

0 comments on commit 4506046

Please sign in to comment.