Skip to content
Snippets Groups Projects
Commit d6db9e90 authored by Tom Robinson's avatar Tom Robinson
Browse files

Add render prop with onClose support to Triggerable. Use in table formatting setting

parent 7ffba5e4
No related branches found
No related tags found
No related merge requests found
......@@ -118,13 +118,16 @@ export default ComposedComponent =>
});
}
// if we have a single child which isn't an HTML element and doesn't have an onClose prop go ahead and inject it directly
let { children } = this.props;
if (
if (typeof children === "function") {
// if children is a render prop, pass onClose to it
children = children({ onClose: this.onClose });
} else if (
React.Children.count(children) === 1 &&
React.Children.only(children).props.onClose === undefined &&
typeof React.Children.only(children).type !== "string"
) {
// if we have a single child which isn't an HTML element and doesn't have an onClose prop go ahead and inject it directly
children = React.cloneElement(children, { onClose: this.onClose });
}
......
......@@ -361,18 +361,23 @@ const ColorRangePicker = ({ colors, onChange, className, style }) => (
/>
}
>
<div className="pt1 mr1 flex flex-wrap" style={{ width: 300 }}>
{COLOR_RANGES.map(range => (
<div className={"mb1 pl1"} style={{ flex: "1 1 50%" }}>
<RangePreview
colors={range}
onClick={() => onChange(range)}
className={cx("bordered rounded overflow-hidden cursor-pointer")}
style={{ height: 30 }}
/>
</div>
))}
</div>
{({ onClose }) => (
<div className="pt1 mr1 flex flex-wrap" style={{ width: 300 }}>
{COLOR_RANGES.map(range => (
<div className={"mb1 pl1"} style={{ flex: "1 1 50%" }}>
<RangePreview
colors={range}
onClick={() => {
onChange(range);
onClose();
}}
className={cx("bordered rounded overflow-hidden cursor-pointer")}
style={{ height: 30 }}
/>
</div>
))}
</div>
)}
</PopoverWithTrigger>
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment