From 04375301ccd14affa2fc3198ab10e431af9d3ec8 Mon Sep 17 00:00:00 2001 From: Daniel Woznicki Date: Mon, 31 Dec 2018 23:52:41 -0800 Subject: [PATCH 1/3] Add option to print props on a single line when component has children --- src/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 0946176..cb3427a 100644 --- a/src/index.js +++ b/src/index.js @@ -77,7 +77,8 @@ function jsxToString (component, options) { ignoreTags: [], keyValueOverride: {}, spacing: 0, - detectFunctions: false + detectFunctions: false, + singleLineProps: false }; const opts = {...baseOpts, ...options}; @@ -120,7 +121,7 @@ function jsxToString (component, options) { value = valueLines.join(`\n${indentation}`); } return `${key}=${value}`; - }).join(`\n${indentation}`); + }).join(opts.singleLineProps ? ' ' : `\n${indentation}`); if (component.key && opts.ignoreProps.indexOf('key') === -1) { componentData.props += `key='${component.key}'`; From cce30bf3230e86c8e9c1fba954af7b785f83eb5e Mon Sep 17 00:00:00 2001 From: Daniel Woznicki Date: Tue, 1 Jan 2019 00:07:25 -0800 Subject: [PATCH 2/3] Add example for singleLineProps to README --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 4f78420..5933fbc 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,32 @@ let Basic = React.createClass({ console.log(jsxToString(, { displayName: 'CustomName' })); //outputs: +``` + + * singleLineProps (boolean) + + Optional. Defaults to false. Prints props on a single line when the component has children. + +```js +import React from 'react'; +import jsxToString from 'jsx-to-string'; +//or var jsxToString = require('jsx-to-string'); + +let Basic = React.createClass({ + render() { + return ( +
+ ); + } +}); //this is your react component + +console.log(jsxToString(child, { + singleLineProps: true +})); +//outputs: +// +// child +// ``` ### License From eb6004adccacece556f5156d3946494da3a5afba Mon Sep 17 00:00:00 2001 From: Daniel Woznicki Date: Tue, 1 Jan 2019 00:10:59 -0800 Subject: [PATCH 3/3] Double quotes -> single quotes (oops) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5933fbc..44b679f 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ console.log(jsxToString(child, { singleLineProps: true })); //outputs: -// +// // child // ```