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/status sizes #1346

Merged
merged 8 commits into from
Sep 2, 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
9 changes: 9 additions & 0 deletions .changeset/beige-grapes-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@alfalab/core-components-status': minor
---

- Добавлен пропс `size`. Теперь помимо дефолтного значения `20` можно также установить `24, 32, 40`
- Для значения `20` изменены скругления
- Добавлен пропс `shape`. С помощью него можно задать тип скругления компонента - `rectangular, rounded`
- Добавлен пропс `uppercase`. Изначально текст в компоненте всегда указывался в верхнем регистре - теперь регистр можно менять. Для обратной совместимости оставили по умолчанию `uppercase=true`
- Внутренние улучшения кода компонента
40 changes: 39 additions & 1 deletion packages/status/src/Component.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { render } from '@testing-library/react';

import { Status, colors } from './index';
import { Status } from './index';
import { colors, sizes } from './consts';

describe('Status', () => {
describe('Snapshots tests', () => {
Expand Down Expand Up @@ -35,6 +36,21 @@ describe('Status', () => {
expect(container.firstElementChild).toHaveClass('green');
});

it('should set size=20 by default', () => {
const { container } = render(<Status />);
expect(container.firstElementChild).toHaveClass('size-20');
});

it('should set shape=rectangular by default', () => {
const { container } = render(<Status />);
expect(container.firstElementChild).toHaveClass('rectangular');
});

it('should set uppercase=true by default', () => {
const { container } = render(<Status />);
expect(container.firstElementChild).toHaveClass('uppercase');
});

it.each(['muted-alt', 'contrast', 'muted'] as const)('should set view="%s"', (view) => {
const { container } = render(<Status view={view}>Label</Status>);

Expand All @@ -46,6 +62,28 @@ describe('Status', () => {

expect(container.firstElementChild).toHaveClass(color);
});

it.each(sizes)('should set size="%s"', (size) => {
const { container } = render(<Status size={size}>Label</Status>);

expect(container.firstElementChild).toHaveClass(`size-${size}`);
});

it.each(['rectangular', 'rounded'] as const)('should set shape="%s"', (shape) => {
const { container } = render(<Status shape={shape}>Label</Status>);

expect(container.firstElementChild).toHaveClass(shape);
});

it('should set uppercase', () => {
const { container } = render(<Status uppercase={true}>Label</Status>);
expect(container.firstElementChild).toHaveClass('uppercase');
});

it('should not set uppercase', () => {
const { container } = render(<Status uppercase={false}>Label</Status>);
expect(container.firstElementChild).not.toHaveClass('uppercase');
});
});

it('should unmount without errors', () => {
Expand Down
37 changes: 34 additions & 3 deletions packages/status/src/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { FC, ReactNode } from 'react';
import cn from 'classnames';

import styles from './index.module.css';
import { colors, sizes } from './consts';

export const colors = ['green', 'orange', 'red', 'blue', 'grey', 'teal', 'purple'] as const;
import styles from './index.module.css';

export type StatusProps = {
/**
Expand Down Expand Up @@ -31,6 +31,24 @@ export type StatusProps = {
* Дочерние элементы.
*/
children?: ReactNode;

/**
* Размер компонента
* @default 20
*/
size?: (typeof sizes)[number];

/**
* Форма компонента
* @default rectangular
*/
shape?: 'rounded' | 'rectangular';

/**
* Текст компонента в верхнем регистре
* @default true
*/
uppercase?: boolean;
};

const logWarning = () => {
Expand All @@ -53,14 +71,27 @@ export const Status: FC<StatusProps> = ({
color = 'green',
children,
dataTestId,
size = 20,
shape = 'rectangular',
uppercase = true,
}) => {
if (view === 'soft') {
logWarning();
}

return (
<span
className={cn(styles.component, styles[color], styles[view], className)}
className={cn(
styles.component,
styles[color],
styles[view],
styles[`size-${size}`],
styles[shape],
className,
{
[styles.uppercase]: uppercase,
},
)}
data-test-id={dataTestId}
>
<span className={styles.ellipsis}>{children}</span>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions packages/status/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Status Snapshots tests should match view="contrast" snapshot 1`] = `
<div>
<span
class="component green contrast"
class="component green contrast size-20 rectangular uppercase"
>
<span
class="ellipsis"
Expand All @@ -17,7 +17,7 @@ exports[`Status Snapshots tests should match view="contrast" snapshot 1`] = `
exports[`Status Snapshots tests should match view="muted" snapshot 1`] = `
<div>
<span
class="component green muted"
class="component green muted size-20 rectangular uppercase"
>
<span
class="ellipsis"
Expand All @@ -31,7 +31,7 @@ exports[`Status Snapshots tests should match view="muted" snapshot 1`] = `
exports[`Status Snapshots tests should match view="muted-alt" snapshot 1`] = `
<div>
<span
class="component green muted-alt"
class="component green muted-alt size-20 rectangular uppercase"
>
<span
class="ellipsis"
Expand Down
31 changes: 29 additions & 2 deletions packages/status/src/component.screenshots.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { createPreview, generateTestCases, setupScreenshotTesting } from '../../screenshot-utils';
import {
createPreview,
createSpriteStorybookUrl,
generateTestCases,
setupScreenshotTesting,
} from '../../screenshot-utils';

import { colors } from './Component';
import { colors, sizes } from './consts';

const screenshotTesting = setupScreenshotTesting({
it,
Expand Down Expand Up @@ -38,3 +43,25 @@ describe(
screenshotOpts: { clip },
}),
);

describe(
'Status | size, shape, uppercase',
screenshotTesting({
cases: [
[
'sprite',
createSpriteStorybookUrl({
componentName: 'Status',
knobs: {
children: 'Label',
view: ['muted-alt'],
color: ['blue'],
size: [...sizes],
shape: ['rectangular', 'rounded'],
uppercase: [true, false],
},
}),
],
],
}),
);
2 changes: 2 additions & 0 deletions packages/status/src/consts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const colors = ['green', 'orange', 'red', 'blue', 'grey', 'teal', 'purple'] as const;
export const sizes = [20, 24, 32, 40] as const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

константы обычно пишем заглавными буквами

8 changes: 6 additions & 2 deletions packages/status/src/docs/Component.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { select, text } from '@storybook/addon-knobs';
import { Status, colors } from '@alfalab/core-components-status';
import { boolean, select, text } from '@storybook/addon-knobs';
import { Status } from '@alfalab/core-components-status';
import { colors, sizes } from '../consts';

const meta: Meta<typeof Status> = {
title: 'Components/Status',
Expand All @@ -17,6 +18,9 @@ export const status: Story = {
<Status
color={select('color', colors, 'green')}
view={select('view', ['muted-alt', 'contrast', 'muted'], 'muted-alt')}
size={select('size', sizes, 20)}
shape={select('shape', ['rectangular', 'rounded'], 'rectangular')}
uppercase={boolean('uppercase', true)}
>
{text('children', 'Label')}
</Status>
Expand Down
Loading
Loading