grommet / jsx-to-string

Parse your React JSX component to string
MIT License
124 stars 26 forks source link

Add indents to multi-line formatted object strings #38

Closed kohlmannj closed 6 years ago

kohlmannj commented 6 years ago

Similar to #27, but based on the latest version of this library. Also, sorry about the delayed follow-up on this!

Description

Depending on its content, an object might be stringified as a multi-line string. I noticed this and added a bit of code to conditionally add indentation to all but the first line of the multi-string value in this case.

Before

The breakpoints prop is a multi-line object, but it doesn't have the correct indentation below.

<Responsive as={ThemedFigure}
  title='Shared Figure Title'
  breakpoints={{
"(max-width: 539px)": {
  "src": "http://placehold.it/320x160",
  "caption": "For some reason, this is just a captioned image on mobile."
},
"(min-width: 540px)": {
  "caption": "On desktop, this is a looping video. Try resizing the window to see what happens on mobile.",
  "children": <FrameAnimation src='https://video1.nytimes.com/paidpost/belvedere/the-view-from-here/tabletop.mp4' />
}
  }} />

After

Now the multi-line object is correctly indented.

<Responsive as={ThemedFigure}
  title='Shared Figure Title'
  breakpoints={{
    "(max-width: 539px)": {
      "src": "http://placehold.it/320x160",
      "caption": "For some reason, this is just a captioned image on mobile."
    },
    "(min-width: 540px)": {
      "caption": "On desktop, this is a looping video. Try resizing the window to see what happens on mobile.",
      "children": <FrameAnimation src='https://video1.nytimes.com/paidpost/belvedere/the-view-from-here/tabletop.mp4' />
    }
  }} />
alansouzati commented 6 years ago

thanks for your contribution @kohlmannj