-
Notifications
You must be signed in to change notification settings - Fork 117
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
Showing
9 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
@import '../../styles'; |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script> | ||
import { onDestroy, onMount } from 'svelte' | ||
export let color | ||
export let onChange | ||
export let showOnTop | ||
let ref | ||
let colorPicker | ||
onMount(async () => { | ||
const VanillaPicker = (await import('vanilla-picker')).default | ||
colorPicker = new VanillaPicker({ | ||
parent: ref, | ||
color: color, | ||
popup: showOnTop ? 'top' : 'bottom', | ||
onDone: function (color) { | ||
const alpha = color.rgba[3] | ||
const hex = | ||
alpha === 1 | ||
? color.hex.substr(0, 7) // return #RRGGBB | ||
: color.hex // return #RRGGBBAA | ||
onChange(hex) | ||
} | ||
}) | ||
colorPicker.show() | ||
}) | ||
onDestroy(() => { | ||
colorPicker.destroy() | ||
}) | ||
</script> | ||
|
||
<div class="jse-color-picker-popup" bind:this={ref} /> | ||
|
||
<style src="./ColorPickerPopup.scss"></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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@import '../../../../styles'; | ||
|
||
.jse-color { | ||
$margin: 2px; | ||
$size: $line-height - 2 * $margin; | ||
|
||
width: $size; | ||
height: $size; | ||
box-sizing: border-box; | ||
padding: 0; | ||
margin: $margin; | ||
|
||
border: 1px solid $black; | ||
border-radius: 2px; | ||
background: $white; | ||
outline: none; | ||
cursor: pointer; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<script> | ||
import { getColorCSS } from '../../../../utils/typeUtils' | ||
import { getWindow } from '../../../../utils/domUtils' | ||
import { compileJSONPointer } from 'immutable-json-patch' | ||
import { getContext } from 'svelte' | ||
import ColorPickerPopup from '../../../../components/controls/ColorPickerPopup.svelte' | ||
const { openAbsolutePopup } = getContext('absolute-popup') | ||
export let onPatch | ||
export let path | ||
export let value | ||
$: color = getColorCSS(value) | ||
function onChange(color) { | ||
onPatch( | ||
[ | ||
{ | ||
op: 'replace', | ||
path: compileJSONPointer(path), | ||
value: color | ||
} | ||
], | ||
null | ||
) | ||
} | ||
function openColorPicker(event) { | ||
// estimate of the color picker height | ||
// we'll render the color picker on top | ||
// when there is not enough space below, and there is enough space above | ||
const height = 300 | ||
const top = event.target.getBoundingClientRect().top | ||
const windowHeight = getWindow(event.target).innerHeight | ||
const showOnTop = windowHeight - top < height && top > height | ||
const props = { | ||
color: value, | ||
onChange, | ||
showOnTop | ||
} | ||
openAbsolutePopup(ColorPickerPopup, props, { | ||
anchor: event.target, | ||
closeOnOuterClick: true, | ||
offsetTop: 18, | ||
offsetLeft: -8, | ||
height | ||
}) | ||
} | ||
</script> | ||
|
||
<button | ||
class="jse-color" | ||
style="background: {color}" | ||
title="Click to open a color picker" | ||
on:click={openColorPicker} | ||
/> | ||
|
||
<style src="./Color.scss"></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