3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

react material-ui のサンプル

Last updated at Posted at 2016-11-30

reactとmaterial-uiのサンプル

チェックボックスを使いたくで、ドキュメントを見ながら配置してみた。

ドキュメントの内容:

import React from 'react';
import Checkbox from 'material-ui/Checkbox';
import ActionFavorite from 'material-ui/svg-icons/action/favorite';
import ActionFavoriteBorder from 'material-ui/svg-icons/action/favorite-border';
import Visibility from 'material-ui/svg-icons/action/visibility';
import VisibilityOff from 'material-ui/svg-icons/action/visibility-off';

const styles = {
  block: {
    maxWidth: 250,
  },
  checkbox: {
    marginBottom: 16,
  },
};

const CheckboxExampleSimple = () => (
  <div style={styles.block}>
    <Checkbox
      label="Simple"
      style={styles.checkbox}
    />
以下略

ふむふむ。なるほどね?っと上記を真似て配置したが、全然うまくいかず・・・

いろいろと探った結果、こんなルールがあった(気付きにくいよー涙)

App.js
import { browserHistory } from 'react-router';
import React, { Component } from 'react';
// MuiThemeProviderをimport
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';

import './App.css';


class App extends Component {
  render() {
    return (
      // <MuiThemeProvider>でラッピング
      <MuiThemeProvider>
      <div>
        <main>
          <div>
               { this.props.children }
          </div>
        </main>
      </div>
      </MuiThemeProvider>
    );
  }
}
使う側のコンポーネント
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import Checkbox from 'material-ui/Checkbox';

・・・・
          <Checkbox
            id="rv_rhd_site"
            label=""
            value="1"
            // ↓をやらないとmuiがないよ!ってエラーが起きる。
            muiTheme={getMuiTheme("checkbox")}
            style={styles.checkbox}
            labelStyle={styles.label}
            defaultChecked={incident.rv_rhd_site==1?true:false}
          />
・・・

へい!アメリカンぴーぽー!
ドキュメントの例は、もっと親切にしてYO!

英語よくわかんねーYO!

ちなみに

usageに書いてあります。

でも、サンプルにも書いてくれてもよくない・・・?

この記事でmaterial-ui使えたよ!!って人は「いいね!」宜しくですw

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?