Content Placeholder
A visual placeholder that conveys the nature of the area when an image or content has not been loaded.
@seed-design/react@1.2.8, @seed-design/css@1.2.6
import { ContentPlaceholder } from "seed-design/ui/content-placeholder";
export default function ContentPlaceholderPreview() {
return <ContentPlaceholder style={{ width: 200, height: 200 }} />;
}
npx @seed-design/cli@latest add ui:content-placeholder
pnpm dlx @seed-design/cli@latest add ui:content-placeholder
yarn dlx @seed-design/cli@latest add ui:content-placeholder
bun x @seed-design/cli@latest add ui:content-placeholder
Install dependencies
npm install @seed-design/react
yarn add @seed-design/react
pnpm add @seed-design/react
bun add @seed-design/react
Copy the code below and paste it in
/**
* @file ui:content-placeholder
* @requires @seed-design/react@^2.0.0
* @requires @seed-design/css@^2.0.0
**/
"use client";
import { ContentPlaceholder as SeedContentPlaceholder } from "@seed-design/react";
import * as React from "react";
export interface ContentPlaceholderProps extends SeedContentPlaceholder.RootProps {}
/**
* @see https://crispy.carrot-soft.tech/react/components/content-placeholder
*/
export const ContentPlaceholder = React.forwardRef<HTMLDivElement, ContentPlaceholderProps>(
({ children, ...props }, ref) => {
return (
<SeedContentPlaceholder.Root {...props} ref={ref}>
<SeedContentPlaceholder.Asset>{children}</SeedContentPlaceholder.Asset>
</SeedContentPlaceholder.Root>
);
},
);
ContentPlaceholder.displayName = "ContentPlaceholder";
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
You can use predefined preset icons and backgrounds by specifying type. If type is not specified, the "default" type is rendered.
import { HStack } from "@seed-design/react";
import { ContentPlaceholder } from "seed-design/ui/content-placeholder";
import { contentPlaceholderVariantMap } from "@seed-design/css/recipes/content-placeholder";
export default function ContentPlaceholderTypeExample() {
return (
<HStack gap="x3" wrap>
{contentPlaceholderVariantMap.type.map((type) => (
<ContentPlaceholder key={type} type={type} style={{ width: 120, height: 120 }} />
))}
</HStack>
);
}
You can use various sizes by directly specifying width and height on the component.
import { HStack, VStack } from "@seed-design/react";
import { ContentPlaceholder } from "seed-design/ui/content-placeholder";
const sizes = [
{ label: "48x48", width: 48, height: 48 },
{ label: "200x80", width: 200, height: 80 },
{ label: "200x120", width: 200, height: 120 },
{ label: "200x50", width: 200, height: 50 },
{ label: "300x300", width: 300, height: 300 },
{ label: "320x200", width: 320, height: 200 },
{ label: "40x120", width: 40, height: 120 },
{ label: "40x40", width: 40, height: 40 },
];
export default function ContentPlaceholderSizes() {
return (
<HStack gap="x4" wrap align="flex-end">
{sizes.map(({ label, width, height }) => (
<VStack key={label} gap="x1" align="center">
<ContentPlaceholder style={{ width, height }} />
<span style={{ fontSize: 11, color: "#999" }}>{label}</span>
</VStack>
))}
</HStack>
);
}
- You can use icons that are not in the
type preset by passing children.
import {
IconAppleFill,
IconDiamondFill,
IconSparkle2Fill,
} from "@karrotmarket/react-monochrome-icon";
import { HStack } from "@seed-design/react";
import { ContentPlaceholder } from "seed-design/ui/content-placeholder";
export default function ContentPlaceholderSvgExample() {
return (
<HStack gap="x3">
<ContentPlaceholder style={{ width: 150, height: 150 }}>
<IconAppleFill />
</ContentPlaceholder>
<ContentPlaceholder style={{ width: 100, height: 150 }}>
<IconSparkle2Fill />
</ContentPlaceholder>
<ContentPlaceholder style={{ width: 200, height: 150 }}>
<IconDiamondFill />
</ContentPlaceholder>
</HStack>
);
}