-
Notifications
You must be signed in to change notification settings - Fork 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
fix: element component + subcomponent type conventions #1273
Conversation
/** | ||
* @deprecated use ITimelineItemProps instead | ||
*/ | ||
export type IItem = ITimelineItemProps; |
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.
IElementSubElement
naming is used rather than ISubElement
for consistent subcomponent type exports that avoid naming confusion or conflicts with other subcomponent types. i.e. Timeline.Item
vs Stepper.Item
just as a contrived example.
@@ -5,5 +5,5 @@ | |||
* found at http://www.apache.org/licenses/LICENSE-2.0. | |||
*/ | |||
|
|||
export { default as Avatar } from './elements/Avatar'; |
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.
no more mix of default vs named exports
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 think MonthSelector
is the only missing default export for components.
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.
As MonthSelector
was neither an exported component or subcomponent, I didn't have it in view for this PR. But I'll go ahead and update the outlier.
export const HeaderItemIcon = ({ | ||
children, | ||
...props | ||
}: PropsWithChildren<HTMLAttributes<HTMLElement>>) => { | ||
const element = Children.only(children) as ReactHTMLElement<HTMLElement>; | ||
|
||
return <StyledHeaderItemIcon as={Element as any} {...props} />; | ||
if (isValidElement(element)) { | ||
const Icon = ({ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
theme, | ||
...iconProps | ||
}: ThemeProps<DefaultTheme> & HTMLAttributes<HTMLElement>) => | ||
cloneElement<HTMLAttributes<HTMLElement>, HTMLElement>(element, { ...props, ...iconProps }); | ||
|
||
return <StyledHeaderItemIcon as={Icon} {...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.
Direct clone of Icon type elements is a future inconsistency that should be addressed throughout the codebase. This change is simply buttoning-up the types for 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.
Could you explain more on this matter?
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 could π What are you looking for exactly? Perhaps we should talk offline. I've captured some of the inconsistencies in our version planning doc.
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.
Nothing in particular, was just wondering, however if we have this recorded, we should be okay.
3. The `displayName` definition should be set to the exported component name and | ||
satisfies linter checks for runtime naming |
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 a little confused here.. "should be set to the exported component name", would that be Element
or ElementComponent
?
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 exported component is Element
βΒ so that should be the displayName
. Do I need to take another crack at the verbiage here?
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.
Hm, I may have taken it too literally with how it is worded? The linting work correctly so it shouldn't be an issue... I just understood it as (example):
/**
* @extends HTMLAttributes<HTMLDivElement>
*/
export const Accordion = AccordionComponent as typeof AccordionComponent & {
...
};
Accordion.displayName = 'Accordion';
Instead of what we are actually doing:
AccordionComponent.displayName = 'Accordion';
/**
* @extends HTMLAttributes<HTMLDivElement>
*/
export const Accordion = AccordionComponent as typeof AccordionComponent & {
...
};
Since Accordion is what is being exported. Possibly making a distinction between
element's and
styled-components` would help.. not too sure frankly.
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.
Your (example) can't happen βΒ it breaks both displayName linting and JSDoc parsing.
We actually need the "actually doing" version. And the point is to highlight the necessary AccordionComponent.displayName = 'Accordion';
mismatch β which satisfies both linting and provides the necessary connective tissue for JSDoc parsing via garden cmd-docgen
.
docs/documentation.md
Outdated
- Only add prop JSDoc to Typescript prop interfaces | ||
- Refrain from documenting React `defaultProps` | ||
- Refrain from documenting styled components props | ||
- Use `@ignore` to prevent a prop from being added to generated documentation |
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.
When would @ignore
usage be appropriate? I did notice ButtonGroup
s isSelected
prop as one usage within react-components
, would this hide functionality or is it intended for the internal API?
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 rare notation hides props that should only be used internally and not intended for external use. Should I state that here?
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 think it would help to state that, maybe using the internal props as an example would frame its purpose 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 is some amazing code collapse here. π
@@ -64,5 +62,3 @@ IconButton.defaultProps = { | |||
isBasic: true, | |||
size: 'medium' | |||
}; | |||
|
|||
export default IconButton; |
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 should be prepared with a boilerplate message (not in code) if any consumers directly import default from these components that they will be broken. They should not be importing files directly in the first place but we might see chatter about this regardless for this and any migrations of subcomponents to their new files.
cloneElement<HTMLAttributes<HTMLElement>, HTMLElement>(element, { ...props, ...iconProps }); | ||
|
||
return <StyledNavItemIcon as={Icon} {...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.
What is the objective of this expanded logic?
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.
Seems this is a repeat of #1273 (comment) but different file. Would like to hear the offline breakdown of what this is doing.
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.
Exact same as #1273 (comment)
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.
These are much needed updates that keep the project structured well. Thanks!
@jzempel this PR brings much needed refinement to the project/packages, thank you π |
Description
A sweep over all exported Garden element components to bring the code inline with the internal "Element component + subcomponent type conventions" coding RFC. Standard coding conventions are outlined in the updated API docs, which provide a good starting point for framing the PR review.
Detail
A website follow-on from this PR is expected to auto (rather than manually) generate all subcomponent prop sheet documentation, which should represent a significant uptick in efficiency and consistency.
Checklist
design updates are Garden Designer approved (add thedesigner as a reviewer)
yarn start
)?bedrock
)analyzed via axe and evaluated using VoiceOverincludes new unit teststested in Chrome, Firefox, Safari, Edge, and IE11