Socket
Socket
Sign inDemoInstall

django-bananas

Package Overview
Dependencies
150
Maintainers
4
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    django-bananas

React admin frontend for Django.


Version published
Weekly downloads
38
decreased by-20.83%
Maintainers
4
Created
Weekly downloads
 

Readme

Source

django-bananas.js

npm install django-bananas react react-dom @material-ui/core @material-ui/icons final-form final-form-arrays react-final-form react-final-form-arrays
import Bananas from "django-bananas";
import React from "react";
import ReactDOM from "react-dom";

ReactDOM.render(
  <Bananas.App
    api="http://localhost:8000/api"
    pages={route => import(`./pages/${route}`)}
  />,
  document.getElementById("root")
);

Settings

PropertyTypeDefaultChoices
apiString, ObjectRequired
pagesFunctionRequired
titleStringBananas
logoFunction, String, Booleantrue
brandingStringBananas
versionStringv1.0.0
themeObject[django-bananas/themes].default (light)
pageThemeObjectundefined
navObject, Boolean{"home": ..., "bananas.me:list": ...}
layoutStringhorizontalhorizontal, vertical
permanentBooleanfalse
collapsedBooleanfalse
denseBooleanfalse
editableSettingsBooleanfalse
loginFormFunctionundefined
logLevelString, ObjectWARNINFO, DEBUG, WARN, ERROR, OFF
prefixString""
customizeContextFunctionundefined
containerFunctionReact.Fragment

api

Base API URL.

<Bananas.App
  // ...
  api="http://localhost:8000/api"
/>

Alternatively, you can pass an object of extra swagger-js options. For example, you could add a custom header:

<Bananas.App
  // ...
  api={{
    url: "http://localhost:8000/api",
    requestInterceptor: request => {
      request.headers.Authorization = "secret";
      return request;
    },
  }}
/>

pages

A function that dynamically imports pages. A page file should export default a React component to render for the given route.

route => import(`./pages/${route}`);

Make sure that the directory containing your page files exists (even if it’s empty)! (./pages/ in the above example.) Otherwise your build tool might throw an error.

title

Sets trailing part of the document title: <current page title> | My Admin-App Title.

Use boolean false to not render a logo, or true to show the default Bananas logo. Use a string for an image URL or a function/component for full control.

<Bananas.App
  // ...
  logo={true | false}
  logo={"https://foo.bar/logo.svg"}
  logo={<MyLogo />}
/>

branding & version

Shown in the navigation header next to the logo.

theme & pageTheme

theme and pageTheme are Material UI theme objects, either partially or fully created. pageTheme is only needed if you want a specific theme for the page area, other than the navigation, boot and login screen.

<Bananas.App
  // ...
  theme={themes.dark}
  pageTheme={themes.light}
/>

nav

The nav setting lets you define the order of items in the navigation, as well as icons for each item. It is a mapping between navigation endpoints (operation-id) and icons, or an array of navigation endpoints if you want to define order but not icons. Items not mentioned in the mapping or array are put last in alphabetical order, with a fallback icon (if needed).

<Bananas.App
  // ...
  nav={{
    // "home": MyCustomDashboardIcon,
    // "bananas.me:list": MyCustomUserIcon,
    "example.user:list": PeopleIcon,
  }}
/>

layout

Defines location of the app navigation. Use horizontal layout for a side drawer, or vertical for a top bar.

permanent & collapsed

The permanent and collapsed settings is only applicable for horizontal layout. Permanent makes the drawer non-collapsable, and collapsable defines the initial state of the drawer.

dense

Set dense={true} for smaller fonts/icons in the navigation.

loginForm

Set loginForm to a react component if you need a custom login form other than the built-in default form/endpoint.

logLevel

Global log level:

<Bananas.App
  // ...
  logLevel="DEBUG",
/>

Log level per application label:

<Bananas.App
  // ...
  logLevel={{
    bananas: "WARN",
    myapp: "DEBUG",
  }}
/>

prefix

Prefix sets the base url for the router. Use this if the admin app is mounted on a sub-path, i.e. /bananas/.

customizeContext

A function that receives the standard AdminContext and returns a new context object.

container

A function (React component) that resides under the AdminContext but above pages. Useful for wrapping the entire app in a custom context so data can persist between pages.

<Bananas.App
  // ...
  container={MyCustomContainer}
/>

Browser support

The code shipped to npm uses modern JavaScript, supported natively by all evergreen browsers. If you need deeper browser support, you need to configure your build system to transpile and polyfill node_modules/ code.

If you use Create React App, which runs Babel on code from npm packages, you can get IE11 support by adding the following to your main entrypoint:

import "react-app-polyfill/ie11";
import "react-app-polyfill/stable";

Example app

This repo contains an example app in the app/ folder.

  1. Set up and start the backend: django-bananas.

  2. Copy the sample settings:

     cp app/src/_bananas.settings.js app/src/bananas.settings.js
    

    You can then play around with different settings in bananas.settings.js.

  3. Start the example app:

    docker-compose up -d
    

    Alternatively, you could run outside docker:

    npm ci
    npm start
    

(If you develop on this package, you need to run npm ci and run tests outside docker. See package.json.)

Keywords

FAQs

Last updated on 28 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc