-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8953bc
commit 1a5ca4c
Showing
15 changed files
with
104 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import style from "./style"; | ||
import style from './style' | ||
|
||
function handleMouseOver() { | ||
this.style.transform = "scale(1.2)"; | ||
this.style.transform = 'scale(1.2)' | ||
} | ||
|
||
function handleMouseOut() { | ||
this.style.transform = "scale(1)"; | ||
this.style.transform = 'scale(1)' | ||
} | ||
|
||
export default function createButton(icon, handleMouseDown) { | ||
const btn = document.createElement("div"); | ||
btn.style.cssText = style; | ||
btn.innerHTML = icon; | ||
btn.onmousedown = handleMouseDown; | ||
btn.onmouseover = handleMouseOver; | ||
btn.onmouseout = handleMouseOut; | ||
const btn = document.createElement('div') | ||
btn.style.cssText = style | ||
btn.innerHTML = icon | ||
btn.onmousedown = handleMouseDown | ||
btn.onmouseover = handleMouseOver | ||
btn.onmouseout = handleMouseOut | ||
|
||
return btn; | ||
return btn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import style from "./style"; | ||
import style from './style' | ||
|
||
export default function Arrow(props) { | ||
const arrow = document.createElement("div"); | ||
arrow.style.cssText = style(props); | ||
const arrow = document.createElement('div') | ||
arrow.style.cssText = style(props) | ||
|
||
return arrow; | ||
return arrow | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
const style = ({ arrowSize, backgroundColor, buttonSize, icons }) => | ||
"position:absolute;" + | ||
"border-left:" + arrowSize + "px solid transparent;" + | ||
"border-right:" + arrowSize + "px solid transparent;" + | ||
"border-top:" + arrowSize + "px solid " + backgroundColor + ";" + | ||
"bottom:-" + (arrowSize - 1) + "px;" + | ||
"left:" + ((buttonSize * icons.length) / 2 - arrowSize) + "px;" + | ||
"width:0;" + | ||
"height:0;" | ||
'position:absolute;' + | ||
'border-left:' + arrowSize + 'px solid transparent;' + | ||
'border-right:' + arrowSize + 'px solid transparent;' + | ||
'border-top:' + arrowSize + 'px solid ' + backgroundColor + ';' + | ||
'bottom:-' + (arrowSize - 1) + 'px;' + | ||
'left:' + ((buttonSize * icons.length) / 2 - arrowSize) + 'px;' + | ||
'width:0;' + | ||
'height:0;' | ||
|
||
export default style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
export const defaultStyle = backgroundColor => | ||
"line-height:0;" + | ||
"transition:all .2s ease-in-out;" + | ||
"background:" + backgroundColor + ";" | ||
'line-height:0;' + | ||
'transition:all .2s ease-in-out;' + | ||
'background:' + backgroundColor + ';' | ||
|
||
export const mobileStyle = buttonSize => | ||
"position:fixed;" + | ||
"bottom:calc(50% - 64px);" + | ||
"left:0;" + | ||
"width:" + buttonSize + "px;" + | ||
"border-top-right-radius:5px;" + | ||
"border-bottom-right-radius:5px;" | ||
'position:fixed;' + | ||
'bottom:calc(50% - 64px);' + | ||
'left:0;' + | ||
'width:' + buttonSize + 'px;' + | ||
'border-top-right-radius:5px;' + | ||
'border-bottom-right-radius:5px;' | ||
|
||
export const desktopStyle = (top, left) => | ||
"position:absolute;" + | ||
"border-radius:3px;" + | ||
"top:" + top + "px;" + | ||
"left:" + left + "px;" | ||
'position:absolute;' + | ||
'border-radius:3px;' + | ||
'top:' + top + 'px;' + | ||
'left:' + left + 'px;' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
export function appendIconStyle({iconColor}) { | ||
const style = document.createElement("style"); | ||
style.id = "sharect-style"; | ||
style.innerHTML = `.sharect svg{fill:${iconColor};}`; | ||
document.body.appendChild(style); | ||
const style = document.createElement('style') | ||
style.id = 'sharect-style' | ||
style.innerHTML = `.sharect svg{fill:${iconColor};}` | ||
document.body.appendChild(style) | ||
} | ||
|
||
export function appendMobileIconStyle(iconColor, mobileIconSize) { | ||
const style = document.getElementById("sharect-style"); | ||
style.innerHTML = `.sharect svg{fill:${iconColor};width:${mobileIconSize}px;height:${mobileIconSize}px;}`; | ||
const style = document.getElementById('sharect-style') | ||
style.innerHTML = `.sharect svg{fill:${iconColor};width:${mobileIconSize}px;height:${mobileIconSize}px;}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
import hasTooltipDrawn from "./hasTooltipDrawn"; | ||
import hasSelection from "./hasSelection"; | ||
import isSelectableElement from "./isSelectableElement"; | ||
import moveTooltip from "./moveTooltip"; | ||
import renderTooltip from "./renderTooltip"; | ||
import { appendMobileIconStyle } from "./appendIconStyles"; | ||
import hasTooltipDrawn from './hasTooltipDrawn' | ||
import hasSelection from './hasSelection' | ||
import isSelectableElement from './isSelectableElement' | ||
import moveTooltip from './moveTooltip' | ||
import renderTooltip from './renderTooltip' | ||
import { appendMobileIconStyle } from './appendIconStyles' | ||
|
||
let isMobile = false; | ||
let isMobile = false | ||
|
||
function handleMouseUp(props) { | ||
setTimeout(function mouseTimeout() { | ||
if (hasTooltipDrawn()) { | ||
if (hasSelection() && isSelectableElement(props.selectableElements)) { | ||
moveTooltip({ ...props, isMobile }); | ||
return; | ||
moveTooltip({ ...props, isMobile }) | ||
return | ||
} else { | ||
document.querySelector(".sharect").remove(); | ||
document.querySelector('.sharect').remove() | ||
} | ||
} | ||
if (hasSelection() && isSelectableElement(props.selectableElements)) { | ||
renderTooltip({ ...props, isMobile }); | ||
renderTooltip({ ...props, isMobile }) | ||
} | ||
}, 10); | ||
}, 10) | ||
} | ||
|
||
function handlePointerUp(e, { iconColor, mobileIconSize }) { | ||
if (e.pointerType !== "mouse" && e.isPrimary) { | ||
isMobile = true; | ||
appendMobileIconStyle(iconColor, mobileIconSize); | ||
window.removeEventListener("pointerup", handlePointerUp); | ||
if (e.pointerType !== 'mouse' && e.isPrimary) { | ||
isMobile = true | ||
appendMobileIconStyle(iconColor, mobileIconSize) | ||
window.removeEventListener('pointerup', handlePointerUp) | ||
} | ||
} | ||
|
||
export default function attachEvents(props) { | ||
window.addEventListener("mouseup", () => handleMouseUp(props), false); | ||
window.addEventListener('mouseup', () => handleMouseUp(props), false) | ||
|
||
if (window.onpointerup !== undefined) { | ||
window.addEventListener("pointerup", (e) => handlePointerUp(e, props), false); | ||
window.addEventListener('pointerup', (e) => handlePointerUp(e, props), false) | ||
} else if (window.orientation !== undefined) { | ||
isMobile = true; | ||
appendMobileIconStyle(props); | ||
isMobile = true | ||
appendMobileIconStyle(props) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
export default function getClosestElement(element, ancestor) { | ||
if (Element.prototype.closest) { | ||
return element.closest(ancestor); | ||
return element.closest(ancestor) | ||
} else { | ||
// IE 9+ polyfill | ||
let el = element; | ||
let el = element | ||
do { | ||
if (el.matches(ancestor)) return el; | ||
el = el.parentNode; | ||
} while (el !== null && el.nodeType === Node.ELEMENT_NODE); | ||
return null; | ||
if (el.matches(ancestor)) return el | ||
el = el.parentNode | ||
} while (el !== null && el.nodeType === Node.ELEMENT_NODE) | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default function hasSelection() { | ||
return !!window.getSelection().toString(); | ||
return !!window.getSelection().toString() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export default function hasTooltipDrawn() { | ||
return !!document.querySelector(".sharect"); | ||
return !!document.querySelector('.sharect') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import getTooltipPosition from "./getTooltipPosition"; | ||
import getTooltipPosition from './getTooltipPosition' | ||
|
||
export default function moveTooltip(props) { | ||
if (props.isMobile) return null; | ||
if (props.isMobile) return null | ||
|
||
const { top, left } = getTooltipPosition(props); | ||
let tooltip = document.querySelector(".sharect"); | ||
tooltip.style.top = `${top}px`; | ||
tooltip.style.left = `${left}px`; | ||
const { top, left } = getTooltipPosition(props) | ||
let tooltip = document.querySelector('.sharect') | ||
tooltip.style.top = `${top}px` | ||
tooltip.style.left = `${left}px` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import Tooltip from "../Tooltip/Tooltip"; | ||
import getTooltipPosition from "./getTooltipPosition"; | ||
import Tooltip from '../Tooltip/Tooltip' | ||
import getTooltipPosition from './getTooltipPosition' | ||
|
||
export default function renderTooltip(props) { | ||
const { top, left } = getTooltipPosition(props); | ||
const { top, left } = getTooltipPosition(props) | ||
|
||
const tooltipSettings = { | ||
...props, | ||
top, | ||
left | ||
}; | ||
} | ||
|
||
document.body.appendChild(Tooltip(tooltipSettings)); | ||
document.body.appendChild(Tooltip(tooltipSettings)) | ||
} |