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(Skeleton): 子要素によって変化しないSkeletonを追加 #1489

Merged
merged 3 commits into from
Jan 4, 2024
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
5 changes: 5 additions & 0 deletions .changeset/clean-toys-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@4design/for-ui": patch
---

feat(Skeleton): 子要素によって変化しないSkeletonを追加
12 changes: 12 additions & 0 deletions packages/for-ui/src/skeleton/Skeleton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ export default {
},
} as Meta;

export const WithoutChildren = () => (
<div className="flex flex-col gap-4">
<Skeleton />
<Skeleton size="xs" />
<Skeleton size="s" />
<Skeleton size="r" />
<Skeleton size="xr" />
<Skeleton size="l" />
<Skeleton size="xl" />
</div>
);

export const WithText = () => {
const [loading, setLoading] = React.useState(false);
React.useEffect(() => {
Expand Down
29 changes: 28 additions & 1 deletion packages/for-ui/src/skeleton/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
import { Children, cloneElement, FC, Fragment, isValidElement, ReactNode } from 'react';
import MuiSkeleton, { SkeletonProps as MuiSkeletonProps } from '@mui/material/Skeleton';
import { fsx } from '../system/fsx';
import { TextProps } from '../text';

export type SkeletonProps = MuiSkeletonProps & {
loading?: boolean;
className?: string;
count?: number;

/**
* テキストの代わりに表示する場合はテキストのサイズを指定
*/
size?: Exclude<TextProps<'span'>['size'], 'inherit'>;
};

export const Skeleton: FC<SkeletonProps> = ({ loading = false, count = 1, className, children, ...rest }) => {
export const Skeleton: FC<SkeletonProps> = ({ loading = false, count = 1, className, children, size, ...rest }) => {
if (!children) {
return (
<MuiSkeleton
variant="rounded"
className={fsx(
`bg-shade-medium-disabled h-4 w-full rounded`,
size &&
{
xs: `h-2.5 my-[.1875rem]`,
s: `h-3 my-1`,
r: `h-3.5 my-[.3125rem]`,
xr: `h-4 my-1.5`,
l: `h-5 my-1.5`,
xl: `h-6 my-2`,
}[size],
className,
)}
{...rest}
/>
);
}
if (loading) {
return (
<>
Expand Down