Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
edited storybook Checkbox component
Browse files Browse the repository at this point in the history
  • Loading branch information
2unbini committed Aug 31, 2021
1 parent b1049e7 commit 275f855
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 40 deletions.
44 changes: 44 additions & 0 deletions docs/src/components/Checkbox/Basic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
Checkbox,
LoadingIndicator,
ThemeProvider,
ThemeType,
useTheme,
} from 'dooboo-ui';
import React, {FC, useState} from 'react';

import {View} from 'react-native';
import {useFonts} from 'expo-font';

const Component: FC = () => {
const [checked, setChecked] = useState<boolean>(false);
const {theme} = useTheme();

const [fontsLoaded] = useFonts({
IcoMoon: require('../../assets/doobooui.ttf'),
});

if (!fontsLoaded) return <LoadingIndicator />;

return (
<View
style={{
backgroundColor: theme.background,
flex: 1,
alignSelf: 'stretch',
flexDirection: 'row',
justifyContent: 'center',
padding: 5,
}}>
<Checkbox checked={checked} onPress={() => setChecked(!checked)} />
</View>
);
};

export const Basic: FC<{themeType: ThemeType}> = ({themeType}) => {
return (
<ThemeProvider initialThemeType={themeType}>
<Component />
</ThemeProvider>
);
};
159 changes: 129 additions & 30 deletions docs/src/components/Checkbox/Checkbox.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {Meta, Story, Canvas} from '@storybook/addon-docs/blocks';
import {ThemeProvider} from 'dooboo-ui';
import {Default, LeftElement, RightElement} from './index';
import {Basic, Solid, Disabled, LeftElement, RightElement} from './index';

<Meta title="Components/Checkbox" />

# Checkbox

> [Checkbox] component with default styles with animation.
> [Checkbox] component that can be used inside the product. Has basic feature like `disabled` state, can apply different color with `type` prop, and also can put the extra element to the `left` and `right` side of the checkbox.
<br />

## Usage

Expand All @@ -18,46 +20,143 @@ import {Checkbox} from 'dooboo-ui';

## Props

| | Types | Description |
| ---------------------- | ---------------------------------------- | --------------------------------------- |
| testID? | `string` | |
| indicatorColor? | `string` | |
| loading? | `boolean` | |
| disabled? | `boolean` | |
| style? | `StyleProp<ViewStyle>` | root `ViewStyle` |
| styles? | `Styles` | List of all style props within [Button] |
| leftElement? | `ReactElement` | Extra element to place on the left |
| rightElement? | `ReactElement` | Extra element to place on the right |
| activeOpacity? | `TouchableOpacityProps['activeOpacity']` | |
| text? | `string` | |
| onPress? | `TouchableOpacityProps['onPress']` | |
| touchableOpacityProps? | `Partial<TouchableOpacityProps>` | |
| textProps? | `Partial<TextProps>` | |
| type? | `ButtonType` | |
| size? | `ButtonSize` | |
| | Necessary | Types | Description | Default |
| ---------------------- | ----------- | ---------------------------------------- | ---------------------------------------------- | -------- |
| onPress? | | `() => void` | | |
| style? | | `StyleProp<ViewStyle>` | root `ViewStyle` | |
| styles? | | `Styles` | List of all style props within [Checkbox] | |
| type? | | `CheckboxType` | | primary |
| disabled? | | `boolean` | | |
| theme? | | `DoobooTheme` | | |
| chekced? | | `boolean` | | |
| leftElement? | | `ReactElement` | Extra element to place on the left | |
| rightElement? | | `ReactElement` | Extra element to place on the right | |


<br/>

## Demo

### Default Checkbox
### Basic Style
```tsx
<Checkbox text="check" checked={checked} onPress={() => setChecked(!checked)} />
```

<Basic themeType="light"/>
<Basic themeType="dark"/>
<br/>


### Solid Color Types
`primary` `secondary` `success` `warning` `info` `danger`

The `type` prop can generate different color of Checkbox. The default value of type is `primary`.

```tsx
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
type="primary"
/>
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
type="secondary"
/>
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
type="success"
/>
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
type="warning"
/>
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
type="info"
/>
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
type="danger"
/>
```

<Solid themeType="light" />
<Solid themeType="dark" />
<br/>


