-
Notifications
You must be signed in to change notification settings - Fork 841
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
add EuiListGroup and EuiListGroupItem type definitions. #1737
Conversation
97b0593
to
df7f4e9
Compare
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.
Thanks for this. EuiListGroupItem
is just a little tricky.
A couple things to change and a couple thing for us to follow up on.
wrapText?: boolean; | ||
}; | ||
|
||
export const EuiListGroupItem: FunctionComponent<EuiListGroupItemProps>; |
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.
Similar to EuiListGroupProps
we need to account for prop ...
spread onto HTML elements. This component is more complex, though, as its props can potentially be spread onto 3 different elements. So we need something like the following:
type EuiListGroupItemElement<Props> =
| (Props & {
onClick: MouseEventHandler<HTMLButtonElement>;
} & ButtonHTMLAttributes<HTMLButtonElement>)
| (Props & {
href: string;
onClick: MouseEventHandler<HTMLAnchorElement>;
} & AnchorHTMLAttributes<HTMLAnchorElement>)
| (Props & HTMLAttributes<HTMLSpanElement>);
Which can then be used like:
export const EuiListGroupItem: FunctionComponent<
EuiListGroupItemElement<EuiListGroupItemProps>
>;
@chandlerprall would be a helpful second set of eyes 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.
Instead of passing EuiListGroupItemProps
through a generic type variable, cleaner to mix it directly into EuiListGroupItemElement
-
type EuiListGroupItemElement =
| (EuiListGroupItemProps & {
onClick: MouseEventHandler<HTMLButtonElement>;
} & ButtonHTMLAttributes<HTMLButtonElement>)
| (EuiListGroupItemProps & {
href: string;
onClick: MouseEventHandler<HTMLAnchorElement>;
} & AnchorHTMLAttributes<HTMLAnchorElement>)
| (EuiListGroupItemProps & HTMLAttributes<HTMLSpanElement>);
@thompsongl did you test that union out to ensure it resolves correctly?
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.
Hmm actually appears that it'll allow passing attributes from both HTMLButtonElement
and HTMLAnchorElement
. For instance, it's fine with both:
formAction="action"
rel="noreferrer"
Seems like EuiButtonPropsForButtonOrLink
would have the same problem
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 64f9e6f I pushed:
type EuiListGroupItemExtendedProps = EuiListGroupItemProps & CommonProps & (
({
onClick: MouseEventHandler<HTMLButtonElement>;
} & ButtonHTMLAttributes<HTMLButtonElement>) |
({
href: string;
onClick: MouseEventHandler<HTMLAnchorElement>;
} & AnchorHTMLAttributes<HTMLAnchorElement>) |
HTMLAttributes<HTMLSpanElement>
);
export const EuiListGroupItem: FunctionComponent<EuiListGroupItemExtendedProps>;
Let me know what you think about it. Another question about this: Now that onClick
and href
are part of the union type EuiListGroupItemExtendedProps
, can those attributes be removed from the original EuiListGroupItemProps
?
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.
Hmm actually appears that it'll allow passing attributes from both HTMLButtonElement and HTMLAnchorElement. For instance, it's fine with both:
Does it work with ExclusiveUnion<>
?
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 appears to work:
type EuiListGroupItemExtendedProps = EuiListGroupItemProps &
CommonProps &
ExclusiveUnion<
ExclusiveUnion<
ButtonHTMLAttributes<HTMLButtonElement>,
AnchorHTMLAttributes<HTMLAnchorElement>
>,
HTMLAttributes<HTMLSpanElement>
>;
Do we need a thing that accepts more than 2 types?
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 added a version using ExclusiveUnion in 4a648e2.
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.
Do we need a thing that accepts more than 2 types?
As long as the autodocs parses this acceptably, I kinda like making it ugly to list multiple version here - it matches the overhead that it pushes down the consuming dev when considering how to use the component. Don't make sub-optimal component design easy :)
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.
Don't make sub-optimal component design easy
💯
isDisabled: PropTypes.boolean, | ||
showToolTip: PropTypes.boolean, | ||
})), | ||
listItems: PropTypes.arrayOf(PropTypes.shape(EuiListGroupItem.propTypes)), |
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.
Can you also just double-check that none of these changes affect the EuiNavDrawer and specifically the EuiNavDrawerGroup:
eui/src/components/nav_drawer/nav_drawer_group.js
Lines 51 to 58 in 90240a0
EuiNavDrawerGroup.propTypes = { | |
listItems: PropTypes.arrayOf(PropTypes.shape({ | |
...EuiListGroup.propTypes.listItems[0], | |
flyoutMenu: PropTypes.shape({ | |
title: PropTypes.string.isRequired, | |
listItems: EuiListGroup.propTypes.listItems.isRequired, | |
}), | |
})), |
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.
Thanks for pointing that out! I now tested it using yarn start-test-server
and propTypes
pass for the EuiListGroup
and EuiNavDrawer
examples - for testing I also temporarily added another required fake prop which then triggered an error for NavDrawer
.
Just a heads up that I'm running into build issues of this PR (due to missing |
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.
Almost ready
src/components/list_group/index.d.ts
Outdated
alwaysShow?: boolean; | ||
} | ||
>; | ||
onClick?(): void; |
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.
One last thing. Just got lost in the shuffle:
onClick?: MouseEventHandler<HTMLButtonElement>
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.
Done in 3490cee.
Summary
EuiListGroup
andEuiListGroupItem
propTypes
ofEuiListGroup
to reuseEuiListGroupItem.propTypes
instead of redefining the shape.Checklist
- [ ] This was checked in mobile- [ ] This was checked in IE11- [ ] This was checked in dark mode- [ ] Any props added have proper autodocs- [ ] Documentation examples were added- [ ] This was checked for breaking changes and labeled appropriately- [] Jest tests were updated or added to match the most common scenarios- [ ] This was checked against keyboard-only and screenreader scenarios- [ ] This required updates to Framer X components