analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
310 lines (285 loc) • 11.7 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkHZE6VBF5js = require('./chunk-HZE6VBF5.js');
var _chunkBJMKBBN3js = require('./chunk-BJMKBBN3.js');
var _chunkMNU45FM3js = require('./chunk-MNU45FM3.js');
var _chunkTN3AYOMVjs = require('./chunk-TN3AYOMV.js');
// src/components/MultipleChoice/MultipleChoice.tsx
var _react = require('react');
// src/components/CheckBox/CheckboxList.tsx
var _zustand = require('zustand');
var _jsxruntime = require('react/jsx-runtime');
var createCheckboxListStore = (name, defaultValues, disabled, onValuesChange) => _zustand.create.call(void 0, (set, get) => ({
values: defaultValues,
setValues: (values) => {
if (!get().disabled) {
set({ values });
_optionalChain([get, 'call', _ => _(), 'access', _2 => _2.onValuesChange, 'optionalCall', _3 => _3(values)]);
}
},
toggleValue: (value) => {
if (!get().disabled) {
const currentValues = get().values;
const newValues = currentValues.includes(value) ? currentValues.filter((v) => v !== value) : [...currentValues, value];
set({ values: newValues });
_optionalChain([get, 'call', _4 => _4(), 'access', _5 => _5.onValuesChange, 'optionalCall', _6 => _6(newValues)]);
}
},
onValuesChange,
disabled,
name
}));
var useCheckboxListStore = (externalStore) => {
if (!externalStore) {
throw new Error("CheckboxListItem must be used within a CheckboxList");
}
return externalStore;
};
var injectStore = (children, store) => _react.Children.map(children, (child) => {
if (!_react.isValidElement.call(void 0, child)) return child;
const typedChild = child;
const shouldInject = typedChild.type === CheckboxListItem;
return _react.cloneElement.call(void 0, typedChild, {
...shouldInject ? { store } : {},
...typedChild.props.children ? { children: injectStore(typedChild.props.children, store) } : {}
});
});
var CheckboxList = _react.forwardRef.call(void 0,
({
values: propValues,
defaultValues = [],
onValuesChange,
name: propName,
disabled = false,
className = "",
children,
...props
}, ref) => {
const generatedId = _react.useId.call(void 0, );
const name = propName || `checkbox-list-${generatedId}`;
const storeRef = _react.useRef.call(void 0, null);
storeRef.current ??= createCheckboxListStore(
name,
defaultValues,
disabled,
onValuesChange
);
const store = storeRef.current;
const { setValues } = _zustand.useStore.call(void 0, store, (s) => s);
_react.useEffect.call(void 0, () => {
const currentValues = store.getState().values;
if (currentValues.length > 0 && onValuesChange) {
onValuesChange(currentValues);
}
}, []);
_react.useEffect.call(void 0, () => {
if (propValues !== void 0) {
setValues(propValues);
}
}, [propValues, setValues]);
_react.useEffect.call(void 0, () => {
store.setState({ disabled });
}, [disabled, store]);
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
"div",
{
ref,
className: _chunkTN3AYOMVjs.cn.call(void 0, "flex flex-col gap-2 w-full", className),
"aria-label": name,
...props,
children: injectStore(children, store)
}
);
}
);
CheckboxList.displayName = "CheckboxList";
var CheckboxListItem = _react.forwardRef.call(void 0,
({
value,
store: externalStore,
disabled: itemDisabled,
size = "medium",
state = "default",
className = "",
id,
...props
}, ref) => {
const store = useCheckboxListStore(externalStore);
const {
values: groupValues,
toggleValue,
disabled: groupDisabled,
name
} = _zustand.useStore.call(void 0, store);
const generatedId = _react.useId.call(void 0, );
const inputId = _nullishCoalesce(id, () => ( `checkbox-item-${generatedId}`));
const isChecked = groupValues.includes(value);
const isDisabled = groupDisabled || itemDisabled;
const currentState = isDisabled ? "disabled" : state;
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
_chunkMNU45FM3js.CheckBox_default,
{
ref,
id: inputId,
name,
value,
checked: isChecked,
disabled: isDisabled,
size,
state: currentState,
className,
onChange: () => {
if (!isDisabled) {
toggleValue(value);
}
},
...props
}
);
}
);
CheckboxListItem.displayName = "CheckboxListItem";
var CheckboxList_default = CheckboxList;
// src/components/MultipleChoice/MultipleChoice.tsx
var _CheckCircle = require('@phosphor-icons/react/dist/csr/CheckCircle');
var _XCircle = require('@phosphor-icons/react/dist/csr/XCircle');
var _Check = require('@phosphor-icons/react/dist/csr/Check');
var MultipleChoiceList = ({
disabled = false,
className = "",
choices,
name,
selectedValues,
onHandleSelectedValues,
mode = "interactive" /* INTERACTIVE */
}) => {
const [actualValue, setActualValue] = _react.useState.call(void 0, selectedValues);
_react.useEffect.call(void 0, () => {
setActualValue(
(prev) => JSON.stringify(prev) === JSON.stringify(selectedValues) ? prev : selectedValues
);
}, [selectedValues]);
const getStatusBadge = (status) => {
switch (status) {
case "correct" /* CORRECT */:
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
_chunkBJMKBBN3js.Badge_default,
{
variant: "solid",
action: "success",
iconLeft: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _CheckCircle.CheckCircleIcon, {}),
children: "Resposta correta"
}
);
case "incorrect" /* INCORRECT */:
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkBJMKBBN3js.Badge_default, { variant: "solid", action: "error", iconLeft: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _XCircle.XCircleIcon, {}), children: "Resposta incorreta" });
default:
return null;
}
};
const getStatusStyles = (status) => {
switch (status) {
case "correct" /* CORRECT */:
return "bg-success-background border-success-300";
case "incorrect" /* INCORRECT */:
return "bg-error-background border-error-300";
default:
return `bg-background border-border-100`;
}
};
const renderVisualCheckbox = (isSelected, isDisabled) => {
const checkboxClasses = _chunkTN3AYOMVjs.cn.call(void 0,
"w-5 h-5 rounded border-2 cursor-default transition-all duration-200 flex items-center justify-center",
isSelected ? "border-primary-950 bg-primary-950 text-text" : "border-border-400 bg-background",
isDisabled && "opacity-40 cursor-not-allowed"
);
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: checkboxClasses, children: isSelected && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Check.CheckIcon, { size: 16, weight: "bold" }) });
};
if (mode === "readonly") {
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: _chunkTN3AYOMVjs.cn.call(void 0, "flex flex-col gap-2", className), children: choices.map((choice, i) => {
const isSelected = _optionalChain([actualValue, 'optionalAccess', _7 => _7.includes, 'call', _8 => _8(choice.value)]) || false;
const statusStyles = getStatusStyles(choice.status);
const statusBadge = getStatusBadge(choice.status);
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
"div",
{
className: _chunkTN3AYOMVjs.cn.call(void 0,
"flex flex-row justify-between gap-2 items-start p-2 rounded-lg transition-all",
statusStyles,
choice.disabled ? "opacity-50 cursor-not-allowed" : ""
),
children: [
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2 flex-1", children: [
renderVisualCheckbox(isSelected, choice.disabled || disabled),
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
_chunkHZE6VBF5js.HtmlMathRenderer_default,
{
content: choice.label,
className: _chunkTN3AYOMVjs.cn.call(void 0,
"flex-1",
isSelected || choice.status && choice.status != "neutral" /* NEUTRAL */ ? "text-text-950" : "text-text-600",
choice.disabled || disabled ? "cursor-not-allowed" : "cursor-default"
)
}
)
] }),
statusBadge && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex-shrink-0", children: statusBadge })
]
},
`readonly-${choice.value}-${i}`
);
}) });
}
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
"div",
{
className: _chunkTN3AYOMVjs.cn.call(void 0,
"flex flex-row justify-between gap-2 items-start p-2 rounded-lg transition-all",
disabled ? "opacity-50 cursor-not-allowed" : "",
className
),
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
CheckboxList_default,
{
name,
values: actualValue,
onValuesChange: (v) => {
setActualValue(v);
_optionalChain([onHandleSelectedValues, 'optionalCall', _9 => _9(v)]);
},
disabled,
children: choices.map((choice, i) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
"div",
{
className: "flex flex-row gap-2 items-center",
children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
CheckboxListItem,
{
value: choice.value,
id: `interactive-${choice.value}-${i}`,
disabled: choice.disabled || disabled
}
),
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
"label",
{
htmlFor: `interactive-${choice.value}-${i}`,
className: _chunkTN3AYOMVjs.cn.call(void 0,
"flex-1",
_optionalChain([actualValue, 'optionalAccess', _10 => _10.includes, 'call', _11 => _11(choice.value)]) ? "text-text-950" : "text-text-600",
choice.disabled || disabled ? "cursor-not-allowed" : "cursor-pointer"
),
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkHZE6VBF5js.HtmlMathRenderer_default, { content: choice.label })
}
)
]
},
`interactive-${choice.value}-${i}`
))
}
)
}
);
};
exports.CheckboxListItem = CheckboxListItem; exports.CheckboxList_default = CheckboxList_default; exports.MultipleChoiceList = MultipleChoiceList;
//# sourceMappingURL=chunk-RPDDVEWK.js.map