-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(factories): add overrideProps #1428
Conversation
@levithomason I've added |
I'd like to think about this one a bit. |
@levithomason It will be great receive some feedback from you. Of course, when you will have enough time |
Whoops, forgot about this thanks! I'm working on the Tabs ATM and also need this feature. Looking now... |
src/lib/factories.js
Outdated
return (val, defaultProps) => { | ||
return createShorthand(Component, mapValueToProps, val, defaultProps, generateKey) | ||
return (val, defaultProps, overrideProps) => { | ||
return createShorthand(Component, mapValueToProps, val, defaultProps, overrideProps, generateKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only comment I have is that the arguments here are getting a little wild. There are cases where you'd want to set generateKey
but not defaultProps
nor overrideProps
. That usage is ugly:
createShorthand(
Menu,
items => ({ items }),
null, // defaultProps
null, // overrideProps
true, // generateKey
)
Perhaps we move these optional arguments to an options object?
createShorthand(
Menu,
items => ({ items }),
{ generateKey: true }
)
EDIT
Fixed completely incorrect signatures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like functions with more that 3 args, so I agree, it will better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would also apply to the returned create
factory. Instead of:
Menu.create(menu, null /* defaultProps */, () => /* override props */)
We'd have something like:
Menu.create(menu, { overrideProps: () => { ... } })
I'll rebase it, complete TODOs and update code with your suggestion tomorrow |
I'd like to try and simplify the factories as we also add more features. There is only one component that currently requires usages of Input.js const actionElement = Button.create(action, elProps => ({
className: cx(
// all action components should have the button className
!_.includes(elProps.className, 'button') && 'button',
),
})) This is ensuring the I think we should then also remove the option for Thoughts? |
Codecov Report
@@ Coverage Diff @@
## master #1428 +/- ##
==========================================
- Coverage 99.74% 99.74% -0.01%
==========================================
Files 141 141
Lines 2384 2383 -1
==========================================
- Hits 2378 2377 -1
Misses 6 6
Continue to review full report at Codecov.
|
Just ran into an issue over at https://github.com/Semantic-Org/Semantic-UI-React/pull/1508/files#r108559120. We currently only enable support for keys if a Although we know which components we need keys for, consumers can also use |
Heads up, I'm gonna push a few changes here. |
Heads up, I've got more pushing coming. Working on some of the tests. |
I've pushed some updates, so only |
Seems we may have an issue with the BreadcrumbDivider test. The common test for a shorthand prop expects the rendered element to |
I'll leave this PR alone for now and come back when I can. I also think we'll need to still make |
TODO
|
return `${k}=${typeof v === 'function' ? v.name || 'func' : v}` | ||
}).join('|') | ||
} | ||
childElements.push(BreadcrumbDivider.create({ content: divider, icon, key })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cruft.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Darn, this is technically a breaking change. Users who are using objects to define a breadcrumb divider and also not defining a key will now need to add the key. Otherwise, they won't all render.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misread this initially, we are one using the factory as an object in this case. The key is then required by us, otherwise, we're getting this in the docs for Breadcrumb:
Each child in an array or iterator should have a unique "key" prop. Check the top-level render call using <div>.
_.invoke(predefinedProps, 'onClick', e, buttonProps) | ||
_.invoke(this.props, 'onConfirm', e, this.props) | ||
}, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We handle there onClick
on Button
s, let's allow user to handle own onClick
👍
@@ -26,13 +26,14 @@ function BreadcrumbDivider(props) { | |||
const rest = getUnhandledProps(BreadcrumbDivider, props) | |||
const ElementType = getElementType(BreadcrumbDivider, props) | |||
|
|||
const iconElement = Icon.create(icon, { ...rest, className: classes }) | |||
if (iconElement) return iconElement | |||
if (!_.isNil(icon)) return Icon.create(icon, { defaultProps: { ...rest, className: classes } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified contidition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levithomason I've added some tests and performed some cleanups, seems we can go after review 😄
EDIT Original We've got #1533 to remove all manually generated keys. This way we can consolidate our breaking changes for |
845944b
to
b6a2e57
Compare
b6a2e57
to
52e6685
Compare
Rebased to master, fixed breadcrumb divider keys. Also tossed in a fix the for "show HTML" button in examples. Will merge on pass. |
b284779
to
28ee505
Compare
Refence: #1424