### Disabled Checkbox
The `disabled` prop can generate disabled Checkbox which is not pressable.

It can't apply `type` prop at the same time.

#### light
<Default themeType="light"/>
```tsx
<Checkbox disabled />
```

<Disabled themeType="light" />
<Disabled themeType="dark" />
<br/>

#### dark
<Default themeType="dark"/>

### Checkbox with leftElement
The `leftElement` prop can generate Checkbox following behind the element.

#### light
<LeftElement themeType="light"/>
It can be used with the `type` prop.

#### dark
```tsx
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
leftElement={<StyledText>Hello this is a checkbox</StyledText>}
/>
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
leftElement={<StyledText>Hello this is a checkbox</StyledText>}
/>
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
leftElement={<StyledText>Hello this is a checkbox</StyledText>}
/>
```

<LeftElement themeType="light"/>
<LeftElement themeType="dark"/>
<br/>


### Checkbox with rightElement

#### light
<RightElement themeType="light"/>
The `rightElement` prop can generate Checkbox in front of the element.

It can be used with the `type` prop.

```tsx
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
rightElement={<StyledText>Hello this is a checkbox</StyledText>}
/>
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
rightElement={<StyledText>Hello this is a checkbox</StyledText>}
/>
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
rightElement={<StyledText>Hello this is a checkbox</StyledText>}
/>
```

#### dark
<RightElement themeType="light"/>
<RightElement themeType="dark"/>
<br/>

43 changes: 43 additions & 0 deletions docs/src/components/Checkbox/Disabled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
Checkbox,
LoadingIndicator,
ThemeProvider,
ThemeType,
useTheme,
} from 'dooboo-ui';
import React, {FC} from 'react';

import {View} from 'react-native';
import {useFonts} from 'expo-font';

const Component: FC = () => {
const {theme} = useTheme();

const [fontsLoaded] = useFonts({
IcoMoon: require('../../assets/doobooui.ttf'),
});

if (!fontsLoaded) return <LoadingIndicator />;

return (
<View
style={{
backgroundColor: theme.background,
flex: 1,
alignSelf: 'stretch',
flexDirection: 'row',
justifyContent: 'center',
padding: 5,
}}>
<Checkbox disabled />
</View>
);
};

export const Disabled: FC<{themeType: ThemeType}> = ({themeType}) => {
return (
<ThemeProvider initialThemeType={themeType}>
<Component />
</ThemeProvider>
);
};
3 changes: 2 additions & 1 deletion docs/src/components/Checkbox/LeftElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ const Component: FC = () => {
backgroundColor: theme.background,
flex: 1,
alignSelf: 'stretch',

flexDirection: 'column',
alignItems: 'center',
padding: 10,
}}>
<Checkbox
checked={checked}
Expand Down
2 changes: 2 additions & 0 deletions docs/src/components/Checkbox/RightElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const Component: FC = () => {
backgroundColor: theme.background,
flex: 1,
alignSelf: 'stretch',
alignItems: 'center',
padding: 10,
}}>
<View style={{flexDirection: 'column'}}>
<Checkbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ const Component: FC = () => {
backgroundColor: theme.background,
flex: 1,
alignSelf: 'stretch',

flexDirection: 'row',
justifyContent: 'center',
padding: 5,
}}>
<Checkbox checked={checked} onPress={() => setChecked(!checked)} />
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
type="primary"
/>
<View style={{width: 8}} />
<Checkbox
checked={checked}
Expand Down Expand Up @@ -60,16 +65,11 @@ const Component: FC = () => {
onPress={() => setChecked(!checked)}
type="danger"
/>
<Checkbox
checked={checked}
onPress={() => setChecked(!checked)}
disabled
/>
</View>
);
};

export const Default: FC<{themeType: ThemeType}> = ({themeType}) => {
export const Solid: FC<{themeType: ThemeType}> = ({themeType}) => {
return (
<ThemeProvider initialThemeType={themeType}>
<Component />
Expand Down
4 changes: 3 additions & 1 deletion docs/src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './Default';
export * from './Basic';
export * from './Disabled';
export * from './LeftElement';
export * from './RightElement';
export * from './Solid';

0 comments on commit 275f855

Please # to comment.