Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add react component as property to another react component (Material-UI) #134

Open
shybyte opened this issue Jul 4, 2017 · 3 comments
Open

Comments

@shybyte
Copy link

shybyte commented Jul 4, 2017

Some libraries like material-ui require to add components as properties to another react component.

JSX Example (See live/complete):

render() {
    const actions = [
      <FlatButton
        label="Cancel"
        primary={true}
        onTouchTap={this.handleClose}
      />,
      <FlatButton
        label="Submit"
        primary={true}
        keyboardFocused={true}
        onTouchTap={this.handleClose}
      />,
    ];

    return (
      <div>
        <RaisedButton label="Dialog" onTouchTap={this.handleOpen} />
        <Dialog
          title="Dialog With Actions"
          actions={actions}
          modal={false}
          open={this.state.open}
          onRequestClose={this.handleClose}
        >
          The actions in this window were passed in as an array of React objects.
        </Dialog>
      </div>
    );
  }

I wonder if this is possible in purescript-pux. The following approach does not work. Is there a way which works?

foreign import raisedButtonClass ::  props. ReactClass props
raisedButton = reactClassWithProps raisedButtonClass "RaisedButton"
foreign import dialogClass ::  props. ReactClass props
dialog  = reactClassWithProps dialogClass "Dialog"

...

dialog {
    -- the next line does not work
    actions: [(raisedButton {label: "Close"} #! onClick (const ToggleDialog) $ mempty)],
    open: state.isDialogOpen,
    title: "Dialog Title"
  }
  #! (on "onRequestClose" (const ToggleDialog))
  $ text "Dialog Text"

You can find a complete example here: https://github.com/shybyte/pux-starter-app-material-ui/blob/master/src/Main.purs

@i-am-the-slime
Copy link

i-am-the-slime commented Aug 15, 2017

I have the same question, for a different library (ant.design). Have you made any progress on this in the meantime @shybyte ?

@shybyte
Copy link
Author

shybyte commented Aug 16, 2017

@i-am-the-slime I haven't found a solution for this problem. Actually I haven't tried much longer. Once a year I start to learn PureScript but every time again in practice I stumble over the pureness part of it and I give up. But still, if you find a solution, please post it here, so I have a better start next year :-)

@kritzcreek
Copy link
Contributor

For these kind of things you'll want to directly use purescript-react purescript-pux is not really compatible with the component model of React. It is a direct port of the Elm architecture, which has a monolithic state atom (Redux is that for the React ecosystem).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants