-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bf8c21
commit 5252d7c
Showing
10 changed files
with
136 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
packages/react/src/components/loaders/Skeleton/Circle/Circle.test.tsx
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
packages/react/src/components/loaders/Skeleton/Circle/Circle.tsx
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
packages/react/src/components/loaders/Skeleton/Rectangle/Rectangle.test.tsx
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
packages/react/src/components/loaders/Skeleton/Rectangle/Rectangle.tsx
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
packages/react/src/components/loaders/Skeleton/Skeletons.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { Skeleton } from '.'; | ||
|
||
beforeAll(() => { | ||
document.getAnimations = () => []; | ||
}); | ||
|
||
describe('Skeleton.Text', () => { | ||
it('should render skeleton', () => { | ||
render(<Skeleton.Text data-testid={'skeleton-text'} />); | ||
|
||
expect(screen.getByTestId('skeleton-text')); | ||
}); | ||
}); | ||
|
||
describe('Skeleton.Circle', () => { | ||
it('should render skeleton', () => { | ||
render(<Skeleton.Circle data-testid={'skeleton-circle'} />); | ||
|
||
expect(screen.getByTestId('skeleton-circle')); | ||
}); | ||
}); | ||
|
||
describe('Skeleton.Rectangle', () => { | ||
it('should render skeleton', () => { | ||
render(<Skeleton.Rectangle data-testid={'skeleton-rectangle'} />); | ||
|
||
expect(screen.getByTestId('skeleton-rectangle')); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
packages/react/src/components/loaders/Skeleton/Skeletons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useMergeRefs } from '@floating-ui/react'; | ||
import { Slot } from '@radix-ui/react-slot'; | ||
import cl from 'clsx/lite'; | ||
import { type ForwardedRef, type HTMLAttributes, forwardRef } from 'react'; | ||
|
||
import { useSynchronizedAnimation } from '../../../utilities'; | ||
|
||
type SkeletonProps = { | ||
/** | ||
* Change the default rendered element for the one passed as a child, merging their props and behavior. | ||
* @default false | ||
*/ | ||
asChild?: boolean; | ||
/** The width of the component */ | ||
width?: string | number; | ||
/** The height of the component */ | ||
height?: string | number; | ||
} & HTMLAttributes<HTMLDivElement>; | ||
|
||
const render = ( | ||
type: string, | ||
{ asChild, className, width, height, style, ...rest }: SkeletonProps, | ||
ref: ForwardedRef<HTMLSpanElement>, | ||
) => { | ||
const Component = asChild ? Slot : 'span'; | ||
const animationRef = useSynchronizedAnimation<HTMLSpanElement>( | ||
'ds-skeleton-opacity-fade', | ||
); | ||
const mergedRefs = useMergeRefs([animationRef, ref]); | ||
|
||
return ( | ||
<Component | ||
aria-hidden='true' | ||
className={cl('ds-skeleton', className)} | ||
data-type={type} | ||
ref={mergedRefs} | ||
style={{ width, height, ...style }} | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
export type SkeletonCircleProps = SkeletonProps; | ||
export const SkeletonCircle = forwardRef<HTMLSpanElement, SkeletonCircleProps>( | ||
function SkeletonCircle(props, ref) { | ||
return render('circle', props, ref); | ||
}, | ||
); | ||
|
||
export type SkeletonRectangleProps = SkeletonProps; | ||
export const SkeletonRectangle = forwardRef< | ||
HTMLSpanElement, | ||
SkeletonRectangleProps | ||
>(function SkeletonRectangle(props, ref) { | ||
return render('rectangle', props, ref); | ||
}); | ||
|
||
export type SkeletonTextProps = SkeletonProps; | ||
export const SkeletonText = forwardRef<HTMLSpanElement, SkeletonTextProps>( | ||
function SkeletonText(props, ref) { | ||
return render('text', props, ref); | ||
}, | ||
); |
15 changes: 0 additions & 15 deletions
15
packages/react/src/components/loaders/Skeleton/Text/Text.test.tsx
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
packages/react/src/components/loaders/Skeleton/Text/Text.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.