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

[IOBP-429] listItemHeader value variant #157

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 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
21 changes: 21 additions & 0 deletions example/src/pages/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
IOThemeContext,
Icon,
ListItemAction,
ListItemAmount,
ListItemHeader,
ListItemInfo,
ListItemInfoCopy,
Expand Down Expand Up @@ -73,6 +74,15 @@ export const ListItems = () => {
</H2>
{renderListItemHeader()}

<H2
color={theme["textHeading-default"]}
weight={"SemiBold"}
style={{ marginBottom: 16, marginTop: 16 }}
>
ListItemAmount
</H2>
{renderListItemAmount()}

<H2
color={theme["textHeading-default"]}
weight={"SemiBold"}
Expand Down Expand Up @@ -489,6 +499,17 @@ const renderListItemHeader = () => (
</ComponentViewerBox>
);

const renderListItemAmount = () => (
<ComponentViewerBox name="ListItemAmount">
<ListItemAmount label="Amount" valueString="€ 1.000,00" />
<ListItemAmount
iconName="creditCard"
label="Amount with card "
valueString="€ 1.000,00"
/>
</ComponentViewerBox>
);

/* LIST ITEM TRANSACTION */

/* Mock assets */
Expand Down
95 changes: 95 additions & 0 deletions src/components/listitems/ListItemAmount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React, { ComponentProps, useMemo } from "react";
import { View } from "react-native";
import {
IOListItemStyles,
IOListItemVisualParams,
IOSpacingScale,
IOStyles,
useIOTheme
} from "../../core";
import { WithTestID } from "../../utils/types";
import { IOIcons, Icon } from "../icons";
import { H3, H6 } from "../typography";

type ValueProps = ComponentProps<typeof H3>;

type IconProps =
| {
iconName: IOIcons;
iconColor?: ComponentProps<typeof Icon>["color"];
}
| { iconName?: never; iconColor?: never };

export type ListItemAmount = WithTestID<{
label: string;
valueElementProps?: ValueProps;
valueString: string;
// Accessibility
accessibilityLabel?: string;
}> &
IconProps;

const iconMargin: IOSpacingScale = 8;

export const ListItemAmount = ({
label,
iconName,
iconColor,
valueElementProps,
valueString,
accessibilityLabel,
testID
}: ListItemAmount) => {
const theme = useIOTheme();

const listItemAccessibilityLabel = useMemo(
() => (accessibilityLabel ? accessibilityLabel : `${label}`),
[label, accessibilityLabel]
);

const itemInfoTextComponent = (
<View
accessible={false}
importantForAccessibility={"no-hide-descendants"}
accessibilityElementsHidden={false}
>
<H6 weight="Regular" color={theme["textBody-tertiary"]}>
{label}
</H6>
</View>
);

return (
<View
style={IOListItemStyles.listItem}
testID={testID}
accessible
accessibilityLabel={listItemAccessibilityLabel}
>
<View style={IOListItemStyles.listItemInner}>
{iconName && (
<View style={{ marginRight: iconMargin }}>
<Icon
name={iconName}
color={iconColor ?? theme["icon-decorative"]}
size={IOListItemVisualParams.iconSize}
/>
</View>
)}
<View style={IOStyles.flex}>{itemInfoTextComponent}</View>
<H3
weight={"SemiBold"}
color={"black"}
{...valueElementProps}
accessibilityLabel={`${listItemAccessibilityLabel}; ${
valueElementProps?.accessibilityLabel ?? ""
}`}
>
{valueString}
</H3>
</View>
</View>
);
};

export default ListItemAmount;
1 change: 1 addition & 0 deletions src/components/listitems/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from "./ListItemSwitch";
export * from "./ListItemCheckbox";
export * from "./ListItemRadio";
export * from "./ListItemRadioWithAmount";
export * from "./ListItemAmount";
Loading