Skip to content

Export functions used to build className for Row & Column #91

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

Merged
merged 4 commits into from
Feb 22, 2017
Merged

Export functions used to build className for Row & Column #91

merged 4 commits into from
Feb 22, 2017

Conversation

nathanstitt
Copy link
Contributor

This will allow other components to act as a Row or Column by sharing the same prop building logic.

For instance I have a <FormField /> component (who doesn't?). I could wrap it with Col, but it would be nice if it would accept all the Col props and set the appropriate classNames on itself.

This will allow other components to act as a Row or Column by sharing the prop building validation
@nathanstitt
Copy link
Contributor Author

nathanstitt commented Feb 21, 2017

While testing #90, I discovered another use case that'd be nice to support. Also happy to rework and/or add to the README if you think it's a good idea.

Copy link
Collaborator

@silvenon silvenon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's useful! Because sometimes I don't want a containing <div>. How about adding those exports to index.js? That way they can be imported like this:

import { getColClassNames } from 'react-flexbox-grid';

Yes, please add this to README.md as well. 👍

What other use case did you had in mind?

@nathanstitt
Copy link
Contributor Author

Just pushed an update to do so.

This is all I've thought of, but I am starting a new project where I'm planning to use react-flexbox-grid extensively, so we'll see if I find anything else.

Copy link
Collaborator

@silvenon silvenon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I really like this idea. 👍 Sorry for requesting changes all the time. 😅

README.md Outdated
Functions for generating Row and Column classNames are exported for use in other components. For example, suppose you have a `MyFormInput` component that should also act as both a `Row` and a `Col`.

```js
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this { is accidental?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry ☹️

src/index.js Outdated
export Row from './components/Row';
export Col from './components/Col';
export * from './components/Row';
export * from './components/Col';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather if these exports were explicit, just so we don't accidentally expose some internal API in the future. Combined with leaving Col and Row as default exports, I think this should be:

export Row, { getRowClassNames } from './components/Row';
export Col, { getColClassNames } from './components/Col';

Not sure if this is valid syntax, though. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's correct - I wrote a spec to test that everything is exported as it should be. I was on the fence about doing as you suggest vs the glob. I went with the glob because it'd make future changes easier to make, but explicit is also a good concern. Made an update

@@ -1,7 +1,7 @@
import expect from 'expect';
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import Col from '../../src/components/Col';
import { Col, getColClassNames } from '../../src/components/Col';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're keeping Col as default, as explained above:

import Col, { getColClassNames } from '../../src/components/Col';

@@ -1,7 +1,7 @@
import expect from 'expect';
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import Row from '../../src/components/Row';
import { Row, getRowClassNames } from '../../src/components/Row';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as Col.

@@ -60,8 +60,8 @@ function getClassNames(props) {
.concat(extraClasses);
}

export default function Col(props) {
const classNames = getClassNames(props);
export function Col(props) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason for converting this default export to a named one, I see this only as a risk of breaking something. I described below how leaving this as a default export would reflect on the rest of the changes.

@@ -38,8 +38,8 @@ function getClassNames(props) {
return modificators;
}

export default function Row(props) {
return React.createElement(props.tagName || 'div', createProps(propTypes, props, getClassNames(props)));
export function Row(props) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as Col.

@nathanstitt
Copy link
Contributor Author

No problem at all - this is your baby; I'm just glad you're willing to accept updates so we can all use it as we'd like. Just made another round for you to look at.

@silvenon silvenon merged commit 3ccfa3c into roylee0704:master Feb 22, 2017
@silvenon
Copy link
Collaborator

Looks good, thanks! 👍

Copy link
Collaborator

@silvenon silvenon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I noticed a problem with this, if you're up for another PR. 😄

export default function MyFormInput(props) {
return (
<form className={getRowclassNames(props)}>
<input className={getColClassNames(props)} />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this example will work correctly, because getRowClasssNames and getColClassNames produce an array, but className requires a string. When I was playing with this, I got something like this:

<form class=",row,around-xs">

I think it relies on createProps to concatenate it to a valid class name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yes good point. I'm actually feeding it into the classnames lib which seems smart enough to be do the right thing. I'll play with it a bit to find the best approach, then make a PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! ❤️

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

Successfully merging this pull request may close these issues.

2 participants