-
Notifications
You must be signed in to change notification settings - Fork 7
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(contentcard): first implementation #935
feat(contentcard): first implementation #935
Conversation
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.
Fantastic implementation 🤩 👏 Just some non blocking comments 🙆
Thanks for being flexible and update the components affected by the updated theme tokens too 🔥 🎉 !
@@ -22,3 +22,17 @@ export function filterProps<T extends Props, K extends keyof T>( | |||
|
|||
return result; | |||
} | |||
|
|||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |||
export const mergeRefs = (refs: any[]) => { |
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.
Really cool util function 💡 🔥 !!
[SDSWarningTypes.ContentCardActionsOnlyButtons]: { | ||
hasWarned: false, | ||
message: | ||
"Warning: Only SDS buttons could be used within ContentCard Actions component slot!", | ||
}, | ||
[SDSWarningTypes.ClickableContentCardNumberOfButtons]: { | ||
hasWarned: false, | ||
message: | ||
"Warning: Clickable Content Cards can only have one or no buttons!", | ||
}, |
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.
Great warnings! So user friendly ❤️
image?: never; | ||
imageSize?: never; | ||
imagePosition?: never; | ||
imagePadding?: never; |
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.
just curious, why the types are never
here? Here and below
Thank you!
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 uses the visualElementType
prop as the union type discriminator, so there can be three different types of ContentCard: an ImageContentCard
, an IconContentCard
, and a regular one without any media elements.
When we set image?: never;
on the IconContentCard
, for example, it forces TypeScript to throw an error if the user adds an image
prop when visualElementType="icon"
, and so on.
Does that make sense? 🥸
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.
Oh!! Thanks so much for the explanation 💡 That totally makes sense now thank you!
): JSX.Element | null { | ||
const { buttonsPosition, clickableCard, children } = 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.
fantastic comments throughout. Very easy to follow 🙏 Thanks so much for the great logics!
* (masoudmanson): This function is used to add the clickableCard and | ||
* buttonsPosition props to the ContentCardActions sub-component. | ||
*/ | ||
const enhanceChildrenWithCardActionsProps = ( |
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.
Very nice pattern!
useEffect(() => { | ||
const element = cardRef.current; | ||
if (!element) return; | ||
|
||
const resizeObserver = new ResizeObserver((entries) => { | ||
for (const entry of entries) { | ||
handleResize(entry.contentRect.width); | ||
} | ||
}); | ||
|
||
resizeObserver.observe(element); | ||
|
||
return () => { | ||
resizeObserver.disconnect(); | ||
}; | ||
}, [handleResize]); |
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.
non-blocking and low priority - just for fun later lol
I wonder if this useEffect can be part of the useResponsiveWidth
hook?
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.
Hmmm, I like the idea. I'll make sure to update the hook 🥳🎉
…date test snapshots
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.
Just one small tweak on ContentCard
and a small name change in the color variables, otherwise looks great!! Thanks for the quick turnaround on this one, @masoudmanson!
… overlapping with border
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.
Looks great, @masoudmanson! Thanks for the quick fixes!
Summary
ContentCard
Jira Ticket
Checklist
defaultTheme.ts
used wherever possible