diff --git a/src/components/Avatar/__tests__/__snapshots__/Avatar.test.tsx.snap b/src/components/Avatar/__tests__/__snapshots__/Avatar.test.tsx.snap index 81e73a20..2e5a7768 100644 --- a/src/components/Avatar/__tests__/__snapshots__/Avatar.test.tsx.snap +++ b/src/components/Avatar/__tests__/__snapshots__/Avatar.test.tsx.snap @@ -1706,10 +1706,12 @@ exports[`Avatar component tests With badge, showBadge: true 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } diff --git a/src/components/Badge/Badge.stories.ts b/src/components/Badge/Badge.stories.ts index c5b7857c..0989f383 100644 --- a/src/components/Badge/Badge.stories.ts +++ b/src/components/Badge/Badge.stories.ts @@ -5,8 +5,9 @@ import { Badge } from './Badge' const meta: Meta = { title: 'Misc/Badge', component: Badge, - args: { severity: 'basic', dot: false, children: 'Test' }, + args: { severity: 'basic', dot: false, children: 'Test', size: 'small' }, argTypes: { + size: { control: 'radio', options: ['small', 'medium', 'large'] }, severity: { control: 'radio', options: ['basic', 'info', 'success', 'warning', 'danger'], diff --git a/src/components/Badge/Badge.tsx b/src/components/Badge/Badge.tsx index 8b0e5f6a..b918988b 100644 --- a/src/components/Badge/Badge.tsx +++ b/src/components/Badge/Badge.tsx @@ -22,6 +22,11 @@ export interface BadgeBase * @default 'basic' */ severity?: BadgeSeverity + /** + * Размер текстового бейджа и точки + * @default 'small' + */ + size?: 'small' | 'medium' | 'large' /** Дополнительная стилизация для контейнера компонента */ style?: StyleProp } @@ -43,16 +48,27 @@ interface BadgeDot extends BadgeBase { export type BadgeProps = BadgeText | BadgeDot /** - * Компонент Badge + * Текстовый счётчик или точка для обозначения статуса. + * Для точки с самостоятельным смыслом задайте accessible и accessibilityLabel. + * В интерактивном родителе включайте значение бейджа в доступное имя родителя. * @param children - Текст внутри бейджа * @param dot - Отображать бейдж в форме точки - * @param severiy - Выбор варианта стиля компонента + * @param severity - Выбор варианта стиля компонента + * @param size - Размер текстового бейджа и точки, по умолчанию small * @param style - Дополнительная стилизация для контейнера компонента - * @link https://www.figma.com/design/4TYeki0MDLhfPGJstbIicf/UI-kit-PrimeFace-(DS)?node-id=484-4871&m=dev + * @see https://www.figma.com/design/HOLKdvQJ8jCLeX17s9d0Yf/UI-Kit--DS--v2.0?node-id=21-1193 */ export const Badge = memo( - ({ children, dot, severity = 'basic', style, testID, ...rest }) => { - badgeStyles.useVariants({ severity }) + ({ + children, + dot, + severity = 'basic', + size = 'small', + style, + testID, + ...rest + }) => { + badgeStyles.useVariants({ severity, size }) const [textLayout, setTextLayout] = useState() const onTextLayout = useCallback((e: LayoutChangeEvent) => { @@ -103,53 +119,88 @@ export const Badge = memo( } ) -const badgeStyles = StyleSheet.create( - ({ theme, border, typography, fonts }) => ({ - container: { alignItems: 'flex-start' }, - dot: { - variants: { - severity: { - basic: { backgroundColor: theme.Misc.Badge.badgeBg }, - info: { - backgroundColor: theme.Button.Severity.Info.Basic.infoButtonBg, - }, - success: { - backgroundColor: - theme.Button.Severity.Success.Basic.successButtonBg, - }, - warning: { - backgroundColor: - theme.Button.Severity.Warning.Basic.warningButtonBg, - }, - danger: { - backgroundColor: theme.Button.Severity.Danger.Basic.dangerButtonBg, - }, +const badgeStyles = StyleSheet.create(({ theme, fonts }) => ({ + container: { alignItems: 'flex-start' }, + dot: { + variants: { + severity: { + basic: { backgroundColor: theme.Misc.Badge.badgeBg }, + info: { + backgroundColor: theme.Button.Severity.Info.Basic.infoButtonBg, + }, + success: { + backgroundColor: theme.Button.Severity.Success.Basic.successButtonBg, + }, + warning: { + backgroundColor: theme.Button.Severity.Warning.Basic.warningButtonBg, + }, + danger: { + backgroundColor: theme.Button.Severity.Danger.Basic.dangerButtonBg, }, }, }, - dotShape: { - width: theme.Misc.Badge.badgeDotSize, - height: theme.Misc.Badge.badgeDotSize, - borderRadius: border.Radius['rounded-full'], - }, - textBadgeContainer: { - height: theme.Misc.Badge.badgeHeight, - paddingHorizontal: theme.Misc.Tag.tagPadding, - justifyContent: 'center', - borderRadius: border.Radius['rounded-full'], + }, + dotShape: { + width: theme.Misc.Badge.badgeDotSize, + height: theme.Misc.Badge.badgeDotSize, + borderRadius: theme.Misc.Badge.badgeBorderRadius, + variants: { + size: { + small: {}, + medium: { + width: theme.Misc.Badge.badgeDotLgSize, + height: theme.Misc.Badge.badgeDotLgSize, + }, + large: { + width: theme.Misc.Badge.badgeDotXlSize, + height: theme.Misc.Badge.badgeDotXlSize, + }, + }, }, - textBadge: { - color: theme.Misc.Badge.badgeTextColor, - fontSize: typography.Size['text-xs'], - includeFontPadding: false, - verticalAlign: 'middle', - fontFamily: fonts.primary, + }, + textBadgeContainer: { + minHeight: theme.Misc.Badge.badgeHeight, + minWidth: theme.Misc.Badge.badgeMinWidth, + paddingHorizontal: theme.Misc.Badge.badgePaddingX, + paddingVertical: theme.Misc.Badge.badgePaddingY, + justifyContent: 'center', + borderRadius: theme.Misc.Badge.badgeBorderRadius, + variants: { + size: { + small: {}, + medium: { + minHeight: theme.Misc.Badge.badgeLgHeight, + minWidth: theme.Misc.Badge.badgeLgMinWidth, + paddingHorizontal: theme.Misc.Badge.badgeLgPaddingX, + paddingVertical: theme.Misc.Badge.badgeLgPaddingY, + }, + large: { + minHeight: theme.Misc.Badge.badgeXlHeight, + minWidth: theme.Misc.Badge.badgeXlMinWidth, + paddingHorizontal: theme.Misc.Badge.badgeXlPaddingX, + paddingVertical: theme.Misc.Badge.badgeXlPaddingY, + }, + }, }, - hiddenContainer: { - width: Dimensions.get('window').width, - height: 0, - flexDirection: 'row', - position: 'absolute', + }, + textBadge: { + color: theme.Misc.Badge.badgeTextColor, + fontSize: theme.Misc.Badge.badgeFontSize, + includeFontPadding: false, + verticalAlign: 'middle', + fontFamily: fonts.primary, + variants: { + size: { + small: {}, + medium: { fontSize: theme.Misc.Badge.badgeLgFontSize }, + large: { fontSize: theme.Misc.Badge.badgeXlFontSize }, + }, }, - }) -) + }, + hiddenContainer: { + width: Dimensions.get('window').width, + height: 0, + flexDirection: 'row', + position: 'absolute', + }, +})) diff --git a/src/components/Badge/__tests__/__snapshots__/Badge.test.tsx.snap b/src/components/Badge/__tests__/__snapshots__/Badge.test.tsx.snap index e4b181ae..5c1a3ae9 100644 --- a/src/components/Badge/__tests__/__snapshots__/Badge.test.tsx.snap +++ b/src/components/Badge/__tests__/__snapshots__/Badge.test.tsx.snap @@ -18,9 +18,9 @@ exports[`Badge component tests dot, severity: basic 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 7, - "width": 7, + "borderRadius": 999, + "height": 10.5, + "width": 10.5, }, ] } @@ -46,9 +46,9 @@ exports[`Badge component tests dot, severity: danger 1`] = ` "backgroundColor": "#fbacaa", }, { - "borderRadius": 100, - "height": 7, - "width": 7, + "borderRadius": 999, + "height": 10.5, + "width": 10.5, }, ] } @@ -74,9 +74,9 @@ exports[`Badge component tests dot, severity: info 1`] = ` "backgroundColor": "#aad7fb", }, { - "borderRadius": 100, - "height": 7, - "width": 7, + "borderRadius": 999, + "height": 10.5, + "width": 10.5, }, ] } @@ -102,9 +102,9 @@ exports[`Badge component tests dot, severity: success 1`] = ` "backgroundColor": "#aafbb7", }, { - "borderRadius": 100, - "height": 7, - "width": 7, + "borderRadius": 999, + "height": 10.5, + "width": 10.5, }, ] } @@ -130,9 +130,9 @@ exports[`Badge component tests dot, severity: warning 1`] = ` "backgroundColor": "#fddeaa", }, { - "borderRadius": 100, - "height": 7, - "width": 7, + "borderRadius": 999, + "height": 10.5, + "width": 10.5, }, ] } @@ -158,10 +158,12 @@ exports[`Badge component tests severity: basic 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -239,10 +241,12 @@ exports[`Badge component tests severity: basic 2`] = ` "backgroundColor": "#aad7fb", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -320,10 +324,12 @@ exports[`Badge component tests severity: basic 3`] = ` "backgroundColor": "#aafbb7", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -401,10 +407,12 @@ exports[`Badge component tests severity: basic 4`] = ` "backgroundColor": "#fddeaa", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -482,10 +490,12 @@ exports[`Badge component tests severity: basic 5`] = ` "backgroundColor": "#fbacaa", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -563,10 +573,12 @@ exports[`Badge component tests severity: default 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -646,9 +658,9 @@ exports[`Badge component tests with custom style 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 7, - "width": 7, + "borderRadius": 999, + "height": 10.5, + "width": 10.5, }, ] } diff --git a/src/components/Button/__tests__/__snapshots__/ButtonBadge.test.tsx.snap b/src/components/Button/__tests__/__snapshots__/ButtonBadge.test.tsx.snap index e72374e0..3679c90e 100644 --- a/src/components/Button/__tests__/__snapshots__/ButtonBadge.test.tsx.snap +++ b/src/components/Button/__tests__/__snapshots__/ButtonBadge.test.tsx.snap @@ -115,10 +115,12 @@ exports[`ButtonSeverity component tests badge - basic 1`] = ` "backgroundColor": "#fbacaa", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -288,9 +290,9 @@ exports[`ButtonSeverity component tests badge - dot 1`] = ` "backgroundColor": "#aad7fb", }, { - "borderRadius": 100, - "height": 7, - "width": 7, + "borderRadius": 999, + "height": 10.5, + "width": 10.5, }, ] } diff --git a/src/components/MenuItem/Template/__tests__/__snapshots__/MenuItemTemplate.test.tsx.snap b/src/components/MenuItem/Template/__tests__/__snapshots__/MenuItemTemplate.test.tsx.snap index cd652db8..ba37c542 100644 --- a/src/components/MenuItem/Template/__tests__/__snapshots__/MenuItemTemplate.test.tsx.snap +++ b/src/components/MenuItem/Template/__tests__/__snapshots__/MenuItemTemplate.test.tsx.snap @@ -220,9 +220,9 @@ exports[`MenuItemTemplate tests MenuItemTemplate full disabled 1`] = ` "backgroundColor": "#fbacaa", }, { - "borderRadius": 100, - "height": 7, - "width": 7, + "borderRadius": 999, + "height": 10.5, + "width": 10.5, }, ] } @@ -1829,9 +1829,9 @@ exports[`MenuItemTemplate tests MenuItemTemplate with icon and badge 1`] = ` "backgroundColor": "#fddeaa", }, { - "borderRadius": 100, - "height": 7, - "width": 7, + "borderRadius": 999, + "height": 10.5, + "width": 10.5, }, ] } diff --git a/src/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap b/src/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap index 70574bf1..c1caddf4 100644 --- a/src/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap +++ b/src/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap @@ -171,10 +171,12 @@ exports[`TabItem component tests active: label, badge 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -611,10 +613,12 @@ exports[`TabItem component tests active: label, icon, badge 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -933,10 +937,12 @@ exports[`TabItem component tests disabled: label, badge 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -1375,10 +1381,12 @@ exports[`TabItem component tests disabled: label, icon, badge 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -1603,10 +1611,12 @@ exports[`TabItem component tests label, badge 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -2035,10 +2045,12 @@ exports[`TabItem component tests label, icon, badge 1`] = ` "backgroundColor": "#44e858", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -2476,10 +2488,12 @@ exports[`Tabs component tests disabled 1`] = ` "backgroundColor": "#fbacaa", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } @@ -2933,10 +2947,12 @@ exports[`Tabs component tests normal 1`] = ` "backgroundColor": "#fbacaa", }, { - "borderRadius": 100, - "height": 21, + "borderRadius": 999, "justifyContent": "center", + "minHeight": 21, + "minWidth": 21, "paddingHorizontal": 7, + "paddingVertical": 3.5, }, ] } diff --git a/src/theme/assets/themeDark.json b/src/theme/assets/themeDark.json index c99838f3..6479f43b 100644 --- a/src/theme/assets/themeDark.json +++ b/src/theme/assets/themeDark.json @@ -399,7 +399,22 @@ "badgeMinWidth": 21, "badgeHeight": 21, "badgeFontSize": 10.5, - "badgeDotSize": 7, + "badgeDotSize": 10.5, + "badgeBorderRadius": 999, + "badgePaddingX": 7, + "badgePaddingY": 3.5, + "badgeLgMinWidth": 23, + "badgeLgHeight": 23, + "badgeLgFontSize": 12.5, + "badgeLgPaddingX": 7, + "badgeLgPaddingY": 3.5, + "badgeDotLgSize": 14, + "badgeXlMinWidth": 25, + "badgeXlHeight": 25, + "badgeXlFontSize": 14, + "badgeXlPaddingX": 7, + "badgeXlPaddingY": 3.5, + "badgeDotXlSize": 17.5, "badgeFontWeight": "bold", "badgeDangerTextColor": "#45120e", "badgeInfoTextColor": "#0e2a45", diff --git a/src/theme/assets/themeLight.json b/src/theme/assets/themeLight.json index d04b5790..1556a9b1 100644 --- a/src/theme/assets/themeLight.json +++ b/src/theme/assets/themeLight.json @@ -399,7 +399,22 @@ "badgeMinWidth": 21, "badgeHeight": 21, "badgeFontSize": 10.5, - "badgeDotSize": 7, + "badgeDotSize": 10.5, + "badgeBorderRadius": 999, + "badgePaddingX": 7, + "badgePaddingY": 3.5, + "badgeLgMinWidth": 23, + "badgeLgHeight": 23, + "badgeLgFontSize": 12.5, + "badgeLgPaddingX": 7, + "badgeLgPaddingY": 3.5, + "badgeDotLgSize": 14, + "badgeXlMinWidth": 25, + "badgeXlHeight": 25, + "badgeXlFontSize": 14, + "badgeXlPaddingX": 7, + "badgeXlPaddingY": 3.5, + "badgeDotXlSize": 17.5, "badgeFontWeight": "bold", "badgeDangerTextColor": "#45120e", "badgeInfoTextColor": "#0e2a45",