1.0.1 • Published 5 days ago

@dslab/ra-dialog-crud v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

React Admin Dialog Crud

Version Documentation Maintenance License: MIT

This package contains three components, each respectively designed to display, create, and edit content within a dialog.

Install

yarn install @dslab/ra-dialog-crud

React Admin Show in Dialog Button

This React Admin component renders a button opening a <Show> view inside a dialog, hence allowing to show a record without leaving the current view.

Usage

import { ShowInDialogButton } from '@dslab/ra-dialog-crud';
import {
    Datagrid,
    EmailField,
    List,
    SimpleShowLayout,
    TextField,
} from 'react-admin';

export const UserList = () => (
    <List>
        <Datagrid>
            <TextField source="first_name" />
            <TextField source="last_name" />
            <EmailField source="email" />

            <ShowInDialogButton>
                <SimpleShowLayout>
                    <TextField source="first_name" />
                    <TextField source="last_name" />
                    <TextField source="email" />
                </SimpleShowLayout>
            </ShowInDialogButton>
        </Datagrid>
    </List>
);

Props

The component accepts the following props:

PropRequiredTypeDefaultDescription
childrenRequiredReactNodeThe content of the dialog
titleOptionalstring or ReactElementThe title of the dialog
maxWidthOptionalstringsmThe max width of the dialog
fullWidthOptionalbooleanfalseIf true, the dialog stretches to the full width of the screen
resourceOptionalstringThe resource name
labelOptionalstringAllows to override the default button label. I18N is supported
idOptionalstring or numberThe record id. If not provided, it will be deduced from the record context
queryOptionsOptionalobjectOptions for the dataProvider.getOne() call
disableAuthenticationOptionalbooleanSet to true to disable the authentication check
emptyWhileLoadingOptionalbooleanSet to true to show a loading indicator while the list is loading
sxOptionalobjectOverride the styles applied to the dialog component

React Admin Create in Dialog Button

This React Admin component offers a way to open a <Create> view inside a dialog, hence allowing to create a new record without leaving the current view.

Usage

import { CreateInDialogButton } from '@dslab/ra-dialog-crud';
import {
    Datagrid,
    EmailField,
    List,
    SimpleForm,
    TextField,
    TextInput,
    TopToolbar,
} from 'react-admin';

const ListActions = () => (
    <TopToolbar>
        <CreateInDialogButton>
            <SimpleForm>
                <TextInput source="first_name" />
                <TextInput source="last_name" />
                <TextInput source="email" />
            </SimpleForm>
        </CreateInDialogButton>
    </TopToolbar>
);

export const UserList = () => (
    <List actions={<ListActions />}>
        <Datagrid>
            <TextField source="first_name" />
            <TextField source="last_name" />
            <EmailField source="email" />
        </Datagrid>
    </List>
);

Props

The component accepts the following props:

PropRequiredTypeDefaultDescription
childrenRequiredReactNodeThe content of the dialog
titleOptionalstring or ReactElementThe title of the dialog
maxWidthOptionalstringsmThe max width of the dialog
fullWidthOptionalbooleanfalseIf true, the dialog stretches to the full width of the screen
resourceOptionalstringThe resource name
labelOptionalstringAllows to override the default button label. I18N is supported
mutationOptionsOptionalobjectOptions for the dataProvider.create() call
disableAuthenticationOptionalbooleanSet to true to disable the authentication check
transformOptionalfunctionAllows to transform a record after the user has submitted the form but before the record is passed to dataProvider.create()
recordOptionalobjectAllows to initialize the form with non-empty values
sxOptionalobjectOverride the styles applied to the dialog component

React Admin Edit in Dialog Button

This React Admin component renders a button opening an <Edit> view inside a dialog, hence allowing to edit a record without leaving the current view.

Usage

import { EditInDialogButton } from '@dslab/ra-dialog-crud';
import {
    Datagrid,
    EmailField,
    List,
    SimpleForm,
    TextField,
    TextInput,
} from 'react-admin';

export const UserList = () => (
    <List>
        <Datagrid>
            <TextField source="first_name" />
            <TextField source="last_name" />
            <EmailField source="email" />

            <EditInDialogButton>
                <SimpleForm>
                    <TextInput source="first_name" />
                    <TextInput source="last_name" />
                    <TextInput source="email" />
                </SimpleForm>
            </EditInDialogButton>
        </Datagrid>
    </List>
);

Props

The component accepts the following props:

PropRequiredTypeDefaultDescription
childrenRequiredReactNodeThe content of the dialog
titleOptionalstring or ReactElementThe title of the dialog
maxWidthOptionalstringsmThe max width of the dialog
fullWidthOptionalbooleanfalseIf true, the dialog stretches to the full width of the screen
resourceOptionalstringThe resource name
labelOptionalstringAllows to override the default button label. I18N is supported
queryOptionsOptionalobjectOptions for the dataProvider.getOne() call
mutationOptionsOptionalobjectOptions for the dataProvider.update() call
mutationModeOptionalstringundoableThe mode that determines when the side effects (redirection, notifications, etc.) are executed. React-admin offers three modes for mutations: pessimistic, optimistic and undoable
idOptionalstring or numberThe record id. If not provided, it will be deduced from the record context
disableAuthenticationOptionalbooleanSet to true to disable the authentication check
transformOptionalfunctionAllows to transform a record after the user has submitted the form but before the record is passed to dataProvider.update()
emptyWhileLoadingOptionalbooleanSet to true to show a loading indicator while the list is loading
sxOptionalobjectOverride the styles applied to the dialog component

Author

SmartCommunityLab

Show your support

Give a ⭐️ if this project helped you!

License

Copyright © 2023 SmartCommunityLab. This project is MIT licensed.

1.0.1

5 days ago

1.0.0

2 months ago