Skip to content

Commit

Permalink
feat(Dropdown): pass all dd context to the render props
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxuoz committed Oct 14, 2019
1 parent bc2ea29 commit 75a17a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/components/Dropdown/DropdownBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import { Z_INDEX } from '../../theme';

type DropdownBodyProps = {
/** takes either react dom element or function */
children: React$Node | ({ closeDropdown: () => void }) => React$Node,
children: React$Node | ({
toggleDropdown: () => void,
closeDropdown?: () => void,
openDropdown?: () => void,
isOpen: boolean,
}) => React$Node,

/** Default content position relative target */
placement?: 'top' | 'left' | 'bottom' | 'right' | 'auto' | 'bottom-end' | 'bottom-start' | 'top-end' | 'top-start',
Expand Down Expand Up @@ -122,10 +127,10 @@ const DropdownBody = dropdownBodyEnhancer(
}

getBodyChildren = () => {
const { children, dropdown: { closeDropdown }} = this.props;
const { children, dropdown: { toggleDropdown, closeDropdown, openDropdown, isOpen }} = this.props;

return typeof children === 'function'
? children({ closeDropdown })
? children({ toggleDropdown, closeDropdown, openDropdown, isOpen })
: children;
}

Expand Down
5 changes: 3 additions & 2 deletions src/components/Dropdown/DropdownHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type DropdownHeadProps = {
toggleDropdown: () => void,
closeDropdown?: () => void,
openDropdown?: () => void,
isOpen: boolean,
}) => React$Node,
/** When exists then stretch drodown head */
stretch?: boolean,
Expand Down Expand Up @@ -56,10 +57,10 @@ const DropdownHead = dropdownHeadEnhancer(
}

getHeadChildren = () => {
const { children, dropdown: { toggleDropdown, closeDropdown, openDropdown }} = this.props;
const { children, dropdown: { toggleDropdown, closeDropdown, openDropdown, isOpen }} = this.props;

return typeof children === 'function'
? children({ toggleDropdown, closeDropdown, openDropdown })
? children({ toggleDropdown, closeDropdown, openDropdown, isOpen })
: children;
}

Expand Down

0 comments on commit 75a17a5

Please sign in to comment.