Skip to content
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

Merged
merged 4 commits into from
Feb 27, 2025

Conversation

masoudmanson
Copy link
Contributor

@masoudmanson masoudmanson commented Feb 27, 2025

Summary

ContentCard

Jira Ticket

Checklist

  • Default Story in Storybook
  • Test Story in Storybook
  • Tests written
  • Semantic Variables from defaultTheme.ts used wherever possible
  • If updating an existing component, depreciate flag has been used where necessary
  • ZeroHeight Documents updated
  • Chromatic build verified by @chanzuckerberg/sds-design

@masoudmanson masoudmanson self-assigned this Feb 27, 2025
@masoudmanson masoudmanson added Feature Request Ready for review This PR is ready for review labels Feb 27, 2025
Copy link
Contributor

@tihuan tihuan left a 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[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool util function 💡 🔥 !!

Comment on lines +63 to +72
[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!",
},
Copy link
Contributor

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 ❤️

Comment on lines +28 to +31
image?: never;
imageSize?: never;
imagePosition?: never;
imagePadding?: never;
Copy link
Contributor

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!

Copy link
Contributor Author

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? 🥸

Copy link
Contributor

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;

/**
Copy link
Contributor

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 = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice pattern!

Comment on lines +96 to +111
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]);
Copy link
Contributor

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?

Copy link
Contributor Author

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 🥳🎉

Copy link

@clarsen-czi clarsen-czi left a 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!

Copy link

@clarsen-czi clarsen-czi left a 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!

@masoudmanson masoudmanson merged commit 82f4f94 into main Feb 27, 2025
11 checks passed
@masoudmanson masoudmanson deleted the SCIDS-961-Content-Card-Implement-in-Codebase branch February 27, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Ready for review This PR is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants