Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.

Make a HOC version #9

Closed
jgoux opened this issue Mar 8, 2016 · 7 comments
Closed

Make a HOC version #9

jgoux opened this issue Mar 8, 2016 · 7 comments

Comments

@jgoux
Copy link

jgoux commented Mar 8, 2016

Hello,

I really like the API you built for this library. 馃憤

What would be the scenario when you want to integrate with custom/third-party components ?

For example, imagine I want to create a layout using multiple Paper from material-ui.

To make the Paper a flex element, I'd have to modify its style property (this is what I do at the moment), but I could do better and encapsulate all the "position/layout" logic inside HOC components which would apply the flexbox styles to their children, taking the API you provide :

import { AppBar, Paper } from "material-ui"
import { Box, Flex, Boxed, Flexed } from "reflexbox"

const view = (props) =>

<Flex auto column>
  <AppBar />
  <Flex auto>
    {/* Apply the styles generated from <Boxed auto> to <Paper>Left</Paper> */}
    <Boxed auto>
      <Paper>Left</Paper>
    </Boxed>
    <Boxed auto>
      <Paper>Right</Paper>
    </Boxed>
  </Flex>
</Flex>

I used Boxed and Flexed but the name/API could be anything.

What do you think ? 馃槃

@jxnblk
Copy link
Owner

jxnblk commented Mar 8, 2016

I've certainly been thinking about this. I was thinking more of having an API that looks something like this, but maybe there's good reason not to go with this approach:

<Box
  Component={Paper}
  {...boxProps}
  {...paperProps} />

The Box component would pass styles based on its props, then render Paper. Curious what you think

@jgoux
Copy link
Author

jgoux commented Mar 8, 2016

I think it's a matter of taste.

I prefer seeing a component's own props attached to its tag.
I also prefer seeing the tags tree composition, it reduces the cognitive load for me.

So I don't have a definitive answer for this, but I'm also curious of reading others opinions. 鈦夛笍

@mrtnbroder
Copy link

I'm with @jgoux. I'd prefer seeing my props on the component tag.

@jxnblk
Copy link
Owner

jxnblk commented Mar 8, 2016

I'm not opposed to the nested component approach. One thing that feels odd to me is that the jsx looks like two elements, but it's only generating one. Maybe that's an okay trade off in this situation.

@jgoux
Copy link
Author

jgoux commented Mar 8, 2016

We could also use a simple function:

import { AppBar, Paper } from "material-ui"
import { Box, Flex, box, flex } from "reflexbox"

const view = (props) =>

<Flex auto column>
  <AppBar />
  <Flex auto>
  {box({ auto: true })(
    <Paper>Left</Paper>
  )}
  {box({ auto: true })(
    <Paper>Right</Paper>
  )}
  </Flex>
</Flex>

With the partial application, you can even prepare common patterns :

import { AppBar, Paper } from "material-ui"
import { Box, Flex, box, flex } from "reflexbox"

const CustomBox = box({ auto: true })

const view = (props) =>

<Flex auto column>
  <AppBar />
  <Flex auto>
  {CustomBox(
    <Paper>Left</Paper>
  )}
  {CustomBox(
    <Paper>Right</Paper>
  )}
  </Flex>
</Flex>

@jxnblk
Copy link
Owner

jxnblk commented Mar 13, 2016

The latest version 1.1.0 supports an is prop to pass components or elements to render as the root. I'll take a stab at wrapper component as well at some point.

@jxnblk jxnblk closed this as completed in a3c4acb Jul 31, 2016
@jgoux
Copy link
Author

jgoux commented Aug 3, 2016

Congrats for the release ! 馃憤

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

No branches or pull requests

3 participants