Skip to content
Open
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
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
8 changes: 7 additions & 1 deletion src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export type Props = $Omit<React.ComponentProps<typeof Surface>, 'mode'> & {
* Sets additional distance outside of element in which a press can be detected.
*/
hitSlop?: TouchableRippleProps['hitSlop'];
/**
* Label text number Of Lines of the button.
*/
numberOfLines?: number;
style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
/**
* Style for the button text.
Expand Down Expand Up @@ -197,6 +201,7 @@ const Button = (
onPressOut,
onLongPress,
delayLongPress,
numberOfLines,
style,
theme: themeOverrides,
uppercase: uppercaseProp,
Expand Down Expand Up @@ -282,6 +287,7 @@ const Button = (

const borderRadius = (isV3 ? 5 : 1) * roundness;
const iconSize = isV3 ? 18 : 16;
const NumberOfLines = numberOfLines ? numberOfLines : 1;

const { backgroundColor, borderColor, textColor, borderWidth } =
getButtonColors({
Expand Down Expand Up @@ -401,7 +407,7 @@ const Button = (
<Text
variant="labelLarge"
selectable={false}
numberOfLines={1}
numberOfLines={NumberOfLines}
testID={`${testID}-text`}
style={[
styles.label,
Expand Down
22 changes: 19 additions & 3 deletions src/components/SegmentedButtons/SegmentedButtonItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getSegmentedButtonDensityPadding,
} from './utils';
import { useInternalTheme } from '../../core/theming';
import CrossFadeIcon from '../CrossFadeIcon';
import type { IconSource } from '../Icon';
import Icon from '../Icon';
import TouchableRipple, {
Expand All @@ -36,6 +37,10 @@ export type Props = {
* Icon to display for the `SegmentedButtonItem`.
*/
icon?: IconSource;
/**
* Whether an icon change is animated.
*/
animated?: boolean;
/**
* @supported Available in v5.x with theme version 3
* Custom color for unchecked Text and Icon.
Expand Down Expand Up @@ -75,6 +80,10 @@ export type Props = {
* Label text of the button.
*/
label?: string;
/**
* Label text number of lines of the button.
*/
numberOfLines?: number;
/**
* Button segment.
*/
Expand Down Expand Up @@ -112,6 +121,7 @@ export type Props = {

const SegmentedButtonItem = ({
checked,
animated = false,
accessibilityLabel,
disabled,
style,
Expand All @@ -124,6 +134,7 @@ const SegmentedButtonItem = ({
icon,
testID,
label,
numberOfLines,
onPress,
segment,
density = 'regular',
Expand Down Expand Up @@ -209,7 +220,8 @@ const SegmentedButtonItem = ({
: theme.fonts.labelLarge),
color: textColor,
};

const IconComponent = animated ? CrossFadeIcon : Icon;
const NumberOfLines = numberOfLines ? numberOfLines : 1;
return (
<View style={[buttonStyle, styles.button, style]}>
<TouchableRipple
Expand Down Expand Up @@ -237,14 +249,18 @@ const SegmentedButtonItem = ({
) : null}
{showIcon ? (
<Animated.View testID={`${testID}-icon`} style={iconStyle}>
<Icon source={icon} size={iconSize} color={textColor} />
<IconComponent
color={textColor}
source={icon ? icon : 'progress-question'}
size={iconSize}
/>
</Animated.View>
) : null}
<Text
variant="labelLarge"
style={[styles.label, labelTextStyle, labelStyle]}
selectable={false}
numberOfLines={1}
numberOfLines={NumberOfLines}
maxFontSizeMultiplier={labelMaxFontSizeMultiplier}
testID={`${testID}-label`}
>
Expand Down
5 changes: 5 additions & 0 deletions src/components/SegmentedButtons/SegmentedButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type Props<T extends string = string> = {
* - `icon`: icon to display for the item
* - `disabled`: whether the button is disabled
* - `accessibilityLabel`: acccessibility label for the button. This is read by the screen reader when the user taps the button.
* - `numberOfLines`: label text number of lines of the button
* - `checkedColor`: custom color for checked Text and Icon
* - `uncheckedColor`: custom color for unchecked Text and Icon
* - `onPress`: callback that is called when button is pressed
Expand All @@ -66,6 +67,7 @@ export type Props<T extends string = string> = {
icon?: IconSource;
disabled?: boolean;
accessibilityLabel?: string;
numberOfLines?: number;
checkedColor?: string;
uncheckedColor?: string;
onPress?: (event: GestureResponderEvent) => void;
Expand All @@ -79,6 +81,7 @@ export type Props<T extends string = string> = {
* Density is applied to the height, to allow usage in denser UIs
*/
density?: 'regular' | 'small' | 'medium' | 'high';
animated?: boolean;
style?: StyleProp<ViewStyle>;
theme?: ThemeProp;
} & ConditionalValue<T>;
Expand Down Expand Up @@ -132,6 +135,7 @@ const SegmentedButtons = <T extends string = string>({
buttons,
multiSelect,
density,
animated,
style,
theme: themeOverrides,
}: Props<T>) => {
Expand Down Expand Up @@ -172,6 +176,7 @@ const SegmentedButtons = <T extends string = string>({
{...item}
key={i}
checked={checked}
animated={animated}
segment={segment}
density={density}
onPress={onPress}
Expand Down