diff --git a/README.md b/README.md
index 90e0d7b..ccfce2d 100644
--- a/README.md
+++ b/README.md
@@ -76,6 +76,9 @@ const BaseExample = () => {
InfoPage.InfoPage.Part
+
+ xxxx
+
);
};
@@ -850,6 +853,47 @@ render();
```
+- 评分
+- 展示评分组件
+- _InfoPage(@kne/current-lib_info-page),(@kne/current-lib_info-page/dist/index.css),antd(antd)
+
+```jsx
+const { Score } = _InfoPage;
+const { Flex } = antd;
+
+const BaseExample = () => {
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
+
+render();
+
+```
+
### API
diff --git a/doc/base.js b/doc/base.js
index 2537ab9..5051007 100644
--- a/doc/base.js
+++ b/doc/base.js
@@ -23,6 +23,9 @@ const BaseExample = () => {
InfoPage.InfoPage.Part
+
+ xxxx
+
);
};
diff --git a/doc/example.json b/doc/example.json
index b465623..1d659df 100644
--- a/doc/example.json
+++ b/doc/example.json
@@ -152,6 +152,24 @@
"packageName": "antd"
}
]
+ },
+ {
+ "title": "评分",
+ "description": "展示评分组件",
+ "code": "./score.js",
+ "scope": [
+ {
+ "name": "_InfoPage",
+ "packageName": "@kne/current-lib_info-page"
+ },
+ {
+ "packageName": "@kne/current-lib_info-page/dist/index.css"
+ },
+ {
+ "name": "antd",
+ "packageName": "antd"
+ }
+ ]
}
]
}
diff --git a/doc/score.js b/doc/score.js
new file mode 100644
index 0000000..3f02ed9
--- /dev/null
+++ b/doc/score.js
@@ -0,0 +1,33 @@
+const { Score } = _InfoPage;
+const { Flex } = antd;
+
+const BaseExample = () => {
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
+
+render();
diff --git a/package.json b/package.json
index a12b0f3..6966561 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@kne/info-page",
- "version": "0.2.3",
+ "version": "0.2.4",
"description": "一般用在复杂的详情展示页面,InfoPage提供了一个标准的展示信息的格式",
"syntax": {
"esmodules": true
diff --git a/src/Score/index.js b/src/Score/index.js
index b9f4d70..33f5ee5 100644
--- a/src/Score/index.js
+++ b/src/Score/index.js
@@ -3,16 +3,24 @@ import classnames from 'classnames';
import { Row, Col } from 'antd';
import style from './style.module.scss';
-const ScoreItem = ({ score, staticScore }) => {
+const ScoreItem = ({ score, total, staticScore, getLevel, levelColors = ['#f1f1f1', '#f66969', '#ffb566', '#a2de91'] }) => {
score = Number.isNaN(score) ? 0 : Number(score);
+ const level = (
+ getLevel ||
+ (score => {
+ if (score <= total / 3) return 1;
+ if (score <= (total * 2) / 3) return 2;
+ if (score > (total * 2) / 3) return 3;
+ })
+ )(score);
+
+ const color = staticScore > score ? levelColors[0] : levelColors[level];
return (
score,
- [style['low-score']]: score < 3,
- [style['middle-score']]: score === 3,
- [style['high-score']]: score > 3
- })}
+ className={classnames('score-item', style['score-item'])}
+ style={{
+ '--score-item-color': color
+ }}
/>
);
};
@@ -21,8 +29,8 @@ const Score = ({ className, value, gap = 4, total = 5 }) => {
return (
{Array.from({ length: total }).map((n, index) => (
-
-
+
+
))}
diff --git a/src/Score/style.module.scss b/src/Score/style.module.scss
index 7fded4d..74b6268 100644
--- a/src/Score/style.module.scss
+++ b/src/Score/style.module.scss
@@ -12,20 +12,6 @@
.score-item {
width: 100%;
height: 14px;
-
- &.is-grey {
- background: #f1f1f1 !important;
- }
-
- &.low-score {
- background: #f66969;
- }
-
- &.middle-score {
- background: #ffb566;
- }
-
- &.high-score {
- background: #a2de91;
- }
+ background: var(--score-item-color);
+ min-width: 10px;
}
\ No newline at end of file