Skip to content

Commit

Permalink
using Pickr to support colour picker on older browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubfiala committed Dec 15, 2020
1 parent 8c75eec commit 0965f80
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
44 changes: 44 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,47 @@ simButton.addEventListener('click', async e => {

atrament.endStroke(prevPoint.x, prevPoint.y);
});

// Simple example, see optional options for more configuration.
const pickr = Pickr.create({
el: '#color-picker',
theme: 'classic',
default: 'rgb(0,0,0)',
swatches: [
'rgb(244, 67, 54)',
'rgb(233, 30, 99)',
'rgb(156, 39, 176)',
'rgb(103, 58, 183)',
'rgb(63, 81, 181)',
'rgb(33, 150, 243)',
'rgb(3, 169, 244)',
'rgb(0, 188, 212)',
'rgb(0, 150, 136)',
'rgb(76, 175, 80)',
'rgb(139, 195, 74)',
'rgb(205, 220, 57)',
'rgb(255, 235, 59)',
'rgb(255, 193, 7)'
],
components: {
// Main components
preview: true,
opacity: true,
hue: true,
// Input / output Options
interaction: {
hex: true,
rgb: true,
hsla: true,
hsva: true,
cmyk: true,
input: true,
clear: true,
save: true
}
},
});

pickr.on('save', color => {
atrament.color = color.toRGBA().toString();
});
20 changes: 14 additions & 6 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<head>
<meta charset="utf-8" />
<title>atrament.js ~ demo</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/themes/classic.min.css"/> <!-- 'classic' theme -->
<script src="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/pickr.min.js"></script>
<script src="../dist/atrament.min.js"></script>
<script defer src="demo.js"></script>
<style>
Expand Down Expand Up @@ -50,6 +52,17 @@
#clear {
display: none;
}

.pickr {
display: inline-block;
height: 1.75em;
overflow: hidden;
border: solid 2px;
border-radius: 5px;
margin-bottom: 0;
vertical-align: middle;
margin-left: 5px;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -96,12 +109,7 @@ <h1>atrament.js</h1>
<option value="disabled" default>Disabled</option>
</select><br />
<label>Colour</label>
<input
type="color"
onchange="atrament.color = event.target.value;"
value="#000000"
autocomplete="off"
/><br />
<div id="color-picker"></div><br />
<output><pre id="events"></pre></output>
</form>
<canvas id="sketcher"></canvas>
Expand Down

0 comments on commit 0965f80

Please # to comment.