Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
京东前端
nutui-react
提交
c5bc5c01
N
nutui-react
项目概览
京东前端
/
nutui-react
通知
0
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nutui-react
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c5bc5c01
编写于
3月 14, 2023
作者:
H
hanyuxinting
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: rate 组件拆分icon
上级
e91eb2f6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
85 deletion
+60
-85
src/packages/rate/rate.taro.tsx
src/packages/rate/rate.taro.tsx
+24
-42
src/packages/rate/rate.tsx
src/packages/rate/rate.tsx
+36
-43
未找到文件。
src/packages/rate/rate.taro.tsx
浏览文件 @
c5bc5c01
import
React
,
{
FunctionComponent
,
useEffect
,
useState
}
from
'
react
'
import
classNames
from
'
classnames
'
import
{
StarFillN
}
from
'
@nutui/icons-react
'
import
bem
from
'
@/utils/bem
'
import
Icon
from
'
@/packages/icon
'
import
{
BasicComponent
,
ComponentDefaults
}
from
'
@/utils/typings
'
...
...
@@ -12,8 +12,7 @@ export interface RateProps extends BasicComponent {
iconSize
:
string
|
number
activeColor
:
string
voidColor
:
string
checkedIcon
:
string
uncheckedIcon
:
string
checkedIcon
:
React
.
ReactNode
disabled
:
boolean
readonly
:
boolean
allowHalf
:
boolean
...
...
@@ -29,8 +28,7 @@ const defaultProps = {
iconSize
:
18
,
activeColor
:
''
,
voidColor
:
''
,
checkedIcon
:
'
star-fill-n
'
,
uncheckedIcon
:
'
star-n
'
,
checkedIcon
:
null
,
disabled
:
false
,
readonly
:
false
,
allowHalf
:
false
,
...
...
@@ -47,14 +45,11 @@ export const Rate: FunctionComponent<Partial<RateProps>> = (props) => {
activeColor
,
voidColor
,
checkedIcon
,
uncheckedIcon
,
disabled
,
readonly
,
allowHalf
,
spacing
,
onChange
,
iconClassPrefix
,
iconFontClassName
,
}
=
{
...
defaultProps
,
...
props
,
...
...
@@ -81,6 +76,18 @@ export const Rate: FunctionComponent<Partial<RateProps>> = (props) => {
return
Number
.
isNaN
(
Number
(
value
))
?
String
(
value
)
:
`
${
value
}
px`
}
const
renderIcon
=
(
size
:
string
|
number
=
iconSize
,
color
:
string
)
=>
{
return
React
.
isValidElement
(
checkedIcon
)
?
(
React
.
cloneElement
<
any
>
(
checkedIcon
,
{
...
checkedIcon
.
props
,
width
:
size
,
height
:
size
,
color
,
})
)
:
(
<
StarFillN
width
=
{
size
}
height
=
{
size
}
color
=
{
color
}
/>
)
}
const
onClick
=
(
e
:
React
.
MouseEvent
,
index
:
number
)
=>
{
e
.
preventDefault
()
e
.
stopPropagation
()
...
...
@@ -91,7 +98,6 @@ export const Rate: FunctionComponent<Partial<RateProps>> = (props) => {
}
value
=
Math
.
max
(
value
,
Number
(
minimizeValue
))
setScore
(
value
)
onChange
&&
onChange
(
value
)
}
const
onHalfClick
=
(
event
:
any
,
n
:
number
)
=>
{
...
...
@@ -111,45 +117,21 @@ export const Rate: FunctionComponent<Partial<RateProps>> = (props) => {
onClick
=
{
(
event
)
=>
onClick
(
event
,
n
)
}
style
=
{
{
marginRight
:
pxCheck
(
spacing
)
}
}
>
<
Icon
classPrefix
=
{
iconClassPrefix
}
fontClassName
=
{
iconFontClassName
}
size
=
{
iconSize
}
<
div
className
=
{
classNames
(
bi
(
'
icon
'
),
{
[
bi
(
'
icon--disabled
'
)]:
disabled
||
n
>
score
,
})
}
name
=
{
n
<=
score
?
checkedIcon
:
uncheckedIcon
}
color
=
{
n
<=
score
?
activeColor
:
voidColor
}
/
>
>
{
renderIcon
(
iconSize
,
n
<=
score
?
activeColor
:
voidColor
)
}
</
div
>
{
allowHalf
&&
score
>
n
-
1
&&
(
<
Icon
classPrefix
=
{
iconClassPrefix
}
fontClassName
=
{
iconFontClassName
}
<
div
className
=
{
`
${
bi
(
'
half
'
)}
${
bi
(
'
icon
'
)}
${
bi
(
'
icon--half
'
)}
`
}
onClick
=
{
(
event
)
=>
onHalfClick
(
event
,
n
)
}
className
=
{
`
${
bi
(
'
icon
'
)}
${
bi
(
'
icon--half
'
)}
`
}
color
=
{
n
<=
score
?
activeColor
:
voidColor
}
size
=
{
iconSize
}
name
=
{
checkedIcon
}
/>
)
}
{
/* {allowHalf && score > n - 1 && (
<Icon classPrefix={iconClassPrefix} fontClassName={iconFontClassName}
className={`${bi('icon')} ${bi('icon--half')}`}
color={n <= score ? activeColor : voidColor}
size={iconSize}
name={checkedIcon}
/>
>
{
renderIcon
(
iconSize
,
n
<=
score
?
activeColor
:
voidColor
)
}
</
div
>
)
}
{allowHalf && score < n - 1 && (
<Icon classPrefix={iconClassPrefix} fontClassName={iconFontClassName}
className={`${bi('icon')} ${bi('icon--disabled')} ${bi(
'icon--half'
)}`}
color={voidColor}
size={iconSize}
name={uncheckedIcon}
/>
)} */
}
</
div
>
)
})
}
...
...
src/packages/rate/rate.tsx
浏览文件 @
c5bc5c01
...
...
@@ -76,6 +76,19 @@ export const Rate: FunctionComponent<Partial<RateProps>> = (props) => {
return
Number
.
isNaN
(
Number
(
value
))
?
String
(
value
)
:
`
${
value
}
px`
}
const
renderIcon
=
(
size
:
string
|
number
=
iconSize
,
color
:
string
)
=>
{
return
React
.
isValidElement
(
checkedIcon
)
?
(
React
.
cloneElement
<
any
>
(
checkedIcon
,
{
...
checkedIcon
.
props
,
width
:
size
,
height
:
size
,
color
,
})
)
:
(
<
StarFillN
width
=
{
size
}
height
=
{
size
}
color
=
{
color
}
/>
)
}
const
onClick
=
(
e
:
React
.
MouseEvent
,
index
:
number
)
=>
{
e
.
preventDefault
()
e
.
stopPropagation
()
...
...
@@ -83,17 +96,20 @@ export const Rate: FunctionComponent<Partial<RateProps>> = (props) => {
let
value
=
0
if
(
!
(
index
===
1
&&
score
===
index
))
{
value
=
index
if
(
allowHalf
)
{
if
((
e
?.
target
as
Element
).
className
.
includes
(
'
__icon--half
'
))
{
value
-=
0.5
}
}
}
value
=
Math
.
max
(
value
,
Number
(
minimizeValue
))
setScore
(
value
)
onChange
&&
onChange
(
value
)
}
const
onHalfClick
=
(
event
:
any
,
n
:
number
)
=>
{
event
.
preventDefault
()
event
.
stopPropagation
()
const
value
=
Math
.
max
(
Number
(
minimizeValue
),
n
-
0.5
)
setScore
(
value
)
onChange
&&
onChange
(
value
)
}
return
(
<
div
className
=
{
classNames
(
b
(),
className
)
}
style
=
{
style
}
>
{
countArray
.
map
((
n
)
=>
{
...
...
@@ -104,44 +120,21 @@ export const Rate: FunctionComponent<Partial<RateProps>> = (props) => {
onClick
=
{
(
event
)
=>
onClick
(
event
,
n
)
}
style
=
{
{
marginRight
:
pxCheck
(
spacing
)
}
}
>
<>
{
checkedIcon
||
(
<
StarFillN
width
=
{
iconSize
}
height
=
{
iconSize
}
color
=
{
n
<=
score
?
activeColor
:
voidColor
}
className
=
{
classNames
(
bi
(
'
icon
'
),
{
[
bi
(
'
icon--disabled
'
)]:
disabled
||
n
>
score
,
})
}
/>
)
}
{
(
allowHalf
&&
score
>
n
-
1
&&
(
<
div
className
=
{
`
${
bi
(
'
half
'
)}
`
}
>
{
checkedIcon
||
(
<
StarFillN
width
=
{
iconSize
}
height
=
{
iconSize
}
color
=
{
n
<=
score
?
activeColor
:
voidColor
}
className
=
{
`
${
bi
(
'
icon
'
)}
${
bi
(
'
icon--half
'
)}
`
}
/>
)
}
</
div
>
))
||
(
allowHalf
&&
score
<
n
-
1
&&
(
<
div
>
{
checkedIcon
||
(
<
StarFillN
width
=
{
iconSize
}
height
=
{
iconSize
}
color
=
{
voidColor
}
className
=
{
`
${
bi
(
'
icon
'
)}
${
bi
(
'
icon--disabled
'
)}
${
bi
(
'
icon--half
'
)}
`
}
/>
)
}
</
div
>
))
}
</>
<
div
className
=
{
classNames
(
bi
(
'
icon
'
),
{
[
bi
(
'
icon--disabled
'
)]:
disabled
||
n
>
score
,
})
}
>
{
renderIcon
(
iconSize
,
n
<=
score
?
activeColor
:
voidColor
)
}
</
div
>
{
allowHalf
&&
score
>
n
-
1
&&
(
<
div
className
=
{
`
${
bi
(
'
half
'
)}
${
bi
(
'
icon
'
)}
${
bi
(
'
icon--half
'
)}
`
}
onClick
=
{
(
event
)
=>
onHalfClick
(
event
,
n
)
}
>
{
renderIcon
(
iconSize
,
n
<=
score
?
activeColor
:
voidColor
)
}
</
div
>
)
}
</
div
>
)
})
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录