-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
graemehouston
committed
Aug 31, 2024
1 parent
241d4d9
commit db36922
Showing
9 changed files
with
226 additions
and
142 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
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 |
---|---|---|
@@ -1,26 +1,37 @@ | ||
import { Meta, StoryFn } from "@storybook/react"; | ||
import React from "react"; | ||
import BadgeTile from "./index"; | ||
import React from 'react'; | ||
import { StoryFn, Meta } from '@storybook/react'; | ||
import BadgeTile from './index'; | ||
import { TileHeight, TileType } from '../../../types/tile'; | ||
|
||
export default { | ||
title: "components/organisms/BadgeTile", | ||
title: 'components/organisms/BadgeTile', | ||
component: BadgeTile, | ||
} as Meta; | ||
|
||
const Template: StoryFn<typeof BadgeTile> = (args) => <BadgeTile {...args} />; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
configuration: { | ||
badgeId: "a7a3e1f2-be70-4e5a-a4b7-0d9870c56f0d", | ||
badge: { | ||
id: "a7a3e1f2-be70-4e5a-a4b7-0d9870c56f0d", | ||
name: "Top Shopper", | ||
description: | ||
"You’ve earned the Top Shopper badge 2 times! Last awarded on 1 Jan 2024.", | ||
artworkUrl: "https://picsum.photos/200/300", | ||
createdAt: "2024-08-15T13:06:14.583Z", | ||
updatedAt: "2024-08-15T13:06:14.583Z", | ||
tile: { | ||
id: '1', | ||
type: TileType.Badge, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
tenantId: 'tenant1', | ||
visibilityCriteria: 'all', | ||
tileHeight: TileHeight.Full, | ||
configuration: { | ||
badgeId: 'a7a3e1f2-be70-4e5a-a4b7-0d9870c56f0d', | ||
badge: { | ||
id: 'a7a3e1f2-be70-4e5a-a4b7-0d9870c56f0d', | ||
name: 'Top Shopper', | ||
description: | ||
'You’ve earned the Top Shopper badge 2 times! Last awarded on 1 Jan 2024.', | ||
artworkUrl: | ||
'https://images.pexels.com/photos/1362534/pexels-photo-1362534.jpeg', | ||
createdAt: '2024-08-15T13:06:14.583Z', | ||
updatedAt: '2024-08-15T13:06:14.583Z', | ||
}, | ||
}, | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,56 +1,94 @@ | ||
import { BadgeTileConfig } from "../../../types/tile"; | ||
import { createResponsiveStyle } from "../../../utils/responsiveHelper"; | ||
import { Icon, Text, BaseTile } from "../../atoms"; | ||
import { useSectionContext } from "../Section"; | ||
|
||
import React from "react"; | ||
import { Image, StyleSheet, View } from "react-native"; | ||
import React, { FC } from 'react'; | ||
import { Image, StyleSheet, View } from 'react-native'; | ||
import { BaseTile, Icon, Text } from '../../atoms'; | ||
import { Tile, TileConfig } from '../../../types/tile'; | ||
import { useTileContext } from '../../atoms/BaseTile'; | ||
import { ImagePropsNoSource } from '../../../types/common'; | ||
import { createResponsiveStyle } from '../../../utils/responsiveHelper'; | ||
import { Badge } from '../../../types/wll'; | ||
import { useTheme } from '../../../context/ThemeContext'; | ||
|
||
type BadgeTileProps = { | ||
configuration: BadgeTileConfig; | ||
tile: Tile; | ||
}; | ||
|
||
type BadgeTileComponent = FC<BadgeTileProps> & { | ||
Title: FC; | ||
Body: FC; | ||
Image: FC<ImagePropsNoSource>; | ||
}; | ||
|
||
const BadgeTile: React.FC<BadgeTileProps> = ({ configuration }) => { | ||
const { loading } = useSectionContext(); | ||
const { badge } = configuration; | ||
const BadgeTileInner: FC<BadgeTileProps> = ({ tile }) => { | ||
const { theme } = useTheme(); | ||
return ( | ||
<Tile> | ||
<View style={styles.imageContainer}> | ||
<Image source={{ uri: badge?.artworkUrl }} style={styles.image} /> | ||
</View> | ||
<BaseTile tile={tile}> | ||
<BadgeTile.Image style={styles.image} /> | ||
<View style={styles.textContainer}> | ||
<View | ||
style={{ | ||
flexDirection: "row", | ||
alignItems: "center", | ||
justifyContent: "space-between", | ||
}} | ||
> | ||
<Text variant="title">{badge?.name}</Text> | ||
<Icon name="ChevronRight" size={16} color="#666" /> | ||
<View style={styles.row}> | ||
<BadgeTile.Title /> | ||
<Icon | ||
name="ChevronRight" | ||
size={16} | ||
color={theme.derivedSurfaceText[20]} | ||
/> | ||
</View> | ||
<Text variant="body">{badge?.description}</Text> | ||
<BadgeTile.Body /> | ||
</View> | ||
</Tile> | ||
</BaseTile> | ||
); | ||
}; | ||
|
||
const BadgeTileImage: FC<ImagePropsNoSource> = (props) => { | ||
const tile = useTileContext(); | ||
const { badge } = tile.configuration as TileConfig & { badge?: Badge }; | ||
if (!badge) return null; | ||
return <Image {...props} source={{ uri: badge.artworkUrl }} />; | ||
}; | ||
|
||
const BadgeTileTitle: FC = (props) => { | ||
const tile = useTileContext(); | ||
const { badge } = tile.configuration as TileConfig & { badge?: Badge }; | ||
if (!badge) return null; | ||
return ( | ||
<Text variant="title" {...props}> | ||
{badge.name} | ||
</Text> | ||
); | ||
}; | ||
|
||
const BadgeTileBody: FC = (props) => { | ||
const tile = useTileContext(); | ||
const { badge } = tile.configuration as TileConfig & { badge?: Badge }; | ||
if (!badge) return null; | ||
return ( | ||
<Text variant="body" {...props}> | ||
{badge.description} | ||
</Text> | ||
); | ||
}; | ||
|
||
export const BadgeTile = BadgeTileInner as BadgeTileComponent; | ||
|
||
BadgeTile.Image = BadgeTileImage; | ||
BadgeTile.Title = BadgeTileTitle; | ||
BadgeTile.Body = BadgeTileBody; | ||
|
||
const styles = StyleSheet.create({ | ||
image: { | ||
width: "100%", | ||
height: "100%", | ||
position: "absolute", | ||
}, | ||
imageContainer: { | ||
width: "100%", | ||
flex: 1, | ||
position: "relative", | ||
overflow: "hidden", | ||
}, | ||
textContainer: createResponsiveStyle({ | ||
padding: [8, 10, 12], | ||
paddingHorizontal: [8, 8, 12], | ||
flex: 1, | ||
}), | ||
image: createResponsiveStyle({ | ||
width: '100%', | ||
flexBasis: '50%', | ||
marginBottom: [8, 8, 12], | ||
}), | ||
row: createResponsiveStyle({ | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
marginBottom: [4, 4, 8], | ||
}), | ||
}); | ||
|
||
export default BadgeTile; |
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,3 @@ | ||
import { ImageProps } from 'react-native'; | ||
|
||
export type ImagePropsNoSource = Omit<ImageProps, 'source'>; |
Oops, something went wrong.