Last active
March 3, 2018 13:58
-
-
Save lonekorean/85f5712f3da634453c847276db1160d8 to your computer and use it in GitHub Desktop.
Paint worklet for placeholder box that uses input properties
This file contains hidden or 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
class PlaceholderBoxPropsPainter { | |
static get inputProperties() { | |
return ['border-top-width', 'border-top-color']; | |
} | |
paint(ctx, size, props) { | |
// default values | |
ctx.lineWidth = 2; | |
ctx.strokeStyle = '#666'; | |
// set line width to top border width (if exists) | |
let borderTopWidthProp = props.get('border-top-width'); | |
if (borderTopWidthProp) { | |
ctx.lineWidth = borderTopWidthProp.value; | |
} | |
// set stroke style to top border color (if exists) | |
let borderTopColorProp = props.get('border-top-color'); | |
if (borderTopColorProp) { | |
ctx.strokeStyle = borderTopColorProp.toString(); | |
} | |
// same drawing code as before goes here... | |
} | |
} | |
registerPaint('placeholder-box-props', PlaceholderBoxPropsPainter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment