Created
November 14, 2016 19:41
-
-
Save aleclarson/74bab239ebd6e869864a5e670ce09449 to your computer and use it in GitHub Desktop.
OuterBorder (for React Native)
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
{Component, Device} = require "modx" | |
hexToRgb = require "hex-rgb" | |
type = Component "OuterBorder" | |
type.defineProps | |
style: Style | |
child: Element | |
width: Number.withDefault 1 / Device.scale | |
color: String.withDefault "#000" | |
opacity: Number.withDefault 1 | |
radius: Number | |
type.defineReactions | |
_borderColor: -> | |
rgb = hexToRgb(unwrap @props.color).join "," | |
opacity = unwrap @props.opacity | |
"rgba(#{rgb}, #{opacity})" | |
_borderRadius: -> | |
width = unwrap @props.width | |
radius = unwrap @props.radius | |
radius + width | |
type.render -> | |
style = | |
borderColor: @_borderColor | |
borderRadius: @_borderRadius | |
borderWidth: @props.width | |
return View | |
style: [@props.style, style] | |
children: @props.child | |
module.exports = type.build() | |
unwrap = (x) -> | |
if isType x, AnimatedValue | |
then x.get() | |
else x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Global dependencies: