-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set up PressableWithFeedback component
- Loading branch information
1 parent
d270158
commit ee2e3b0
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,51 @@ | ||
import React, {forwardRef} from 'react'; | ||
import _ from 'lodash'; | ||
import propTypes from 'prop-types'; | ||
import GenericPressable from './GenericPressable'; | ||
import GenericPressablePropTypes from './GenericPressable/PropTypes'; | ||
import OpacityView from '../OpacityView'; | ||
import variables from '../../styles/variables'; | ||
|
||
export default GenericPressable; | ||
const omitedProps = ['style', 'pressStyle', 'hoverStyle', 'focusStyle', 'wrapperStyle']; | ||
|
||
const PressableWithFeedbackPropTypes = { | ||
..._.omit(GenericPressablePropTypes.propTypes, omitedProps), | ||
pressDimmingValue: propTypes.number, | ||
hoverDimmingValue: propTypes.number, | ||
}; | ||
|
||
const PressableWithFeedbackDefaultProps = { | ||
..._.omit(GenericPressablePropTypes.defaultProps, omitedProps), | ||
pressDimmingValue: variables.pressDimValue, | ||
hoverDimmingValue: variables.hoverDimValue, | ||
wrapperStyle: [], | ||
}; | ||
|
||
const PressableWithFeedback = forwardRef((props, ref) => { | ||
const propsWithoutStyling = _.omit(props, omitedProps); | ||
return ( | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
<GenericPressable ref={ref} style={props.wrapperStyle} {...propsWithoutStyling}> | ||
{state => ( | ||
<OpacityView | ||
shouldDim={state.pressed || state.hovered} | ||
dimmingValue={state.pressed ? props.pressDimmingValue : props.hoverDimmingValue} | ||
style={[ | ||
props.style, | ||
state.pressed && props.pressStyle, | ||
state.hovered && props.hoverStyle, | ||
state.focused && props.focusStyle, | ||
]} | ||
> | ||
{props.children} | ||
</OpacityView> | ||
)} | ||
</GenericPressable> | ||
); | ||
}); | ||
|
||
PressableWithFeedback.displayName = 'PressableWithFeedback'; | ||
PressableWithFeedback.propTypes = PressableWithFeedbackPropTypes; | ||
PressableWithFeedback.defaultProps = PressableWithFeedbackDefaultProps; | ||
|
||
export default PressableWithFeedback; |
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