UNPKG

saydata

Version:

Saydata seamlessly integrates AI-driven analytics for your customers into your app. Designed for beautiful visualization. Engineered for simplicity.

120 lines (119 loc) 4.1 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { jsx as _jsx } from "react/jsx-runtime"; import chroma from 'chroma-js'; import { Switch, styled } from "@mui/material"; export function stringToColor(string) { var hash = 0; var i; /* eslint-disable no-bitwise */ for (i = 0; i < string.length; i += 1) { hash = string.charCodeAt(i) + ((hash << 5) - hash); } var color = "#"; for (i = 0; i < 3; i += 1) { var value = (hash >> (i * 8)) & 0xff; color += "00".concat(value.toString(16)).slice(-2); } /* eslint-enable no-bitwise */ return color; } export function stringAvatar(email) { return { sx: { bgcolor: stringToColor(email), width: 28, height: 28, }, children: "".concat(email[0].toUpperCase()), }; } export function generateShades(baseColor, lightColor, numberOfShades) { if (!lightColor) { lightColor = "#DBABFF"; } var colorScale = chroma .scale([baseColor, lightColor]) .mode("lch") .colors(numberOfShades); return colorScale; } export function dataFormater(value) { var _a, _b, _c; if (value >= 1000000000) { return removeTrailingZeroes((_a = (value / 1000000000)) === null || _a === void 0 ? void 0 : _a.toFixed(2)).toString() + "B"; } else if (value >= 1000000) { return removeTrailingZeroes((_b = (value / 1000000)) === null || _b === void 0 ? void 0 : _b.toFixed(2)).toString() + "M"; } else if (value >= 1000) { return removeTrailingZeroes((_c = (value / 1000)) === null || _c === void 0 ? void 0 : _c.toFixed(2)).toString() + "K"; } else { return removeTrailingZeroes(value === null || value === void 0 ? void 0 : value.toFixed(2)).toString(); } } ; function removeTrailingZeroes(value) { return value.includes('.') ? value.replace(/\.?0*$/, '') : value; } export var StyledSwitch = styled(function (props) { return (_jsx(Switch, __assign({ focusVisibleClassName: ".Mui-focusVisible", disableRipple: true }, props))); })(function (_a) { var theme = _a.theme, shade = _a.shade; return ({ width: 32, height: 16, padding: 0, marginLeft: 16, "& .MuiSwitch-switchBase": { padding: 0, margin: 2, transitionDuration: "300ms", "&.Mui-checked": { transform: "translateX(16px)", color: "#fff", "& + .MuiSwitch-track": { backgroundColor: theme.palette.mode === "dark" ? "#2ECA45" : shade, opacity: 1, border: 0, }, "&.Mui-disabled + .MuiSwitch-track": { opacity: 0.5, }, }, "&.Mui-focusVisible .MuiSwitch-thumb": { color: "#33cf4d", border: "6px solid #fff", }, "&.Mui-disabled .MuiSwitch-thumb": { color: theme.palette.mode === "light" ? theme.palette.grey[100] : theme.palette.grey[600], }, "&.Mui-disabled + .MuiSwitch-track": { opacity: theme.palette.mode === "light" ? 0.7 : 0.3, }, }, "& .MuiSwitch-thumb": { boxSizing: "border-box", width: 12, height: 12, }, "& .MuiSwitch-track": { borderRadius: 16 / 2, backgroundColor: theme.palette.mode === "light" ? "#E9E9EA" : "#39393D", opacity: 1, transition: theme.transitions.create(["background-color"], { duration: 500, }), }, }); });