Skip to content

Commit

Permalink
Update FilterPopup: add labelMaxWidth prop and ellipsis:
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnito committed Jul 18, 2019
1 parent 492e640 commit 500155c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/components/FilterPopup/FilterPopup.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
border: 1px solid var(--marketplaceColorDark);
}
}
.labelEllipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.popup {
/* By default hide the content */
Expand Down
11 changes: 10 additions & 1 deletion src/components/FilterPopup/FilterPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class FilterPopup extends Component {
popupClassName,
id,
label,
labelMaxWidth,
isSelected,
children,
initialValues,
Expand All @@ -114,6 +115,8 @@ class FilterPopup extends Component {
const popupClasses = classNames(css.popup, { [css.isOpen]: this.state.isOpen });
const popupSizeClasses = popupClassName || css.popupSize;
const labelStyles = isSelected ? css.labelSelected : css.label;
const labelMaxWidthMaybe = labelMaxWidth ? { maxWidth: `${labelMaxWidth}px` } : {};
const labelMaxWidthStyles = labelMaxWidth ? css.labelEllipsis : null;
const contentStyle = this.positionStyleForContent();

return (
Expand All @@ -125,7 +128,11 @@ class FilterPopup extends Component {
this.filter = node;
}}
>
<button className={labelStyles} onClick={() => this.toggleOpen()}>
<button
className={classNames(labelStyles, labelMaxWidthStyles)}
style={labelMaxWidthMaybe}
onClick={() => this.toggleOpen()}
>
{label}
</button>
<div
Expand Down Expand Up @@ -167,6 +174,7 @@ FilterPopup.defaultProps = {
contentPlacementOffset: 0,
liveEdit: false,
label: null,
labelMaxWidth: null,
};

FilterPopup.propTypes = {
Expand All @@ -180,6 +188,7 @@ FilterPopup.propTypes = {
keepDirtyOnReinitialize: bool,
contentPlacementOffset: number,
label: string.isRequired,
labelMaxWidth: number,
isSelected: bool.isRequired,
children: node.isRequired,

Expand Down

0 comments on commit 500155c

Please sign in to comment.