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 3 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
25 changes: 25 additions & 0 deletions components/badge/__tests__/__snapshots__/ribbon.test.tsx.snap
Expand Up @@ -16,3 +16,28 @@ exports[`Ribbon rtl render component should be rendered correctly in RTL directi
</div>
</div>
`;

exports[`Ribbon should support custom styles 1`] = `
<div>
<div
class="ant-ribbon-wrapper"
style="color: red;"
>
<div>
custom styles
</div>
<div
class="ant-ribbon ant-ribbon-placement-end"
>
<span
class="ant-ribbon-text"
>
Hippies
</span>
<div
class="ant-ribbon-corner"
/>
</div>
</div>
</div>
`;
9 changes: 9 additions & 0 deletions components/badge/__tests__/ribbon.test.tsx
Expand Up @@ -79,4 +79,13 @@ 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>,
);
expect(container).toMatchSnapshot();
Copy link
Member

Choose a reason for hiding this comment

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

这里不用留快照,用 toHaveStyle 断言就好了,参考其它地方

});
});
6 changes: 6 additions & 0 deletions components/badge/index.en-US.md
Expand Up @@ -62,6 +62,12 @@ Common props ref:[Common props](/docs/react/common-props)
| 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` attribute

| Property | Description |
| -------- | ------------------------------------- |
| body | The style of Ribbon Wrapper Container |

## Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>
Expand Down
6 changes: 6 additions & 0 deletions components/badge/index.zh-CN.md
Expand Up @@ -63,6 +63,12 @@ group: 数据展示
| placement | 缎带的位置,`start` 和 `end` 随文字方向(RTL 或 LTR)变动 | `start` \| `end` | `end` | |
| text | 缎带中填入的内容 | ReactNode | - | |

### `styles` 属性

| 名称 | 说明 |
Copy link
Member

Choose a reason for hiding this comment

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

加上默认值和版本,另外要在 Badge.Ribbon 那一栏加上 styles

| ---- | ------------ |
| body | 缎带容器样式 |

## Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>
Expand Down