简体   繁体   English

如何将Material-UI FlatButton CSS传递到其他Button组件

[英]How to pass Material-UI FlatButton CSS into other Button component

I'm using a loading button object in my website ( https://github.com/mathieudutour/react-progress-button ), and I'm trying to pass the Material-UI FlatButton CSS into it so that it looks the same as the FlatButton. 我在我的网站( https://github.com/mathieudutour/react-progress-button )中使用了加载按钮对象,并且试图将Material-UI FlatButton CSS传递给它,以使其看起来相同作为FlatButton。 However, I'm not sure how to do this. 但是,我不确定如何执行此操作。

import ProgressButton from 'react-progress-button'

const App = React.createClass({
  getInitialState () {
    return {
      buttonState: ''
    }
  },

  render () {
    return (
      <div>
        <ProgressButton onClick={this.handleClick} state={this.state.buttonState}
style={//flat button CSS goes here.....}>
          Go!
        </ProgressButton>
      </div>
    )
  },

  handleClick () {
    this.setState({buttonState: 'loading'})
    // make asynchronous call
    setTimeout(() => {
      this.setState({buttonState: 'success'})
    }, 3000)
  }
})

Thanks for your help. 谢谢你的帮助。

You can create an invisible flat button and get the style by using something like: 您可以创建一个不可见的平面按钮,并使用以下方法获取样式:

<FlatButton id="mock1"/> 
let flatButtonStyle = window.getComputedStyle(document.getElementById('mock1'));

Then assign it to <ProgressButton> . 然后将其分配给<ProgressButton> You might have to modify the CSS style object a bit since it is returning you all the computed styles. 您可能需要稍微修改CSS样式对象,因为它会返回所有计算出的样式。

<ProgressButton onClick={this.handleClick} state={this.state.buttonState} style={this.flatButtonStyle}>

For example in your code import ProgressButton from 'react-progress-button' 例如,在您的代码中,从“ react-progress-button”导入ProgressButton

const App = React.createClass({
  getInitialState () {
    return {
      buttonState: ''
    }
  },

  render () {
    let flatButtonStyle = window.getComputedStyle(document.getElementById('mock1'));
    return (
      <div>
        <FlatButton id="mock1"/>
        <ProgressButton onClick={this.handleClick} state={this.state.buttonState}
style={this.flatButtonStyle}>
          Go!
        </ProgressButton>
      </div>
    )
  },

  handleClick () {
    this.setState({buttonState: 'loading'})
    // make asynchronous call
    setTimeout(() => {
      this.setState({buttonState: 'success'})
    }, 3000)
  }
})

This should give you a roughly idea. 这应该给您一个大概的想法。 You have to modify the code a little bit to make it work. 您必须稍微修改一下代码才能使其工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM