@airplane/views
Version:
A React library for building Airplane views. Views components are optimized in style and functionality to produce internal apps that are easy to build and maintain.
49 lines (48 loc) • 1.4 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { ComponentErrorBoundary } from "../errorBoundary/ComponentErrorBoundary.js";
import { useStyles } from "./Chip.styles.js";
const ChipComponent = ({
children,
color = "primary",
size = "md",
variant = "light",
className,
style
}) => {
if (color === "auto") {
color = pickColor(children);
}
const {
classes,
cx
} = useStyles({
color,
size,
variant
});
return /* @__PURE__ */ jsx("span", { style, className: cx(classes.root, className), children });
};
const AUTO_COLOR_CHOICES = ["gray", "red", "pink", "grape", "violet", "indigo", "blue", "cyan", "teal", "green", "lime", "yellow", "orange"];
const pickColor = (children) => {
let color;
if (typeof children === "string") {
color = AUTO_COLOR_CHOICES[hashStr(children) % AUTO_COLOR_CHOICES.length];
} else if (typeof children === "number") {
color = AUTO_COLOR_CHOICES[children % AUTO_COLOR_CHOICES.length];
}
return color || "primary";
};
const hashStr = (str) => {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash += str.charCodeAt(i);
}
return hash;
};
const Chip = (props) => /* @__PURE__ */ jsx(ComponentErrorBoundary, { componentName: Chip.displayName, children: /* @__PURE__ */ jsx(ChipComponent, { ...props }) });
Chip.displayName = "Chip";
export {
Chip,
ChipComponent
};
//# sourceMappingURL=Chip.js.map