react-next-star-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/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +64 -0
- package/dist/index.mjs +37 -0
- package/package.json +30 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
interface StarRatingProps {
|
|
4
|
+
value?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
size?: number;
|
|
7
|
+
readOnly?: boolean;
|
|
8
|
+
onChange?: (value: number) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const StarRating: React.FC<StarRatingProps>;
|
|
11
|
+
|
|
12
|
+
export { StarRating, type StarRatingProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
interface StarRatingProps {
|
|
4
|
+
value?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
size?: number;
|
|
7
|
+
readOnly?: boolean;
|
|
8
|
+
onChange?: (value: number) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const StarRating: React.FC<StarRatingProps>;
|
|
11
|
+
|
|
12
|
+
export { StarRating, type StarRatingProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
StarRating: () => StarRating
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/StarRating.tsx
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
var StarRating = ({
|
|
31
|
+
value = 0,
|
|
32
|
+
max = 5,
|
|
33
|
+
size = 24,
|
|
34
|
+
readOnly = false,
|
|
35
|
+
onChange
|
|
36
|
+
}) => {
|
|
37
|
+
const [hover, setHover] = (0, import_react.useState)(null);
|
|
38
|
+
const displayValue = hover != null ? hover : value;
|
|
39
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", gap: 4 }, children: Array.from({ length: max }).map((_, i) => {
|
|
40
|
+
const starValue = i + 1;
|
|
41
|
+
const filled = starValue <= displayValue;
|
|
42
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
43
|
+
"svg",
|
|
44
|
+
{
|
|
45
|
+
width: size,
|
|
46
|
+
height: size,
|
|
47
|
+
viewBox: "0 0 24 24",
|
|
48
|
+
fill: filled ? "gold" : "none",
|
|
49
|
+
stroke: "gold",
|
|
50
|
+
strokeWidth: "2",
|
|
51
|
+
style: { cursor: readOnly ? "default" : "pointer" },
|
|
52
|
+
onMouseEnter: () => !readOnly && setHover(starValue),
|
|
53
|
+
onMouseLeave: () => !readOnly && setHover(null),
|
|
54
|
+
onClick: () => !readOnly && (onChange == null ? void 0 : onChange(starValue)),
|
|
55
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polygon", { points: "12 2 15 9 22 9 17 14 19 22 12 18 5 22 7 14 2 9 9 9" })
|
|
56
|
+
},
|
|
57
|
+
i
|
|
58
|
+
);
|
|
59
|
+
}) });
|
|
60
|
+
};
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
StarRating
|
|
64
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/StarRating.tsx
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
var StarRating = ({
|
|
5
|
+
value = 0,
|
|
6
|
+
max = 5,
|
|
7
|
+
size = 24,
|
|
8
|
+
readOnly = false,
|
|
9
|
+
onChange
|
|
10
|
+
}) => {
|
|
11
|
+
const [hover, setHover] = useState(null);
|
|
12
|
+
const displayValue = hover != null ? hover : value;
|
|
13
|
+
return /* @__PURE__ */ jsx("div", { style: { display: "flex", gap: 4 }, children: Array.from({ length: max }).map((_, i) => {
|
|
14
|
+
const starValue = i + 1;
|
|
15
|
+
const filled = starValue <= displayValue;
|
|
16
|
+
return /* @__PURE__ */ jsx(
|
|
17
|
+
"svg",
|
|
18
|
+
{
|
|
19
|
+
width: size,
|
|
20
|
+
height: size,
|
|
21
|
+
viewBox: "0 0 24 24",
|
|
22
|
+
fill: filled ? "gold" : "none",
|
|
23
|
+
stroke: "gold",
|
|
24
|
+
strokeWidth: "2",
|
|
25
|
+
style: { cursor: readOnly ? "default" : "pointer" },
|
|
26
|
+
onMouseEnter: () => !readOnly && setHover(starValue),
|
|
27
|
+
onMouseLeave: () => !readOnly && setHover(null),
|
|
28
|
+
onClick: () => !readOnly && (onChange == null ? void 0 : onChange(starValue)),
|
|
29
|
+
children: /* @__PURE__ */ jsx("polygon", { points: "12 2 15 9 22 9 17 14 19 22 12 18 5 22 7 14 2 9 9 9" })
|
|
30
|
+
},
|
|
31
|
+
i
|
|
32
|
+
);
|
|
33
|
+
}) });
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
StarRating
|
|
37
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-next-star-rating",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Star rating component for React and Next.js",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup src/index.ts --format esm,cjs --dts"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"react",
|
|
16
|
+
"nextjs",
|
|
17
|
+
"star-rating",
|
|
18
|
+
"rating"
|
|
19
|
+
],
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=17"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/react": "^19.2.13",
|
|
27
|
+
"tsup": "^8.5.1",
|
|
28
|
+
"typescript": "^5.9.3"
|
|
29
|
+
}
|
|
30
|
+
}
|