diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2021-03-24 12:12:52 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2021-03-24 12:12:52 +0100 |
| commit | b5435cf3a892efdef3efe0a137076b3408556434 (patch) | |
| tree | 607c221f6adc18d9afba9530ddd9ffa3954f6189 /frontend/app/views/tile | |
| parent | c88efbb3d056e543a8c6eb9903cc79692a5277f6 (diff) | |
tile gradients
Diffstat (limited to 'frontend/app/views/tile')
| -rw-r--r-- | frontend/app/views/tile/components/tile.form.js | 108 | ||||
| -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 |
4 files changed, 176 insertions, 5 deletions
diff --git a/frontend/app/views/tile/components/tile.form.js b/frontend/app/views/tile/components/tile.form.js index 8a6a08e..6a65194 100644 --- a/frontend/app/views/tile/components/tile.form.js +++ b/frontend/app/views/tile/components/tile.form.js @@ -17,7 +17,7 @@ import * as pageActions from 'app/views/page/page.actions' import * as tileActions from 'app/views/tile/tile.actions' const SELECT_TYPES = [ - "image", "text", "video", "link", "script", + "image", "text", "video", "link", "gradient", "script", ].map(s => ({ name: s, label: s })) const ALIGNMENTS = [ @@ -36,6 +36,7 @@ const REQUIRED_KEYS = { video: ['url'], text: ['content'], link: [], + gradient: [], script: [], } @@ -146,6 +147,24 @@ const newText = (data) => ({ ...data, }) +const newGradient = (data) => ({ + settings: { + ...newPosition({ width: 100, height: 100 }), + from_color: '#ffffff', + from_opacity: 1.0, + to_color: '#000000', + to_opacity: 1.0, + angle: 0, + stop: 50, + units: '%', + external_link_url: "", + cursor: 'hand_up', + }, + type: 'gradient', + target_page_id: 0, + ...data, +}) + const newLink = (data) => ({ settings: { ...newPosition({ width: 100, height: 100, }), @@ -185,6 +204,7 @@ const TYPE_CONSTRUCTORS = { video: newVideo, text: newText, link: newLink, + gradient: newGradient, script: newScript, } @@ -232,7 +252,7 @@ class TileForm extends Component { ] this.setState({ pageList, popupList }) if (isNew) { - const newTile = newImage({ + const newTile = newGradient({ id: "new", graph_id: graph.show.res.id, page_id: page.show.res.id, @@ -462,6 +482,8 @@ class TileForm extends Component { ? this.renderTextForm() : temporaryTile.type === 'link' ? this.renderLinkForm() + : temporaryTile.type === 'gradient' + ? this.renderGradientForm() : temporaryTile.type === 'script' ? this.renderScriptForm() : ""} @@ -741,7 +763,7 @@ class TileForm extends Component { name="width" data={temporaryTile.settings} min={0} - max={1200} + max={2400} error={errorFields.has('width')} onChange={this.handleSettingsChange} autoComplete="off" @@ -751,7 +773,7 @@ class TileForm extends Component { name="height" data={temporaryTile.settings} min={0} - max={1200} + max={2400} error={errorFields.has('height')} onChange={this.handleSettingsChange} autoComplete="off" @@ -761,6 +783,84 @@ class TileForm extends Component { ) } + renderGradientForm() { + const { temporaryTile } = this.props + return ( + <div> + <ColorInput + title='From' + name='from_color' + data={temporaryTile.settings} + onChange={this.handleSettingsChange} + autoComplete="off" + /> + <Slider + title='Opacity' + name='from_opacity' + value={temporaryTile.settings.from_opacity} + onChange={this.handleSettingsSelect} + min={0.0} + max={1.0} + step={0.01} + /> + <ColorInput + title='To' + name='to_color' + data={temporaryTile.settings} + onChange={this.handleSettingsChange} + autoComplete="off" + /> + <Slider + title='Opacity' + name='to_opacity' + value={temporaryTile.settings.to_opacity} + onChange={this.handleSettingsSelect} + min={0.0} + max={1.0} + step={0.01} + /> + <Slider + title='Angle' + name='angle' + value={temporaryTile.settings.angle} + onChange={this.handleSettingsSelect} + min={0.0} + max={360.0} + step={0.1} + /> + <Slider + title='Stop' + name='stop' + value={temporaryTile.settings.stop} + onChange={this.handleSettingsSelect} + min={0.0} + max={100.0} + step={0.1} + /> + <div className='row pair'> + <NumberInput + title="Width" + name="width" + data={temporaryTile.settings} + min={0} + max={2400} + onChange={this.handleSettingsChange} + autoComplete="off" + /> + <NumberInput + title="Height" + name="height" + data={temporaryTile.settings} + min={0} + max={2400} + onChange={this.handleSettingsChange} + autoComplete="off" + /> + </div> + </div> + ) + } + renderScriptForm() { const { temporaryTile } = this.props const { errorFields } = this.state 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), |
