From 29ff533fdb7d208242a275054ffb76d3d59cfe0f Mon Sep 17 00:00:00 2001 From: Pete Watters <2938440+pete-watters@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:57:45 +0100 Subject: [PATCH] fix: add ItemLayout for native, closes leather-io/issues#263 --- .../ui/src/components/box/hstack.native.tsx | 11 +++ .../ui/src/components/box/stack.native.tsx | 11 +++ .../item-layout.native.stories.tsx | 35 ++++++++++ .../item-layout/item-layout.native.tsx | 70 +++++++++++++++++++ .../item-layout/item-layout.shared.tsx | 0 5 files changed, 127 insertions(+) create mode 100644 packages/ui/src/components/box/hstack.native.tsx create mode 100644 packages/ui/src/components/box/stack.native.tsx create mode 100644 packages/ui/src/components/item-layout/item-layout.native.stories.tsx create mode 100644 packages/ui/src/components/item-layout/item-layout.native.tsx create mode 100644 packages/ui/src/components/item-layout/item-layout.shared.tsx diff --git a/packages/ui/src/components/box/hstack.native.tsx b/packages/ui/src/components/box/hstack.native.tsx new file mode 100644 index 000000000..ef76e1845 --- /dev/null +++ b/packages/ui/src/components/box/hstack.native.tsx @@ -0,0 +1,11 @@ +import { createBox } from '@shopify/restyle'; + +import { type Theme } from '../../theme-native'; + +export const HStack = createBox(); + +HStack.defaultProps = { + flex: 1, + flexDirection: 'row', + alignItems: 'center', +}; diff --git a/packages/ui/src/components/box/stack.native.tsx b/packages/ui/src/components/box/stack.native.tsx new file mode 100644 index 000000000..64dbbee77 --- /dev/null +++ b/packages/ui/src/components/box/stack.native.tsx @@ -0,0 +1,11 @@ +import { createBox } from '@shopify/restyle'; + +import { type Theme } from '../../theme-native'; + +export const Stack = createBox(); + +Stack.defaultProps = { + flex: 1, + flexDirection: 'column', + alignItems: 'center', +}; diff --git a/packages/ui/src/components/item-layout/item-layout.native.stories.tsx b/packages/ui/src/components/item-layout/item-layout.native.stories.tsx new file mode 100644 index 000000000..7cc1fc247 --- /dev/null +++ b/packages/ui/src/components/item-layout/item-layout.native.stories.tsx @@ -0,0 +1,35 @@ +import { View } from 'react-native'; + +import type { Meta, StoryObj } from '@storybook/react'; + +import { Box } from '../box/box.native'; +import { ItemLayout } from './item-layout.native'; + +const meta: Meta = { + title: 'Layout/ItemLayout', + component: ItemLayout, + tags: ['autodocs'], + argTypes: {}, + parameters: {}, + decorators: [ + Story => ( + + + + ), + ], +}; + +export default meta; + +export const ItemLayoutStory = { + args: { + captionLeft: 'Hello', + captionRight: 'World', + flagImg: , + showChevron: true, + titleRight: 'Goodbye', + titleLeft: 'World', + }, + argTypes: {}, +} satisfies StoryObj; diff --git a/packages/ui/src/components/item-layout/item-layout.native.tsx b/packages/ui/src/components/item-layout/item-layout.native.tsx new file mode 100644 index 000000000..4e8b36f7a --- /dev/null +++ b/packages/ui/src/components/item-layout/item-layout.native.tsx @@ -0,0 +1,70 @@ +import { ReactNode, isValidElement } from 'react'; + +import { Flag } from '../../components/flag/flag.native'; +import { Text } from '../../components/text/text.native'; +import { ChevronUpIcon } from '../../icons/chevron-up-icon.native'; +import { Box } from '../box/box.native'; +import { HStack } from '../box/hstack.native'; +import { Stack } from '../box/stack.native'; + +export interface ItemLayoutProps { + captionLeft: ReactNode; + captionRight?: ReactNode; + flagImg: ReactNode; + isDisabled?: boolean; + isSelected?: boolean; + showChevron?: boolean; + titleLeft: ReactNode; + titleRight: ReactNode; +} + +export function ItemLayout({ + captionLeft, + captionRight, + flagImg, + showChevron, + titleLeft, + titleRight, +}: ItemLayoutProps) { + return ( + + + + {isValidElement(titleLeft) ? titleLeft : {titleLeft}} + {isValidElement(captionLeft) ? ( + captionLeft + ) : ( + + {captionLeft} + + )} + + + + + {isValidElement(titleRight) ? titleRight : {titleRight}} + {isValidElement(captionRight) ? ( + captionRight + ) : ( + + {captionRight} + + )} + + {showChevron && ( + + )} + + + + ); +} diff --git a/packages/ui/src/components/item-layout/item-layout.shared.tsx b/packages/ui/src/components/item-layout/item-layout.shared.tsx new file mode 100644 index 000000000..e69de29bb