Skip to content
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

[UI]-Dropdown Button #24034

Merged
merged 22 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fd4f9b2
test:
dhairyasenjaliya Jul 17, 2023
ea3a55d
Merge branch 'main' of https://github.com/dhairyasenjaliya/Expensify …
dhairyasenjaliya Aug 1, 2023
399fa55
Adjust styling as per new design
dhairyasenjaliya Aug 1, 2023
cd58d75
remove height from another button
dhairyasenjaliya Aug 1, 2023
da12fd0
use borderwidth instead of normal width
dhairyasenjaliya Aug 2, 2023
76ace6f
remove unused import
dhairyasenjaliya Aug 2, 2023
946c71f
Merge branch 'main' of https://github.com/dhairyasenjaliya/Expensify …
dhairyasenjaliya Aug 3, 2023
4655faa
adjust border as per design
dhairyasenjaliya Aug 3, 2023
638d032
Added both size for dropDown option
dhairyasenjaliya Aug 7, 2023
2890cf0
Merge branch 'main' of https://github.com/dhairyasenjaliya/Expensify …
dhairyasenjaliya Aug 7, 2023
a576c7e
Merge branch 'main' of https://github.com/dhairyasenjaliya/Expensify …
dhairyasenjaliya Aug 9, 2023
64590b7
Merge branch 'main' of https://github.com/dhairyasenjaliya/Expensify …
dhairyasenjaliya Aug 14, 2023
bd1c57f
code improvements
dhairyasenjaliya Aug 14, 2023
c1d9765
Added size const and refactor code
dhairyasenjaliya Aug 14, 2023
0e77483
Merge branch 'main' of https://github.com/dhairyasenjaliya/Expensify …
dhairyasenjaliya Aug 14, 2023
d70a51a
unit test failed
dhairyasenjaliya Aug 14, 2023
85feb74
Merge branch 'main' of https://github.com/dhairyasenjaliya/Expensify …
dhairyasenjaliya Aug 16, 2023
2aa0735
Merge branches 'DropButton' and 'main' of https://github.com/dhairyas…
dhairyasenjaliya Aug 18, 2023
50e4e08
Merge branch 'main' of https://github.com/dhairyasenjaliya/Expensify …
dhairyasenjaliya Aug 18, 2023
1c35cb5
use variable.js
dhairyasenjaliya Aug 18, 2023
6ab178e
name correction
dhairyasenjaliya Aug 18, 2023
2d55df0
Merge branch 'main' of https://github.com/dhairyasenjaliya/Expensify …
dhairyasenjaliya Aug 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,14 @@ const CONST = {
DISTANCE: 'distance',
},
STATUS_TEXT_MAX_LENGTH: 100,

DROPDOWN_BUTTON_SIZE: {
LARGE: 'large',
MEDIUM: 'medium',
},

SF_COORDINATES: [-122.4194, 37.7749],

