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

[RFR] Improve form look and feel #3594

Merged
merged 31 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
09b1800
Allow forms to override variant and margin of their inputs
fzaninotto Aug 23, 2019
f94410b
Switch inputs to Dense and filled by default
fzaninotto Aug 23, 2019
e905c33
Style rich text input
fzaninotto Aug 27, 2019
1022b76
style AutocompleteInput
fzaninotto Aug 27, 2019
b12bb26
style DateInput
fzaninotto Aug 27, 2019
c288fc8
Fix margin in Labeled element
fzaninotto Aug 27, 2019
bb3d348
Change style of more inputs
fzaninotto Aug 27, 2019
e1f6e67
Hide helper text if content is empty (more compact layout)
fzaninotto Aug 28, 2019
3d81670
Reduce BulkActions toolbar height
fzaninotto Aug 28, 2019
403f399
Fix HideFilter button position
fzaninotto Aug 28, 2019
e95b7bc
Hide rich text label when label=""
fzaninotto Aug 28, 2019
5f3329b
Fix tabbedForm maegins
fzaninotto Aug 28, 2019
9fff66e
Fix Create card margin on Mobile
fzaninotto Aug 28, 2019
a33077e
reduce search input height
fzaninotto Aug 28, 2019
0fa9410
Fix filterForm when not containing SearchInput
fzaninotto Aug 28, 2019
3292b3a
Tweak demo product edition form
fzaninotto Aug 28, 2019
9512492
Fix demo menu margins
fzaninotto Aug 28, 2019
97ea448
Fix disabled field default theming
fzaninotto Aug 28, 2019
3d6c5df
fix RichTextInput with standard variant
fzaninotto Aug 28, 2019
8992576
Fix variant transmission in autocomplete inputs
fzaninotto Aug 28, 2019
575b2f6
Fix Filter variant transmission
fzaninotto Aug 28, 2019
f5e254c
Document form variant and margin
fzaninotto Aug 28, 2019
e670a45
Add Upgrade guide
fzaninotto Aug 28, 2019
485e167
Fix TypeScript error
fzaninotto Aug 28, 2019
3e69b81
Fix ra-input-rich-text tests
fzaninotto Aug 28, 2019
d340380
Fix unit tests
fzaninotto Aug 28, 2019
b9aa450
Update docs/CreateEdit.md
fzaninotto Aug 28, 2019
21ed442
Fix RichTextInput HelperText display
djhi Aug 29, 2019
a741020
Ensure we pass all final props down in our Forms
djhi Aug 29, 2019
eacbcc0
Fix SaveButton click event handling
djhi Aug 29, 2019
54ad293
Fix unit tests
djhi Aug 29, 2019
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
35 changes: 35 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,3 +799,38 @@ const OrderEdit = (props) => (

Some components (such as `<SelectArrayInput />`) accepted the `helperText` in their `meta` prop. They now receive it directly in their props.
Besides, all components now display their error or their helperText, but not both at the same time.

## Form Inputs are now filled and dense by default

To better match the [Material Design](https://material.io/components/text-fields/) specification, react-admin defaults to the 'filled' variant for form inputs, and uses a *dense* margin to allow more compact forms. This will change the look and fill of existing forms built with `<SimpleForm>`, `<TabbedForm>`, and `<Filter>`. If you want your forms to look just like before, you need to set the `variant` and `margin` props as follows:

```diff
// for SimpleForm
const PostEdit = props =>
<Edit {...props}>
<SimpleForm
+ variant="standard"
+ margin="normal"
>
// ...
</SimpleForm>
</Edit>;
// for TabbedForm
const PostEdit = props =>
<Edit {...props}>
<TabbedForm
+ variant="standard"
+ margin="normal"
>
<FormTab label="Identity>
// ...
</FormTab>
</TabbedForm>
</Edit>;
// for Filter
const PostFilter = props =>
- <Filter>
+ <Filter variant="standard">
// ...
</Filter>;
```
33 changes: 33 additions & 0 deletions docs/CreateEdit.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ Here are all the props accepted by the `<SimpleForm>` component:
* [`submitOnEnter`](#submit-on-enter)
* [`redirect`](#redirection-after-submission)
* [`toolbar`](#toolbar)
* [`variant`](#variant)
* [`margin`](#margin)
* `save`: The function invoked when the form is submitted. This is passed automatically by `react-admin` when the form component is used inside `Create` and `Edit` components.
* `saving`: A boolean indicating whether a save operation is ongoing. This is passed automatically by `react-admin` when the form component is used inside `Create` and `Edit` components.

Expand Down Expand Up @@ -394,6 +396,8 @@ Here are all the props accepted by the `<TabbedForm>` component:
* [`submitOnEnter`](#submit-on-enter)
* [`redirect`](#redirection-after-submission)
* [`toolbar`](#toolbar)
* [`variant`](#variant)
* [`margin`](#margin)
* `save`: The function invoked when the form is submitted. This is passed automatically by `react-admin` when the form component is used inside `Create` and `Edit` components.
* `saving`: A boolean indicating whether a save operation is ongoing. This is passed automatically by `react-admin` when the form component is used inside `Create` and `Edit` components.

Expand Down Expand Up @@ -440,6 +444,7 @@ To style the tabs, the `<FormTab>` component accepts two props:
- `contentClassName` is passed to the tab *content*

### TabbedFormTabs

By default `<TabbedForm>` uses `<TabbedFormTabs>`, an internal react-admin component to renders tabs. You can pass a custom component as the `tabs` prop to override the default component. Besides, props from `<TabbedFormTabs>` are passed to material-ui's `<Tabs>` component inside `<TabbedFormTabs>`.

The following example shows how to make use of scrollable `<Tabs>`. Pass the `scrollable` prop to `<TabbedFormTabs>` and pass that as the `tabs` prop to `<TabbedForm>`
Expand Down Expand Up @@ -827,6 +832,34 @@ Here are the props received by the `Toolbar` component when passed as the `toolb

**Tip**: To alter the form values before submitting, you should use the `handleSubmit` prop. See [Altering the Form Values before Submitting](./Actions.md#altering-the-form-values-before-submitting) for more information and examples.

## Variant

By default, react-admin input components use the Material Design "filled" variant. If you want to use the "standard" or "outlined" variants, you can either set the `variant` prop on each Input component individually, or set the `variant` prop directly on the Form component. In that case, the Form component will transmit the `variant` to each Input.

```jsx
export const PostEdit = (props) => (
<Edit {...props}>
<SimpleForm variant="standard">
...
</SimpleForm>
</Edit>
);
```

## Margin

By default, react-admin input components use the Material Design "dense" margin. If you want to use the "normal" or "none" margins, you can either set the `margin` prop on each Input component individually, or set the `margin` prop directly on the Form component. In that case, the Form component will transmit the `margin` to each Input.

```jsx
export const PostEdit = (props) => (
<Edit {...props}>
<SimpleForm margin="normal">
...
</SimpleForm>
</Edit>
);
```

## Customizing Input Container Styles

The input components are wrapped inside a `div` to ensure a good looking form by default. You can pass a `formClassName` prop to the input components to customize the style of this `div`. For example, here is how to display two inputs on the same line:
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.2.1",
"@material-ui/core": "^4.3.3",
"@material-ui/icons": "^4.2.1",
"data-generator-retail": "^2.7.0",
"fakerest": "~2.1.0",
Expand Down
2 changes: 2 additions & 0 deletions examples/demo/src/layout/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const Menu = ({ onMenuClick, open, logout }) => {
leftIcon={<reviews.icon />}
onClick={onMenuClick}
sidebarIsOpen={open}
dense
/>
{isXsmall && (
<MenuItemLink
Expand All @@ -127,6 +128,7 @@ const Menu = ({ onMenuClick, open, logout }) => {
leftIcon={<SettingsIcon />}
onClick={onMenuClick}
sidebarIsOpen={open}
dense
/>
)}
{isXsmall && logout}
Expand Down
10 changes: 10 additions & 0 deletions examples/demo/src/layout/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ export const lightTheme = {
contrastText: '#fff',
},
},
overrides: {
MuiFilledInput: {
root: {
backgroundColor: 'rgba(0, 0, 0, 0.04)',
'&$disabled': {
backgroundColor: 'rgba(0, 0, 0, 0.04)',
},
},
},
},
};
36 changes: 29 additions & 7 deletions examples/demo/src/products/ProductCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import {
TextInput,
required,
} from 'react-admin';
import { InputAdornment } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import RichTextInput from 'ra-input-rich-text';

export const styles = {
stock: { width: '5em' },
price: { width: '5em' },
width: { width: '5em' },
price: { width: '7em' },
width: { width: '7em' },
height: { width: '7em' },
stock: { width: '7em' },
widthFormGroup: { display: 'inline-block' },
height: { width: '5em' },
heightFormGroup: { display: 'inline-block', marginLeft: 32 },
};

Expand All @@ -32,12 +33,12 @@ const ProductCreate = props => {
<TextInput
autoFocus
source="image"
options={{ fullWidth: true }}
fullWidth
validate={required()}
/>
<TextInput
source="thumbnail"
options={{ fullWidth: true }}
fullWidth
validate={required()}
/>
</FormTab>
Expand All @@ -47,18 +48,39 @@ const ProductCreate = props => {
source="price"
validate={required()}
className={classes.price}
InputProps={{
startAdornment: (
<InputAdornment position="start">
</InputAdornment>
),
}}
/>
<NumberInput
source="width"
validate={required()}
className={classes.width}
formClassName={classes.widthFormGroup}
InputProps={{
endAdornment: (
<InputAdornment position="start">
cm
</InputAdornment>
),
}}
/>
<NumberInput
source="height"
validate={required()}
className={classes.height}
formClassName={classes.heightFormGroup}
InputProps={{
endAdornment: (
<InputAdornment position="start">
cm
</InputAdornment>
),
}}
/>
<ReferenceInput
source="category_id"
Expand All @@ -77,7 +99,7 @@ const ProductCreate = props => {
label="resources.products.tabs.description"
path="description"
>
<RichTextInput source="description" addLabel={false} />
<RichTextInput source="description" label="" />
</FormTab>
</TabbedForm>
</Create>
Expand Down
37 changes: 30 additions & 7 deletions examples/demo/src/products/ProductEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TextField,
TextInput,
} from 'react-admin';
import { InputAdornment } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import RichTextInput from 'ra-input-rich-text';

Expand Down Expand Up @@ -43,24 +44,45 @@ const ProductEdit = props => {
<TabbedForm>
<FormTab label="resources.products.tabs.image">
<Poster />
<TextInput source="image" options={{ fullWidth: true }} />
<TextInput
source="thumbnail"
options={{ fullWidth: true }}
/>
<TextInput source="image" fullWidth />
<TextInput source="thumbnail" fullWidth />
</FormTab>
<FormTab label="resources.products.tabs.details" path="details">
<TextInput source="reference" />
<NumberInput source="price" className={classes.price} />
<NumberInput
source="price"
className={classes.price}
InputProps={{
startAdornment: (
<InputAdornment position="start">
</InputAdornment>
),
}}
/>
<NumberInput
source="width"
className={classes.width}
formClassName={classes.widthFormGroup}
InputProps={{
endAdornment: (
<InputAdornment position="start">
cm
</InputAdornment>
),
}}
/>
<NumberInput
source="height"
className={classes.height}
formClassName={classes.heightFormGroup}
InputProps={{
endAdornment: (
<InputAdornment position="start">
cm
</InputAdornment>
),
}}
/>
<ReferenceInput source="category_id" reference="categories">
<SelectInput source="name" />
Expand All @@ -71,14 +93,15 @@ const ProductEdit = props => {
label="resources.products.tabs.description"
path="description"
>
<RichTextInput source="description" addLabel={false} />
<RichTextInput source="description" label="" />
</FormTab>
<FormTab label="resources.products.tabs.reviews" path="reviews">
<ReferenceManyField
reference="reviews"
target="product_id"
addLabel={false}
pagination={<Pagination />}
fullWidth
>
<Datagrid>
<DateField source="date" />
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@babel/polyfill": "^7.0.0",
"@material-ui/core": "^4.2.1",
"@material-ui/core": "^4.3.3",
"@material-ui/icons": "^4.2.1",
"ra-data-fakerest": "^3.0.0-alpha.0",
"ra-input-rich-text": "^3.0.0-alpha.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/src/posts/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const PostIcon = BookIcon;

const useQuickFilterStyles = makeStyles(theme => ({
chip: {
marginBottom: theme.spacing(3),
marginBottom: theme.spacing(1),
},
}));
const QuickFilter = ({ label }) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.2.1",
"@material-ui/core": "^4.3.3",
"ra-data-json-server": "^3.0.0-alpha.0",
"react": "~16.8.0",
"react-admin": "^3.0.0-alpha.0",
Expand Down
Loading