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

Hide arrow when window width is lower then given amount #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import CurvedArrow from "react-curved-arrow";
|middleY|number|Middle point Y position.|0|
|width|number|Width of the arrow and arrowhead.|8|
|color|color|Color of the arrow and arrowhead.|"black"|
|hideUnderWidth|number|Optional. if the window width is lower then hideUnderWidth, then arrow will be hidden (display none).|0|
|hideIfFoundSelector|DOM selector|Optional. if the arrow can find this selector, it will hide itself. Useful for product tours when you only want to show an arrow whenever a user hasn't performed an action yet such as opening a menu.||
|debugLine|boolean|Show debug dots and lines for fromOffset, toOffset and middle vectors.|false|
|dynamicUpdate|boolean|Automatically adjust the arrow whenever the from/to DOM elements update. Useful for dynamic content such as sliding menus or content that is within a scrolling container.|false|
Expand Down
9 changes: 9 additions & 0 deletions src/CurvedArrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CurvedArrow extends React.PureComponent {
middleY = 0,
width = 8,
color = "black",
hideUnderWidth = 0,
hideIfFoundSelector,
debugLine = false,
dynamicUpdate = false,
Expand Down Expand Up @@ -134,6 +135,14 @@ class CurvedArrow extends React.PureComponent {
canvas.width = x_max - x_min;
canvas.height = y_max - y_min;

if (hideUnderWidth > 0) {
if (window.matchMedia(`(max-width: ${hideUnderWidth}px)`).matches) {
canvas.style.display = "none";
} else {
canvas.style.display = "inline-block";
}
}

if (zIndex) {
canvas.style.zIndex = zIndex;
}
Expand Down