-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Create Permit Simulation #12606
base: main
Are you sure you want to change the base?
Changes from all commits
87b746e
60086e1
ae2a2cb
5b5d094
dfc086f
d96f9aa
a665679
518e51d
f069e37
fe15f12
6777319
4bc90e0
b65adf3
a79f2cd
a5d96ec
05669d3
bcccb06
22f754f
567fc66
0c215c4
1683123
79a4003
aa43eb9
8577591
d53035f
2bdb950
1ffe22e
779f36f
5852d87
fce5367
f0cc923
98d89c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Third party dependencies. | ||
import { StyleSheet } from 'react-native'; | ||
|
||
// External dependencies. | ||
import { Theme } from '../../../../util/theme/models'; | ||
|
||
/** | ||
* Style sheet input parameters. | ||
*/ | ||
export interface ButtonPillStyleSheetVars { | ||
isDisabled: boolean; | ||
isPressed: boolean; | ||
} | ||
|
||
/** | ||
* Style sheet function for ButtonPill component | ||
* | ||
* @param params Style sheet params | ||
* @param params.theme Theme object | ||
* @param params.vars Arbitrary inputs this style sheet depends on | ||
* @returns StyleSheet object | ||
*/ | ||
const styleSheet = (params: { | ||
theme: Theme; | ||
vars: ButtonPillStyleSheetVars; | ||
}) => { | ||
const { | ||
theme: { colors }, | ||
vars: { isDisabled, isPressed } | ||
} = params; | ||
|
||
return StyleSheet.create({ | ||
base: { | ||
backgroundColor: colors.background.alternative, | ||
color: colors.text.default, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
paddingHorizontal: 8, | ||
paddingVertical: 4, | ||
borderRadius: 99, | ||
opacity: isDisabled ? 0.5 : 1, | ||
...(isPressed && { | ||
backgroundColor: colors.background.alternativePressed, | ||
}), | ||
}, | ||
}); | ||
}; | ||
|
||
export default styleSheet; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Third party dependencies. | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
|
||
// Internal dependencies. | ||
import ButtonPill from './ButtonPill'; | ||
|
||
describe('ButtonPill', () => { | ||
it('should render correctly', () => { | ||
const { toJSON } = render( | ||
<ButtonPill onPress={jest.fn} />, | ||
); | ||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Third party dependencies. | ||
import React, { useCallback, useState } from 'react'; | ||
import { GestureResponderEvent, TouchableOpacity, TouchableOpacityProps } from 'react-native'; | ||
|
||
// External dependencies. | ||
import { useStyles } from '../../../hooks'; | ||
|
||
// Internal dependencies. | ||
import stylesheet from './ButtonPill.styles'; | ||
|
||
/** | ||
* ButtonPill component props. | ||
*/ | ||
export interface ButtonPillProps extends TouchableOpacityProps { | ||
/** | ||
* Optional param to disable the button. | ||
*/ | ||
isDisabled?: boolean; | ||
} | ||
|
||
const ButtonPill = ({ | ||
onPress, | ||
onPressIn, | ||
onPressOut, | ||
style, | ||
isDisabled = false, | ||
children, | ||
...props | ||
}: ButtonPillProps) => { | ||
const [isPressed, setIsPressed] = useState(false); | ||
const { styles } = useStyles(stylesheet, { | ||
style, | ||
isPressed, | ||
isDisabled, | ||
}); | ||
|
||
const triggerOnPressedIn = useCallback( | ||
(e: GestureResponderEvent) => { | ||
setIsPressed(true); | ||
onPressIn?.(e); | ||
}, | ||
[setIsPressed, onPressIn], | ||
); | ||
|
||
const triggerOnPressedOut = useCallback( | ||
(e: GestureResponderEvent) => { | ||
setIsPressed(false); | ||
onPressOut?.(e); | ||
}, | ||
[setIsPressed, onPressOut], | ||
); | ||
|
||
return ( | ||
<TouchableOpacity | ||
style={styles.base} | ||
onPress={!isDisabled ? onPress : undefined} | ||
onPressIn={!isDisabled ? triggerOnPressedIn : undefined} | ||
onPressOut={!isDisabled ? triggerOnPressedOut : undefined} | ||
accessible | ||
activeOpacity={1} | ||
disabled={isDisabled} | ||
{...props} | ||
> | ||
{children} | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
export default ButtonPill; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ButtonPill should render correctly 1`] = ` | ||
<TouchableOpacity | ||
accessible={true} | ||
activeOpacity={1} | ||
disabled={false} | ||
onPress={[Function]} | ||
onPressIn={[Function]} | ||
onPressOut={[Function]} | ||
style={ | ||
{ | ||
"alignItems": "center", | ||
"backgroundColor": "#f2f4f6", | ||
"borderRadius": 99, | ||
"color": "#141618", | ||
"justifyContent": "center", | ||
"opacity": 1, | ||
"paddingHorizontal": 8, | ||
"paddingVertical": 4, | ||
} | ||
} | ||
/> | ||
`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are avoiding snapshot testing now in mobile re-design effort. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sgtm! I was mimicking the existing DS ButtonIcon component. It isn't too bad at this lower-level component, unlike a parent component to have the snapshot. I created a separate issue to handle this suggestion #12910 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './ButtonPill'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be nicer to create separate PR for this component and also possibly addd storybook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the review @jpuri!
yeah, I agree. In retrospect, having a tree trunk branch for this feature would have been nice since it requires much more than I anticipated initially. This PR is my first mobile feat PR, so I didn't expect to need all of these dependencies
good idea to add a storybook page. I created a separate issue ticket for this + related unit tests
#12910