Skip to content

Commit a2c7918

Browse files
authored
Revert "sync(badge): update from web-code" (#5397)
This reverts commit 153ed05.
1 parent 153ed05 commit a2c7918

11 files changed

Lines changed: 164 additions & 457 deletions

File tree

documentation-site/examples/badge/hint-dot.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

documentation-site/examples/badge/notification-circle.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

documentation-site/pages/components/badge.mdx

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import badgeYardConfig from "../../components/yard/config/badge";
1111
import PrimaryInline from "examples/badge/primary-inline.tsx";
1212
import SecondaryInline from "examples/badge/secondary-inline.tsx";
1313
import Offset from "examples/badge/offset.tsx";
14-
import NotificationCircleExample from "examples/badge/notification-circle.tsx";
15-
import HintDotExample from "examples/badge/hint-dot.tsx";
1614

1715
export default Layout;
1816

@@ -26,7 +24,7 @@ Badge content should generally be 3 words or less.
2624

2725
## Hierarchy
2826

29-
Primary badges are bright in color to grab a user's attention to an entry point of either a new product/feature, promotion or alert. Another usage is for transit lines. Avoid using multiple primary badges in the same view.
27+
Primary badges are bright in color to grab a users attention to an entry point of either a new product/feature, promotion or alert. Another usage is for transit lines. Avoid using multiple primary badges in the same view.
3028

3129
Secondary badges should be part of the content inside the component. They are often meta data, highlighted information or simplified information.
3230

@@ -55,24 +53,4 @@ There may be situations where it makes sense to deviate from the standard badge
5553
- `horizontalOffset` sets the `right` CSS attribute when `placement` is `topRight` or `bottomRight`. Otherwise it sets the `left` attribute.
5654
- `verticalOffset` sets the `top` CSS attribute when `placement` is `topLeft`, `top`, or `topRight`. Otherwise it sets the `bottom` attribute.
5755

58-
## NotificationCircle
59-
60-
Use `NotificationCircle` to display a count or icon indicator anchored to an element — for example, an unread message count on a navigation icon.
61-
62-
<Example title="Notification circle" path="badge/notification-circle.tsx">
63-
<NotificationCircleExample />
64-
</Example>
65-
66-
The `content` prop accepts a number, an icon element, or a render prop `(size: number) => ReactNode`. Numbers greater than 99 are automatically clamped to `99+`. Use the `size` prop (`small` or `medium`, defaults to `medium`) to control the circle dimensions. `NotificationCircle` supports `topLeft`, `topRight`, `bottomLeft`, and `bottomRight` placements.
67-
68-
## HintDot
69-
70-
Use `HintDot` to render a small colored dot anchored to an element, drawing attention without conveying specific information.
71-
72-
<Example title="Hint dot" path="badge/hint-dot.tsx">
73-
<HintDotExample />
74-
</Example>
75-
76-
The dot supports `topRight`, `topLeft`, `bottomRight`, and `bottomLeft` placements (defaults to `topRight`). By default a border separates the dot from its anchor; set `hasBorder={false}` to remove it. When no `children` are provided the dot renders inline without an anchor.
77-
7856
<Exports component={BadgeExports} title="Badge exports" path="baseui/badge" />

src/badge/__tests__/utils.test.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/badge/constants.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,17 @@ export const HIERARCHY = Object.freeze({
99
secondary: 'secondary',
1010
});
1111

12-
export const NOTIFICATION_CIRCLE_SIZE = {
13-
small: 'small',
14-
medium: 'medium',
15-
} as const;
16-
1712
export const SHAPE = Object.freeze({
1813
pill: 'pill',
1914
rectangle: 'rectangle',
2015
});
2116

2217
export const COLOR = Object.freeze({
2318
accent: 'accent',
24-
primary: 'primary', // deprecated
19+
primary: 'primary',
2520
positive: 'positive',
2621
negative: 'negative',
2722
warning: 'warning',
28-
onBrand: 'onBrand',
2923
});
3024

3125
export const PLACEMENT = Object.freeze({

src/badge/hint-dot.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This source code is licensed under the MIT license found in the
55
LICENSE file in the root directory of this source tree.
66
*/
77
import * as React from 'react';
8+
import { useStyletron } from '../styles/index';
89
import { getOverrides } from '../helpers/overrides';
910
import { StyledHintDot, StyledRoot, StyledPositioner } from './styled-components';
1011
import type { HintDotProps } from './types';
@@ -17,15 +18,14 @@ const HintDot = ({
1718
horizontalOffset: horizontalOffsetProp,
1819
verticalOffset: verticalOffsetProp,
1920
hidden,
20-
// placement was not there for hintBadge, but we need to support in for Avatar and other potential use cases.
21-
placement = PLACEMENT.topRight,
22-
hasBorder = true,
2321
overrides = {},
2422
}: HintDotProps) => {
2523
const [HintDot, hintDotProps] = getOverrides(overrides.Badge, StyledHintDot);
2624
const [Root, rootProps] = getOverrides(overrides.Root, StyledRoot);
2725
const [Positioner, positionerProps] = getOverrides(overrides.Positioner, StyledPositioner);
2826

27+
const [, theme] = useStyletron();
28+
2929
const anchor = getAnchorFromChildren(children);
3030

3131
// if the anchor is a string, we supply default offsets
@@ -39,28 +39,22 @@ const HintDot = ({
3939
verticalOffset = '-4px';
4040
}
4141
}
42-
4342
return (
4443
<Root {...rootProps}>
4544
{anchor}
4645

4746
<Positioner
48-
aria-hidden={true}
4947
$horizontalOffset={horizontalOffset}
5048
$verticalOffset={verticalOffset}
51-
$placement={placement}
49+
$placement={theme.direction === 'rtl' ? PLACEMENT.topLeft : PLACEMENT.topRight}
5250
$role={ROLE.hintDot}
53-
$noAnchor={!anchor}
54-
$hasBorder={hasBorder}
5551
{...positionerProps}
5652
>
5753
<HintDot
58-
data-baseweb="hint-badge"
54+
{...hintDotProps}
5955
$color={color}
6056
$horizontalOffset={horizontalOffset}
6157
$hidden={hidden}
62-
$hasBorder={hasBorder}
63-
{...hintDotProps}
6458
/>
6559
</Positioner>
6660
</Root>

src/badge/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export { default as Badge } from './badge';
1919
export { default as NotificationCircle } from './notification-circle';
2020
export { default as HintDot } from './hint-dot';
2121

22-
export { HIERARCHY, SHAPE, COLOR, PLACEMENT, NOTIFICATION_CIRCLE_SIZE } from './constants';
22+
export { HIERARCHY, SHAPE, COLOR, PLACEMENT } from './constants';
2323

2424
export * from './styled-components';
2525

src/badge/notification-circle.tsx

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as React from 'react';
88
import { getOverrides } from '../helpers/overrides';
99
import { StyledNotificationCircle, StyledRoot, StyledPositioner } from './styled-components';
1010
import type { NotificationCircleProps } from './types';
11-
import { PLACEMENT, ROLE, NOTIFICATION_CIRCLE_SIZE } from './constants';
11+
import { PLACEMENT, ROLE } from './constants';
1212
import { getAnchorFromChildren } from './utils';
1313

1414
const NotificationCircle = ({
@@ -19,7 +19,6 @@ const NotificationCircle = ({
1919
horizontalOffset,
2020
verticalOffset,
2121
hidden,
22-
size = NOTIFICATION_CIRCLE_SIZE.medium,
2322
overrides = {},
2423
}: NotificationCircleProps) => {
2524
const [NotificationCircle, NotificationCircleProps] = getOverrides(
@@ -35,48 +34,22 @@ const NotificationCircle = ({
3534
if (typeof contentProp === 'string') {
3635
console.error(`[baseui] NotificationCircle child must be number or icon, found string`);
3736
}
38-
if (
39-
placement &&
40-
placement !== PLACEMENT.topLeft &&
41-
placement !== PLACEMENT.topRight &&
42-
placement !== PLACEMENT.bottomLeft &&
43-
placement !== PLACEMENT.bottomRight
44-
) {
37+
if (placement && placement !== PLACEMENT.topLeft && placement !== PLACEMENT.topRight) {
4538
console.error(
46-
`[baseui] NotificationCircle must be placed topLeft, topRight, bottomLeft, or bottomRight, found ${placement}`
39+
`[baseui] NotificationCircle must be placed topLeft or topRight, found ${placement}`
4740
);
4841
}
4942
}
5043

5144
let content = contentProp;
52-
const ICON_SIZE = size === NOTIFICATION_CIRCLE_SIZE.small ? 10 : 12;
53-
const isContentNumber = typeof content === 'number';
54-
if (typeof content === 'number' && content > 99) {
55-
content = '99+';
56-
} else if (typeof content === 'function') {
57-
// add support for render prop, content = (size) => <Icon size={size} />
58-
content = content(ICON_SIZE);
59-
} else if (React.isValidElement(content)) {
60-
// backwards compatibility for icon element as child, clone the element and pass size as prop
61-
// content = <Icon />
62-
// React.cloneElement is not recommended but we need this to support the old way of passing icon element as content
63-
content = React.cloneElement(content as React.ReactElement<{ size?: number }>, {
64-
size: ICON_SIZE,
65-
});
45+
if (typeof content === 'number' && content > 9) {
46+
content = '9+';
6647
}
6748

6849
// If there's no anchor, render the badge inline
6950
if (!anchor) {
7051
return (
71-
<NotificationCircle
72-
data-baseweb="notification-badge"
73-
$color={color}
74-
$hidden={hidden}
75-
$size={size}
76-
$extraPadding={isContentNumber}
77-
aria-hidden={true}
78-
{...NotificationCircleProps}
79-
>
52+
<NotificationCircle $color={color} $hidden={hidden} {...NotificationCircleProps}>
8053
{content}
8154
</NotificationCircle>
8255
);
@@ -91,17 +64,9 @@ const NotificationCircle = ({
9164
$verticalOffset={verticalOffset}
9265
$placement={placement}
9366
$role={ROLE.notificationCircle}
94-
aria-hidden={true}
9567
{...positionerProps}
9668
>
97-
<NotificationCircle
98-
data-baseweb="notification-badge"
99-
$color={color}
100-
$hidden={hidden}
101-
$size={size}
102-
$extraPadding={isContentNumber}
103-
{...NotificationCircleProps}
104-
>
69+
<NotificationCircle {...NotificationCircleProps} $color={color} $hidden={hidden}>
10570
{content}
10671
</NotificationCircle>
10772
</Positioner>

0 commit comments

Comments
 (0)