Skip to content

Commit

Permalink
chore: add all comonent docs (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordmccord authored Oct 29, 2024
1 parent 9ac7c8e commit 234d271
Show file tree
Hide file tree
Showing 20 changed files with 314 additions and 1,781 deletions.
1 change: 1 addition & 0 deletions apps/native-ui-storybook/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const preview: Preview = {
],
'Components',
[
'All',
'Alert',
'Badge',
'Box',
Expand Down
21 changes: 12 additions & 9 deletions apps/native-ui-storybook/components/Icon/Icon.docs.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Meta, Canvas, Story } from '@storybook/blocks';
import { Meta, Canvas, Story, Primary, Controls } from '@storybook/blocks';
import * as IconStories from './Icon.stories';
import { GluestackIcon } from './Icon';
import { Center, Pressable, Text, NativeUIProvider } from '@utilitywarehouse/native-ui';
Expand All @@ -20,14 +20,19 @@ import { colorsCommon } from '@utilitywarehouse/colour-system';

Icons are often used to enhance the usability and accessibility of digital products by providing users with clear and intuitive visual cues. It serves as an intuitive and easily recognizable way to communicate with users.

- [Playground](#playground)
- [Usage](#usage)
- [Props](#props)
- [SVG & Custom Icons](#svg--custom-icons)
- [All Icons](#all-icons)

## Usage
## Playground

<Primary />

> This component should be wrapped in a `NativeUIProvider` component to ensure that the correct theme is applied.
<Controls />

## Usage

<Canvas>
<NativeUIProvider>
Expand Down Expand Up @@ -78,9 +83,6 @@ import {
} from '@utilitywarehouse/react-native-icons';

const MyComponent = () => {
const {
theme: { colors },
} = useStyles();
return (
<HStack space="lg">
<Icon as={ElectricityMediumIcon} color="$serviceElectricity" />
Expand All @@ -94,9 +96,10 @@ const MyComponent = () => {

## Props

| Name | Type | Description | Default |
| ---- | --------------------- | ----------------------------- | ------- |
| `as` | `React.ComponentType` | The icon component to render. | - |
| Name | Type | Description | Default |
| ------- | --------------------- | ----------------------------- | ------- |
| `as` | `React.ComponentType` | The icon component to render. | - |
| `color` | `string` | The color of the icon. | - |

## SVG & Custom Icons

Expand Down
39 changes: 28 additions & 11 deletions apps/native-ui-storybook/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
import React from 'react';

import { Icon, createIcon, HStack } from '@utilitywarehouse/native-ui';
import {
ElectricityMediumIcon,
MobileMediumIcon,
BroadbandMediumIcon,
InsuranceMediumIcon,
} from '@utilitywarehouse/react-native-icons';
import * as Icons from '@utilitywarehouse/react-native-icons';
import { Path, Rect } from 'react-native-svg';
import { colors } from '@utilitywarehouse/colour-system';
import { StoryFn } from '@storybook/react';

const IconBasic = () => {
const IconBasic: StoryFn<{ as: string; color: string }> = ({ as: icon, color }) => {
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
// @ts-expect-error - This is a playground
const as: ComponentType | undefined = icon === 'none' ? undefined : Icons[icon];
return (
<HStack space="lg">
<Icon as={ElectricityMediumIcon} color="$serviceElectricity" />
<Icon as={MobileMediumIcon} color="$serviceMobile" />
<Icon as={BroadbandMediumIcon} color="$serviceLandline" />
<Icon as={InsuranceMediumIcon} color="$serviceInsurance" />
{/* @ts-expect-error - This is a playground */}
<Icon as={as} color={colors[color]} />
</HStack>
);
};

IconBasic.argTypes = {
as: {
control: 'select',
options: [...Object.keys(Icons)],
description: 'The Icon that should render in as the component',
defaultValue: 'Helper text icon',
},
color: {
options: [...Object.keys(colors)],
control: 'select',
description: 'Background color of the Icon. Use the color name from the theme.',
},
};

IconBasic.args = {
as: Object.keys(Icons)[0],
color: 'grey1000',
};

export const GluestackIcon = createIcon({
viewBox: '0 0 32 32',
path: (
Expand Down
251 changes: 251 additions & 0 deletions apps/native-ui-storybook/docs/components/AllComponents.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
import React, { PropsWithChildren } from 'react';
import { ScrollView, View } from 'react-native';
import {
Button,
createStyleSheet,
HStack,
Text,
useStyles,
Heading,
Pressable,
Alert,
NativeUIProvider,
Center,
Checkbox,
FormField,
Input,
Icon,
IconButton,
List,
ListItem,
RadioGroup,
Radio,
Skeleton,
VStack,
Spinner,
} from '@utilitywarehouse/native-ui';
import { Actionsheet, Box } from '@utilitywarehouse/native-ui/lab';
import { useDarkMode } from 'storybook-dark-mode';
import {
ElectricityMediumIcon,
MobileMediumIcon,
BroadbandMediumIcon,
InsuranceMediumIcon,
ChevronRightMediumIcon,
} from '@utilitywarehouse/react-native-icons';

const ComponentWrapper: React.FC<PropsWithChildren<{ name: string; link: string }>> = ({
name,
link,
children,
}) => {
const { styles } = useStyles(stylesheet);
const navigate = () => {
if (window.top) {
window.top.location.href = link;
}
};
return (
<View style={styles.component}>
<View style={styles.componentWrap}>{children}</View>
<Pressable style={styles.textWrap} onPress={navigate}>
<Text style={styles.text} highlight>
{name}
</Text>
</Pressable>
</View>
);
};

const AllComponents: React.FC = () => {
const { styles } = useStyles(stylesheet);
const [showActionsheet, setShowActionsheet] = React.useState(false);
const toggleActionsheet = () => setShowActionsheet(!showActionsheet);
const colorScheme = useDarkMode() ? 'dark' : 'light';
const isDark = colorScheme === 'dark';
return (
<NativeUIProvider colorMode={colorScheme}>
<ScrollView contentContainerStyle={styles.container}>
<HStack wrap space="md">
<ComponentWrapper
name="Actionsheet (Lab)"
link="/?path=/docs/native-ui-components-lab-actionsheet--docs"
>
<Center flex={1}>
<Actionsheet isOpen={showActionsheet} onClose={toggleActionsheet}>
<Heading>Actionsheet</Heading>
<Text>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque sint facilis autem
quia expedita quasi consequuntur dolorum magnam, laboriosam recusandae iure quos
itaque cum officia repellat rem quas labore numquam?
</Text>
</Actionsheet>
<Button onPress={toggleActionsheet}>Show Actionsheet</Button>
</Center>
</ComponentWrapper>
<ComponentWrapper name="Alert" link="/?path=/docs/native-ui-components-alert--docs">
<Center flex={1}>
<Alert text="This is an alert" />
</Center>
</ComponentWrapper>
<ComponentWrapper name="Box (Lab)" link="/?path=/docs/native-ui-components-lab-box--docs">
<Center flex={1}>
<Box backgroundColor="$grey900" padding="$4" width={200} height={100}>
<Text color={isDark ? '$grey100' : '$white'} highlight>
This is a Box
</Text>
</Box>
</Center>
</ComponentWrapper>
<ComponentWrapper name="Button" link="/?path=/docs/native-ui-components-button--docs">
<Center flex={1}>
<Button variant="outline">Press me</Button>
</Center>
</ComponentWrapper>
<ComponentWrapper name="Center" link="/?path=/docs/native-ui-components-center--docs">
<Center flex={1}>
<Center backgroundColor="$grey900" padding="$4" width={200} height={100}>
<Text color={isDark ? '$grey100' : '$white'} highlight>
I am in the Center
</Text>
</Center>
</Center>
</ComponentWrapper>
<ComponentWrapper name="Checkbox" link="/?path=/docs/native-ui-components-checkbox--docs">
<Center flex={1}>
<Checkbox label="I'm a Checkbox" value="" />
</Center>
</ComponentWrapper>
<ComponentWrapper
name="Form Field"
link="/?path=/docs/native-ui-components-form-field--docs"
>
<Center flex={1}>
<FormField
validationStatus="invalid"
label="Label"
helperText="Helper text"
validText="Valid form field text"
invalidText="Invalid form field text"
>
<Input onChange={() => console.log('###')} placeholder="" />
</FormField>
</Center>
</ComponentWrapper>
<ComponentWrapper name="Heading" link="/?path=/docs/native-ui-components-heading--docs">
<Center flex={1}>
<Heading>This is a Heading</Heading>
</Center>
</ComponentWrapper>
<ComponentWrapper name="HStack" link="/?path=/docs/native-ui-components-hstack--docs">
<Center flex={1}>
<HStack space="md">
<Box w={40} h={40} bg="$cyan300" />
<Box w={40} h={40} bg="$cyan400" />
<Box w={40} h={40} bg="$cyan500" />
<Box w={40} h={40} bg="$cyan600" />
</HStack>
</Center>
</ComponentWrapper>
<ComponentWrapper name="Icons" link="/?path=/docs/native-ui-components-icons--docs">
<Center flex={1}>
<HStack space="lg">
<Icon as={ElectricityMediumIcon} color="$serviceElectricity" />
<Icon as={MobileMediumIcon} color="$serviceMobile" />
<Icon as={BroadbandMediumIcon} color="$serviceLandline" />
<Icon as={InsuranceMediumIcon} color="$serviceInsurance" />
</HStack>
</Center>
</ComponentWrapper>
<ComponentWrapper
name="Icon Button"
link="/?path=/docs/native-ui-components-iconbutton--docs"
>
<Center flex={1}>
<IconButton icon={ChevronRightMediumIcon} size="large" onPress={() => null} />
</Center>
</ComponentWrapper>
<ComponentWrapper name="List" link="/?path=/docs/native-ui-components-list--docs">
<Center flex={1}>
<List>
<ListItem text="List Item 1" divider onPress={() => console.log('item pressed')} />
<ListItem text="List Item 2" onPress={() => console.log('item pressed')} />
</List>
</Center>
</ComponentWrapper>
<ComponentWrapper name="Radio" link="/?path=/docs/native-ui-components-radio--docs">
<Center flex={1}>
<RadioGroup>
<Radio label="I'm a Radio" value="1" />
<Radio label="Me too" value="2" />
</RadioGroup>
</Center>
</ComponentWrapper>
<ComponentWrapper name="Skeleton" link="/?path=/docs/native-ui-components-skeleton--docs">
<Center flex={1}>
<HStack space="sm">
<Skeleton width={30} height={30} />
<VStack space="sm">
<Skeleton width={120} height={15} />
<Skeleton width={100} height={15} />
</VStack>
</HStack>
</Center>
</ComponentWrapper>
<ComponentWrapper name="Spinner" link="/?path=/docs/native-ui-components-spinner--docs">
<Center flex={1}>
<Spinner size="lg" />
</Center>
</ComponentWrapper>
<ComponentWrapper name="Text" link="/?path=/docs/native-ui-components-text--docs">
<Center flex={1}>
<Text>This is some Text</Text>
</Center>
</ComponentWrapper>
<ComponentWrapper name="VStack" link="/?path=/docs/native-ui-components-vstack--docs">
<Center flex={1}>
<VStack space="md">
<Box w={20} h={20} bg="$cyan300" />
<Box w={20} h={20} bg="$cyan400" />
<Box w={20} h={20} bg="$cyan500" />
<Box w={20} h={20} bg="$cyan600" />
</VStack>
</Center>
</ComponentWrapper>
</HStack>
</ScrollView>
</NativeUIProvider>
);
};

const stylesheet = createStyleSheet(({ radii, colorMode, colors, space, borderWidths }) => ({
container: {
gap: space['2'],
},
component: {
borderColor: colorMode === 'light' ? colors.grey100 : colors.grey400,
borderWidth: borderWidths['1'],
borderRadius: radii['lg'],
overflow: 'hidden',
glexGrow: 1,
height: 200,
flexBasis: {
xs: '100%',
md: 300,
},
},
componentWrap: {
padding: space['4'],
flexGrow: 1,
},
text: {},
textWrap: {
borderTopColor: colorMode === 'light' ? colors.grey100 : colors.grey400,
borderTopWidth: borderWidths['1'],
paddingHorizontal: space['4'],
paddingVertical: space['2'],
backgroundColor: colors.grey25,
},
}));

export default AllComponents;
1 change: 1 addition & 0 deletions apps/native-ui-storybook/docs/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as BackToTopButton } from './BackToTopButton';
export { default as ViewFigmaButton } from './ViewFigmaButton';
export { default as ScrollWrap } from './ScrollWrap';
export { default as VariantTitle } from './VariantTitle';
export { default as AllComponents } from './AllComponents';
Loading

0 comments on commit 234d271

Please sign in to comment.