Skip to content

Commit

Permalink
fix: add ItemLayout for native, closes leather-io/issues#263
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed Aug 26, 2024
1 parent b3ad31a commit 29ff533
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/ui/src/components/box/hstack.native.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createBox } from '@shopify/restyle';

import { type Theme } from '../../theme-native';

export const HStack = createBox<Theme>();

HStack.defaultProps = {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
};
11 changes: 11 additions & 0 deletions packages/ui/src/components/box/stack.native.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createBox } from '@shopify/restyle';

import { type Theme } from '../../theme-native';

export const Stack = createBox<Theme>();

Stack.defaultProps = {
flex: 1,
flexDirection: 'column',
alignItems: 'center',
};
Original file line number Diff line number Diff line change
@@ -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<typeof ItemLayout> = {
title: 'Layout/ItemLayout',
component: ItemLayout,
tags: ['autodocs'],
argTypes: {},
parameters: {},
decorators: [
Story => (
<View style={{ height: 40 }}>
<Story />
</View>
),
],
};

export default meta;

export const ItemLayoutStory = {
args: {
captionLeft: 'Hello',
captionRight: 'World',
flagImg: <Box style={{ flex: 1, backgroundColor: 'green' }} />,
showChevron: true,
titleRight: 'Goodbye',
titleLeft: 'World',
},
argTypes: {},
} satisfies StoryObj<typeof ItemLayout>;
70 changes: 70 additions & 0 deletions packages/ui/src/components/item-layout/item-layout.native.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Flag img={flagImg} spacing="3">
<Box flex={1} alignItems="center" justifyContent="space-between">
<Stack
alignItems="flex-start"
justifyContent="space-between"
flexGrow={2}
overflow="hidden"
>
<HStack>{isValidElement(titleLeft) ? titleLeft : <Text>{titleLeft}</Text>}</HStack>
{isValidElement(captionLeft) ? (
captionLeft
) : (
<Text variant="caption01" color="ink.text-subdued">
{captionLeft}
</Text>
)}
</Stack>

<HStack gap="3">
<Stack alignItems="flex-end" gap="2" height={42}>
{isValidElement(titleRight) ? titleRight : <Text variant="label02">{titleRight}</Text>}
{isValidElement(captionRight) ? (
captionRight
) : (
<Text variant="caption01" color="ink.text-subdued">
{captionRight}
</Text>
)}
</Stack>
{showChevron && (
<ChevronUpIcon
color="ink.action-primary-default"
transform="rotate(90deg)"
variant="small"
/>
)}
</HStack>
</Box>
</Flag>
);
}
Empty file.

0 comments on commit 29ff533

Please sign in to comment.