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/steps rework #1580

Merged
merged 7 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions .changeset/angry-tables-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@alfalab/core-components-steps': minor
---

- Изменена работа пропса `minSpaceBetweenSteps`. Теперь отступы между шагами определяются по другому. Размер `8` в расчетах не учитывается. Добавлен отступ `32`. Также `minSpaceBetweenSteps` теперь никак не влияет на работу компонента в горизонтальном расположении.
- Добавлен пропс `completedDashColor` с помощью которого можно переопределить цвет "тире" выполенного шага.
1 change: 1 addition & 0 deletions packages/steps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@alfalab/core-components-badge": "^5.6.4",
"@alfalab/core-components-shared": "^0.14.1",
"@alfalab/hooks": "^1.13.1",
"@alfalab/icons-glyph": "^2.210.0",
"classnames": "^2.5.1",
Expand Down
82 changes: 82 additions & 0 deletions packages/steps/src/Component.screenshots.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { setupScreenshotTesting, createSpriteStorybookUrl } from '../../screenshot-utils';

const screenshotTesting = setupScreenshotTesting({
it,
beforeAll,
afterAll,
expect,
});

describe(
'Vertical sprite`',
screenshotTesting({
cases: [
[
'minSpaceBetweenSteps',
createSpriteStorybookUrl({
componentName: 'Steps',
knobs: {
children: [['Шаг 1', 'Шаг 2', 'Шаг 3', 'Шаг 4']],
isVerticalAlign: true,
minSpaceBetweenSteps: [16, 24, 32],
},
}),
],
[
'completedDashColor',
createSpriteStorybookUrl({
componentName: 'Steps',
knobs: {
children: [['Шаг 1', 'Шаг 2', 'Шаг 3', 'Шаг 4']],
isVerticalAlign: true,
activeStep: 3,
completedDashColor: ['', 'tomato', 'var(--color-dark-status-attention)'],
},
}),
],
],
screenshotOpts: {
clip: { x: 0, y: 0, width: 720, height: 320 },
},
}),
);

describe(
'Horizontal sprite`',
screenshotTesting({
cases: [
[
'dash stretching',
createSpriteStorybookUrl({
componentName: 'Steps',
knobs: {
children: [
['Шаг 1', 'Шаг 2', 'Шаг 3'],
['Шаг 1', 'Шаг 2', 'Шаг 3', 'Шаг 4'],
['Шаг 1', 'Шаг 2', 'Шаг 3', 'Шаг 4', 'Шаг 5'],
],
isVerticalAlign: false,
activeStep: 2,
},
size: { width: 720, height: 50 },
}),
],
[
'completedDashColor',
createSpriteStorybookUrl({
componentName: 'Steps',
knobs: {
children: [['Шаг 1', 'Шаг 2', 'Шаг 3', 'Шаг 4']],
isVerticalAlign: false,
activeStep: 3,
completedDashColor: ['', 'tomato', 'var(--color-dark-status-attention)'],
},
size: { width: 720, height: 50 },
}),
],
],
screenshotOpts: {
clip: { x: 0, y: 0, width: 720, height: 280 },
},
}),
);
53 changes: 51 additions & 2 deletions packages/steps/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { render } from '@testing-library/react';

import { Steps } from './index';
import { getStepsTestIds } from './utils/getStepsTestIds';

