redux-form-material-ui

A set of wrapper components to facilitate using Material UI with Redux Form

  • 所有者: erikras/redux-form-material-ui
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖


redux-form-material-ui


NPM Version
NPM Downloads
Build Status
codecov.io
CDNJS version

For material-ui v1-beta support see 5.0 Documentation.

redux-form-material-ui is a set of
wrappers to facilitate the use of
material-ui components with
redux-form.


Live Demo :eyes:

Installation

Using npm:

  $ npm install --save redux-form-material-ui

Available Components

Usage

Rather than import your component class from material-ui, import it from redux-form-material-ui
and then pass the component class directly to the component prop of Field.

import { reduxForm, Field } from 'redux-form'
import MenuItem from 'material-ui/MenuItem'
import { RadioButton } from 'material-ui/RadioButton'
import {
  Checkbox,
  RadioButtonGroup,
  SelectField,
  TextField,
  Toggle,
  DatePicker
} from 'redux-form-material-ui'

class MyForm extends Component {
  render() {
    return (
      <form>
        <Field name="username" component={TextField} hintText="Street"/>

        <Field name="plan" component={SelectField} hintText="Select a plan">
          <MenuItem value="monthly" primaryText="Monthly"/>
          <MenuItem value="yearly" primaryText="Yearly"/>
          <MenuItem value="lifetime" primaryText="Lifetime"/>
        </Field>

        <Field name="agreeToTerms" component={Checkbox} label="Agree to terms?"/>

        <Field name="eventDate" component={DatePicker} format={null} hintText="What day is the event?"/>

        <Field name="receiveEmails" component={Toggle} label="Please spam me!"/>

        <Field name="bestFramework" component={RadioButtonGroup}>
          <RadioButton value="react" label="React"/>
          <RadioButton value="angular" label="Angular"/>
          <RadioButton value="ember" label="Ember"/>
        </Field>
      </form>
    )
  }
}

// Decorate with redux-form
MyForm = reduxForm({
  form: 'myForm'
})(MyForm)

export default MyForm

No Default Values

Because of the strict "controlled component" nature of redux-form,
some of the Material UI functionality related to defaulting of values has been disabled
e.g. defaultValue, defaultDate, defaultTime, defaultToggled, defaultChecked, etc.
If you need a field to be initialized to a certain state, you should use the initialValues
API of redux-form.

Instance API

getRenderedComponent()

Returns a reference to the Material UI component that has been rendered. This is useful for
calling instance methods on the Material UI components. For example, if you wanted to focus on
the username element when your form mounts, you could do:

componentWillMount() {
  this.refs.firstField      // the Field
    .getRenderedComponent() // on Field, returns ReduxFormMaterialUITextField
    .getRenderedComponent() // on ReduxFormMaterialUITextField, returns TextField
    .focus()                // on TextField
}

as long as you specified a ref and withRef on your Field component.

render() {
  return (
    <form>
      ...
      <Field name="username" component={TextField} withRef ref="firstField"/>
      ...
    </form>
  )
}

主要指標

概覽
名稱與所有者erikras/redux-form-material-ui
主編程語言JavaScript
編程語言JavaScript (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2016-05-23 23:25:32
推送於2023-01-12 08:23:25
最后一次提交2018-04-07 12:48:19
發布數19
最新版本名稱v5.0.0-beta-3 (發布於 )
第一版名稱v1.0.0 (發布於 )
用户参与
星數832
關注者數18
派生數227
提交數82
已啟用問題?
問題數226
打開的問題數55
拉請求數43
打開的拉請求數17
關閉的拉請求數22
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?