Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Improve Input docs #8316

Merged
merged 10 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/ArrayInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ const OrderEdit = () => (

Check [the `<SimpleFormIterator>` documentation](./SimpleFormIterator.md) for details about how to customize the sub form layout.

`<ArrayInput>` also accepts the [common input props](./Inputs.md#common-input-props) (except `format` and `parse`).
## Props

`<ArrayInput>` accepts the [common input props](./Inputs.md#common-input-props) (except `format` and `parse`).

## Global validation

Expand Down
22 changes: 17 additions & 5 deletions docs/BooleanInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,31 @@ title: "The BooleanInput Component"

# `<BooleanInput>`

`<BooleanInput />` is a toggle button allowing you to attribute a `true` or `false` value to a record field.
`<BooleanInput />` renders a switch allowing users to set the value `true` or `false` to a record field.

![BooleanInput](./img/boolean-input.gif)

**Tip**: This input doesn't let users set a `null` value - only `true` or `false`. Use the [`<NullableBooleanInput />`](./NullableBooleanInput.md) component if you have to handle non-required booleans.

## Usage

```jsx
import { BooleanInput } from 'react-admin';

<BooleanInput label="Commentable" source="commentable" />
```

![BooleanInput](./img/boolean-input.png)
## Props

| Prop | Required | Type | Default | Description |
|-----------|----------|----------|---------|----------------------------------------------------------------------------|
| `options` | Optional | `Object` | `{}` | Options object to pass to the underlying material-ui `<Switch>` component. |

This input does not handle `null` values. You would need the [`<NullableBooleanInput />`](./NullableBooleanInput.md) component if you have to handle non-set booleans.
`<BooleanInput>` also accepts the [common input props](./Inputs.md#common-input-props).

## `options`

You can use the `options` prop to pass any option supported by the MUI's `Switch` components. For example, here's how to set a custom checked icon:
Use the `options` prop to pass any option supported by the MUI's `Switch` components. For example, here's how to set a custom checked icon:

{% raw %}
```jsx
Expand All @@ -32,4 +44,4 @@ import FavoriteIcon from '@mui/icons-material/Favorite';

Refer to [MUI Switch documentation](https://mui.com/api/switch) for more details.

`<BooleanInput>` also accepts the [common input props](./Inputs.md#common-input-props).

29 changes: 25 additions & 4 deletions docs/DateInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,41 @@ title: "The DateInput Component"

# `<DateInput>`

Ideal for editing dates, `<DateInput>` renders an HTML `<input type="date">` element, that most browsers display as a standard [Date Picker](https://mui.com/components/pickers/#date-pickers).
Ideal for editing dates, `<DateInput>` renders an HTML `<input type="date">` element, that most browsers display as a [date picker](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date).

![DateInput](./img/date-input.gif)

The appearance of `<DateInput>` depends on the browser, and falls back to a text input on Safari. The date formatting in this input depends on the user's locale.

## Usage

```jsx
import { DateInput } from 'react-admin';

<DateInput source="published_at" />
```

`<DateInput>` also accepts the [common input props](./Inputs.md#common-input-props).
The field value must be a string with the pattern `YYYY-MM-DD` (ISO 8601), e.g. `'2022-04-30'`.
slax57 marked this conversation as resolved.
Show resolved Hide resolved

## Props

`<DateInput>` accepts the [common input props](./Inputs.md#common-input-props).

## Validation

To validate that a date is before or after a given date, use the `maxValue` and `minValue` validators with a date string.

```jsx
import { DateInput, minValue } from 'react-admin';

// requires dates after October 10th, 2022
<DateInput source="published" validate={minValue('2022-10-26')} />
```

## Internationalization

It is not possible to customize the date format. Browsers use the user locale to display the date in the correct format.

**Tip**: For a MUI styled `<DateInput>` component, check out [vascofg/react-admin-date-inputs](https://github.com/vascofg/react-admin-date-inputs).
If you need to render a UI despite the browser locale, MUI also proposes a [Date Picker](https://mui.com/components/pickers/#date-pickers) component, which is more customizable than the native date picker, but requires additional packages.

![MUI style DateInput](https://github.com/vascofg/react-admin-date-inputs/raw/master/date-time-picker.gif)
![MUI Date picker](./img/date-picker.gif)
17 changes: 14 additions & 3 deletions docs/DateTimeInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@ title: "The DateTimeInput Component"

# `<DateTimeInput>`

An input for editing dates with time. `<DateTimeInput>` renders a standard browser [Date and Time Picker](https://mui.com/components/pickers/#date-amp-time-pickers), so the appearance depends on the browser (and falls back to a text input on safari).
An input for editing dates with time. `<DateTimeInput>` renders an `<input type="datetime-local" >` element, that most browsers display as [date and time picker](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local).

![DateTimeInput](./img/date-time-input.gif)

The appearance depends on the browser, and falls back to a text input on safari. The date formatting in this input depends on the user's locale.

## Usage

```jsx
import { DateTimeInput } from 'react-admin';

<DateTimeInput source="published_at" />
```

`<DateTimeInput>` also accepts the [common input props](./Inputs.md#common-input-props).
The input value must be a valid date string, i.e. a string understood by JavasSript's [`Date.parse()` method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse). Strings with [the ISO 8601 format](https://en.wikipedia.org/wiki/ISO_8601) 'yyyy-MM-ddThh:mm' are the most common (e.g. `'2022-04-30T12:30'`). The field value may contain a timezone offset, e.g. `'2022-04-30T12:30+02:00'`. If no timezone is specified, the browser's timezone is used.
slax57 marked this conversation as resolved.
Show resolved Hide resolved

After modification by the user, the value is stored as a `Date` object, using the browser's timezone. When transformed to JSON, the date is serialized as a string in the ISO 8601 format ('yyyy-MM-ddThh:mm').

**Tip**: For a MUI styled `<DateTimeInput>` component, check out [MUI Date pickers](https://mui.com/x/react-date-pickers/getting-started/#date-pickers)

## Props

`<DateTimeInput>` accepts the [common input props](./Inputs.md#common-input-props).

**Tip**: For a MUI styled `<DateTimeInput>` component, check out [vascofg/react-admin-date-inputs](https://github.com/vascofg/react-admin-date-inputs).
Loading