diff options
Diffstat (limited to 'frontend/app/views/tile/handles')
| -rw-r--r-- | frontend/app/views/tile/handles/index.js | 2 | ||||
| -rw-r--r-- | frontend/app/views/tile/handles/tile.gradient.js | 69 | ||||
| -rw-r--r-- | frontend/app/views/tile/handles/tile.link.js | 2 |
3 files changed, 72 insertions, 1 deletions
diff --git a/frontend/app/views/tile/handles/index.js b/frontend/app/views/tile/handles/index.js index 8aaeb06..877c9be 100644 --- a/frontend/app/views/tile/handles/index.js +++ b/frontend/app/views/tile/handles/index.js @@ -3,6 +3,7 @@ import TileImage from './tile.image' import TileVideo from './tile.video' import TileLink from './tile.link' import TileText from './tile.text' +import TileGradient from './tile.gradient' import TileScript from './tile.script' export default { @@ -10,5 +11,6 @@ export default { video: TileVideo, link: TileLink, text: TileText, + gradient: TileGradient, script: TileScript, } diff --git a/frontend/app/views/tile/handles/tile.gradient.js b/frontend/app/views/tile/handles/tile.gradient.js new file mode 100644 index 0000000..1b3cd80 --- /dev/null +++ b/frontend/app/views/tile/handles/tile.gradient.js @@ -0,0 +1,69 @@ +import React from 'react' +import { generateTransform, unitsDimension } from 'app/views/tile/tile.utils' + +export default function TileGradient({ tile, box, bounds, videoBounds, viewing, onMouseDown, onDoubleClick, onMouseEnter }) { + // console.log(tile) + const style = { + transform: generateTransform(tile, box, bounds, videoBounds), + opacity: tile.settings.opacity, + } + // console.log(generateTransform(tile)) + let className = ['tile', tile.type].join(' ') + if (tile.target_page_id || (viewing && tile.href)) { + if (viewing || tile.settings.cursor !== 'unclickable') { + className += ' ' + (tile.settings.cursor || 'hand_up') + } + } + + className += ' ' + tile.settings.align + style.width = unitsDimension(tile, 'width', bounds, videoBounds) + style.height = unitsDimension(tile, 'height', bounds, videoBounds) + style.background = linearGradient(tile) + + return ( + <div + className={className} + onMouseDown={onMouseDown} + onDoubleClick={onDoubleClick} + onMouseEnter={onMouseEnter} + style={style} + /> + ) +} + +function linearGradient(tile) { + let from_color = tileRGBA(tile.settings.from_color, tile.settings.from_opacity) + let to_color = tileRGBA(tile.settings.to_color, tile.settings.to_opacity) + let stop = parseFloat(tile.settings.stop) + return [ + "linear-gradient(", + tile.settings.angle, "deg,", + to_color, + ",", + stop + "%", + ",", + from_color, + ")" + ].join("") +} + +function tileRGBA(hex, opacity) { + const { r, g, b } = hexToRgb(hex) + return "rgba(" + [r,g,b,opacity].join(",") + ")" +} + +function hexToRgb(hex) { + let result; + if (hex.length === 7) { + result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) + } else if (hex.length === 4) { + result = /^#?([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$/i.exec(hex) + } else { + return { r: 255, g: 0, b: 255 } + } + return result ? { + r: parseInt(result[1], 16), + g: parseInt(result[2], 16), + b: parseInt(result[3], 16) + } : null +}
\ No newline at end of file diff --git a/frontend/app/views/tile/handles/tile.link.js b/frontend/app/views/tile/handles/tile.link.js index 93db9e1..8ddc3ea 100644 --- a/frontend/app/views/tile/handles/tile.link.js +++ b/frontend/app/views/tile/handles/tile.link.js @@ -1,7 +1,7 @@ import React from 'react' import { generateTransform, unitsDimension } from 'app/views/tile/tile.utils' -export default function TileScript({ tile, box, bounds, videoBounds, viewing, onMouseDown, onDoubleClick, onMouseEnter }) { +export default function TileLink({ tile, box, bounds, videoBounds, viewing, onMouseDown, onDoubleClick, onMouseEnter }) { // console.log(tile) const style = { transform: generateTransform(tile, box, bounds, videoBounds), |
