Skip to content

Commit

Permalink
feat(ButtonGroup): add stretch modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ej9x committed Jun 28, 2019
1 parent 5076f12 commit 16a171c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"deepmerge": "^3.0.0",
"emotion": "^9.1.1",
"emotion-theming": "^9.1.2",
"luxon": "^1.7.1",
"luxon": "1.7.1",
"prop-types": "^15.6.1",
"react-datepicker": "^2.3.0",
"react-dropdown-tree-select": "1.13.0",
Expand Down
2 changes: 2 additions & 0 deletions src/components/Button/Button.theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const getSquaredStyle = (props: *) => {
if (props.squared && props.size) {
return {
width: BUTTON_HEIGHT_BY_SIZE[props.size],
minWidth: BUTTON_HEIGHT_BY_SIZE[props.size],
height: BUTTON_HEIGHT_BY_SIZE[props.size],
};
}
Expand Down Expand Up @@ -118,6 +119,7 @@ const [ButtonTag, theme] = createThemeTag(name, ({ COLORS, SIZES }: *) => ({
},
ghost: {
backgroundColor: 'transparent',
color: COLORS.BLACK,
},
},

Expand Down
1 change: 1 addition & 0 deletions src/components/ButtonGroup/ButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ButtonGroupTag } from './ButtonGroup.theme';

type ButtonGroupProps = {
children: React$Node,
stretch?: Boolean,
};


Expand Down
6 changes: 6 additions & 0 deletions src/components/ButtonGroup/ButtonGroup.theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const [ButtonGroupTag, theme] = createThemeTag(name, {
},
},
}),

modifiers: {
stretch: {
width: '100%',
},
},
});


Expand Down
4 changes: 3 additions & 1 deletion src/components/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type DropdownContextData = {|
isOpen: boolean,
toggleDropdown: () => void,
closeDropdown?: () => void,
openDropdown?: () => void,
targetWidth?: number,
outsideClickIgnoreClass: string,
|}
Expand Down Expand Up @@ -87,12 +88,13 @@ const DropdownPlate = dropDownEnhancer(
getIgnoreClickOutsideClass = () => `ignore-react-onclickoutside-${this.instanceIndex}`;

render() {
const { children, onCloseDropdown, isOpen, ...rest } = this.props;
const { children, onCloseDropdown, onOpenDropdown, isOpen, ...rest } = this.props;

const contextData: DropdownContextData = {
isOpen,
toggleDropdown: this.toggleDropdown,
closeDropdown: onCloseDropdown,
openDropdown: onOpenDropdown,
targetWidth: this.getDropdownWidth(),
outsideClickIgnoreClass: this.getIgnoreClickOutsideClass(),
};
Expand Down
1 change: 1 addition & 0 deletions src/components/Dropdown/DropdownContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type DropdownContextType = {|
isOpen: boolean,
toggleDropdown: () => void,
closeDropdown:() => void,
openDropdown:() => void,
outsideClickIgnoreClass: string,
|}

Expand Down
17 changes: 15 additions & 2 deletions src/components/Dropdown/DropdownHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { DropdownHeadTag, DropdownPopperTarget } from './DropdownHead.theme';


type DropdownHeadProps = {
children: React$Node,
children: React$Node | ({
toggleDropdown: () => void,
closeDropdown?: () => void,
openDropdown?: () => void,
}) => React$Node,
/** When exists then stretch drodown head */
stretch?: boolean,
/** Prevent propagation on click */
Expand Down Expand Up @@ -51,15 +55,24 @@ const DropdownHead = dropdownHeadEnhancer(
stopClickPropagation && event.stopPropagation();
}

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

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

render() {
const { dropdown: { outsideClickIgnoreClass }, children, ...rest } = this.props;
const renderChildren = this.getHeadChildren();

return (
<DropdownHeadTag { ...rest } tagName="div" className={ outsideClickIgnoreClass } onClick={ this.onClick }>
<Reference>
{ ({ ref }) => (
<DropdownPopperTarget tagName="div" insideRef={ ref }>
{ children }
{ renderChildren }
</DropdownPopperTarget>
) }
</Reference>
Expand Down

0 comments on commit 16a171c

Please sign in to comment.