-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
dcc redesign: tabs #3484
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
base: v4
Are you sure you want to change the base?
dcc redesign: tabs #3484
Conversation
522b8c9 to
577158a
Compare
| const tabContainerClassNames = [ | ||
| 'tab-container', | ||
| vertical ? 'tab-container--vert' : null, | ||
| props.className, | ||
| ].filter(Boolean); | ||
|
|
||
| const tabContentClassNames = [ | ||
| 'tab-content', | ||
| vertical ? 'tab-content--vert' : null, | ||
| props.content_className, | ||
| ].filter(Boolean); | ||
|
|
||
| const tabParentClassNames = [ | ||
| 'tab-parent', | ||
| vertical ? ' tab-parent--vert' : null, | ||
| isAboveBreakpoint ? ' tab-parent--above-breakpoint' : null, | ||
| props.parent_className, | ||
| ].filter(Boolean); |
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.
Not sure this filter pattern is very efficient compared to regular if += in a useMemo in a direct string concat
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 started using this pattern since I noticed a few places where null & undefined became part of the className. This was a compact way to prevent that.
Also, it seems more readable to me to have one className per line instead of string concats with ternary operators (and prettier somehow makes that "uglier", lol).
I put it in a useMemo, as you suggested. What do you think of this? If you still prefer an if statement for each, I'm happy to switch to that format, but it's twice as many code lines.
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.
It's more about the performance, altho it probably doesn't matter much in this case, but in this you end up with 2x array traversal (filter+join) vs a couple ifs, the footprint is just not on the same level of complexity.
| export interface DashComponentApi { | ||
| ExternalWrapper: typeof ExternalWrapper; | ||
| DashContext: typeof DashContext; | ||
| useDashContext: typeof useDashContext; | ||
| getLayout: (componentPathOrId: DashLayoutPath | string) => any; | ||
| stringifyId: typeof stringifyId; | ||
| } |
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 branch is out of sync with dev, the api changed and devtool was added. Might be worth to sync the branches now to prevent further conflicts down the line.
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.
Good call. I synced with dev and updated the type here.
This PR refactors Tabs to follow the same pattern as the other DCC components: Typescript, function components, with CSS in a sidecar file.
A few other improvements along the way:
dash-rendererexports Typescript interface forwindow.dash_component_api(Tabs uses this api internally)DashComponentas a prop type (in addition to a genericReactNode)extract-meta.jscomprehends this the same way asReactNodeDashComponent.props,namespace, etc.