MAPBOX_STYLE_URL: 'mapbox://styles/expensify/cllcoiqds00cs01r80kp34tmq',
NAVIGATION: {
TYPE: {
Expand Down
31 changes: 26 additions & 5 deletions src/components/ButtonWithDropdownMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import themeColors from '../styles/themes/default';
import CONST from '../CONST';
import * as StyleUtils from '../styles/StyleUtils';

const propTypes = {
/** Text to display for the menu header */
Expand All @@ -21,6 +22,9 @@ const propTypes = {
/** Whether we should show a loading state for the main button */
isLoading: PropTypes.bool,

/** The size of button size */
buttonSize: PropTypes.oneOf(_.values(CONST.DROPDOWN_BUTTON_SIZE)),

/** Should the confirmation button be disabled? */
isDisabled: PropTypes.bool,

Expand Down Expand Up @@ -55,6 +59,7 @@ const defaultProps = {
isDisabled: false,
menuHeaderText: '',
style: [],
buttonSize: CONST.DROPDOWN_BUTTON_SIZE.MEDIUM,
anchorAlignment: {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
Expand All @@ -69,6 +74,8 @@ function ButtonWithDropdownMenu(props) {
const {windowWidth, windowHeight} = useWindowDimensions();
const caretButton = useRef(null);
const selectedItem = props.options[selectedItemIndex];
const innerStyleDropButton = StyleUtils.getDropDownButtonHeight(props.buttonSize);
const isButtonSizeLarge = props.buttonSize === CONST.DROPDOWN_BUTTON_SIZE.LARGE;

useEffect(() => {
if (!caretButton.current) {
Expand Down Expand Up @@ -102,20 +109,31 @@ function ButtonWithDropdownMenu(props) {
shouldRemoveRightBorderRadius
style={[styles.flex1, styles.pr0]}
pressOnEnter
large={isButtonSizeLarge}
medium={!isButtonSizeLarge}
innerStyles={[innerStyleDropButton]}
/>
<View style={styles.buttonDivider} />

<Button
ref={caretButton}
success
isDisabled={props.isDisabled}
style={[styles.pl0]}
onPress={() => setIsMenuVisible(!isMenuVisible)}
shouldRemoveLeftBorderRadius
large={isButtonSizeLarge}
medium={!isButtonSizeLarge}
innerStyles={[styles.dropDownButtonCartIconContainerPadding, innerStyleDropButton]}
>
<Icon
src={Expensicons.DownArrow}
fill={themeColors.textLight}
/>
<View style={[styles.dropDownButtonCartIconView, innerStyleDropButton]}>
<View style={[styles.buttonDivider]} />
<View style={[styles.dropDownButtonArrowContain]}>
<Icon
src={Expensicons.DownArrow}
fill={themeColors.textLight}
/>
</View>
</View>
</Button>
</View>
) : (
Expand All @@ -127,6 +145,9 @@ function ButtonWithDropdownMenu(props) {
text={selectedItem.text}
onPress={(event) => props.onPress(event, props.options[0].value)}
pressOnEnter
large={isButtonSizeLarge}
medium={!isButtonSizeLarge}
innerStyles={[innerStyleDropButton]}
/>
)}
{props.options.length > 1 && !_.isEmpty(popoverAnchorPosition) && (
Expand Down
2 changes: 2 additions & 0 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ function MoneyRequestConfirmationList(props) {
currency={props.iouCurrencyCode}
policyID={props.policyID}
shouldShowPaymentOptions
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.LARGE}
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
Expand All @@ -310,6 +311,7 @@ function MoneyRequestConfirmationList(props) {
isDisabled={shouldDisableButton}
onPress={(_event, value) => confirm(value)}
options={splitOrRequestOptions}
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.LARGE}
/>
);
}, [confirm, props.selectedParticipants, props.bankAccountRoute, props.iouCurrencyCode, props.iouType, props.isReadOnly, props.policyID, selectedParticipants, splitOrRequestOptions]);
Expand Down
6 changes: 6 additions & 0 deletions src/components/SettlementButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ const propTypes = {
/** Total money amount in form <currency><amount> */
formattedAmount: PropTypes.string,

/** The size of button size */
buttonSize: PropTypes.oneOf(_.values(CONST.DROPDOWN_BUTTON_SIZE)),

/** The anchor alignment of the popover menu */

anchorAlignment: PropTypes.shape({
horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)),
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
Expand All @@ -77,6 +81,7 @@ const defaultProps = {
iouReport: {},
policyID: '',
formattedAmount: '',
buttonSize: CONST.DROPDOWN_BUTTON_SIZE.MEDIUM,
anchorAlignment: {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
Expand Down Expand Up @@ -189,6 +194,7 @@ class SettlementButton extends React.Component {
}}
options={this.getButtonOptionsFromProps()}
style={this.props.style}
buttonSize={this.props.buttonSize}
anchorAlignment={this.props.anchorAlignment}
/>
)}
Expand Down
17 changes: 17 additions & 0 deletions src/styles/StyleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,22 @@ function getCheckboxContainerStyle(size, borderRadius) {
};
}

/**
* Returns style object for the dropbutton height
* @param {String} buttonSize
* @returns {Object}
*/
function getDropDownButtonHeight(buttonSize) {
if (buttonSize === CONST.DROPDOWN_BUTTON_SIZE.LARGE) {
return {
height: variables.componentSizeLarge,
};
}
return {
height: variables.componentSizeNormal,
};
}

export {
getAvatarSize,
getAvatarWidthStyle,
Expand Down Expand Up @@ -1375,4 +1391,5 @@ export {
getMenuItemTextContainerStyle,
getDisabledLinkStyles,
getCheckboxContainerStyle,
getDropDownButtonHeight,
};
24 changes: 20 additions & 4 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,9 @@ const styles = {
},

buttonDivider: {
width: 1,
alignSelf: 'stretch',
backgroundColor: themeColors.appBG,
marginVertical: 1,
height: variables.dropDownButtonDividerHeight,
borderWidth: 0.7,
borderColor: themeColors.text,
},

noBorderRadius: {
Expand Down Expand Up @@ -3695,6 +3694,23 @@ const styles = {
willChange: 'transform',
},

dropDownButtonCartIconContainerPadding: {
paddingRight: 0,
dhairyasenjaliya marked this conversation as resolved.
Show resolved Hide resolved
paddingLeft: 0,
},

dropDownButtonArrowContain: {
marginLeft: 12,
marginRight: 14,
},

dropDownButtonCartIconView: {
borderTopRightRadius: variables.buttonBorderRadius,
borderBottomRightRadius: variables.buttonBorderRadius,
...flex.flexRow,
...flex.alignItemsCenter,
},

emojiPickerButtonDropdown: {
justifyContent: 'center',
backgroundColor: themeColors.activeComponentBG,
Expand Down
1 change: 1 addition & 0 deletions src/styles/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default {
addPaymentPopoverTopSpacing: 8,
addPaymentPopoverRightSpacing: 13,
anonymousReportFooterBreakpoint: 650,
dropDownButtonDividerHeight: 28,

// The height of the empty list is 14px (2px for borders and 12px for vertical padding)
// This is calculated based on the values specified in the 'getGoogleListViewStyle' function of the 'StyleUtils' utility
Expand Down
Loading