UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

285 lines (281 loc) 8.59 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/components/CheckBox/CheckBox.tsx var CheckBox_exports = {}; __export(CheckBox_exports, { default: () => CheckBox_default }); module.exports = __toCommonJS(CheckBox_exports); var import_react = require("react"); // src/utils/utils.ts var import_clsx = require("clsx"); var import_tailwind_merge = require("tailwind-merge"); function cn(...inputs) { return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs)); } // src/components/Text/Text.tsx var import_jsx_runtime = require("react/jsx-runtime"); var Text = ({ children, size = "md", weight = "normal", color = "text-text-950", as, className = "", ...props }) => { let sizeClasses = ""; let weightClasses = ""; const sizeClassMap = { "2xs": "text-2xs", xs: "text-xs", sm: "text-sm", md: "text-md", lg: "text-lg", xl: "text-xl", "2xl": "text-2xl", "3xl": "text-3xl", "4xl": "text-4xl", "5xl": "text-5xl", "6xl": "text-6xl" }; sizeClasses = sizeClassMap[size] ?? sizeClassMap.md; const weightClassMap = { hairline: "font-hairline", light: "font-light", normal: "font-normal", medium: "font-medium", semibold: "font-semibold", bold: "font-bold", extrabold: "font-extrabold", black: "font-black" }; weightClasses = weightClassMap[weight] ?? weightClassMap.normal; const baseClasses = "font-primary"; const Component = as ?? "p"; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( Component, { className: cn(baseClasses, sizeClasses, weightClasses, color, className), ...props, children } ); }; var Text_default = Text; // src/components/CheckBox/CheckBox.tsx var import_phosphor_react = require("phosphor-react"); var import_jsx_runtime2 = require("react/jsx-runtime"); var SIZE_CLASSES = { small: { checkbox: "w-4 h-4", // 16px x 16px textSize: "sm", spacing: "gap-1.5", // 6px borderWidth: "border-2", iconSize: 14, // pixels for Phosphor icons labelHeight: "h-[21px]" }, medium: { checkbox: "w-5 h-5", // 20px x 20px textSize: "md", spacing: "gap-2", // 8px borderWidth: "border-2", iconSize: 16, // pixels for Phosphor icons labelHeight: "h-6" }, large: { checkbox: "w-6 h-6", // 24px x 24px textSize: "lg", spacing: "gap-2", // 8px borderWidth: "border-[3px]", // 3px border iconSize: 20, // pixels for Phosphor icons labelHeight: "h-[27px]" } }; var BASE_CHECKBOX_CLASSES = "rounded border cursor-pointer transition-all duration-200 flex items-center justify-center focus:outline-none"; var STATE_CLASSES = { default: { unchecked: "border-border-400 bg-background hover:border-border-500", checked: "border-primary-950 bg-primary-950 text-text hover:border-primary-800 hover:bg-primary-800" }, hovered: { unchecked: "border-border-500 bg-background", checked: "border-primary-800 bg-primary-800 text-text" }, focused: { unchecked: "border-indicator-info bg-background ring-2 ring-indicator-info/20", checked: "border-indicator-info bg-primary-950 text-text ring-2 ring-indicator-info/20" }, invalid: { unchecked: "border-error-700 bg-background hover:border-error-600", checked: "border-error-700 bg-primary-950 text-text" }, disabled: { unchecked: "border-border-400 bg-background cursor-not-allowed opacity-40", checked: "border-primary-600 bg-primary-600 text-text cursor-not-allowed opacity-40" } }; var CheckBox = (0, import_react.forwardRef)( ({ label, size = "medium", state = "default", indeterminate = false, errorMessage, helperText, className = "", labelClassName = "", checked: checkedProp, disabled, id, onChange, ...props }, ref) => { const generatedId = (0, import_react.useId)(); const inputId = id ?? `checkbox-${generatedId}`; const [internalChecked, setInternalChecked] = (0, import_react.useState)(false); const isControlled = checkedProp !== void 0; const checked = isControlled ? checkedProp : internalChecked; const handleChange = (event) => { if (!isControlled) { setInternalChecked(event.target.checked); } onChange?.(event); }; const currentState = disabled ? "disabled" : state; const sizeClasses = SIZE_CLASSES[size]; const checkVariant = checked || indeterminate ? "checked" : "unchecked"; const stylingClasses = STATE_CLASSES[currentState][checkVariant]; const borderWidthClass = state === "focused" || state === "hovered" && size === "large" ? "border-[3px]" : sizeClasses.borderWidth; const checkboxClasses = cn( BASE_CHECKBOX_CLASSES, sizeClasses.checkbox, borderWidthClass, stylingClasses, className ); const renderIcon = () => { if (indeterminate) { return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( import_phosphor_react.Minus, { size: sizeClasses.iconSize, weight: "bold", color: "currentColor" } ); } if (checked) { return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( import_phosphor_react.Check, { size: sizeClasses.iconSize, weight: "bold", color: "currentColor" } ); } return null; }; return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-col", children: [ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)( "div", { className: cn( "flex flex-row items-center", sizeClasses.spacing, disabled ? "opacity-40" : "" ), children: [ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "input", { ref, type: "checkbox", id: inputId, checked, disabled, onChange: handleChange, className: "sr-only", ...props } ), /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: inputId, className: checkboxClasses, children: renderIcon() }), label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "div", { className: cn( "flex flex-row items-center", sizeClasses.labelHeight ), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( Text_default, { as: "label", htmlFor: inputId, size: sizeClasses.textSize, weight: "normal", className: cn( "cursor-pointer select-none leading-[150%] flex items-center font-roboto", labelClassName ), children: label } ) } ) ] } ), errorMessage && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( Text_default, { size: "sm", weight: "normal", className: "mt-1.5", color: "text-error-600", children: errorMessage } ), helperText && !errorMessage && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( Text_default, { size: "sm", weight: "normal", className: "mt-1.5", color: "text-text-500", children: helperText } ) ] }); } ); CheckBox.displayName = "CheckBox"; var CheckBox_default = CheckBox; //# sourceMappingURL=index.js.map