Simple React Dashboard
A library to create dashboard with widgets
Installation
Install the react-dashboard-lib using npm:
npm install react-dashboard-lib
Usage
You can use this library when you want to create dashboard for your
application.
Widgets or Components on Dashboard are fully resizable and their positions
can be easily set by your user.
Used Libraries
React-Grid-Layout - for resizable & draggable container
Features
- 100% React - no jQuery
- Compatible with server-rendered apps
- Dashboard with Draggable and Resizable widgets
- Configurable gravity : top , bottom , off
- Dashboard with fixed number of adjustable widgets
- Preserve state of dashboard anywhere you want
- Dashboard with widgets menu for add/remove functionality
- Responsive Dashboard
- Grid Items placed using CSS Transforms
Available Dashboard Types
- DashboardWithEditKey - In this type, use can adjust the widgets passed by you
as per his/her choice. you can persist state anywhere you want by passing functions
- DashboardWithWidgetMenu - Here, you can provide user set of widgets, from
which user can select and configure some/all widgets on dashboard as per need.
- FloatingDashboard{Comming Soon...} - This dashboard is like assistive touch for
your application, using which you can provide dashboard with floting icon.
- MultiDashboard - It's combo of dashboard container, In which user can create as many
dashboards, he/she wants using provided widgets.
- Dashboard - It is the base component used by all other dashboards, you can use it, if you
want to create your own custom dashboard
Unit Methodology
- For shake of simplicity and responsiveness, i have used custom unit instead of pixel
- In code, there is constant named MULTIPLIER, which is used to derive partition of dashboard.
ex. MULTIPLIER = 10 means, dashboard board have 100 columns in large view, and it will decrease
to 90,80,70,60 as screen size decreases.
- you can check value of MULTIPLIER in code, for now it is fixed.
- you need to give all properties to widgets using this unit method.
ex. if you want to set minimum width of widget to feel 50% dashboard then you need to pass 50 as minWidth.
- It is like passing percentage value with respect to dashboard. dashboard will manage its propertiy changes
as per screens size changes.
- Height of the compnent is also relative to the width, so you need to use same units for that.
How to create Widgets
- It's as simple as fitting little legos on one giant lego(dashboard)
- You can use any _ component as a widget by just specifying some properties.
- Let assume You Have Component named 'Clock',
you just need to create an object which have following properties :
const ClockWidget = {
id : 'clock',
Component : Clock,
}
Hurraa!!! ,you have just created 'Clock' widget , ready to use in dashboard.
Available properties for Widget
- Currently, Widget supports the following properties (suggest more properties by raising issue or by pull request):
id : string
Component : object
backgroundColor : string
refreshInterval = number (in milli-seconds / 10e-3 seconds )
-
* : refresh hook is kind of hook which will be altered every time based on passed time interval.
For Class Component
You can use it inside useEffect hook as dependency to refresh for functional component.
example of refresh hook is provided in below link refreshHook
-
following properties are in terms of custom unit metrix used by dashboard (not in pixels)
preferedX = number (units*)
preferedY = number (units*)
minWidth = number (units*)
maxWidth = number (units*)
minHeight = number (units*)
maxHeight = number (units*)
Common properties for all dashboards
- this are the properties either essential for creating dashboard or related to styling of the dashboard
- you can pass this properties as props to any of the dashboard available
widgets = array of object
dashboardStyle = object
backgroundColor = string
widgetBackgroundColorGeneral = string
fixedHeight = number
enableGravity = number,
leftGravity = boolean
widgetMarginLeftRight = number
widgetMarginTopBottom = number
dashboardLeftPadding = number
dashboardTopPadding = number
preventCollision = boolean
DashboardWithEditKey
- In this type, you will get dashboard with edit button
- User can edit dashboard state, it will be stored/retrieved from storage specified by passed function
-DashboardWithEditKey has following properties to configure other than common properties
id = string
EditButton = function
saveLayoutState = function
retrieveLayoutState = function
- And now , In this Component you will get Widget menu along with dashboard.
- User can add or remove widgets to or from dashboard
- Removed widget will automatically added to Widget menu and shown when user clicks on add
- This component also provide custom save / retrieve function as DashboardWithEditKey component
EditButton = function
AddButton: PropTypes.func
SaveButton: PropTypes.func
WidgetMenuContainer: PropTypes.func
widgetMenuStyle = object
initialWidgetIds: array of widget ids
saveLayoutState = function
retrieveLayoutState = function
Dashboard
It is the base component for all other complex components. So yup , you can create custom dashboard using this component.
It provides you basic container for widgets, you can play with it and create awesome custom dashboard as you like
-Dashboard has following properties to configure
layoutsState = object
setLayoutsState = function
editable = boolean
onRemoveWidget = function
Thank you!!!!!!!!!!!!!!!!!!!! Back To Top ↑