Package Exports
- react-responsive-ui
- react-responsive-ui/commonjs/Select
- react-responsive-ui/commonjs/Tooltip
- react-responsive-ui/modules/Select
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-responsive-ui) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
react-responsive-ui
Responsive React UI components.
Installation
npm install react-responsive-ui --saveUsage
See the demo page. It has code examples for every component.
<Select/> component requires Promise (get a polyfill for IE 11).
Reducing footprint
Webpack 4 still can't "tree-shake" simple cases like
import { Modal, Button, TextInput } from 'react-responsive-ui'So if one's using only a small subset of this library it could be imported like so
import Modal from 'react-responsive-ui/commonjs/Modal'
import Button from 'react-responsive-ui/commonjs/Button'
import TextInput from 'react-responsive-ui/commonjs/TextInput'Which results in a much smaller bundle size.
CSS
The CSS for this library must be included on a page too.
When using Webpack
require('react-responsive-ui/variables.css')
require('react-responsive-ui/style.css')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.
<head>
<link rel="stylesheet" href="/css/react-responsive-ui/variables.css"/>
<link rel="stylesheet" href="/css/react-responsive-ui/style.css"/>
</head>Small Screen
The small-screen directory contains "small screen" ("mobile devices") styles for some of the components. E.g. <Select/>s, <DatePicker/>s and <Modal/>s can open in fullscreen and <Snackbar/> can be centered rather than placed in the lower left corner.
Native CSS @import example:
@import url(~react-responsive-ui/style.css)
@import url(~react-responsive-ui/small-screen/Modal.css) (max-width: 720px)
@import url(~react-responsive-ui/small-screen/Snackbar.css) (max-width: 720px)
@import url(~react-responsive-ui/small-screen/DatePicker.InputOverlay.css) (max-width: 720px)SCSS @import example:
@import "~react-responsive-ui/style";
@media (max-width: 720px) {
@import "~react-responsive-ui/small-screen/Modal";
@import "~react-responsive-ui/small-screen/Snackbar";
@import "~react-responsive-ui/small-screen/DatePicker.InputOverlay";
}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
<head>
<!-- React Responsive UI -->
<link rel="stylesheet" href="/css/react-responsive-ui/style.css"/>
<!-- Custom variable values -->
<link rel="stylesheet" href="/css/react-responsive-ui-variables.css"/>
</head>When using Webpack
// React Responsive UI.
require('react-responsive-ui/style.css')
// Custom variable values.
require('./src/styles/react-responsive-ui-variables.css')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 (a working example).
An example for Webpack and SCSS:
@import "~react-responsive-ui/style";
@media (max-width: 720px) {
@import "~react-responsive-ui/small-screen/Modal";
@import "~react-responsive-ui/small-screen/Snackbar";
@import "~react-responsive-ui/small-screen/DatePicker.InputOverlay";
}
:root {
--rrui-unit : 12px;
--rrui-white-color : #f0f7ff;
--rrui-black-color : #112233;
--rrui-accent-color : #cc0000;
--rrui-accent-color-light : #ee0000;
--rrui-gray-color : #7f7f7f;
}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 theerrormessage)
When both of these properties are set the form component appends --invalid postfixes to its CSS classNames.
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.
import { DragAndDrop } from 'react-responsive-ui'
@DragAndDrop()
class Application extends Component {
render() {
const { isDragging, children } = this.props
return <div>{ children }</div>
}
}import { CanDrop, FILE, FILES, FileUpload } from 'react-responsive-ui'
class FileUploadPage extends Component {
onUpload = (file, action) => {
alert(`File ${action}: ${file.name}`)
}
render() {
return (
<div>
<h1> File upload </h1>
<FileUploadArea
onUpload={ this.onUpload }
className="file-upload"/>
</div>
)
}
}
// `FILE` is for single-file upload.
// `FILES` is for multiple files upload.
@CanDrop(FILE, (props, file) => {
props.onUpload(file, 'dropped')
})
class FileUploadArea extends Component {
render() {
const {
dropTarget,
draggedOver,
onUpload,
className
} = this.props
return dropTarget(
<div>
<FileUpload
action={(file) => onUpload(file, 'chosen')}
className={`${className} ${draggedOver ? 'rrui__file-upload--dragged-over' : ''}`}>
Click here to choose a file
or drop a file here
</FileUpload>
</div>
)
}
}.rrui__file-upload
{
display : inline-block;
padding : 20px;
border : 1px dashed #afafaf;
border-radius : 5px;
background-color : #fbfbfb;
cursor : pointer;
text-align : center;
}
.rrui__file-upload--dragged-over
{
background-color : #3678D1;
color : white;
}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:
npm installThis module is written in ES6 and uses Babel for ES5 transpilation. Widely consumable JavaScript can be produced by running:
npm run buildOnce npm run build has run, you may import or require() directly from
node.
After developing, the full test suite can be evaluated by running:
npm testWhen you're ready to test your new functionality on a real project, you can run
npm packIt will build, test and then create a .tgz archive which you can then install in your project folder
npm install [module name with version].tar.gz