Skip to content

Commit

Permalink
Add documentation for the DateInput component
Browse files Browse the repository at this point in the history
  • Loading branch information
maurobender committed Dec 19, 2022
1 parent cdbf31d commit c32da1d
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 62 deletions.
231 changes: 231 additions & 0 deletions docs/docs/components/forms/date_input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import {VStack, Icon, DateInput} from '@amalgama/embassy-ui'
import CodePreview from '@site/src/components/CodePreview'
import Feather from 'react-native-vector-icons/Feather';
import ExampleTextInput from '@site/src/components/ExampleTextInput'
import { useState } from 'react';

# DateInput

The `DateInput` component allows a user to provide a date by inputing it directly to the field or selecting it from a date picker.

## Example

<CodePreview browserOnly>
<DateInput width="300px" />
</CodePreview>

```jsx
import { DateInput } from '@amalgama/embassy-ui';

<DateInput width="300px" />
```

## Peer Dependencies

The `DateInput` component requires different dependencies depending if it's being used in a ReactNative or ReactJS project.

### ReactNative
For ReactNative you must install the [react-native-date-picker](https://github.com/henninghall/react-native-date-picker) package for the date picker to work correctly.

```bash
yarn add react-native-date-picker
```

### ReactJS
For ReactJS you must install the [react-calendar](https://github.com/wojtekmaj/react-calendar) package for the date picker to work correctly.

```bash
yarn add react-calendar
```

## Props

Besides the props from `TextInput`, the `DateInput` has the following props:

### format
The format to be used for the date string. By default the default format for the selected `locale` will be used. For a complete list of the format tokens you can check [here](https://date-fns.org/v2.29.3/docs/format).

| TYPE | REQUIRED | DEFAULT |
| ---- | -------- | ------- |
| `string` | No | The default format for the selected `locale`. |

<CodePreview browserOnly>
<VStack space="2">
<DateInput format="MM/dd/yyyy" width="300px" />
<DateInput format="dd/MM/yyyy" width="300px" />
</VStack>
</CodePreview>

```jsx
<DateInput format="MM/dd/yyyy" width="300px" />
<DateInput format="dd/MM/yyyy" width="300px" />
```

### locale
The `locale` to use. If you don't specify a `format` the default format for the specified `locale` will be used. The specified `locale` is also used to localize the date picker.

| TYPE | REQUIRED | DEFAULT |
| ---- | -------- | ------- |
| `string` | No | `current locale` |

<CodePreview browserOnly>
<VStack space="2">
<DateInput locale="en-US" width="300px" />
<DateInput locale="es-AR" width="300px" />
<DateInput locale="fa" width="300px" />
<DateInput locale="es-AR" format="yyyy-MM-dd" width="300px" />
</VStack>
</CodePreview>

```jsx
<DateInput locale="en-US" width="300px" />
<DateInput locale="es-AR" width="300px" />
<DateInput locale="fa" width="300px" />
<DateInput locale="es-AR" format="yyyy-MM-dd" width="300px" />
```

### value
The date value for the input. It should respect the selected `format`.

| TYPE | REQUIRED | DEFAULT |
| ---- | -------- | ------- |
| `string` | No | |

<CodePreview browserOnly>
<DateInput locale="en-US" value="12/22/2022" width="300px" />
</CodePreview>

```jsx
<DateInput locale="en-US" value="12/22/2022" width="300px" />
```

### onChange
Callback that is called when the input value changes with the new date.

| TYPE | REQUIRED | DEFAULT |
| ---- | -------- | ------- |
| `( date: string ) => void` | No | |

<CodePreview browserOnly>
<DateInput width="300px" />
</CodePreview>

```jsx
const [ date, setDate ] = useState( '' );

<DateInput value={date} onChange={setDate} width="300px" />
```

### disable
Disables the input.

| TYPE | REQUIRED | DEFAULT |
| ---- | -------- | ------- |
| `boolean` | No | `false` |

<CodePreview browserOnly>
<DateInput
width="300px"
disabled
/>
</CodePreview>

```jsx
<DateInput
width="300px"
disabled
/>
```
### icon
An icon to show instead of the calendar one.

| TYPE | REQUIRED | DEFAULT |
| ---- | -------- | ------- |
| `JSX.Element` | No | `null` |

<CodePreview browserOnly>
<DateInput
width="300px"
icon={<Icon as={Feather} name="calendar" size="xs" />}
/>
</CodePreview>

```jsx
import Feather from 'react-native-vector-icons/Feather';

<DateInput
width="300px"
icon={<Icon as={Feather} name="calendar" size="xs" />}
/>
```

### error
Marks the input as invalid.

| TYPE | REQUIRED | DEFAULT |
| ---- | -------- | ------- |
| `boolean` | No | `false` |

<CodePreview browserOnly>
<DateInput
value="33/33/3333"
width="300px"
error
/>
</CodePreview>

```jsx
<DateInput
value="33/33/3333"
width="300px"
error
/>
```

## Pseudo-props

### __icon
Props to be applied to the internal `IconButton` component that opens the date picker.

| TYPE | REQUIRED |
| ------ | -------- |
| `IIconProps` | No |

<CodePreview browserOnly>
<DateInput
width="300px"
height="70px"
__icon={{ color: 'success.500', size: 'md' }}
/>
</CodePreview>

```jsx
<DateInput
width="300px"
height="70px"
__icon={{ color: 'success.500', size: 'md' }}
/>
```

:::caution
The `__icon` prop has less priority than the `icon` prop. This means that the styles applied to the `__icon` prop will be overridden by the styles applied to the `icon` prop. For example:
:::

<CodePreview browserOnly>
<DateInput
width="300px"
height="80px"
icon={<Icon as={Feather} name="search" color="black" />}
__icon={{ color: 'success.500', size: 'md' }}
/>
</CodePreview>

```jsx
<DateInput
width="300px"
height="80px"
icon={<Icon as={Feather} name="search" color="black" />}
__icon={{ color: 'success.500', size: 'md' }}
/>
```
As you can see the `size` from the `__icon` prop is being used but the `color` is being overridden by the `icon` props.
60 changes: 18 additions & 42 deletions docs/docs/components/forms/text_input.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@ import { TextInput } from '@amalgama/embassy-ui';

## Props

### type
The type of the input. Allowed values are:
- `text`: A text field.
- `password`: A password field that obscures the input text by default and has a icon button to show it.

| TYPE | REQUIRED | DEFAULT |
| ---- | -------- | ------- |
| `text` \| `password` | No | `text` |

<CodePreview>
<VStack space="2">
<TextInput placeholder="Enter your username" width="300px" />
<TextInput placeholder="Enter your password" type="password" width="300px" />
</VStack>
</CodePreview>

```jsx
<TextInput placeholder="Enter your text" width="300px" />
```

### placeholder
A placeholder text for the input.

Expand Down Expand Up @@ -250,31 +230,29 @@ Props to be applied to the internal `TextInput` component.
```

### __icon
Props to be applied to the internal `IconButton` component that toggles the password visibility.
Props to be applied to the internal `IconButton` component that is shown when the `icon` prop is set.

| TYPE | REQUIRED |
| ------ | -------- |
| `IIconProps` | No |

<CodePreview>
<TextInput
placeholder="Enter your password"
type="password"
placeholder="Search"
width="300px"
height="80px"
icon={<Icon as={Feather} name="unlock" color="success.500" />}
__icon={{ color: 'success.500', size: 'xl' }}
height="60px"
icon={<Icon as={Feather} name="search" />}
__icon={{ color: 'success.500', size: 'md' }}
/>
</CodePreview>

```jsx
<TextInput
placeholder="Enter your password"
type="password"
placeholder="Search"
width="300px"
height="80px"
icon={<Icon as={Feather} name="unlock" />}
__icon={{ color: 'success.500', size: 'xl' }}
height="60px"
icon={<Icon as={Feather} name="search" />}
__icon={{ color: 'success.500', size: 'md' }}
/>
```

Expand All @@ -284,23 +262,21 @@ The `__icon` prop has less priority than the `icon` prop. This means that the st

<CodePreview>
<TextInput
placeholder="Enter your password"
type="password"
placeholder="Search"
width="300px"
height="80px"
icon={<Icon as={Feather} name="unlock" color="black" />}
__icon={{ color: 'success.500', size: 'xl' }}
height="60px"
icon={<Icon as={Feather} name="search" color="black" />}
__icon={{ color: 'success.500', size: 'md' }}
/>
</CodePreview>

```jsx
<TextInput
placeholder="Enter your password"
type="password"
placeholder="Search"
width="300px"
height="80px"
icon={<Icon as={Feather} name="unlock" color="black" />}
__icon={{ color: 'success.500', size: 'xl' }}
height="60px"
icon={<Icon as={Feather} name="search" color="black" />}
__icon={{ color: 'success.500', size: 'md' }}
/>
```
As you can see the `size` from the `__icon` prop is beign used but the `color` is being overridden by the `icon` props.
As you can see the `size` from the `__icon` prop is being used but the `color` is being overridden by the `icon` props.
9 changes: 9 additions & 0 deletions docs/docs/getting_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ You need to install these peer dependencies in order to use the library:
You need to add [react-native-svg](https://www.npmjs.com/package/react-native-svg) to your project and set it up properly (see [project's README](https://github.com/react-native-svg/react-native-svg#installation)) for the default icons package to work. This package is needed by several componentes including: [TextInput](../components/forms/text_input.md), [Radio](../components/forms/radio.md), [Checkbox](../components/forms/checkbox.md), etc.
:::

### Plataform specific
Some peer-dependencies are platform dependent:

#### For ReactNative projects
- [react-native-date-picker](https://github.com/henninghall/react-native-date-picker) (required by the [DateInput](../components/forms/date_input.md) component)

#### For ReactJS projects
- [react-calendar](https://github.com/wojtekmaj/react-calendar) (required by the [DateInput](../components/forms/date_input.md) component)

## Default Fonts

### ReactNative
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/react": "17.0.2",
"@types/react-dom": "17.0.2",
"@types/react-native-vector-icons": "^6.4.11",
"babel-plugin-react-native-web": "^0.18.6",
"babel-plugin-react-native-web": "^0.18.10",
"docusaurus-plugin-react-native-web": "^1.0.0",
"patch-package": "^6.4.7",
"react-native-svg-web": "^1.0.9",
Expand Down
Loading

0 comments on commit c32da1d

Please sign in to comment.