편집 : 업데이트 응답 (v0.22.0)에 CSS 여전히 일반 CSS를 사용하여 설정을위한
:
<link rel="stylesheet" href="LINK_TO/material-components-web.css">
을하지만하는 SCS를 사용하는 것이 좋습니다를, 당신이 할 수있는이 방법 테마 색상과 같은 다른 값을 재정의하고 원하는 방식대로 모든 것을 사용자 정의하십시오. 예 :
$mdc-theme-primary: #404040;
$mdc-theme-accent: #a349a3;
$mdc-theme-background: #fff;
@import "@material/ripple/mdc-ripple";
@import "@material/typography/mdc-typography";
@import "@material/theme/mdc-theme";
@import "@material/button/mdc-button";
자바 스크립트와 관련하여 논리가 필요한 구성 요소를 사용하려면 보통이 구성 요소에 react.js 래퍼를 씁니다.
import React from 'react';
import { MDCDialog } from '@material/dialog/dist/mdc.dialog';
class AcceptDialog extends React.Component {
constructor(props) {
super(props);
this.passThroughInfo;
}
componentDidMount() {
this.dialog = new MDCDialog(this.refs.dialog);
// provide control to parent component to open the dialog from there
this.props.provideCtrl({
show: (passThroughInfo) => {
this.passThroughInfo = passThroughInfo;
this.dialog.show();
},
close:() => {
this.passThroughInfo = undefined;
this.dialog.close();
}
});
this.dialog.listen('MDCDialog:accept',() => {
this.props.acceptCb(this.passThroughInfo);
})
this.dialog.listen('MDCDialog:cancel',() => {
this.props.declineCb(this.passThroughInfo);
})
}
componentWillUnmount() {
this.props.provideCtrl(null);
}
defaultProps = {
className: "",
id: "",
header: "",
text: "",
acceptCb: function() { },
declineCb: function() { }
}
render() {
let className = "mdc-dialog accept_dialog" + this.props.className;
return (
<aside className={className} role="alertdialog" ref="dialog" id={this.props.id}>
<div className="mdc-dialog__surface">
{this.props.header !== "" &&
<header className="mdc-dialog__header">
<h2 className="mdc-dialog__header__title">
{this.props.header}
</h2>
</header>
}
<section className="mdc-dialog__body">
{this.props.section}
</section>
<footer className="mdc-dialog__footer">
<button type="button" className="mdc-button mdc-dialog__footer__button mdc-dialog__footer__button--cancel">Decline</button>
<button type="button" className="mdc-button mdc-dialog__footer__button mdc-dialog__footer__button--accept">Accept</button>
</footer>
</div>
<div className="mdc-dialog__backdrop"></div>
</aside>
);
}
}
export default AcceptDialog
그런 다음 다른 구성 요소에서 다음과 같이 사용합니다 :
// How to open the accept dialog
this.accept_dialog.show(data);
// The callback called on accept
callback(data){...}
<AcceptDialog
acceptCb={this.callback}
provideCtrl={ctrl => this.accept_dialog = ctrl}>
</AcceptDialog>
____________OLD ANSWER_______________
1) 추가 CSS 다음은 거절/동의 대화 상자 구성 요소에 대한 예입니다
정말 쉽습니다. 당신은 당신의 index.html 파일에 추가 할 수 있습니다 :
<link rel="stylesheet" href="LINK_TO/material-components-web.css">
당신은 또한 (당신이 @material NPM 모듈을 설치해야합니다 : --save @material를 설치 NPM을)를 말대꾸 파일에 액세스 할 수 SASS를 사용하는 경우 . 그런 다음 node-sass가 필요하고 webpack config에 @material 폴더의 경로를 포함시킵니다. 나는 이것을 시도하지 않았지만 이론적으로는 효과가있다.
자바 스크립트 추가
2) 다시 당신은 더 많은 가능성을 가지고있다. 여기 내가 한 일이있다. 당신은 지금 당신이 입력 필드의 구성 요소 (래퍼)를 만들 수 있습니다이
class Foo extends Component(){
componentDidMount(){
// either this like that
mdc.textfield.MDCTextfield.attachTo(this.refs.textfield);
// or like that
const MDCTextfield = mdc.textfield.MDCTextfield;
const textfield = new MDCTextfield(this.refs.textfield);
}
render() {
return(
<form className="form-group" onSubmit={this.submitForm}>
<div className="mdc-textfield" ref="textfield">
<input type="text" id="my-textfield" className="mdc-textfield__input"/>
<label className="mdc-textfield__label" htmlFor="my-textfield">Hint text</label>
</div>
</form>
);
}
}
같은 MDC를 가져올 수 있습니다.당신이하지 않으려면 해당 할 수도 있습니다 추가하여 자동 초기화 모든 구성 요소 :
// app.component.js
import * as mdc from 'material-components-web/dist/material-components-web';
class App extends React.Component {
componentDidMount(){
mdc.autoInit();
}
render(){
return(
<div className="my-app">
{this.props.children}
</div>
);
}
}
를하고 텍스트 필드에이를 추가
이 <div className="mdc-textfield" data-mdc-auto-init="MDCTextfield">
이제 다른 가능성이다 이런 식으로 가져 : 여기
import {MDCCheckbox} from '@material/checkbox';
당신이 당신의 웹팩 설정 파일에 bable 로더 말할 필요 node_modules/@ material 폴더도 포함시킵니다. 다른 모든 것은 기본적으로 동일하게 유지됩니다.
여기에 대한 답은 텍스트 심판을 사용하여 아주 좋은 그러나 만들었 반응을 변경하고 여기에 메소드는 추천 할 예정이다. 다음 문서를 참조하십시오. [https://reactjs.org/docs/refs-and-the-dom.html](https://reactjs.org/docs/refs-and-the-dom.html) 해결책은 클래스의 속성에 값을 설정하는 함수를 사용하는 것입니다.이 경우 this.refs.dialog는 아래 예제와 같이 this.dialog가됩니다. 'code'