Skip to content

Commit e4b8e17

Browse files
authored
feat(rate): v14 (#2797)
* feat(rate): v14适配 * fix: amend * fix: update marking * fix: amend * fix: modify font import * fix: 设计稿更改间距跟随修改 * fix: 移除 * feat: update migrate-from文档 * fix: 修改pr * fix: update test * fix: update calc
1 parent f6acd2b commit e4b8e17

23 files changed

+275
-70
lines changed

migrate-from-v2.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,8 @@ plugins: [
829829
- `upIconName` 重命名为 `riseIcon`,类型修改为 `React.Node`
830830
- `downIconName` 重命名为 `dropIcon`,类型修改为 `React.Node`
831831
- 移除 `iconSize`,通过`riseIcon``dropIcon`自定义传入icon大小
832+
- 新增 `size`,star 尺寸, 默认值 `normal``12px`
833+
- 新增 `showScore`, 展示评分
832834

833835
#### Video
834836

src/config.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@
642642
"sort": 1,
643643
"show": true,
644644
"taro": true,
645+
"v14": true,
645646
"author": "dsj"
646647
},
647648
{
@@ -1003,8 +1004,8 @@
10031004
"sort": 17,
10041005
"show": true,
10051006
"taro": true,
1006-
"author": "songsong",
1007-
"v14": true
1007+
"v14": true,
1008+
"author": "songsong"
10081009
},
10091010
{
10101011
"version": "2.0.0",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`size test 1`] = `
4+
<div>
5+
<div
6+
class="nut-rate"
7+
>
8+
<div
9+
class="nut-rate-item nut-rate-item-large"
10+
>
11+
<div
12+
class="nut-rate-item-icon nut-rate-item-icon-disabled"
13+
>
14+
<svg
15+
aria-labelledby="StarFill"
16+
class="nut-icon nut-icon-StarFill "
17+
role="presentation"
18+
viewBox="0 0 1024 1024"
19+
xmlns="http://www.w3.org/2000/svg"
20+
>
21+
<path
22+
d="m908.1 353.1-253.9-36.9L540.7 86.1c-3.1-6.3-8.2-11.4-14.5-14.5-15.8-7.8-35-1.3-42.9 14.5L369.8 316.2l-253.9 36.9c-7 1-13.4 4.3-18.3 9.3-12.3 12.7-12.1 32.9.6 45.3l183.7 179.1-43.4 252.9c-1.2 6.9-.1 14.1 3.2 20.3 8.2 15.6 27.6 21.7 43.2 13.4L512 754l227.1 119.4c6.2 3.3 13.4 4.4 20.3 3.2 17.4-3 29.1-19.5 26.1-36.9l-43.4-252.9 183.7-179.1c5-4.9 8.3-11.3 9.3-18.3 2.7-17.5-9.5-33.7-27-36.3"
23+
fill="currentColor"
24+
fill-opacity="0.9"
25+
/>
26+
</svg>
27+
</div>
28+
</div>
29+
</div>
30+
</div>
31+
`;

src/packages/rate/__test__/rate.spec.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ test('allowHalf test', () => {
7474
)
7575
}
7676
})
77+
test('size test', () => {
78+
const { container } = render(<Rate count={1} size="large" />)
79+
const el = container.querySelector('.nut-rate-item')
80+
if (el) {
81+
expect(el).toHaveClass('nut-rate-item-large')
82+
}
83+
expect(container).toMatchSnapshot()
84+
})
85+
86+
test('showScore test', () => {
87+
const { container } = render(<Rate count={1} showScore defaultValue={0.5} />)
88+
const el = container.querySelector('.nut-rate-score')
89+
if (el) {
90+
expect(el?.innerHTML).toBe('0.5')
91+
}
92+
})
7793

7894
test('touchable', () => {
7995
const state = {
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import React from 'react'
2-
import { Rate } from '@nutui/nutui-react'
2+
import { Rate, Space } from '@nutui/nutui-react'
33

44
const Demo1 = () => {
5-
return <Rate defaultValue={3} />
5+
return (
6+
<Space direction="vertical">
7+
<Rate defaultValue={3} size="large" />
8+
<Rate defaultValue={3} />
9+
<Rate defaultValue={3} size="small" />
10+
</Space>
11+
)
612
}
713
export default Demo1

src/packages/rate/demos/h5/demo2.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { Rate } from '@nutui/nutui-react'
33

44
const Demo2 = () => {
55
const [score, setScore] = useState(2)
6-
return <Rate value={score} onChange={(value) => setScore(value)} />
6+
return <Rate value={score} showScore onChange={(value) => setScore(value)} />
77
}
88
export default Demo2

src/packages/rate/demos/h5/demo5.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import React from 'react'
22
import { Rate } from '@nutui/nutui-react'
33

44
const Demo5 = () => {
5-
return <Rate count={6} defaultValue={3} />
5+
return <Rate count={1} defaultValue={1} />
66
}
77
export default Demo5
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import React from 'react'
2-
import { Rate } from '@nutui/nutui-react-taro'
2+
import { Rate, Space } from '@nutui/nutui-react-taro'
33

44
const Demo1 = () => {
5-
return <Rate defaultValue={3} />
5+
return (
6+
<Space direction="vertical">
7+
<Rate defaultValue={3} size="large" />
8+
<Rate defaultValue={3} />
9+
<Rate defaultValue={3} size="small" />
10+
</Space>
11+
)
612
}
713
export default Demo1

src/packages/rate/demos/taro/demo2.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { Rate } from '@nutui/nutui-react-taro'
33

44
const Demo2 = () => {
55
const [score, setScore] = useState(2)
6-
return <Rate value={score} onChange={(value) => setScore(value)} />
6+
return <Rate value={score} showScore onChange={(value) => setScore(value)} />
77
}
88
export default Demo2

src/packages/rate/demos/taro/demo5.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import React from 'react'
22
import { Rate } from '@nutui/nutui-react-taro'
33

44
const Demo5 = () => {
5-
return <Rate count={6} defaultValue={3} />
5+
return <Rate count={1} defaultValue={1} />
66
}
77
export default Demo5

0 commit comments

Comments
 (0)