geoiq-frontend-ui-kit
Version:
This project is a UI kit for GeoIQ's frontend. It's built with React, TypeScript, and Vite.
75 lines (74 loc) • 2.52 kB
JavaScript
import { Typography as m } from "./index.es17.js";
import e from "react";
import { Skeleton as S } from "./index.es12.js";
const u = {
/**
* utility function to get full and half stars count
*/
getStarsCount: (r) => {
if (r < 0 || r > 100) return { full: 0, half: 0, error: !0 };
const a = (i, n) => ({
full: i,
half: n,
error: !1
}), t = Math.floor(r / 20), l = r % 20;
return l === 0 ? a(t, 0) : l / 10 <= 1 ? a(t, 1) : a(t + 1, 0);
},
/**
* utility function to convert score from string to 'out of 5'
*/
getScoreOutOf5: function(r) {
const { full: a = 0, half: t = 0, error: l = !1 } = this.getStarsCount(r);
return l ? 0 : a * 1 + t * 0.5;
}
}, x = (r) => {
const {
score: a = 0,
starSize: t = 24,
starGap: l = 1,
isLoading: i = !1,
showScore: n = !1,
showScorePercentage: p = !1
} = r, f = isFinite(a) ? +a : 0, {
full: g = 0,
half: h = 0,
error: d = !1
} = u.getStarsCount(f), y = 5 - (g + h), c = {
height: t,
width: t
};
if (i) {
const o = 5 * t + 4 * l, s = t;
return /* @__PURE__ */ e.createElement(S, { style: { width: o, height: s } });
}
return d ? /* @__PURE__ */ e.createElement(m, { variant: "display1", className: "text-light-1" }, "NA") : /* @__PURE__ */ e.createElement("div", { className: "flex items-center", style: { gap: l } }, /* @__PURE__ */ e.createElement("div", { className: "flex", style: { gap: l } }, Array(g).fill(1).map((o, s) => /* @__PURE__ */ e.createElement(
"img",
{
key: s,
src: "https://frontend-static-files.geoiq.io/strapi/rating_star_full_0ddf33ca2f.svg",
alt: "full-star",
...c
}
)), Array(h).fill(1).map((o, s) => /* @__PURE__ */ e.createElement(
"img",
{
key: s,
src: "https://frontend-static-files.geoiq.io/strapi/rating_star_half_dbe5b8f659.svg",
alt: "half-star",
...c
}
)), Array(y).fill(1).map((o, s) => /* @__PURE__ */ e.createElement(
"img",
{
key: s,
src: "https://frontend-static-files.geoiq.io/strapi/rating_star_empty_e05d9a2463.svg",
alt: "empty-star",
...c
}
))), n ? /* @__PURE__ */ e.createElement(m, { variant: "body5", className: "ml-1 text-light-3" }, u.getScoreOutOf5(f).toFixed(1), "/5") : null, p ? /* @__PURE__ */ e.createElement(m, { variant: "body5", className: "ml-1 text-light-3" }, "(", f, "%)") : null);
};
export {
x as StarScore,
u as StarScoreUtils
};
//# sourceMappingURL=index.es45.js.map