-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add
ModuleNavigation
component (#251)
## Short description This PR adds the `ModuleNavigation` component ## List of changes proposed in this pull request - Added `ModuleNavigation` component - Added examples in the example app ## How to test Navigate to the Module screen and check that the component is correctly rendered ## Preview <img width="250" alt="Screenshot 2024-04-30 alle 11 06 02" src="https://github.com/pagopa/io-app-design-system/assets/6160324/da252a8f-5c88-4f30-890e-ea4ce9b78b39">
- Loading branch information
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
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,116 @@ | ||
import React from "react"; | ||
import { | ||
Image, | ||
ImageSourcePropType, | ||
ImageURISource, | ||
StyleSheet, | ||
View | ||
} from "react-native"; | ||
import Placeholder from "rn-placeholder"; | ||
import { | ||
IOListItemVisualParams, | ||
IOModuleStyles, | ||
IOSelectionListItemVisualParams, | ||
IOStyles, | ||
useIOTheme | ||
} from "../../core"; | ||
import { WithTestID } from "../../utils/types"; | ||
import { Badge } from "../badge"; | ||
import { IOIcons, Icon } from "../icons"; | ||
import { VSpacer } from "../spacer"; | ||
import { Chip, LabelSmallAlt } from "../typography"; | ||
import { | ||
PressableModuleBase, | ||
PressableModuleBaseProps | ||
} from "./PressableModuleBase"; | ||
|
||
type LoadingProps = { | ||
isLoading: true; | ||
}; | ||
|
||
type ImageProps = | ||
| { icon: IOIcons; image?: never } | ||
| { icon?: never; image: ImageURISource | ImageSourcePropType }; | ||
|
||
type BaseProps = { | ||
isLoading?: false; | ||
title: string; | ||
subtitle?: string; | ||
badge?: Badge; | ||
} & ImageProps & | ||
PressableModuleBaseProps; | ||
|
||
type ModuleNavigationProps = LoadingProps | BaseProps; | ||
|
||
export const ModuleNavigation = (props: WithTestID<ModuleNavigationProps>) => { | ||
const theme = useIOTheme(); | ||
|
||
if (props.isLoading) { | ||
return <ModuleNavigationSkeleton />; | ||
} | ||
|
||
const { icon, image, title, subtitle, onPress, badge, ...pressableProps } = | ||
props; | ||
|
||
const iconComponent = ( | ||
<> | ||
{icon && <Icon name={icon} size={24} color="grey-300" />} | ||
{image && ( | ||
<Image | ||
source={image} | ||
style={styles.image} | ||
accessibilityIgnoresInvertColors={true} | ||
/> | ||
)} | ||
</> | ||
); | ||
|
||
return ( | ||
<PressableModuleBase {...pressableProps} onPress={onPress}> | ||
<View>{iconComponent}</View> | ||
<View style={{ flexGrow: 1, flexShrink: 1, paddingHorizontal: 8 }}> | ||
<LabelSmallAlt | ||
color="blueIO-500" | ||
numberOfLines={2} | ||
lineBreakMode="middle" | ||
> | ||
{title} | ||
</LabelSmallAlt> | ||
{subtitle && <Chip color="grey-700">{subtitle}</Chip>} | ||
</View> | ||
<View> | ||
{badge ? ( | ||
<Badge {...badge} /> | ||
) : onPress ? ( | ||
<Icon | ||
name="chevronRightListItem" | ||
color={theme["interactiveElem-default"]} | ||
size={IOListItemVisualParams.chevronSize} | ||
/> | ||
) : null} | ||
</View> | ||
</PressableModuleBase> | ||
); | ||
}; | ||
|
||
const ModuleNavigationSkeleton = () => ( | ||
<View style={IOModuleStyles.button}> | ||
<View style={[IOStyles.row, IOStyles.alignCenter]}> | ||
<Placeholder.Box animate="fade" width={24} height={24} radius={8} /> | ||
<View style={{ paddingHorizontal: 8 }}> | ||
<Placeholder.Box animate="fade" width={96} height={19} radius={8} /> | ||
<VSpacer size={4} /> | ||
<Placeholder.Box animate="fade" width={180} height={16} radius={8} /> | ||
</View> | ||
</View> | ||
<Placeholder.Box animate="fade" width={64} height={22} radius={8} /> | ||
</View> | ||
); | ||
|
||
const styles = StyleSheet.create({ | ||
image: { | ||
width: IOSelectionListItemVisualParams.iconSize, | ||
height: IOSelectionListItemVisualParams.iconSize, | ||
resizeMode: "contain" | ||
} | ||
}); |
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