README
react-html-components
Generic html react components for materializecss
[![Build Status](https://travis-ci.org/mykhailokoretskyi/react-html-components.svg?branch=master)](https://travis-ci.org/react-html-components/react-html-components) [![npm version](http://img.shields.io/npm/v/react-html-components.svg?style=flat)](https://npmjs.org/package/react-html-components "View this project on npm")
Getting started
Install npm package
npm install --save react-html-components
This package requires materializecss.
Usage
import {TextInput, Switch} from 'react-html-components';
Currently supported materialize elements:
- Form elements
- input type text (TextInput)
- input type email (EmailInput)
- input type password (PasswordInput)
- input type radio (RadioButton)
- input type checkbox (Checkbox)
- switch (Switch)
- Icons
- Icon
- TinyIcon
- SmallIcon
- MediumIcon
- LargeIcon
- Buttons
- Button
- LargeButton
- FlatButton
- FloatingButton
- Modal
Documentation
Form elements
Common attributes
value
- typestring
;checked
- typeboolean
;name
- typestring
;disabled
- typeboolean
;id
- typestring
;required
- typeboolean
;extraClass
- typestring
(is added toclass
attribute of<input/>
);label
- typestring
(injected withdangerouslySetInnerHTML
);changeCallback
- typefunction
(executed when input changes value/checked);mouseEnterCallback
- typefunction
(executed on hover of<input/>
);mouseLeaveCallback
- typefunction
(executed on mouse leave the<input/>
);
Methods
Following accessor methods are available through the React`s refs
:
value
- getter/setter;checked
- getter/setter;disabled
- getter/setter;required
- getter/setter;type
- getter;
Example:
someMethod(){
this.refs.textInput.value("new value"); // setter
this.refs.textInput.value() // getter
}
.......
render(){
return (
<TextInput ref="textInput" value="initial value" />
);
type="text"
)
TextInput (Supports common attributes.
Attributes
placeholder
- typestring
;
type="password"
)
PasswordInput (Supports common attributes.
Attributes
placeholder
- typestring
;
type="email"
)
EmailInput (Supports common attributes.
Attributes
placeholder
- typestring
;validate
- typebool
(reference materializecss documentation);errorMessage
- typestring
(data-error
attribute of<input/>
);successMessage
- typestring
(data-success
attribute of<input/>
);
type="checkbox"
)
Checkbox (Supports common attributes.
type="radio"
)
RadioButton (Supports common attributes.
Attributes
withGap
- typebool
(reference materializecss documentation);
Icons
Icon - base icon component
Attributes
classes
- typeArray
of css classes which will be concatenated with space;iconName
- typestring
- reference to materializecss docs;size
- typestring
(one of ["","tiny","small","medium","large"]);
TinyIcon (type={"tiny"})
SmallIcon (type={"small"})
MediumIcon (type={"medium"})
LargeIcon (type={"large"})
Example:
import { SmallIcon } from 'react-html-components';
.......
render(){
return (
<SmallIcon classes={["left"]} iconName={"cloud"} />
);
Buttons
Button
Button
- is a base component for buttons.
refs
)
Methods (available through disabled
- setter/getter;
Attributes
classes
- typeArray
of css classes which will be concatenated with space;clickCallback
- typefunc
- will be triggered on click (is not triggered on disabled buttons);disabled
- typebool
;type
- type oneOf(["", "btn-large", "btn-flat", "btn-floating"]) - should not be used normaly;
LargeButton (Button type={"btn-large"})
FlatButton (Button type={"btn-flat"})
FloatingButton (Button type={"btn-floating"})
Example:
import { LargeButton } from 'react-html-components';
.......
render(){
return (
<LargeButton disabled={true}>Test Button</LargeButton>
);
Modal
Attributes
type
- typestring
(default modal, if empty;bottom-sheet
,modal-fixed-footer
);
refs
)
Methods (available through open
- open modal;close
- close modal;
Example:
import { Modal, ModalContent, ModalFooter, FlatButton } from 'react-html-components';
render(){
return (
<Modal ref="modal" type="bottom-sheet">
<ModelContent>
Content
</ModalContent>
<ModalFooter>
<FlatButton classes={["modal-action modal-close waves-effect waves-green"]}>Agree</FlatButton>
</ModelFooter>
</Modal>
);
openModal(){
this.refs.modal.open();
}
closeModal(){
this.refs.modal.close();
}