Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/component-library/src/Skeleton/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
}
}

.fullSkeleton {
display: inline-block;
}

.skeleton {
border-radius: theme.border-radius("lg");

&[data-fill] {
width: 100%;
}

.skeletonInner {
display: inline flow-root;
width: calc(theme.spacing(1) * var(--skeleton-width));
Expand Down
7 changes: 6 additions & 1 deletion packages/component-library/src/Skeleton/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ const meta = {
export default meta;

export const Skeleton = {
render: (args) => (
<div style={{ width: "100vw", display: "flex", justifyContent: "center" }}>
<SkeletonComponent {...args} />
</div>
),
args: {
label: "Loading",
width: 20,
fill: false,
width: 20,
},
} satisfies StoryObj<typeof SkeletonComponent>;
31 changes: 17 additions & 14 deletions packages/component-library/src/Skeleton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ type Props = Omit<ComponentProps<"span">, "children"> & {
fill?: boolean | undefined;
};

export const Skeleton = ({ className, label, width, fill, ...props }: Props) =>
fill ? (
<span className={clsx(styles.fullSkeleton, className)} {...props}>
export const Skeleton = ({
className,
label,
width,
fill,
...props
}: Props) => (
<span
data-fill-width={width === undefined ? "" : undefined}
{...(width &&
!fill && { style: { "--skeleton-width": width } as CSSProperties })}
data-fill={fill ? "" : undefined}
className={clsx(styles.skeleton, className)}
>
<span className={clsx(styles.skeletonInner, className)} {...props}>
<Label>{label ?? "Loading"}</Label>
</span>
) : (
<span
data-fill-width={width === undefined ? "" : undefined}
{...(width && { style: { "--skeleton-width": width } as CSSProperties })}
className={clsx(styles.skeleton, { [className ?? ""]: fill })}
>
<span className={clsx(styles.skeletonInner, className)} {...props}>
<Label>{label ?? "Loading"}</Label>
</span>
</span>
);
</span>
);

const Label = ({ children }: { children: string | undefined }) => (
<span className={styles.skeletonLabel}>{children ?? "Loading"}</span>
Expand Down
Loading