Skip to content

Commit

Permalink
feat(Skeleton): 子要素によって変化しないSkeletonを追加 (#1489)
Browse files Browse the repository at this point in the history
* Add Skeleton without children

* Add story for WithoutChildren pattern

* Add change log
  • Loading branch information
Qs-F committed Jan 4, 2024
1 parent e12d109 commit ea8110a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
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

0 comments on commit ea8110a

Please sign in to comment.