Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #81 from dmapper/fix-div
Browse files Browse the repository at this point in the history
[ui -> Div] add opacity to bg on press
  • Loading branch information
pturchik authored Feb 17, 2020
2 parents c1fd3e6 + 065c0d8 commit 4e39c29
Show file tree
Hide file tree
Showing 23 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/ui/components/Avatar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Avatar.defaultProps = {
}

Avatar.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
url: propTypes.string,
size: propTypes.oneOf(['xxl', 'xl', 'l', 'm', 's', 'xs']),
status: propTypes.oneOf(['online', 'away']),
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Br/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Br.defaultProps = {
}

Br.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
half: propTypes.bool,
lines: propTypes.number

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Button.defaultProps = {
}

Button.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
color: propTypes.string,
children: propTypes.node,
disabled: propTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Card.defaultProps = {
}

Card.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
level: propTypes.oneOf(SHADOWS.map((key, index) => index).slice(1)),
onPress: propTypes.func
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Collapse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Collapse.defaultProps = {
}

Collapse.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node.isRequired,
title: propTypes.string.isRequired,
open: propTypes.bool
Expand Down
28 changes: 19 additions & 9 deletions packages/ui/components/Div/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useMemo } from 'react'
import { View, TouchableOpacity } from 'react-native'
import propTypes from 'prop-types'
import { TouchableOpacity, View } from 'react-native'
import { observer } from 'startupjs'
import config from '../../config/rootConfig'
import { colorToRGBA } from '../../config/helpers'
Expand All @@ -25,21 +25,26 @@ function Div ({
const _backgroundColor = backgroundColor || (level ? colors.white : null)

const [hover, setHover] = useState()
const [active, setActive] = useState()
const wrapperExtraStyles = useMemo(() => {
if (!_backgroundColor) return {}
if (!hover) return { backgroundColor: _backgroundColor }
return { backgroundColor: colorToRGBA(_backgroundColor, hoverOpacity) }
}, [hover, _backgroundColor])
if (active) {
return {
backgroundColor: colorToRGBA(_backgroundColor, activeStateOpacity)
}
}
if (hover) {
return { backgroundColor: colorToRGBA(_backgroundColor, hoverOpacity) }
}
return { backgroundColor: _backgroundColor }
}, [hover, active, _backgroundColor])

const isClickable = typeof onPress === 'function' && !disabled
let Wrapper = isClickable
? TouchableOpacity
: View

const extraProps = {}

if (isClickable) {
extraProps.activeOpacity = activeStateOpacity
extraProps.activeOpacity = 1
extraProps.onPress = onPress

extraProps.onMouseEnter = (...args) => {
Expand All @@ -50,8 +55,13 @@ function Div ({
setHover()
onMouseLeave && onMouseLeave(...args)
}

extraProps.onPressIn = () => setActive(true)
extraProps.onPressOut = () => setActive()
}

const Wrapper = isClickable ? TouchableOpacity : View

return pug`
Wrapper.root(
style=[style, SHADOWS[level], wrapperExtraStyles]
Expand All @@ -71,7 +81,7 @@ Div.defaultProps = {
}

Div.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
backgroundColor: propTypes.string,
disabled: propTypes.bool,
Expand Down
5 changes: 0 additions & 5 deletions packages/ui/components/Div/index.styl
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
.root
&.clickable
+web()
&:active
opacity $UI.Div.activeStateOpacity !important
2 changes: 1 addition & 1 deletion packages/ui/components/Drawer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Drawer.defaultProps = {
}

Drawer.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
backgroundColor: propTypes.string,
position: propTypes.oneOf(Object.values(DrawerLayout.positions)),
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Headers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function generateTag (tag) {
}

header.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
bold: propTypes.bool
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Hr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Hr.defaultProps = {
}

Hr.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
align: propTypes.oneOf(['left', 'center', 'right'])
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Icon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Icon.defaultProps = {
}

Icon.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
icon: propTypes.object,
color: propTypes.string,
size: propTypes.oneOf(Object.keys(SIZES)),
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Layout ({ style, children }) {
}

Layout.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Modal.defaultProps = {
}

Modal.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
visible: propTypes.bool,
title: propTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Progress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Progress.defaultProps = {
}

Progress.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
value: propTypes.number,
label: propTypes.string,
variant: propTypes.oneOf(['full', 'compact'])
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Rating/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Rating.defaultProps = {
}

Rating.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
value: propTypes.number,
readonly: propTypes.bool,
onChange: propTypes.func
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Row/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Row ({
}

Row.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
wrap: propTypes.bool,
reverse: propTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Sidebar.defaultProps = {
}

Sidebar.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
backgroundColor: propTypes.string,
position: propTypes.oneOf(['left', 'right']),
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/SmartSidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ SmartSidebar.defaultProps = {
}

SmartSidebar.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
backgroundColor: propTypes.string,
fixedLayoutBreakpoint: propTypes.number,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Span/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Span.defaultProps = {
}

Span.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
size: propTypes.oneOf(['xxl', 'xl', 'l', 'm', 's', 'xs']),
bold: propTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/StatusBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function StatusBar ({
}

StatusBar.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
backgroundColor: propTypes.string
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/Tag/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Tag.defaultProps = {
}

Tag.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
children: propTypes.node,
color: propTypes.string,
textColor: propTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/TextInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TextInput.defaultProps = {
}

TextInput.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
label: propTypes.string,
placeholder: propTypes.string.isRequired,
value: propTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/User/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ User.defaultProps = {
}

User.propTypes = {
style: propTypes.object,
style: propTypes.oneOfType([propTypes.object, propTypes.array]),
avatarUrl: propTypes.string,
description: propTypes.string,
name: propTypes.string.isRequired,
Expand Down

0 comments on commit 4e39c29

Please sign in to comment.