lecom-ui 5.4.2 → 5.4.4

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.
@@ -56,7 +56,8 @@ const MultiSelect = React.forwardRef(
56
56
  allowTypoDistance = 0,
57
57
  groupedOptions,
58
58
  classNameContent,
59
- size = "medium"
59
+ size = "medium",
60
+ disabled = false
60
61
  }, ref) => {
61
62
  const { t } = useTranslation();
62
63
  const [selectedValues, setSelectedValues] = React.useState(value);
@@ -331,33 +332,63 @@ const MultiSelect = React.forwardRef(
331
332
  [treeOptions]
332
333
  );
333
334
  const collectAllValues = (node) => {
334
- const self = treeSelectionStrategy === "all" ? [node.value] : [];
335
- if (!node.children || node.children.length === 0) {
336
- return treeSelectionStrategy === "all" ? [node.value] : [node.value];
335
+ if (treeSelectionStrategy === "leaf") {
336
+ if (!node.children || node.children.length === 0) {
337
+ return [node.value];
338
+ }
339
+ return node.children.flatMap((c) => collectAllValues(c));
340
+ } else {
341
+ if (!node.children || node.children.length === 0) {
342
+ return [node.value];
343
+ }
344
+ return [node.value, ...node.children.flatMap((c) => collectAllValues(c))];
337
345
  }
338
- return [...self, ...node.children.flatMap((c) => collectAllValues(c))];
339
346
  };
340
347
  const isNodeFullySelected = (node) => {
341
- const values = collectAllValues(node);
342
- return values.every((v) => selectedValues.includes(v));
348
+ if (treeSelectionStrategy === "all") {
349
+ return selectedValues.includes(node.value);
350
+ } else {
351
+ const values = collectAllValues(node);
352
+ return values.every((v) => selectedValues.includes(v));
353
+ }
343
354
  };
344
355
  const isNodePartiallySelected = (node) => {
345
- const values = collectAllValues(node);
346
- const some = values.some((v) => selectedValues.includes(v));
347
- const all = values.every((v) => selectedValues.includes(v));
348
- return some && !all;
356
+ if (treeSelectionStrategy === "all") {
357
+ if (selectedValues.includes(node.value)) return false;
358
+ if (!node.children || node.children.length === 0) return false;
359
+ const hasSelectedDescendant = (n) => {
360
+ if (selectedValues.includes(n.value)) return true;
361
+ if (n.children) {
362
+ return n.children.some(hasSelectedDescendant);
363
+ }
364
+ return false;
365
+ };
366
+ return node.children.some(hasSelectedDescendant);
367
+ } else {
368
+ const values = collectAllValues(node);
369
+ const some = values.some((v) => selectedValues.includes(v));
370
+ const all = values.every((v) => selectedValues.includes(v));
371
+ return some && !all;
372
+ }
349
373
  };
350
374
  const toggleTreeNode = (node) => {
351
- const nodeValues = collectAllValues(node);
352
- const allSelected = nodeValues.every((v) => selectedValues.includes(v));
353
- let next;
354
- if (allSelected) {
355
- next = selectedValues.filter((v) => !nodeValues.includes(v));
375
+ if (treeSelectionStrategy === "all") {
376
+ const isSelected = selectedValues.includes(node.value);
377
+ const next = isSelected ? selectedValues.filter((v) => v !== node.value) : [...selectedValues, node.value];
378
+ setSelectedValues(next);
379
+ onValueChange(next);
356
380
  } else {
357
- next = Array.from(/* @__PURE__ */ new Set([...selectedValues, ...nodeValues]));
381
+ const nodeValues = collectAllValues(node);
382
+ const allSelected = nodeValues.every((v) => selectedValues.includes(v));
383
+ let next;
384
+ if (allSelected) {
385
+ next = selectedValues.filter((v) => !nodeValues.includes(v));
386
+ } else {
387
+ next = Array.from(/* @__PURE__ */ new Set([...selectedValues, ...nodeValues]));
388
+ }
389
+ setSelectedValues(next);
390
+ onValueChange(next);
358
391
  }
359
- setSelectedValues(next);
360
- onValueChange(next);
361
392
  };
362
393
  const highlight = React.useCallback(
363
394
  (label, q) => {
@@ -424,7 +455,6 @@ const MultiSelect = React.forwardRef(
424
455
  {
425
456
  className: cn(
426
457
  "flex items-center gap-2 px-2 py-1 cursor-pointer rounded-sm text-grey-800 hover:bg-grey-100",
427
- getFontVariant(size),
428
458
  (fully || isSelectedLeaf) && "bg-blue-50"
429
459
  ),
430
460
  style: { paddingLeft: depth * 14 + 8 }
@@ -447,6 +477,7 @@ const MultiSelect = React.forwardRef(
447
477
  /* @__PURE__ */ React.createElement(
448
478
  Typography,
449
479
  {
480
+ variant: getFontVariant(size),
450
481
  className: "flex-1 truncate cursor-pointer overflow-hidden",
451
482
  onClick: (e) => {
452
483
  e.stopPropagation();
@@ -484,9 +515,11 @@ const MultiSelect = React.forwardRef(
484
515
  transition-all duration-300 outline-none
485
516
  [&_svg]:pointer-events-auto`,
486
517
  maxCount === void 0 && TRIGGER_HEIGHT_CLASSES[size],
518
+ disabled && "opacity-50 cursor-not-allowed pointer-events-none",
487
519
  className
488
520
  ),
489
- "aria-expanded": isPopoverOpen
521
+ "aria-expanded": isPopoverOpen,
522
+ disabled
490
523
  },
491
524
  selectedValues.length > 0 ? /* @__PURE__ */ React.createElement("div", { className: "flex justify-between items-center w-full" }, /* @__PURE__ */ React.createElement("div", { className: "flex flex-wrap items-center gap-1" }, selectedValues.slice(0, dynamicMaxCount).map((value2) => {
492
525
  const selectedOption = options.find((option) => option.value === value2);
@@ -507,7 +540,7 @@ const MultiSelect = React.forwardRef(
507
540
  className: "truncate"
508
541
  },
509
542
  label
510
- )), /* @__PURE__ */ React.createElement(
543
+ )), !disabled && /* @__PURE__ */ React.createElement(
511
544
  X,
512
545
  {
513
546
  className: "h-4 w-4 cursor-pointer flex-shrink-0",
@@ -517,7 +550,7 @@ const MultiSelect = React.forwardRef(
517
550
  }
518
551
  }
519
552
  ));
520
- }), selectedValues.length > dynamicMaxCount && /* @__PURE__ */ React.createElement(Tag, { color: "blue", className: "focus:ring-0" }, /* @__PURE__ */ React.createElement(Typography, { variant: getFontVariant(size), className: "text-blue-600" }, `+ ${selectedValues.length - dynamicMaxCount}`))), /* @__PURE__ */ React.createElement("div", { className: "flex items-center justify-between" }, /* @__PURE__ */ React.createElement(
553
+ }), selectedValues.length > dynamicMaxCount && /* @__PURE__ */ React.createElement(Tag, { color: "blue", className: "focus:ring-0" }, /* @__PURE__ */ React.createElement(Typography, { variant: getFontVariant(size), className: "text-blue-600" }, `+ ${selectedValues.length - dynamicMaxCount}`))), /* @__PURE__ */ React.createElement("div", { className: "flex items-center justify-between" }, !disabled && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
521
554
  X,
522
555
  {
523
556
  className: "h-4 w-4 cursor-pointer text-grey-800",
@@ -532,7 +565,7 @@ const MultiSelect = React.forwardRef(
532
565
  orientation: "vertical",
533
566
  className: "flex min-h-4 mx-1 h-full"
534
567
  }
535
- ), isPopoverOpen ? /* @__PURE__ */ React.createElement(ChevronUp, { className: "h-4 w-4 cursor-pointer text-grey-800" }) : /* @__PURE__ */ React.createElement(ChevronDown, { className: "h-4 w-4 cursor-pointer text-grey-800" }))) : /* @__PURE__ */ React.createElement("div", { className: "flex items-center justify-between w-full mx-auto" }, /* @__PURE__ */ React.createElement(
568
+ )), isPopoverOpen ? /* @__PURE__ */ React.createElement(ChevronUp, { className: "h-4 w-4 cursor-pointer text-grey-800" }) : /* @__PURE__ */ React.createElement(ChevronDown, { className: "h-4 w-4 cursor-pointer text-grey-800" }))) : /* @__PURE__ */ React.createElement("div", { className: "flex items-center justify-between w-full mx-auto" }, /* @__PURE__ */ React.createElement(
536
569
  Typography,
537
570
  {
538
571
  variant: getFontVariant(size),
@@ -45,7 +45,7 @@ const Typography = ({
45
45
  return /* @__PURE__ */ React.createElement(
46
46
  Comp,
47
47
  {
48
- className: cn(typographyVariants({ variant, className }), textColor, ""),
48
+ className: cn(typographyVariants({ variant }), className, textColor),
49
49
  ...props
50
50
  },
51
51
  children
package/dist/index.d.ts CHANGED
@@ -990,7 +990,7 @@ declare const RadioGroup: React$1.ForwardRefExoticComponent<Omit<RadioGroupPrimi
990
990
  declare const RadioGroupItem: React$1.ForwardRefExoticComponent<Omit<RadioGroupPrimitive.RadioGroupItemProps & React$1.RefAttributes<HTMLButtonElement>, "ref"> & React$1.RefAttributes<HTMLButtonElement>>;
991
991
 
992
992
  declare const ResizablePanelGroup: ({ className, ...props }: React$1.ComponentProps<typeof ResizablePrimitive.PanelGroup>) => React$1.JSX.Element;
993
- declare const ResizablePanel: React$1.ForwardRefExoticComponent<Omit<React$1.HTMLAttributes<HTMLDivElement | HTMLElement | HTMLButtonElement | HTMLOListElement | HTMLLIElement | HTMLAnchorElement | HTMLSpanElement | HTMLHeadingElement | HTMLParagraphElement | HTMLInputElement | HTMLLabelElement | HTMLObjectElement | HTMLAreaElement | HTMLAudioElement | HTMLBaseElement | HTMLQuoteElement | HTMLBodyElement | HTMLBRElement | HTMLCanvasElement | HTMLTableCaptionElement | HTMLTableColElement | HTMLDataElement | HTMLDataListElement | HTMLModElement | HTMLDetailsElement | HTMLDialogElement | HTMLDListElement | HTMLEmbedElement | HTMLFieldSetElement | HTMLFormElement | HTMLHeadElement | HTMLHRElement | HTMLHtmlElement | HTMLIFrameElement | HTMLImageElement | HTMLLegendElement | HTMLLinkElement | HTMLMapElement | HTMLMenuElement | HTMLMetaElement | HTMLMeterElement | HTMLOptGroupElement | HTMLOptionElement | HTMLOutputElement | HTMLPictureElement | HTMLPreElement | HTMLProgressElement | HTMLScriptElement | HTMLSelectElement | HTMLSlotElement | HTMLSourceElement | HTMLStyleElement | HTMLTableElement | HTMLTableSectionElement | HTMLTableCellElement | HTMLTemplateElement | HTMLTextAreaElement | HTMLTimeElement | HTMLTitleElement | HTMLTableRowElement | HTMLTrackElement | HTMLUListElement | HTMLVideoElement>, "id" | "onResize"> & {
993
+ declare const ResizablePanel: React$1.ForwardRefExoticComponent<Omit<React$1.HTMLAttributes<HTMLDivElement | HTMLElement | HTMLButtonElement | HTMLOListElement | HTMLLIElement | HTMLAnchorElement | HTMLSpanElement | HTMLHeadingElement | HTMLParagraphElement | HTMLInputElement | HTMLLabelElement | HTMLUListElement | HTMLObjectElement | HTMLAreaElement | HTMLAudioElement | HTMLBaseElement | HTMLQuoteElement | HTMLBodyElement | HTMLBRElement | HTMLCanvasElement | HTMLTableCaptionElement | HTMLTableColElement | HTMLDataElement | HTMLDataListElement | HTMLModElement | HTMLDetailsElement | HTMLDialogElement | HTMLDListElement | HTMLEmbedElement | HTMLFieldSetElement | HTMLFormElement | HTMLHeadElement | HTMLHRElement | HTMLHtmlElement | HTMLIFrameElement | HTMLImageElement | HTMLLegendElement | HTMLLinkElement | HTMLMapElement | HTMLMenuElement | HTMLMetaElement | HTMLMeterElement | HTMLOptGroupElement | HTMLOptionElement | HTMLOutputElement | HTMLPictureElement | HTMLPreElement | HTMLProgressElement | HTMLScriptElement | HTMLSelectElement | HTMLSlotElement | HTMLSourceElement | HTMLStyleElement | HTMLTableElement | HTMLTableSectionElement | HTMLTableCellElement | HTMLTemplateElement | HTMLTextAreaElement | HTMLTimeElement | HTMLTitleElement | HTMLTableRowElement | HTMLTrackElement | HTMLVideoElement>, "id" | "onResize"> & {
994
994
  className?: string;
995
995
  collapsedSize?: number | undefined;
996
996
  collapsible?: boolean | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lecom-ui",
3
- "version": "5.4.02",
3
+ "version": "5.4.04",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",