Skip to content

Commit

Permalink
Merge pull request #464 from sima-land/453-skeleton
Browse files Browse the repository at this point in the history
 Шаг 4 #453 Добавить компонент Skeleton
  • Loading branch information
krutoo authored Jul 12, 2024
2 parents b4b266e + 94a5f13 commit 321a60a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/stories/tokens/colors/usage.m.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use '@sima-land/ui-nucleons/colors';
@use 'pkg:@sima-land/ui-nucleons/colors';

.section + .section {
margin-top: 32px;
Expand Down
63 changes: 63 additions & 0 deletions src/skeleton/__test__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { fireEvent, render } from '@testing-library/react';
import { Skeleton } from '../skeleton';
import { createRef } from 'react';

describe('Skeleton', () => {
it('should handle div props', () => {
const spy = jest.fn();

const { container } = render(
<Skeleton id='primary' className='styled' onClick={spy}>
Hello, world!
</Skeleton>,
);

expect(container.querySelectorAll('#primary.styled')).toHaveLength(1);
expect(container.querySelector('#primary.styled')?.textContent).toBe('Hello, world!');

expect(spy).toHaveBeenCalledTimes(0);
fireEvent.click(container.querySelector('#primary.styled')!);
expect(spy).toHaveBeenCalledTimes(1);
});

it('should handle "rootRef"', () => {
const ref = createRef<HTMLDivElement>();

render(<Skeleton rootRef={ref}>Hello, world!</Skeleton>);

expect(ref.current instanceof HTMLElement).toBe(true);
});

it('should handle "theme" prop', () => {
const { container, rerender } = render(<Skeleton theme={undefined} />);

expect(container.querySelectorAll('.theme-light')).toHaveLength(1);
expect(container.querySelectorAll('.theme-dark')).toHaveLength(0);

rerender(<Skeleton theme='light' />);

expect(container.querySelectorAll('.theme-light')).toHaveLength(1);
expect(container.querySelectorAll('.theme-dark')).toHaveLength(0);

rerender(<Skeleton theme='dark' />);

expect(container.querySelectorAll('.theme-light')).toHaveLength(0);
expect(container.querySelectorAll('.theme-dark')).toHaveLength(1);

rerender(<Skeleton theme='unset' />);

expect(container.querySelectorAll('.theme-light')).toHaveLength(0);
expect(container.querySelectorAll('.theme-dark')).toHaveLength(0);
});

it('should handle "shining" prop', () => {
const { container, rerender } = render(<Skeleton shining={undefined} />);
expect(container.querySelectorAll('.shining')).toHaveLength(1);

rerender(<Skeleton shining />);
expect(container.querySelectorAll('.shining')).toHaveLength(1);

rerender(<Skeleton shining={false} />);
expect(container.querySelectorAll('.shining')).toHaveLength(0);
});
});
1 change: 1 addition & 0 deletions src/skeleton/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export type { SkeletonStyle, SkeletonProps } from './types';
export { Skeleton } from './skeleton';
3 changes: 2 additions & 1 deletion src/skeleton/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { CSSProperties, HTMLAttributes, Ref } from 'react';
import type { WithTestId } from '../types';

export interface SkeletonStyle extends CSSProperties {
'--skeleton-width'?: string;
'--skeleton-height'?: string;
'--skeleton-shine-size'?: string;
}

export interface SkeletonProps extends HTMLAttributes<HTMLDivElement> {
export interface SkeletonProps extends HTMLAttributes<HTMLDivElement>, WithTestId {
/** Нужно ли включить анимацию блеска. */
shining?: boolean;

Expand Down

0 comments on commit 321a60a

Please sign in to comment.