-
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.
Merge branch 'main' into Rory-AutomatedThemeHookMigration
- Loading branch information
Showing
7 changed files
with
139 additions
and
79 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, {useCallback} from 'react'; | ||
import {GestureResponderEvent, PressableStateCallbackType, StyleProp, TextStyle, View, ViewStyle} from 'react-native'; | ||
import styles from '@styles/styles'; | ||
import * as StyleUtils from '@styles/StyleUtils'; | ||
import CONST from '@src/CONST'; | ||
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback'; | ||
import Text from './Text'; | ||
|
||
type BadgeProps = { | ||
/** Is Success type */ | ||
success?: boolean; | ||
|
||
/** Is Error type */ | ||
error?: boolean; | ||
|
||
/** Whether badge is clickable */ | ||
pressable?: boolean; | ||
|
||
/** Text to display in the Badge */ | ||
text: string; | ||
|
||
/** Text to display in the Badge */ | ||
environment?: string; | ||
|
||
/** Styles for Badge */ | ||
badgeStyles?: StyleProp<ViewStyle>; | ||
|
||
/** Styles for Badge Text */ | ||
textStyles?: StyleProp<TextStyle>; | ||
|
||
/** Callback to be called on onPress */ | ||
onPress: (event?: GestureResponderEvent | KeyboardEvent) => void; | ||
}; | ||
|
||
function Badge({success = false, error = false, pressable = false, text, environment = CONST.ENVIRONMENT.DEV, badgeStyles, textStyles, onPress = () => {}}: BadgeProps) { | ||
const textColorStyles = success || error ? styles.textWhite : undefined; | ||
const Wrapper = pressable ? PressableWithoutFeedback : View; | ||
|
||
const wrapperStyles: (state: PressableStateCallbackType) => StyleProp<ViewStyle> = useCallback( | ||
({pressed}) => [styles.badge, styles.ml2, StyleUtils.getBadgeColorStyle(success, error, pressed, environment === CONST.ENVIRONMENT.ADHOC), badgeStyles], | ||
[success, error, environment, badgeStyles], | ||
); | ||
|
||
return ( | ||
<Wrapper | ||
style={pressable ? wrapperStyles : wrapperStyles({focused: false, hovered: false, isDisabled: false, isScreenReaderActive: false, pressed: false})} | ||
onPress={onPress} | ||
role={pressable ? CONST.ACCESSIBILITY_ROLE.BUTTON : CONST.ACCESSIBILITY_ROLE.TEXT} | ||
accessibilityLabel={pressable ? text : undefined} | ||
aria-label={!pressable ? text : undefined} | ||
accessible={false} | ||
> | ||
<Text | ||
style={[styles.badgeText, textColorStyles, textStyles]} | ||
numberOfLines={1} | ||
> | ||
{text} | ||
</Text> | ||
</Wrapper> | ||
); | ||
} | ||
|
||
Badge.displayName = 'Badge'; | ||
|
||
export default Badge; |
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import styles from '@styles/styles'; | ||
import variables from '@styles/variables'; | ||
import Icon from './Icon'; | ||
import * as Expensicons from './Icon/Expensicons'; | ||
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback'; | ||
|
||
const propTypes = { | ||
/** Whether or not there is an error */ | ||
hasError: PropTypes.bool, | ||
|
||
/** Callback to be called on onPress */ | ||
onPress: PropTypes.func, | ||
}; | ||
|
||
const defaultProps = { | ||
hasError: false, | ||
onPress: () => {}, | ||
}; | ||
|
||
// Returns an SVG icon indicating that the user should attach a receipt | ||
function ReceiptEmptyState({hasError, onPress}) { | ||
return ( | ||
<PressableWithoutFeedback | ||
accessibilityRole="imagebutton" | ||
onPress={onPress} | ||
style={[styles.alignItemsCenter, styles.justifyContentCenter, styles.moneyRequestViewImage, styles.moneyRequestAttachReceipt, hasError && styles.borderColorDanger]} | ||
> | ||
<Icon | ||
src={Expensicons.EmptyStateAttachReceipt} | ||
width={variables.eReceiptIconWidth} | ||
height={variables.eReceiptIconHeight} | ||
fill="transparent" | ||
/> | ||
</PressableWithoutFeedback> | ||
); | ||
} | ||
|
||
ReceiptEmptyState.displayName = 'ReceiptEmptyState'; | ||
ReceiptEmptyState.propTypes = propTypes; | ||
ReceiptEmptyState.defaultProps = defaultProps; | ||
|
||
export default ReceiptEmptyState; |
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
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