@sproutsocial/seeds-react-rating 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +6 -0
- package/.eslintrc.js +4 -0
- package/.turbo/turbo-build.log +21 -0
- package/CHANGELOG.md +7 -0
- package/dist/esm/index.js +52 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -0
- package/jest.config.js +9 -0
- package/package.json +44 -0
- package/src/Rating.stories.tsx +29 -0
- package/src/Rating.tsx +44 -0
- package/src/RatingTypes.ts +9 -0
- package/src/__tests__/rating.test.tsx +15 -0
- package/src/index.ts +5 -0
- package/src/styled.d.ts +7 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +12 -0
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
yarn run v1.22.22
|
|
2
|
+
$ tsup --dts
|
|
3
|
+
CLI Building entry: src/index.ts
|
|
4
|
+
CLI Using tsconfig: tsconfig.json
|
|
5
|
+
CLI tsup v8.0.2
|
|
6
|
+
CLI Using tsup config: /home/runner/work/seeds/seeds/seeds-react/seeds-react-rating/tsup.config.ts
|
|
7
|
+
CLI Target: es2022
|
|
8
|
+
CLI Cleaning output folder
|
|
9
|
+
CJS Build start
|
|
10
|
+
ESM Build start
|
|
11
|
+
CJS dist/index.js 3.48 KB
|
|
12
|
+
CJS dist/index.js.map 2.60 KB
|
|
13
|
+
CJS ⚡️ Build success in 158ms
|
|
14
|
+
ESM dist/esm/index.js 1.49 KB
|
|
15
|
+
ESM dist/esm/index.js.map 2.55 KB
|
|
16
|
+
ESM ⚡️ Build success in 162ms
|
|
17
|
+
DTS Build start
|
|
18
|
+
DTS ⚡️ Build success in 34737ms
|
|
19
|
+
DTS dist/index.d.ts 358.00 B
|
|
20
|
+
DTS dist/index.d.mts 358.00 B
|
|
21
|
+
Done in 42.86s.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/Rating.tsx
|
|
2
|
+
import "react";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import { Icon } from "@sproutsocial/seeds-react-icon";
|
|
5
|
+
import { Badge } from "@sproutsocial/seeds-react-badge";
|
|
6
|
+
|
|
7
|
+
// src/RatingTypes.ts
|
|
8
|
+
import "react";
|
|
9
|
+
|
|
10
|
+
// src/Rating.tsx
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
var RatingContainer = styled.div`
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
`;
|
|
16
|
+
var Rating = ({
|
|
17
|
+
emptyIcon = /* @__PURE__ */ jsx(Icon, { name: "star-outline", color: "yellow.600" }),
|
|
18
|
+
halfIcon = /* @__PURE__ */ jsx(Icon, { name: "star-half-outline", color: "yellow.600" }),
|
|
19
|
+
filledIcon = /* @__PURE__ */ jsx(Icon, { name: "star-full-solid", color: "yellow.600" }),
|
|
20
|
+
rating,
|
|
21
|
+
scale = 5
|
|
22
|
+
}) => {
|
|
23
|
+
return /* @__PURE__ */ jsxs(RatingContainer, { children: [
|
|
24
|
+
Array.from({ length: scale }, (_, index) => {
|
|
25
|
+
if (index < Math.floor(rating)) {
|
|
26
|
+
return /* @__PURE__ */ jsx("span", { children: filledIcon }, index);
|
|
27
|
+
} else if (index === Math.floor(rating) && rating % 1 !== 0) {
|
|
28
|
+
return /* @__PURE__ */ jsx("span", { children: halfIcon }, index);
|
|
29
|
+
} else {
|
|
30
|
+
return /* @__PURE__ */ jsx("span", { children: emptyIcon }, index);
|
|
31
|
+
}
|
|
32
|
+
}),
|
|
33
|
+
/* @__PURE__ */ jsx(
|
|
34
|
+
Badge,
|
|
35
|
+
{
|
|
36
|
+
size: "small",
|
|
37
|
+
badgeColor: "neutral",
|
|
38
|
+
ml: 200,
|
|
39
|
+
children: `${rating}/${scale}`
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
] });
|
|
43
|
+
};
|
|
44
|
+
var Rating_default = Rating;
|
|
45
|
+
|
|
46
|
+
// src/index.ts
|
|
47
|
+
var index_default = Rating_default;
|
|
48
|
+
export {
|
|
49
|
+
Rating_default as Rating,
|
|
50
|
+
index_default as default
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Rating.tsx","../../src/RatingTypes.ts","../../src/index.ts"],"sourcesContent":["import React from \"react\";\nimport styled from \"styled-components\";\nimport { Icon } from \"@sproutsocial/seeds-react-icon\";\nimport { Badge } from \"@sproutsocial/seeds-react-badge\";\nimport { type TypeRatingProps } from \"./RatingTypes\";\n\nconst RatingContainer = styled.div`\n display: flex;\n align-items: center;\n`;\n\nconst Rating: React.FC<TypeRatingProps> = ({\n emptyIcon = <Icon name=\"star-outline\" color=\"yellow.600\" />,\n halfIcon = <Icon name=\"star-half-outline\" color=\"yellow.600\" />,\n filledIcon = <Icon name=\"star-full-solid\" color=\"yellow.600\" />,\n rating,\n scale = 5,\n}) => {\n return (\n <RatingContainer>\n {Array.from({ length: scale }, (_, index) => {\n if (index < Math.floor(rating)) {\n // Full star\n return <span key={index}>{filledIcon}</span>;\n } else if (index === Math.floor(rating) && rating % 1 !== 0) {\n // Half star\n return <span key={index}>{halfIcon}</span>;\n } else {\n // Empty star\n return <span key={index}>{emptyIcon}</span>;\n }\n })}\n {\n <Badge\n size=\"small\"\n badgeColor=\"neutral\"\n ml={200}\n >{`${rating}/${scale}`}</Badge>\n }\n </RatingContainer>\n );\n};\n\nexport default Rating;\n","import * as React from \"react\";\n\nexport interface TypeRatingProps {\n emptyIcon?: React.ReactNode;\n halfIcon?: React.ReactNode;\n filledIcon?: React.ReactNode;\n rating: number;\n scale?: number;\n}\n","import Rating from \"./Rating\";\n\nexport default Rating;\nexport { Rating };\nexport * from \"./RatingTypes\";\n"],"mappings":";AAAA,OAAkB;AAClB,OAAO,YAAY;AACnB,SAAS,YAAY;AACrB,SAAS,aAAa;;;ACHtB,OAAuB;;;ADYT,cAOV,YAPU;AANd,IAAM,kBAAkB,OAAO;AAAA;AAAA;AAAA;AAK/B,IAAM,SAAoC,CAAC;AAAA,EACzC,YAAY,oBAAC,QAAK,MAAK,gBAAe,OAAM,cAAa;AAAA,EACzD,WAAW,oBAAC,QAAK,MAAK,qBAAoB,OAAM,cAAa;AAAA,EAC7D,aAAa,oBAAC,QAAK,MAAK,mBAAkB,OAAM,cAAa;AAAA,EAC7D;AAAA,EACA,QAAQ;AACV,MAAM;AACJ,SACE,qBAAC,mBACE;AAAA,UAAM,KAAK,EAAE,QAAQ,MAAM,GAAG,CAAC,GAAG,UAAU;AAC3C,UAAI,QAAQ,KAAK,MAAM,MAAM,GAAG;AAE9B,eAAO,oBAAC,UAAkB,wBAAR,KAAmB;AAAA,MACvC,WAAW,UAAU,KAAK,MAAM,MAAM,KAAK,SAAS,MAAM,GAAG;AAE3D,eAAO,oBAAC,UAAkB,sBAAR,KAAiB;AAAA,MACrC,OAAO;AAEL,eAAO,oBAAC,UAAkB,uBAAR,KAAkB;AAAA,MACtC;AAAA,IACF,CAAC;AAAA,IAEC;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,YAAW;AAAA,QACX,IAAI;AAAA,QACJ,aAAG,MAAM,IAAI,KAAK;AAAA;AAAA,IAAG;AAAA,KAE3B;AAEJ;AAEA,IAAO,iBAAQ;;;AEzCf,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
|
|
4
|
+
interface TypeRatingProps {
|
|
5
|
+
emptyIcon?: React.ReactNode;
|
|
6
|
+
halfIcon?: React.ReactNode;
|
|
7
|
+
filledIcon?: React.ReactNode;
|
|
8
|
+
rating: number;
|
|
9
|
+
scale?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare const Rating: React__default.FC<TypeRatingProps>;
|
|
13
|
+
|
|
14
|
+
export { Rating, type TypeRatingProps, Rating as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
|
|
4
|
+
interface TypeRatingProps {
|
|
5
|
+
emptyIcon?: React.ReactNode;
|
|
6
|
+
halfIcon?: React.ReactNode;
|
|
7
|
+
filledIcon?: React.ReactNode;
|
|
8
|
+
rating: number;
|
|
9
|
+
scale?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare const Rating: React__default.FC<TypeRatingProps>;
|
|
13
|
+
|
|
14
|
+
export { Rating, type TypeRatingProps, Rating as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Rating: () => Rating_default,
|
|
34
|
+
default: () => index_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/Rating.tsx
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
41
|
+
var import_seeds_react_icon = require("@sproutsocial/seeds-react-icon");
|
|
42
|
+
var import_seeds_react_badge = require("@sproutsocial/seeds-react-badge");
|
|
43
|
+
|
|
44
|
+
// src/RatingTypes.ts
|
|
45
|
+
var React = require("react");
|
|
46
|
+
|
|
47
|
+
// src/Rating.tsx
|
|
48
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
49
|
+
var RatingContainer = import_styled_components.default.div`
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
`;
|
|
53
|
+
var Rating = ({
|
|
54
|
+
emptyIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_seeds_react_icon.Icon, { name: "star-outline", color: "yellow.600" }),
|
|
55
|
+
halfIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_seeds_react_icon.Icon, { name: "star-half-outline", color: "yellow.600" }),
|
|
56
|
+
filledIcon = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_seeds_react_icon.Icon, { name: "star-full-solid", color: "yellow.600" }),
|
|
57
|
+
rating,
|
|
58
|
+
scale = 5
|
|
59
|
+
}) => {
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(RatingContainer, { children: [
|
|
61
|
+
Array.from({ length: scale }, (_, index) => {
|
|
62
|
+
if (index < Math.floor(rating)) {
|
|
63
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: filledIcon }, index);
|
|
64
|
+
} else if (index === Math.floor(rating) && rating % 1 !== 0) {
|
|
65
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: halfIcon }, index);
|
|
66
|
+
} else {
|
|
67
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: emptyIcon }, index);
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
70
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
71
|
+
import_seeds_react_badge.Badge,
|
|
72
|
+
{
|
|
73
|
+
size: "small",
|
|
74
|
+
badgeColor: "neutral",
|
|
75
|
+
ml: 200,
|
|
76
|
+
children: `${rating}/${scale}`
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
] });
|
|
80
|
+
};
|
|
81
|
+
var Rating_default = Rating;
|
|
82
|
+
|
|
83
|
+
// src/index.ts
|
|
84
|
+
var index_default = Rating_default;
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
Rating
|
|
88
|
+
});
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/Rating.tsx","../src/RatingTypes.ts"],"sourcesContent":["import Rating from \"./Rating\";\n\nexport default Rating;\nexport { Rating };\nexport * from \"./RatingTypes\";\n","import React from \"react\";\nimport styled from \"styled-components\";\nimport { Icon } from \"@sproutsocial/seeds-react-icon\";\nimport { Badge } from \"@sproutsocial/seeds-react-badge\";\nimport { type TypeRatingProps } from \"./RatingTypes\";\n\nconst RatingContainer = styled.div`\n display: flex;\n align-items: center;\n`;\n\nconst Rating: React.FC<TypeRatingProps> = ({\n emptyIcon = <Icon name=\"star-outline\" color=\"yellow.600\" />,\n halfIcon = <Icon name=\"star-half-outline\" color=\"yellow.600\" />,\n filledIcon = <Icon name=\"star-full-solid\" color=\"yellow.600\" />,\n rating,\n scale = 5,\n}) => {\n return (\n <RatingContainer>\n {Array.from({ length: scale }, (_, index) => {\n if (index < Math.floor(rating)) {\n // Full star\n return <span key={index}>{filledIcon}</span>;\n } else if (index === Math.floor(rating) && rating % 1 !== 0) {\n // Half star\n return <span key={index}>{halfIcon}</span>;\n } else {\n // Empty star\n return <span key={index}>{emptyIcon}</span>;\n }\n })}\n {\n <Badge\n size=\"small\"\n badgeColor=\"neutral\"\n ml={200}\n >{`${rating}/${scale}`}</Badge>\n }\n </RatingContainer>\n );\n};\n\nexport default Rating;\n","import * as React from \"react\";\n\nexport interface TypeRatingProps {\n emptyIcon?: React.ReactNode;\n halfIcon?: React.ReactNode;\n filledIcon?: React.ReactNode;\n rating: number;\n scale?: number;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAClB,+BAAmB;AACnB,8BAAqB;AACrB,+BAAsB;;;ACHtB,YAAuB;;;ADYT;AANd,IAAM,kBAAkB,yBAAAA,QAAO;AAAA;AAAA;AAAA;AAK/B,IAAM,SAAoC,CAAC;AAAA,EACzC,YAAY,4CAAC,gCAAK,MAAK,gBAAe,OAAM,cAAa;AAAA,EACzD,WAAW,4CAAC,gCAAK,MAAK,qBAAoB,OAAM,cAAa;AAAA,EAC7D,aAAa,4CAAC,gCAAK,MAAK,mBAAkB,OAAM,cAAa;AAAA,EAC7D;AAAA,EACA,QAAQ;AACV,MAAM;AACJ,SACE,6CAAC,mBACE;AAAA,UAAM,KAAK,EAAE,QAAQ,MAAM,GAAG,CAAC,GAAG,UAAU;AAC3C,UAAI,QAAQ,KAAK,MAAM,MAAM,GAAG;AAE9B,eAAO,4CAAC,UAAkB,wBAAR,KAAmB;AAAA,MACvC,WAAW,UAAU,KAAK,MAAM,MAAM,KAAK,SAAS,MAAM,GAAG;AAE3D,eAAO,4CAAC,UAAkB,sBAAR,KAAiB;AAAA,MACrC,OAAO;AAEL,eAAO,4CAAC,UAAkB,uBAAR,KAAkB;AAAA,MACtC;AAAA,IACF,CAAC;AAAA,IAEC;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,YAAW;AAAA,QACX,IAAI;AAAA,QACJ,aAAG,MAAM,IAAI,KAAK;AAAA;AAAA,IAAG;AAAA,KAE3B;AAEJ;AAEA,IAAO,iBAAQ;;;ADzCf,IAAO,gBAAQ;","names":["styled"]}
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sproutsocial/seeds-react-rating",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Seeds React Rating",
|
|
5
|
+
"author": "Sprout Social, Inc.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/esm/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsup --dts",
|
|
12
|
+
"build:debug": "tsup --dts --metafile",
|
|
13
|
+
"dev": "tsup --watch --dts",
|
|
14
|
+
"clean": "rm -rf .turbo dist",
|
|
15
|
+
"clean:modules": "rm -rf node_modules",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"test:watch": "jest --watch --coverage=false"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@sproutsocial/seeds-react-theme": "^2.2.0",
|
|
22
|
+
"@sproutsocial/seeds-react-system-props": "^3.0.1",
|
|
23
|
+
"@sproutsocial/seeds-react-icon": "^1.0.0",
|
|
24
|
+
"@sproutsocial/seeds-react-badge": "^1.0.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/react": "^18.0.0",
|
|
28
|
+
"@types/styled-components": "^5.1.26",
|
|
29
|
+
"@sproutsocial/eslint-config-seeds": "*",
|
|
30
|
+
"react": "^18.0.0",
|
|
31
|
+
"styled-components": "^5.2.3",
|
|
32
|
+
"tsup": "^8.0.2",
|
|
33
|
+
"typescript": "^5.6.2",
|
|
34
|
+
"@sproutsocial/seeds-tsconfig": "*",
|
|
35
|
+
"@sproutsocial/seeds-testing": "*",
|
|
36
|
+
"@sproutsocial/seeds-react-testing-library": "*"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"styled-components": "^5.2.3"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
|
+
import Rating from "./Rating";
|
|
4
|
+
import { Icon } from "@sproutsocial/seeds-react-icon";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: "Components/Rating",
|
|
8
|
+
component: Rating,
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
type Story = StoryObj<typeof Rating>;
|
|
12
|
+
|
|
13
|
+
export const Default: Story = {
|
|
14
|
+
args: {
|
|
15
|
+
rating: 3,
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
render: (args) => <Rating {...args} />,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const Custom: Story = {
|
|
22
|
+
args: {
|
|
23
|
+
rating: 3,
|
|
24
|
+
emptyIcon: <Icon name="tripadvisor-circle-outline" />,
|
|
25
|
+
filledIcon: <Icon name="tripadvisor-circle-solid" />,
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
render: (args) => <Rating {...args} />,
|
|
29
|
+
};
|
package/src/Rating.tsx
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import styled from "styled-components";
|
|
3
|
+
import { Icon } from "@sproutsocial/seeds-react-icon";
|
|
4
|
+
import { Badge } from "@sproutsocial/seeds-react-badge";
|
|
5
|
+
import { type TypeRatingProps } from "./RatingTypes";
|
|
6
|
+
|
|
7
|
+
const RatingContainer = styled.div`
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
const Rating: React.FC<TypeRatingProps> = ({
|
|
13
|
+
emptyIcon = <Icon name="star-outline" color="yellow.600" />,
|
|
14
|
+
halfIcon = <Icon name="star-half-outline" color="yellow.600" />,
|
|
15
|
+
filledIcon = <Icon name="star-full-solid" color="yellow.600" />,
|
|
16
|
+
rating,
|
|
17
|
+
scale = 5,
|
|
18
|
+
}) => {
|
|
19
|
+
return (
|
|
20
|
+
<RatingContainer>
|
|
21
|
+
{Array.from({ length: scale }, (_, index) => {
|
|
22
|
+
if (index < Math.floor(rating)) {
|
|
23
|
+
// Full star
|
|
24
|
+
return <span key={index}>{filledIcon}</span>;
|
|
25
|
+
} else if (index === Math.floor(rating) && rating % 1 !== 0) {
|
|
26
|
+
// Half star
|
|
27
|
+
return <span key={index}>{halfIcon}</span>;
|
|
28
|
+
} else {
|
|
29
|
+
// Empty star
|
|
30
|
+
return <span key={index}>{emptyIcon}</span>;
|
|
31
|
+
}
|
|
32
|
+
})}
|
|
33
|
+
{
|
|
34
|
+
<Badge
|
|
35
|
+
size="small"
|
|
36
|
+
badgeColor="neutral"
|
|
37
|
+
ml={200}
|
|
38
|
+
>{`${rating}/${scale}`}</Badge>
|
|
39
|
+
}
|
|
40
|
+
</RatingContainer>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default Rating;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@sproutsocial/seeds-react-testing-library";
|
|
3
|
+
import Rating from "../Rating";
|
|
4
|
+
|
|
5
|
+
describe("Rating Features", () => {
|
|
6
|
+
it("should display text that reflects the rating", () => {
|
|
7
|
+
render(<Rating rating={3} />);
|
|
8
|
+
expect(screen.getByText("3/5")).toBeInTheDocument();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should support half star ratings", () => {
|
|
12
|
+
render(<Rating rating={3.5} />);
|
|
13
|
+
expect(screen.getByText("3.5/5")).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
});
|
package/src/index.ts
ADDED
package/src/styled.d.ts
ADDED
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig((options) => ({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
format: ["cjs", "esm"],
|
|
6
|
+
clean: true,
|
|
7
|
+
legacyOutput: true,
|
|
8
|
+
dts: options.dts,
|
|
9
|
+
external: ["react"],
|
|
10
|
+
sourcemap: true,
|
|
11
|
+
metafile: options.metafile,
|
|
12
|
+
}));
|