feat(AssetInput): add AssetInput component#2726
Conversation
🦋 Changeset detectedLatest commit: 79ac3bf The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for fondue-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
noahwaldner
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
The component works and looks correct 💪🏻
I added comments regarding optimization. Many things could be done with css to avoid the expensive parsing of children.
I did not yet review the scss file as it will change a lot once more layout logic is moved there.
| }; | ||
|
|
||
| export const AssetInputPreview = ({ children }: AssetInputPreviewProps) => { | ||
| const previewParts = useMemo(() => { |
There was a problem hiding this comment.
not necessary, we can use types to ensure only the correct children are passed
There was a problem hiding this comment.
I adjusted all implementations to avoid the Children.forEach and rely on typing the children prop like this:
type AssetInputPreviewPart = ReactElement<
AssetInputPreviewImageProps | AssetInputPreviewIconProps | AssetInputPreviewLoadingProps
>;
type AssetInputPreviewProps = {
children: AssetInputPreviewPart | AssetInputPreviewPart[];
};
However, this does not seem to be working for me, type validation does not kick in. E.g. I can do this without any errors:
<AssetInputPreview>
<div>Invalid part</div>
<AssetInputPreviewImage src="https://picsum.photos/101/150" />
</AssetInputPreview>
What am I missing?
| }); | ||
| if (previewParts.length > 1 && previewParts.length < 4) { | ||
| const emptyParts = Array.from({ length: 4 - previewParts.length }, (_, i) => ( | ||
| <div className={styles.previewSlot} key={`empty-part-${i}`} /> |
There was a problem hiding this comment.
not necessary, can be done by setting a bg on the preview container

This PR contributes a rewritten version of the legacy
AssetInputto thecomponentspackage.Example usages:
Placeholder
Preview
See storybook for more examples.