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: add styles props to support Badge wrapper style #48169

Open
wants to merge 7 commits into
base: feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/badge/Ribbon.tsx
Expand Up @@ -13,6 +13,9 @@ export interface RibbonProps {
className?: string;
prefixCls?: string;
style?: React.CSSProperties; // style of ribbon element, not the wrapper
styles?: {
body?: React.CSSProperties;
};
text?: React.ReactNode;
color?: LiteralUnion<PresetColorType>;
children?: React.ReactNode;
Expand All @@ -25,6 +28,7 @@ const Ribbon: React.FC<RibbonProps> = (props) => {
className,
prefixCls: customizePrefixCls,
style,
styles,
color,
children,
text,
Expand Down Expand Up @@ -55,7 +59,7 @@ const Ribbon: React.FC<RibbonProps> = (props) => {
cornerColorStyle.color = color;
}
return wrapCSSVar(
<div className={classNames(wrapperCls, rootClassName, hashId, cssVarCls)}>
<div className={classNames(wrapperCls, rootClassName, hashId, cssVarCls)} style={styles?.body}>
{children}
<div className={classNames(ribbonCls, hashId)} style={{ ...colorStyle, ...style }}>
<span className={`${prefixCls}-text`}>{text}</span>
Expand Down
10 changes: 10 additions & 0 deletions components/badge/__tests__/ribbon.test.tsx
Expand Up @@ -79,4 +79,14 @@ describe('Ribbon', () => {
expect(container.querySelectorAll('.cool').length).toEqual(1);
});
});

it('should support custom styles', () => {
const { container } = render(
<Badge.Ribbon text="Hippies" styles={{ body: { color: 'red' } }}>
<div>custom styles</div>
</Badge.Ribbon>,
);
const element = container.querySelector<HTMLDivElement>('.ant-ribbon-wrapper');
expect(element).toHaveStyle({ color: 'red' });
});
});
7 changes: 7 additions & 0 deletions components/badge/index.en-US.md
Expand Up @@ -61,6 +61,13 @@ Common props ref:[Common props](/docs/react/common-props)
| color | Customize Ribbon color | string | - | |
| placement | The placement of the Ribbon, `start` and `end` follow text direction (RTL or LTR) | `start` \| `end` | `end` | |
| text | Content inside the Ribbon | ReactNode | - | |
| styles | Configure Ribbon build-in module's style | body?: CSSProperties; | - | 5.16.0 |

### `styles` attribute

| Property | Description | Version |
| -------- | ------------------------------------- | ------- |
| body | The style of Ribbon Wrapper Container | 5.16.0 |
Copy link
Member

Choose a reason for hiding this comment

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

5.16.0 已经发布了,这里应该是 5.17.0

Copy link
Member

Choose a reason for hiding this comment

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

另外这个命名可能还需要在讨论一下


## Semantic DOM

Expand Down
7 changes: 7 additions & 0 deletions components/badge/index.zh-CN.md
Expand Up @@ -62,6 +62,13 @@ group: 数据展示
| color | 自定义缎带的颜色 | string | - | |
| placement | 缎带的位置,`start` 和 `end` 随文字方向(RTL 或 LTR)变动 | `start` \| `end` | `end` | |
| text | 缎带中填入的内容 | ReactNode | - | |
| styles | 配置缎带内置模块的 style | body?: CSSProperties; | - | 5.16.0 |

### `styles` 属性

| 名称 | 说明 | 版本 |
| ---- | ------------ | ------ |
| body | 缎带容器样式 | 5.16.0 |

## Semantic DOM

Expand Down