BusinessOptics Frontend Library
This library consists of modern and useful reusable components for React based BusinessOptics apps. It works best with apps that have been built using create-react-app version 2+. It consists of three primary sections:
- Small but useful utilities
- A resusable component library
- SCSS based theme components
All modern BusinessOptics apps should use it, and abstract any common functionality to it. The library is a little disorganised right now, but we will strive to keep the external interfaces reasonably stable.
Usage
the library can be installed with npm
straight off Github assuming you have the correct permissions, via:
npm install @businessoptics/frontend-library
Development usage
Use npm link to make devlopment usage easier (this is probably mandatory for now). This allows changes you make to automatically be picked up by projects using it on your local development machine.
-
git clone the library
-
Navigate to the root folder
-
Run npm link
(you may have to sudo)
-
Run npm run build:watch
(this will automatically build the library when you make changes)
-
Navigate to a project that is using the library (and already has it installed)
-
Run npm link @businessoptics/frontend-library
-
Run npm start
Now if you make a change in this library, the application using it should automatically update, making for a great development cycle.
You will have to rerun the second part of the steps when you run npm install
in an application.
Components
Utilities
These can be imported directly form the root module. They include a small set of helpers particularly useful for dealing with redux stores, without heavy weight dependencies like immutable.js.
Immutability helpers
These all work off iupdate
root
is a nested objectpath
is an array of strings/numbers, or a single itemupdateFn
is a function that takes a single value and returns the value to replace it with
export const iupdate = (root, path, updateFn) => ..
export const iset = (root, path, value) => iupdate(root, path, () => value);
export const ipush = (root, path, value) =>
iupdate(root, path, list => list.concat([value]));
export const iremove = (root, path, index) =>
iupdate(root, path, list => [
...list.slice(0, index),
...list.slice(index + 1)
]);
Other useful helpers can be found in utilities.js.
General Input Component
The <Input/>
component is a generalised input component that deals with many edge cases around the traditional inputs and has a unified styling system. Primarily it accepts a type
prop which defines the data type (and default widget), and an optional widget
prop which customises what widget is used. These are meant to be used as controlled components. The options are
- type: text, number, currency, boolean
- widget: text, number, currency, checkbox, toggle, select, radiogroup, radiogroup-vertical
Obviously only some types can support some widgets, use common sense. Null is correctly supported and the value is always of the correct type.
The input takes an onChange(value)
event handler which is given the value of the control of the correct type.
Other props include:
- value: The value
- disabled: Disable the input
- choices: a list of {value, label} pairs for use by select, radiogroup, radiogroup-vertical.
- Other props are passed directly to the implementing component, look at the code for more details.
Additionally there is a list widget which takes a list of objects as it's value, and required a list of field definitions, which are props for the various columns field types.
SCSS based mixins
These assume a create-react-app v2+ is using the library. The scss can be included through:
@import "~@businessoptics/frontend-library/css/mixins.scss";
The following mixins are available.
@include businessoptics-input-components($primaryColor, $secondaryColor);
@include standard-input-components($primaryColor, $secondaryColor);
@include data-tables($primaryColor, $secondaryColor);
@include businessoptics-typography;
@include utility-classes($primaryColor, $secondaryColor);