Core UI is a dead-simple wrapper around your (React) component library, which aims to provide two benefits: simple, flat paths for import statements and 'switchable' presentational components
npm install core-ui``
npm install --save core-ui
`
+ Create a registeration file (e.g. utils/compRegister.js).registerComponents
+ Import from core-ui
+ Import all components you wish to register.
+ Create an object from your imported components
+ call registerComponents, passing in your object of components.
`
import { registerComponents } from 'core-ui';
import AppBar from 'react-toolbox/lib/app_bar';
import Autocomplete from 'some/other/place';
....
// little helper from ES6
const appUI = {
AppBar,
Autocomplete,
};
// now register the components
registerComponents(appUI);
`
The file needs to be imported before any register components are needed.
`
import AppComponents from './utils/compRegister';
import React from 'react';
import { render } from 'react-dom';
import { createStore, applyMiddleware } from 'redux';
...
`
Now we can easily require our components wherever we need them within the application without worring about paths.
``
import React from 'react';
import { AppBar, NavMenu, Hamburger} from 'core-ui';
...
render() {
return (
onOverlayClick={this.toggleOffCanvasNav}
links={links} />
handleClick={this.toggleOffCanvasNav} />
);
}$3
Image one of the following situations:
+ Someone wrote a killer new Table component, and your team intends to use this new Table component throughout our application.
+ Your project undergoes some file and directory restructoring.
In the latter situation, components using core-ui will not be effected because they are not dependent upon relative paths. In the former scenario (introducing a new Component, or replacing an existing one), we simply need to modify our utils/compRegister.js file:
```
import Table from 'SOME/NEW/LOCATION';
Notice, everything else is the same. We only needed to change one line to start using our new Table component! Also, note that we are simply importing a file. That file can do whatever we need it to do, including any API 'bridging' that may need to take place between the 'old' and 'new' components.