analytica-frontend-lib 1.2.28 → 1.2.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -517,7 +517,10 @@ import { useEffect, useMemo, useRef, useState as useState2 } from "react";
517
517
  import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
518
518
  var CheckboxGroup = ({
519
519
  categories,
520
- onCategoriesChange
520
+ onCategoriesChange,
521
+ compactSingleItem = true,
522
+ showDivider = true,
523
+ showSingleItem = false
521
524
  }) => {
522
525
  const [openAccordion, setOpenAccordion] = useState2("");
523
526
  const autoSelectionAppliedRef = useRef(false);
@@ -876,16 +879,43 @@ var CheckboxGroup = ({
876
879
  return `${selectedVisibleCount} de ${totalVisible} ${selectedVisibleCount === 1 ? "selecionado" : "selecionados"}`;
877
880
  })() })
878
881
  ] });
882
+ const renderCompactSingleItem = (category) => {
883
+ const formattedItems = getFormattedItems(category.key);
884
+ const allItems = formattedItems.flatMap((group) => group.itens || []);
885
+ if (allItems.length !== 1) {
886
+ return null;
887
+ }
888
+ const singleItem = allItems[0];
889
+ return /* @__PURE__ */ jsxs5(
890
+ "div",
891
+ {
892
+ className: "flex items-center justify-between w-full px-3 py-2",
893
+ children: [
894
+ /* @__PURE__ */ jsx6(Text_default, { size: "sm", weight: "bold", className: "text-text-800", children: category.label }),
895
+ /* @__PURE__ */ jsx6(Text_default, { size: "sm", className: "text-text-950", children: singleItem.name })
896
+ ]
897
+ },
898
+ category.key
899
+ );
900
+ };
879
901
  const renderCategoryAccordion = (category) => {
880
902
  const isEnabled = !category.dependsOn || category.dependsOn.every((depKey) => {
881
903
  const depCat = categories.find((c) => c.key === depKey);
882
904
  return depCat?.selectedIds && depCat.selectedIds.length > 0;
883
905
  });
884
906
  const hasOnlyOneItem = category.itens?.length === 1;
885
- if (hasOnlyOneItem) {
907
+ if (hasOnlyOneItem && !compactSingleItem && !showSingleItem) {
886
908
  return null;
887
909
  }
888
910
  const formattedItems = getFormattedItems(category.key);
911
+ const allItems = formattedItems.flatMap((group) => group.itens || []);
912
+ const hasOnlyOneAvailableItem = allItems.length === 1;
913
+ if (compactSingleItem && hasOnlyOneAvailableItem && isEnabled) {
914
+ return /* @__PURE__ */ jsxs5("div", { children: [
915
+ renderCompactSingleItem(category),
916
+ showDivider && /* @__PURE__ */ jsx6(Divider_default, {})
917
+ ] }, category.key);
918
+ }
889
919
  const hasNoItems = formattedItems.every(
890
920
  (group) => !group.itens || group.itens.length === 0
891
921
  );
@@ -905,7 +935,7 @@ var CheckboxGroup = ({
905
935
  ) })
906
936
  }
907
937
  ),
908
- openAccordion !== category.key && /* @__PURE__ */ jsx6(Divider_default, {})
938
+ openAccordion !== category.key && showDivider && /* @__PURE__ */ jsx6(Divider_default, {})
909
939
  ] }, category.key);
910
940
  };
911
941
  useEffect(() => {