Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate message in favour of content #66

Merged
merged 5 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/react-drylus/src/components/Popover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const PopoverSides = new Enum(
const Popover = ({
children,
message,
content: _content,
side,
style,
exitOnClick,
Expand All @@ -108,6 +109,12 @@ const Popover = ({
const { rect, setRect } = useRect();
const popoverRect = popoverRef.current?.getBoundingClientRect();

if (message != null) {
console.warn('Deprecation warning: `message` has been replaced by `content`. It will be removed in the next major version');
}

const content = _content != null ? _content : message;

useEffect(() => {
if ( ! document.getElementById('popovers-outlet')) {
const popoversOutlet = document.createElement('div');
Expand Down Expand Up @@ -192,7 +199,7 @@ const Popover = ({
[styles.visible]: visible,
})}
style={{ ...popoverStyle, ...style }}>
{message}
{content}
</div>
</div>,
document.getElementById('popovers-outlet'),
Expand All @@ -203,8 +210,11 @@ const Popover = ({


Popover.propTypes = {
/** DEPRECATED */
message: PropTypes.node,

/** Content shown when the Popover is visible */
message: PropTypes.node.isRequired,
content: PropTypes.node,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsbs not sure if to make this required or not. Technically it should be, but then you get the deprecation warning message and the prop type not matching since you might still be using message. Thoughts?


/** Component wrapped by the Popover */
children: PropTypes.node.isRequired,
Expand Down
21 changes: 18 additions & 3 deletions packages/react-drylus/src/components/Tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,26 @@ export const TooltipSides = new Enum(
);


const Tooltip = ({ children, message, side, style }) => {
const Tooltip = ({
children,
message,
content: _content,
side,
style,
}) => {
const [ visible, setVisible ] = useState(false);
const [ outletElement, setOutletElement ] = useState(null);
const childrenRef = useRef();
const tooltipRef = useRef();
const { rect, setRect } = useRect();
const tooltipRect = tooltipRef.current?.getBoundingClientRect();

if (message != null) {
console.warn('Deprecation warning: `message` has been replaced by `content`. It will be removed in the next major version');
}

const content = _content != null ? _content : message;

useEffect(() => {
if ( ! document.getElementById('tooltips-outlet')) {
const tooltipsOutlet = document.createElement('div');
Expand Down Expand Up @@ -181,7 +193,7 @@ const Tooltip = ({ children, message, side, style }) => {
[styles.visible]: visible,
})}
style={{ ...tooltipStyle, ...style }}>
{message}
{content}
</div>
</div>,
document.getElementById('tooltips-outlet'),
Expand All @@ -192,8 +204,11 @@ const Tooltip = ({ children, message, side, style }) => {


Tooltip.propTypes = {
/** DEPRECATED */
message: PropTypes.node,

/** Content shown when the tooltip is visible */
message: PropTypes.node.isRequired,
content: PropTypes.node,

/** Component wrapped by the tooltip */
children: PropTypes.node.isRequired,
Expand Down