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-badge): add StatusBadgeBlank; without preload icons #1500

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .changeset/honest-dryers-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@alfalab/core-components-status-badge': minor
---

- Добавлен StatusBadgeBlank, без предзагрузки иконок
- Расширен пропс customIcons, теперь он принимает не только структуру иконок, но и массив таких структур
1 change: 1 addition & 0 deletions packages/status-badge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"access": "public",
"directory": "dist"
},
"sideEffects": false,
"peerDependencies": {
"react": ">=16.8.0"
},
Expand Down
86 changes: 86 additions & 0 deletions packages/status-badge/src/Component.base.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import cn from 'classnames';

import type { IconMap } from './consts/iconMap';
import { useStatusBadgeIcon } from './hooks/useStatusBadgeIcon';
import {
StatusBadgeCustomIcon,
StatusBadgeSizes,
StatusBadgeViews,
} from './types/statusBadgePropTypes';

import defaultColors from './default.module.css';
import styles from './index.module.css';
import invertedColors from './inverted.module.css';

const colorStyles = {
default: defaultColors,
inverted: invertedColors,
};

export type StatusBadgeProps = {
/**
* Дополнительный класс
*/
className?: string;

/**
* Размер компонента
* @default 24
*/
size?: StatusBadgeSizes;

/**
* Набор цветов для компонента
*/
colors?: 'default' | 'inverted';

/**
* Вид бейджа.
*/
view: StatusBadgeViews;

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

/**
* Кастомные иконки
*/
customIcons?: StatusBadgeCustomIcon | StatusBadgeCustomIcon[];
};

type StatusBadgePrivateProps = {
/**
* Базовый набор иконок
*/
iconMap: IconMap;
};

export const StatusBadgeBase = ({
className,
dataTestId,
size = 24,
view,
colors = 'default',
customIcons,
iconMap,
}: StatusBadgeProps & StatusBadgePrivateProps) => {
const { Icon } = useStatusBadgeIcon(view, size, iconMap, customIcons);

return (
<div
className={cn(
styles.component,
className,
styles[`size-${size}`],
colorStyles[colors].component,
colorStyles[colors][view],
)}
data-test-id={dataTestId}
>
<Icon />
</div>
);
};
8 changes: 8 additions & 0 deletions packages/status-badge/src/Component.blank.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';

import { ICON_MAP_BLANK } from './consts/iconMap.blank';
import { type StatusBadgeProps, StatusBadgeBase } from './Component.base';

export const StatusBadgeBlank = (props: StatusBadgeProps) => (
<StatusBadgeBase {...props} iconMap={ICON_MAP_BLANK} />
);
2 changes: 1 addition & 1 deletion packages/status-badge/src/Component.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';

import { StatusBadge, StatusBadgeProps } from '.';
import { StatusBadge, type StatusBadgeProps } from '.';

const viewOptions: StatusBadgeProps['view'][] = [
'positive-checkmark',
Expand Down
79 changes: 5 additions & 74 deletions packages/status-badge/src/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,8 @@
import React from 'react';
import cn from 'classnames';

import { useStatusBadgeIcon } from './hooks/useStatusBadgeIcon';
import {
StatusBadgeCustomIcon,
StatusBadgeSizes,
StatusBadgeViews,
} from './types/statusBadgePropTypes';
import { ICON_MAP } from './consts/iconMap';
import { type StatusBadgeProps, StatusBadgeBase } from './Component.base';

import defaultColors from './default.module.css';
import styles from './index.module.css';
import invertedColors from './inverted.module.css';

const colorStyles = {
default: defaultColors,
inverted: invertedColors,
};

export type StatusBadgeProps = {
/**
* Дополнительный класс
*/
className?: string;

/**
* Размер компонента
* @default 24
*/
size?: StatusBadgeSizes;

/**
* Набор цветов для компонента
*/
colors?: 'default' | 'inverted';

/**
* Вид бейджа.
*/
view: StatusBadgeViews;

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

/**
* Кастомные иконки
*/
customIcons?: StatusBadgeCustomIcon;
};

export const StatusBadge = ({
className,
dataTestId,
size = 24,
view,
colors = 'default',
customIcons,
}: StatusBadgeProps) => {
const { Icon } = useStatusBadgeIcon(view, size, customIcons);

return (
<div
className={cn(
styles.component,
className,
styles[`size-${size}`],
colorStyles[colors].component,
colorStyles[colors][view],
)}
data-test-id={dataTestId}
>
<Icon />
</div>
);
};
export const StatusBadge = (props: StatusBadgeProps) => (
<StatusBadgeBase {...props} iconMap={ICON_MAP} />
);
15 changes: 15 additions & 0 deletions packages/status-badge/src/consts/iconMap.blank.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { IconMap } from './iconMap';

/**
* Базовая структура, без иконок
*/
export const ICON_MAP_BLANK: IconMap = {
'positive-checkmark': {},
'negative-cross': {},
'negative-alert': {},
'negative-block': {},
'attention-alert': {},
'neutral-information': {},
'neutral-operation': {},
'neutral-cross': {},
} as IconMap;
Loading
Loading