diff options
Diffstat (limited to 'frontend/app/views/tile/handles/tile.gradient.js')
| -rw-r--r-- | frontend/app/views/tile/handles/tile.gradient.js | 69 |
1 files changed, 69 insertions, 0 deletions
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 |
