-
Notifications
You must be signed in to change notification settings - Fork 54
feat: 'render' callback for shorthand props #519
Conversation
Codecov Report
@@ Coverage Diff @@
## master #519 +/- ##
=========================================
Coverage ? 87.96%
=========================================
Files ? 42
Lines ? 1404
Branches ? 183
=========================================
Hits ? 1235
Misses ? 165
Partials ? 4
Continue to review full report at Codecov.
|
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 tested it locally and it works as expected. Left two comments for consideration. I vote that we start applying the changes to all components.
I want to mention that we have a case where It's a real case: <Tree items={items} renderItemTitle={titleRenderer} /> How we will get the same behaviour after this PR? |
we are not losing anything with this change - for those components where this |
* @param {object} props - The computed props for this slot. | ||
* @param {ReactNode|ReactNodeArray} children - The computed children for this slot. | ||
*/ | ||
renderContent?: ShorthandRenderFunction |
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.
In this case, I find this methods useful. They are not callback render for a shorthand, but for each item of array. Do we want to get rid of this as well? It would be nice from user perspective for the array shorthands, to be able to define this logic via an API property. What are your thoughts on this @kuzhelov ?
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.
Solution with no additional API changes
// this could be a helper util
const customTreeShorthand = (value, renderTree) => (render => render(value, renderTree))
const renderCustomMenuItem = (Component, props) => <Component {...props} />
<Menu items={[
{ as: ..., ... },
...
]
.map(shorthandValue => customTreeShorthand(shorthandValue, renderCustomMenuItem))
}
.. />
Solution with render
method introduced for limited set of components - specifically, collection and hierarchical ones: Menu, Tree, Accordion, List (?)
Needs changes, but we may talk about the final result even now:
<Menu items={[
{ as: ..., ... },
...
]}
renderItem={(Component, props) => ... } { /* is treated a default rendering logic, if not overwritten by shorthand */ }
.. />
What I don't like here is that it is not absolutely clear for the client where Component
and props
have come from, and where the data that is provided as shorthand object (i.e. { as: ..., ...}
resides in those Component
and 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.
I am okay with both approaches, but when we have shorthand array, with two shorthands inside, as the panels are inside the Accordion, the user will have to define two maps for both shorthand, which may look awkward... Let's hear other folks' opinion before deciding.
* @param {object} props - The computed props for this slot. | ||
* @param {ReactNode|ReactNodeArray} children - The computed children for this slot. | ||
*/ | ||
renderProgress?: ShorthandRenderFunction |
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.
👍 much cleaner API!
* @param {object} props - The computed props for this slot. | ||
* @param {ReactNode|ReactNodeArray} children - The computed children for this slot. | ||
*/ | ||
renderItem?: ShorthandRenderFunction |
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.
Same as the Accordion, I know that the user can use the current API and mapping logic for introducing this, but notice that this was not added with the renderXXX methods PR, it was here before, because it introduces clearer API for rendering each item in the Menu.
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.
Let's decide whether we want to keep in the API the render method for the arrays of shorthands available in some components like Accordion, Menu, Tree etc. Other than that, the changes looks good!
<Icon name="user" circular variables={{ color: 'blue' }} styles={{ padding: '8px' }} /> | ||
)} | ||
} |
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.
👍
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.
After offline discussion, we decided to add explicit render method just for the Tree component, the other ones can easily be defined by the user. Let's merge this after that is added.
@mnajdova, this was already added, and I've not touched this method: https://github.com/stardust-ui/react/blob/master/src/components/Tree/Tree.tsx#L35 . It works as before :) |
…tardust-ui/react into feat/shorthand-render-callback
Implements #355.
TODO
Provided changes introduce additional ways to specify shorthand's value using
render
callback. Following examples are aimed to deliver key points.Base case
Render primitive value
Render object value
Render React element (no evaluated props consumed)
Render custom tree with evaluated shorthand props
Note, this is a functionality we've previously had with
render
methods.OR