describe('Steps', () => {
describe('Snapshots tests', () => {
Expand Down Expand Up @@ -43,17 +44,21 @@ describe('Steps', () => {
});

describe('Attributes tests', () => {
it('should set `data-test-id` atribute', () => {
it('should set `data-test-id` attribute', () => {
const dataTestId = 'test-id';

const { getByTestId } = render(
const testIds = getStepsTestIds(dataTestId);

const { getByTestId, getAllByTestId } = render(
<Steps dataTestId={dataTestId}>
<div>Шаг 1</div>
<div>Шаг 2</div>
</Steps>,
);

expect(getByTestId(dataTestId).tagName).toBe('DIV');
expect(getByTestId(testIds.steps)).toBeInTheDocument();
expect(getAllByTestId(testIds.step).length).toBe(2);
});
});

Expand Down Expand Up @@ -113,4 +118,48 @@ describe('Steps', () => {
expect(unmount).not.toThrowError();
});
});

describe('Custom dash color', () => {
it('should set custom color', () => {
const dataTestId = 'test-id';

const testIds = getStepsTestIds(dataTestId);

const { getAllByTestId } = render(
<Steps activeStep={3} dataTestId={dataTestId} completedDashColor='tomato'>
<div>Шаг 1</div>
<div>Шаг 2</div>
<div>Шаг 3</div>
</Steps>,
);

const stepCollection = getAllByTestId(testIds.step);
const dash = stepCollection[0].querySelector('.dash');

expect(dash).toHaveStyle('border-color:tomato');
});

it('should set custom var color', () => {
const dataTestId = 'test-id';

const testIds = getStepsTestIds(dataTestId);

const { getAllByTestId } = render(
<Steps
activeStep={3}
dataTestId={dataTestId}
completedDashColor='var(--color-dark-status-attention)'
>
<div>Шаг 1</div>
<div>Шаг 2</div>
<div>Шаг 3</div>
</Steps>,
);

const stepCollection = getAllByTestId(testIds.step);
const dash = stepCollection[0].querySelector('.dash');

expect(dash).toHaveStyle('border-color:var(--color-dark-status-attention)');
});
});
});
46 changes: 6 additions & 40 deletions packages/steps/src/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { ReactNode, useState } from 'react';
import React, { useState } from 'react';
import cn from 'classnames';

import { Step } from './components/step';
import { StepIndicatorProps } from './components/step-indicator';
import { CommonProps } from './types/common-props';

import styles from './index.module.css';

Expand All @@ -12,11 +13,6 @@ export type StepsProps = {
*/
className?: string;

/**
* Дочерние элементы
*/
children: ReactNode;

/**
* Активный шаг, указанный по умолчанию
* @default 1
Expand All @@ -34,34 +30,6 @@ export type StepsProps = {
*/
isMarkCompletedSteps?: boolean;

/**
* Управление ориентацией компонента
* @default false
*/
isVerticalAlign?: boolean;

/**
* Управление отображением номера шага
*/
ordered?: boolean;

/**
* Включение / отключение интерактивности шагов
*/
interactive?: boolean;

/**
* Растягивание шагов на всю ширину блока для вертикальной ориентации
* @default false
*/
fullWidth?: boolean;

/**
* Минимальное расстояние между шагами
* @default 24
*/
minSpaceBetweenSteps?: 8 | 16 | 24;

/**
* Кастомный метод для управления состоянием disabled шага и
* возможностью перехода на этот шаг
Expand Down Expand Up @@ -110,12 +78,7 @@ export type StepsProps = {
* @param stepNumber - номер активного шага
*/
onChange?: (stepNumber: number) => void;

/**
* Идентификатор для систем автоматизированного тестирования
*/
dataTestId?: string;
};
} & CommonProps;

export const Steps: React.FC<StepsProps> = ({
className,
Expand All @@ -136,6 +99,7 @@ export const Steps: React.FC<StepsProps> = ({
checkIsStepCustom,
onChange,
dataTestId,
completedDashColor,
}) => {
const uncontrolled = activeStepProp === undefined;
const [activeStep, setActiveStep] = useState(defaultActiveStep);
Expand Down Expand Up @@ -195,6 +159,8 @@ export const Steps: React.FC<StepsProps> = ({
key={stepNumber}
fullWidth={fullWidth}
minSpaceBetweenSteps={minSpaceBetweenSteps}
completedDashColor={completedDashColor}
dataTestId={dataTestId}
>
{step}
</Step>
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.
52 changes: 34 additions & 18 deletions packages/steps/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Object {
class="component"
>
<div
class="step selected interactive"
class="step selected interactive horizontal"
role="button"
tabindex="0"
>
Expand All @@ -23,18 +23,22 @@ Object {
</div>
</div>
<div
class="text interactive"
class="textWrapper gap-24"
>
<div>
Шаг 1
<div
class="text interactive"
>
<div>
Шаг 1
</div>
</div>
</div>
<div
class="dash size-24"
class="dash"
/>
</div>
<div
class="step interactive"
class="step interactive horizontal"
role="button"
tabindex="0"
>
Expand All @@ -48,10 +52,14 @@ Object {
</div>
</div>
<div
class="text interactive"
class="textWrapper gap-24"
>
<div>
Шаг 2
<div
class="text interactive"
>
<div>
Шаг 2
</div>
</div>
</div>
</div>
Expand All @@ -63,7 +71,7 @@ Object {
class="component"
>
<div
class="step selected interactive"
class="step selected interactive horizontal"
role="button"
tabindex="0"
>
Expand All @@ -77,18 +85,22 @@ Object {
</div>
</div>
<div
class="text interactive"
class="textWrapper gap-24"
>
<div>
Шаг 1
<div
class="text interactive"
>
<div>
Шаг 1
</div>
</div>
</div>
<div
class="dash size-24"
class="dash"
/>
</div>
<div
class="step interactive"
class="step interactive horizontal"
role="button"
tabindex="0"
>
Expand All @@ -102,10 +114,14 @@ Object {
</div>
</div>
<div
class="text interactive"
class="textWrapper gap-24"
>
<div>
Шаг 2
<div
class="text interactive"
>
<div>
Шаг 2
</div>
</div>
</div>
</div>
Expand Down
Loading