react-responsive-ui
Responsive React UI components.
Installation
npm install react-responsive-ui --save
Usage
See the demo page. It has code examples for every component.
Expandable components require Promise
(get a polyfill for IE 11).
Reducing footprint
Webpack 4 still can't "tree-shake" simple cases like
So if one's using only a small subset of this library it could be imported like so
Which results in a much smaller bundle size.
The same can be done for CSS: instead of importing the whole react-responsive-ui/style.css
bundle one could import only the necessary styles from react-responsive-ui/styles/
like react-responsive-ui/styles/Button.css
. There's a catch though: those stylesheets are usually dependent on each other and, for example, the <Button/>
component actually requires three different stylesheets to be imported:
react-responsive-ui/styles/Button.css
react-responsive-ui/styles/ButtonReset.css
react-responsive-ui/styles/Input.css
CSS
The CSS for this library must be included on a page too.
When using Webpack
And set up a postcss-loader
with a CSS autoprefixer for supporting old web browsers (e.g. last 4 versions
, iOS >= 7
, Android >= 4
).
When not using Webpack
Get the style.css
file from this package, process it with a CSS autoprefixer for supporting old web browsers (e.g. last 4 versions
, iOS >= 7
, Android >= 4
), and then include it on a page.
Small Screen
The small-screen
directory contains "small screen" ("mobile devices") styles for some of the components. E.g. <Select/>
s, <Autocomplete/>
s, <ExpandableMenu/>
s, <DatePicker/>
s and <Modal/>
s can open in fullscreen and <Snackbar/>
are expanded in full screen (not neccessarily a good idea though).
Native CSS @import
example:
SCSS @import
example:
Variables
This library uses native CSS variables for easier styling. See variables.css
for the list of all available variables. These variables have some sensible defaults which can be overridden in a separate react-responsive-ui-variables.css
file (analogous to the original variables.css
file).
When not using Webpack
When using Webpack
Native CSS variables work in all modern browsers, but older ones like Internet Explorer wont't support them. For compatibility with such older browsers one can use a CSS transformer like PostCSS with a "CSS custom properties" plugin like postcss-css-variables
. Check that it actually replaces var()
s with the actual values in the output CSS.
An example for Webpack and SCSS:
Validation
Each form component receives two validation-specific properties
error : String
– error messageindicateInvalid : boolean
– whether the field should be displayed as an invalid one (including showing theerror
message)
When both of these properties are set the form component appends --invalid
postfixes to its CSS className
s.
Drag'n'drop
Drag'n'drop is implemented internally using react-dnd
providing a much simpler-to-use API. Currently only file upload is supported but new features could be added upon request.
Use babel-plugin-transform-decorators-legacy for decorators syntax support.
Known Issues
An overflown <Modal/>
scroll is janky on iOS because it tries to scroll <body/>
instead of the <Modal/>
contents. That's how it is on iOS.
Contributing
After cloning this repo, ensure dependencies are installed by running:
This module is written in ES6 and uses Babel for ES5
transpilation. Widely consumable JavaScript can be produced by running:
Once npm run build
has run, you may import
or require()
directly from
node.
After developing, the full test suite can be evaluated by running:
When you're ready to test your new functionality on a real project, you can run
It will build
, test
and then create a .tgz
archive which you can then install in your project folder