4.0.0-rc17 • Published 5 months ago

ra-friendsofbabba v4.0.0-rc17

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

FriendsOfBabba/RA 🥧 - React Admin extended components

This library is compatible with React Admin v3.x

I'm a big fan of react-admin and I've built a simple layout using Mini drawer variant. The layout has a simple navigation bar and a drawer with a navigation menu and it can be used as a starting point for your own layout. Any component can be overridden by using the layout prop.

React-Admin Mini Drawer

How To Use

Install the package:

npm i --save ra-friendsofbabba

and then you have to import and use it in you react-admin app:

import { Layout } from "ra-friendsofbabba";
import { Admin, Resource } from "react-admin";
const App = () => (
  <Admin layout={Layout}>
    <Resource name="..." />
  </Admin>
);

The first step is to add some configuration to your resources files. They need to instruct the layout component on how to render the resource in group of items inside the drawer. For example, if you want to show posts in the drawer under Dashboard group you need to add the following configuration:

export default {
  ...,
  options: { group: "dashboard", roles: ["user"] }
}

In this example, the resource will be rendered in the drawer under the Dashboard group and only the user role will be able to see it (roles is another option exposed in this layout that can be helpful to customize resources access).

Data

Configure Data Provider

import { dataProvider, prepareUpload } from "ra-friendsofbabba";
// Define list of uploadable fields:
const UPLOADABLE_FIELDS = ["image", "document", "profile.picture"];
const dp = dataProvider({
  apiUrl: "...",
  prepareUpload: (data) => prepareUpload(data, UPLOADABLE_FIELDS),
});

Components

Layout

The Layout component follow the same props as the react-admin.

You can override components like AppBar, Sidebar or Menu by passing them to the layout as prop, in addition I've added the following props (useful for the mini drawer):

Prop nameTypeDefaultDescription
drawerWidthnumber240the width of the drawer
titlestringReact-Adminthe title of the app
subTitlestringMaterial-UIthe subtitle of the app

If you want to override them you can do it as follow:

import { Layout } from "ra-friendsofbabba";
import { Admin, Resource } from "react-admin";
const MyLayout = (props) => (
  <Layout {...props} drawerWidth={300} title="My App" subtitle="My Subtitle" />
);
const App = () => (
  <Admin layout={MyLayout}>
    <Resource name="..." />
  </Admin>
);

Menu

The menu component has been designed to be fully customizable and you can use it in many ways. Suppose you want to customize everything withouth use default menu items and groups:

import { Layout, Menu, MenuGroup, MenuItem } from "ra-friendsofbabba";
const CustomMenu = (props) => (
  <Menu {...props} mode="custom">
    <MenuGroup label="My Group">
      <MenuItem label="My Item" />
    </MenuGroup>
  </Menu>
);

The mode prop can be used to customize the menu. The default menu is a Menu component with mode="build" prop, this means that the menu will be built from the MenuItem and MenuGroup components generated scanning the resources. You can also use mode="custom" to customize the menu and show what you really need or mode="build" to use the default menu and add your custom items that will be placed at the end of the menu.

MenuItem

Menu item can be used in many ways, you can use it to redirect users to external URL like docs or links or you can publish your own custom routes to specific pages like in this example:

import { Layout, Menu, MenuGroup, MenuItem } from "ra-friendsofbabba";
const CustomMenu = (props) => (
  <Menu {...props}>
    <MenuGroup label="Useful Link">
      <MenuItem {...props} href="https://www.google.it" target="_blank" />
      <MenuItem {...props} to="/local-custom-page">
    </MenuGroup>
  </Menu>
)

Remember that MenuItem must be used inside a MenuGroup component. The current version of this library doesn't support nested menus or root items.

Badges

You can pass a badge prop to the MenuItem component to show a badge. The Menu component accept badges props that allows you to customize the badges for all menu items, this prop can be an object of key/value pairs where the key is the resource name and the value is the badge config.

For every badge you have to provide these props:

  • value: the badge value
  • color: the badge color
  • icon: the badge icon
  • variant: the badge variant
  • show (not required): a boolean to show or hide the badge

For example, an output badges config can be like this:

{
  posts: {
    value: 10,
    color: "primary",
    icon: "notifications",
    variant: "dot"
  }
}

UserMenu

The UserMenu component allows you to customize the user menu (in the top right corner). Please refer to this example:

import { UserMenu, UserMenuItem } from "ra-friendsofbabba";
import * as Icons from "@material-ui/icons";
const MyUserMenu = (props) => (
  <UserMenu {...props}>
    <UserMenuItem
      label="User Profile"
      to="/user-profile"
      icon={<Icons.AccountUser />}
    />
    {props.logout}
  </UserMenu>
);

How to contribute

Clone the repository and run npm run i-all to install dependencies. After that, you can start to testing your app running npm run dev. Use playground to test app with your own modifications.

4.0.0-rc17

5 months ago

4.0.0-rc16

5 months ago

4.0.0-rc15

5 months ago

4.0.0-rc13

8 months ago

4.0.0-rc12

8 months ago

4.0.0-rc11

8 months ago

4.0.0-rc10

10 months ago

4.0.0-rc8

10 months ago

4.0.0-rc9

10 months ago

4.0.0-rc6

10 months ago

4.0.0-rc7

10 months ago

4.0.0-rc4

11 months ago

4.0.0-rc5

10 months ago

4.0.0-rc2

11 months ago

4.0.0-rc3

11 months ago

4.0.0-rc1

11 months ago

1.2.39

9 months ago

4.0.0-alpha2

1 year ago

4.0.0-alpha1

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.12

1 year ago

1.2.13

1 year ago

1.2.10

1 year ago

1.2.11

1 year ago

1.2.16

1 year ago

1.2.17

1 year ago

1.2.14

1 year ago

1.2.15

1 year ago

1.2.9

1 year ago

1.2.18

1 year ago

1.2.19

1 year ago

1.2.20

1 year ago

1.2.23

1 year ago

1.2.24

1 year ago

1.2.21

1 year ago

1.2.22

1 year ago

1.2.27

1 year ago

1.2.28

1 year ago

1.2.25

1 year ago

1.2.26

1 year ago

1.2.29

1 year ago

1.2.30

1 year ago

1.2.31

1 year ago

1.2.34

1 year ago

1.2.35

1 year ago

1.2.32

1 year ago

1.2.33

1 year ago

1.2.38

1 year ago

1.2.36

1 year ago

1.2.37

1 year ago

1.2.0

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.52

2 years ago

1.1.51

2 years ago

1.1.50

2 years ago

1.1.56

2 years ago

1.1.55

2 years ago

1.1.54

2 years ago

1.1.53

2 years ago

1.1.58

1 year ago

1.1.57

1 year ago

1.1.41

2 years ago

1.1.45

2 years ago

1.1.44

2 years ago

1.1.43

2 years ago

1.1.42

2 years ago

1.1.49

2 years ago

1.1.48

2 years ago

1.1.47

2 years ago

1.1.46

2 years ago

1.1.40

2 years ago

1.1.39

2 years ago

1.1.38

2 years ago

1.1.37

2 years ago

1.1.36

2 years ago

1.1.35

2 years ago

1.1.34

2 years ago

1.1.33

2 years ago

1.1.32

2 years ago

1.1.31

2 years ago

1.1.30

2 years ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.27

2 years ago

1.1.26

2 years ago

1.1.25

2 years ago

1.1.24

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago