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

[Categories] Add support for long category names #37389

Merged
merged 15 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/components/CategoryPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function CategoryPicker({selectedCategory, policyCategories, policyRecentlyUsedC
onSelectRow={onSubmit}
ListItem={RadioListItem}
initiallyFocusedOptionKey={selectedOptionKey}
isRowMultilineSupported
/>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function BaseSelectionList<TItem extends ListItem>(
onLayout,
customListHeader,
listHeaderWrapperStyle,
isRowMultilineSupported = false,
}: BaseSelectionListProps<TItem>,
inputRef: ForwardedRef<RNTextInput>,
) {
Expand Down Expand Up @@ -293,6 +294,7 @@ function BaseSelectionList<TItem extends ListItem>(
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
rightHandSideComponent={rightHandSideComponent}
keyForList={item.keyForList}
isMultilineSupported={isRowMultilineSupported}
/>
);
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/SelectionList/RadioListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function RadioListItem({
onDismissError,
shouldPreventDefaultFocusOnSelectRow,
rightHandSideComponent,
isMultilineSupported = false,
}: RadioListItemProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -44,9 +45,10 @@ function RadioListItem({
styles.optionDisplayName,
isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText,
styles.sidebarLinkTextBold,
styles.pre,
isMultilineSupported ? styles.preWrap : styles.pre,
item.alternateText ? styles.mb1 : null,
]}
numberOfLines={isMultilineSupported ? 2 : 1}
/>

{!!item.alternateText && (
Expand Down
9 changes: 9 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type CommonListItemProps<TItem> = {

/** Styles for the checkbox wrapper view if select multiple option is on */
selectMultipleStyle?: StyleProp<ViewStyle>;

/** Whether to wrap long text up to 2 lines */
isMultilineSupported?: boolean;
};

type ListItem = {
Expand Down Expand Up @@ -83,6 +86,9 @@ type ListItem = {

/** Whether this option should show subscript */
shouldShowSubscript?: boolean;

/** Whether to wrap long text up to 2 lines */
isMultilineSupported?: boolean;
};

type ListItemProps = CommonListItemProps<ListItem> & {
Expand Down Expand Up @@ -258,6 +264,9 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {

/** Styles for the list header wrapper */
listHeaderWrapperStyle?: StyleProp<ViewStyle>;

/** Whether to wrap long text up to 2 lines */
isRowMultilineSupported?: boolean;
};

type ItemLayout = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextWithTooltip/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react';
import Text from '@components/Text';
import type TextWithTooltipProps from './types';

function TextWithTooltip({text, textStyles}: TextWithTooltipProps) {
function TextWithTooltip({text, textStyles, numberOfLines = 1}: TextWithTooltipProps) {
return (
<Text
style={textStyles}
numberOfLines={1}
numberOfLines={numberOfLines}
>
{text}
</Text>
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextWithTooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type LayoutChangeEvent = {
target: HTMLElement;
};

function TextWithTooltip({text, shouldShowTooltip, textStyles}: TextWithTooltipProps) {
function TextWithTooltip({text, shouldShowTooltip, textStyles, numberOfLines = 1}: TextWithTooltipProps) {
const [showTooltip, setShowTooltip] = useState(false);

return (
Expand All @@ -17,7 +17,7 @@ function TextWithTooltip({text, shouldShowTooltip, textStyles}: TextWithTooltipP
>
<Text
style={textStyles}
numberOfLines={1}
numberOfLines={numberOfLines}
onLayout={(e) => {
const target = (e.nativeEvent as unknown as LayoutChangeEvent).target;
if (!shouldShowTooltip) {
Expand Down
8 changes: 8 additions & 0 deletions src/components/TextWithTooltip/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import type {StyleProp, TextStyle} from 'react-native';

type TextWithTooltipProps = {
/** The text to display */
text: string;

/** Whether to show the toolip text */
shouldShowTooltip: boolean;

/** Additional text styles */
textStyles?: StyleProp<TextStyle>;

/** Custom number of lines for text wrapping */
numberOfLines?: number;
};

export default TextWithTooltipProps;
Loading