Skip to content

Commit

Permalink
Add title prop to Badge that shows when hovering it
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludwig Bäcklund authored and yesmeck committed Apr 12, 2018
1 parent 66f5e75 commit 74d81c2
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 1 deletion.
174 changes: 174 additions & 0 deletions components/badge/__tests__/__snapshots__/demo.test.js.snap
Expand Up @@ -1617,3 +1617,177 @@ exports[`renders ./components/badge/demo/status.md correctly 1`] = `
</span> </span>
</div> </div>
`; `;

exports[`renders ./components/badge/demo/title.md correctly 1`] = `
<div>
<span
class="ant-badge"
>
<a
class="head-example"
href="#"
/>
<sup
class="ant-scroll-number ant-badge-count"
data-show="true"
title="Custom hover text"
>
<span
class="ant-scroll-number-only"
style="transition:none;-ms-transform:translateY(-1500%);-webkit-transform:translateY(-1500%);transform:translateY(-1500%)"
>
<p
class=""
>
0
</p>
<p
class=""
>
1
</p>
<p
class=""
>
2
</p>
<p
class=""
>
3
</p>
<p
class=""
>
4
</p>
<p
class=""
>
5
</p>
<p
class=""
>
6
</p>
<p
class=""
>
7
</p>
<p
class=""
>
8
</p>
<p
class=""
>
9
</p>
<p
class=""
>
0
</p>
<p
class=""
>
1
</p>
<p
class=""
>
2
</p>
<p
class=""
>
3
</p>
<p
class=""
>
4
</p>
<p
class="current"
>
5
</p>
<p
class=""
>
6
</p>
<p
class=""
>
7
</p>
<p
class=""
>
8
</p>
<p
class=""
>
9
</p>
<p
class=""
>
0
</p>
<p
class=""
>
1
</p>
<p
class=""
>
2
</p>
<p
class=""
>
3
</p>
<p
class=""
>
4
</p>
<p
class=""
>
5
</p>
<p
class=""
>
6
</p>
<p
class=""
>
7
</p>
<p
class=""
>
8
</p>
<p
class=""
>
9
</p>
</span>
</sup>
</span>
</div>
`;
6 changes: 6 additions & 0 deletions components/badge/__tests__/index.test.js
Expand Up @@ -7,8 +7,14 @@ describe('Badge', () => {
const badge = mount(<Badge count={10} dot />); const badge = mount(<Badge count={10} dot />);
expect(badge.find('.ant-card-multiple-words').length).toBe(0); expect(badge.find('.ant-card-multiple-words').length).toBe(0);
}); });

test('badge dot not showing count == 0', () => { test('badge dot not showing count == 0', () => {
const badge = mount(<Badge count={0} dot />); const badge = mount(<Badge count={0} dot />);
expect(badge.find('.ant-badge-dot').length).toBe(0); expect(badge.find('.ant-badge-dot').length).toBe(0);
}); });

it('should have an overriden title attribute', () => {
const badge = mount(<Badge count={10} title="Custom title" />);
expect(badge.find('.ant-scroll-number').getDOMNode().attributes.getNamedItem('title').value).toEqual('Custom title');
});
}); });
39 changes: 39 additions & 0 deletions components/badge/demo/title.md
@@ -0,0 +1,39 @@
---
order: 7
title:
zh-CN: 自定义标题
en-US: Title
---

## zh-CN

设置鼠标放在状态点上时显示的文字

## en-US

The badge will display `title` when hovered over, instead of `count`.

````jsx
import { Badge } from 'antd';

ReactDOM.render(
<div>
<Badge count={5} title="Custom hover text">
<a href="#" className="head-example" />
</Badge>
</div>
, mountNode);
````

<style>
.ant-badge:not(.ant-badge-status) {
margin-right: 20px;
}
.head-example {
width: 42px;
height: 42px;
border-radius: 4px;
background: #eee;
display: inline-block;
}
</style>
1 change: 1 addition & 0 deletions components/badge/index.en-US.md
Expand Up @@ -31,3 +31,4 @@ Badge normally appears in proximity to notifications or user avatars with eye-ca
| showZero | Whether to show badge when `count` is zero | boolean | `false` | | showZero | Whether to show badge when `count` is zero | boolean | `false` |
| status | Set Badge as a status dot | `success` \| `processing` \| `default` \| `error` \| `warning` | `''` | | status | Set Badge as a status dot | `success` \| `processing` \| `default` \| `error` \| `warning` | `''` |
| text | If `status` is set, `text` sets the display text of the status `dot` | string | `''` | | text | If `status` is set, `text` sets the display text of the status `dot` | string | `''` |
| title | Text to show when hovering over the badge | string | `count` |
4 changes: 3 additions & 1 deletion components/badge/index.tsx
Expand Up @@ -21,6 +21,7 @@ export interface BadgeProps {
status?: 'success' | 'processing' | 'default' | 'error' | 'warning'; status?: 'success' | 'processing' | 'default' | 'error' | 'warning';
text?: string; text?: string;
offset?: [number | string, number | string]; offset?: [number | string, number | string];
title?: string;
} }


export default class Badge extends React.Component<BadgeProps, any> { export default class Badge extends React.Component<BadgeProps, any> {
Expand Down Expand Up @@ -57,6 +58,7 @@ export default class Badge extends React.Component<BadgeProps, any> {
status, status,
text, text,
offset, offset,
title,
...restProps, ...restProps,
} = this.props; } = this.props;
let displayCount = (count as number) > (overflowCount as number) ? `${overflowCount}+` : count; let displayCount = (count as number) > (overflowCount as number) ? `${overflowCount}+` : count;
Expand Down Expand Up @@ -103,7 +105,7 @@ export default class Badge extends React.Component<BadgeProps, any> {
data-show={!hidden} data-show={!hidden}
className={scrollNumberCls} className={scrollNumberCls}
count={displayCount} count={displayCount}
title={count} title={title || count}
style={styleWithOffset} style={styleWithOffset}
/> />
); );
Expand Down
1 change: 1 addition & 0 deletions components/badge/index.zh-CN.md
Expand Up @@ -32,3 +32,4 @@ title: Badge
| showZero | 当数值为 0 时,是否展示 Badge | boolean | false | | showZero | 当数值为 0 时,是否展示 Badge | boolean | false |
| status | 设置 Badge 为状态点 | Enum{ 'success', 'processing, 'default', 'error', 'warning' } | '' | | status | 设置 Badge 为状态点 | Enum{ 'success', 'processing, 'default', 'error', 'warning' } | '' |
| text | 在设置了 `status` 的前提下有效,设置状态点的文本 | string | '' | | text | 在设置了 `status` 的前提下有效,设置状态点的文本 | string | '' |
| title | 设置鼠标放在状态点上时显示的文字 | string | `count` |

0 comments on commit 74d81c2

Please sign in to comment.