fictoan-react 1.11.7 → 1.11.9-alpha.0

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.
@@ -4228,7 +4228,7 @@ var NotificationItem = /* @__PURE__ */ React.forwardRef(function(_ref, ref) {
4228
4228
  className: "sr-only"
4229
4229
  }, "Close notification")));
4230
4230
  });
4231
- var _excluded$g = ["children", "allowMultipleSelections", "showTickIcon", "onSelectionChange", "tickPosition"], _excluded2$2 = ["id", "children", "disabled"];
4231
+ var _excluded$g = ["children", "allowMultipleSelections", "showTickIcon", "onSelectionChange", "tickPosition", "selectionLimit"], _excluded2$2 = ["id", "children", "disabled"];
4232
4232
  function _extends$g() {
4233
4233
  return _extends$g = Object.assign ? Object.assign.bind() : function(n) {
4234
4234
  for (var e = 1; e < arguments.length; e++) {
@@ -4261,8 +4261,10 @@ function _iterableToArrayLimit$5(r, l) {
4261
4261
  if (null != t) {
4262
4262
  var e, n, i, u, a = [], f = true, o = false;
4263
4263
  try {
4264
- if (i = (t = t.call(r)).next, 0 === l) ;
4265
- else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
4264
+ if (i = (t = t.call(r)).next, 0 === l) {
4265
+ if (Object(t) !== t) return;
4266
+ f = false;
4267
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
4266
4268
  } catch (r2) {
4267
4269
  o = true, n = r2;
4268
4270
  } finally {
@@ -4303,12 +4305,27 @@ var OptionCardsContext = /* @__PURE__ */ createContext({
4303
4305
  toggleSelection: function toggleSelection() {
4304
4306
  },
4305
4307
  showTickIcon: false,
4306
- tickPosition: "top-right"
4308
+ tickPosition: "top-right",
4309
+ selectAllOptions: function selectAllOptions() {
4310
+ },
4311
+ clearAllOptions: function clearAllOptions() {
4312
+ },
4313
+ registerOption: function registerOption() {
4314
+ },
4315
+ unregisterOption: function unregisterOption() {
4316
+ }
4307
4317
  });
4308
- var OptionCardsGroup = function OptionCardsGroup2(_ref) {
4309
- var children = _ref.children, _ref$allowMultipleSel = _ref.allowMultipleSelections, allowMultipleSelections = _ref$allowMultipleSel === void 0 ? false : _ref$allowMultipleSel, showTickIcon = _ref.showTickIcon, onSelectionChange = _ref.onSelectionChange, _ref$tickPosition = _ref.tickPosition, tickPosition = _ref$tickPosition === void 0 ? "top-right" : _ref$tickPosition;
4318
+ var OptionCardsGroup = /* @__PURE__ */ React.forwardRef(function(_ref, ref) {
4319
+ var children = _ref.children, _ref$allowMultipleSel = _ref.allowMultipleSelections, allowMultipleSelections = _ref$allowMultipleSel === void 0 ? false : _ref$allowMultipleSel, showTickIcon = _ref.showTickIcon, onSelectionChange = _ref.onSelectionChange, _ref$tickPosition = _ref.tickPosition, tickPosition = _ref$tickPosition === void 0 ? "top-right" : _ref$tickPosition, selectionLimit = _ref.selectionLimit;
4310
4320
  _objectWithoutProperties$g(_ref, _excluded$g);
4311
4321
  var _useState = useState(/* @__PURE__ */ new Set()), _useState2 = _slicedToArray$5(_useState, 2), selectedIds = _useState2[0], setSelectedIds = _useState2[1];
4322
+ var availableOptionsRef = useRef(/* @__PURE__ */ new Map());
4323
+ var registerOption2 = useCallback(function(id, disabled) {
4324
+ availableOptionsRef.current.set(id, disabled);
4325
+ }, []);
4326
+ var unregisterOption2 = useCallback(function(id) {
4327
+ availableOptionsRef.current["delete"](id);
4328
+ }, []);
4312
4329
  var toggleSelection2 = useCallback(function(id) {
4313
4330
  setSelectedIds(function(prevSelectedIds) {
4314
4331
  var newSelectedIds = new Set(prevSelectedIds);
@@ -4316,6 +4333,9 @@ var OptionCardsGroup = function OptionCardsGroup2(_ref) {
4316
4333
  if (newSelectedIds.has(id)) {
4317
4334
  newSelectedIds["delete"](id);
4318
4335
  } else {
4336
+ if (selectionLimit && newSelectedIds.size >= selectionLimit) {
4337
+ return prevSelectedIds;
4338
+ }
4319
4339
  newSelectedIds.add(id);
4320
4340
  }
4321
4341
  } else {
@@ -4329,22 +4349,58 @@ var OptionCardsGroup = function OptionCardsGroup2(_ref) {
4329
4349
  onSelectionChange === null || onSelectionChange === void 0 || onSelectionChange(newSelectedIds);
4330
4350
  return newSelectedIds;
4331
4351
  });
4332
- }, [allowMultipleSelections, onSelectionChange]);
4352
+ }, [allowMultipleSelections, onSelectionChange, selectionLimit]);
4353
+ var selectAllOptions2 = useCallback(function() {
4354
+ if (!allowMultipleSelections) return;
4355
+ setSelectedIds(function(prevSelectedIds) {
4356
+ var newSelectedIds = new Set(prevSelectedIds);
4357
+ var enabledOptions = Array.from(availableOptionsRef.current.entries()).filter(function(_ref2) {
4358
+ var _ref3 = _slicedToArray$5(_ref2, 2);
4359
+ _ref3[0];
4360
+ var disabled = _ref3[1];
4361
+ return !disabled;
4362
+ }).map(function(_ref4) {
4363
+ var _ref5 = _slicedToArray$5(_ref4, 1), id = _ref5[0];
4364
+ return id;
4365
+ });
4366
+ var optionsToAdd = selectionLimit ? enabledOptions.slice(0, selectionLimit) : enabledOptions;
4367
+ optionsToAdd.forEach(function(id) {
4368
+ return newSelectedIds.add(id);
4369
+ });
4370
+ onSelectionChange === null || onSelectionChange === void 0 || onSelectionChange(newSelectedIds);
4371
+ return newSelectedIds;
4372
+ });
4373
+ }, [allowMultipleSelections, selectionLimit, onSelectionChange]);
4374
+ var clearAllOptions2 = useCallback(function() {
4375
+ setSelectedIds(/* @__PURE__ */ new Set());
4376
+ onSelectionChange === null || onSelectionChange === void 0 || onSelectionChange(/* @__PURE__ */ new Set());
4377
+ }, [onSelectionChange]);
4333
4378
  var isSelected2 = useCallback(function(id) {
4334
4379
  return selectedIds.has(id);
4335
4380
  }, [selectedIds]);
4381
+ React.useImperativeHandle(ref, function() {
4382
+ return {
4383
+ selectAllOptions: selectAllOptions2,
4384
+ clearAllOptions: clearAllOptions2
4385
+ };
4386
+ });
4387
+ var contextValue = {
4388
+ isSelected: isSelected2,
4389
+ toggleSelection: toggleSelection2,
4390
+ showTickIcon,
4391
+ tickPosition,
4392
+ selectAllOptions: selectAllOptions2,
4393
+ clearAllOptions: clearAllOptions2,
4394
+ registerOption: registerOption2,
4395
+ unregisterOption: unregisterOption2
4396
+ };
4336
4397
  return /* @__PURE__ */ React.createElement(OptionCardsContext.Provider, {
4337
- value: {
4338
- isSelected: isSelected2,
4339
- toggleSelection: toggleSelection2,
4340
- showTickIcon,
4341
- tickPosition
4342
- }
4398
+ value: contextValue
4343
4399
  }, /* @__PURE__ */ React.createElement(Div, {
4344
4400
  "data-option-cards-group": true,
4345
4401
  className: "tick-".concat(tickPosition)
4346
4402
  }, children));
4347
- };
4403
+ });
4348
4404
  var useOptionCard = function useOptionCard2(id) {
4349
4405
  var context = useContext(OptionCardsContext);
4350
4406
  return {
@@ -4355,13 +4411,19 @@ var useOptionCard = function useOptionCard2(id) {
4355
4411
  showTickIcon: context.showTickIcon
4356
4412
  };
4357
4413
  };
4358
- var OptionCard = function OptionCard2(_ref2) {
4359
- var id = _ref2.id, children = _ref2.children, _ref2$disabled = _ref2.disabled, disabled = _ref2$disabled === void 0 ? false : _ref2$disabled, props = _objectWithoutProperties$g(_ref2, _excluded2$2);
4360
- var _useOptionCard = useOptionCard(id), isSelected2 = _useOptionCard.isSelected, toggleSelection2 = _useOptionCard.toggleSelection, showTickIcon = _useOptionCard.showTickIcon;
4414
+ var OptionCard = function OptionCard2(_ref6) {
4415
+ var id = _ref6.id, children = _ref6.children, _ref6$disabled = _ref6.disabled, disabled = _ref6$disabled === void 0 ? false : _ref6$disabled, props = _objectWithoutProperties$g(_ref6, _excluded2$2);
4416
+ var _useContext2 = useContext(OptionCardsContext), isSelected2 = _useContext2.isSelected, toggleSelection2 = _useContext2.toggleSelection, showTickIcon = _useContext2.showTickIcon, registerOption2 = _useContext2.registerOption, unregisterOption2 = _useContext2.unregisterOption;
4361
4417
  var _useState3 = useState(false), _useState4 = _slicedToArray$5(_useState3, 2), showDeselect = _useState4[0], setShowDeselect = _useState4[1];
4362
4418
  var _useState5 = useState(true), _useState6 = _slicedToArray$5(_useState5, 2), isInitialHover = _useState6[0], setIsInitialHover = _useState6[1];
4419
+ React.useEffect(function() {
4420
+ registerOption2(id, disabled);
4421
+ return function() {
4422
+ return unregisterOption2(id);
4423
+ };
4424
+ }, [id, disabled, registerOption2, unregisterOption2]);
4363
4425
  var classNames = [];
4364
- if (isSelected2) {
4426
+ if (isSelected2(id)) {
4365
4427
  classNames.push("selected");
4366
4428
  }
4367
4429
  if (disabled) {
@@ -4371,7 +4433,7 @@ var OptionCard = function OptionCard2(_ref2) {
4371
4433
  classNames.push("show-deselect");
4372
4434
  }
4373
4435
  var handleMouseEnter = function handleMouseEnter2() {
4374
- if (isSelected2 && !isInitialHover) {
4436
+ if (isSelected2(id) && !isInitialHover) {
4375
4437
  setShowDeselect(true);
4376
4438
  }
4377
4439
  };
@@ -4384,7 +4446,7 @@ var OptionCard = function OptionCard2(_ref2) {
4384
4446
  var _props$onClick;
4385
4447
  setIsInitialHover(true);
4386
4448
  setShowDeselect(false);
4387
- toggleSelection2();
4449
+ toggleSelection2(id);
4388
4450
  (_props$onClick = props.onClick) === null || _props$onClick === void 0 || _props$onClick.call(props, e);
4389
4451
  }
4390
4452
  };
@@ -4393,7 +4455,7 @@ var OptionCard = function OptionCard2(_ref2) {
4393
4455
  e.preventDefault();
4394
4456
  setIsInitialHover(true);
4395
4457
  setShowDeselect(false);
4396
- toggleSelection2();
4458
+ toggleSelection2(id);
4397
4459
  }
4398
4460
  };
4399
4461
  return /* @__PURE__ */ React.createElement(Element, _extends$g({
@@ -4402,7 +4464,7 @@ var OptionCard = function OptionCard2(_ref2) {
4402
4464
  role: "button",
4403
4465
  tabIndex: disabled ? -1 : 0,
4404
4466
  "aria-disabled": disabled ? "true" : "false",
4405
- "aria-selected": isSelected2 ? "true" : "false",
4467
+ "aria-selected": isSelected2(id) ? "true" : "false",
4406
4468
  classNames,
4407
4469
  onClick: handleClick,
4408
4470
  onKeyDown: handleKeyDown,
@@ -8,17 +8,26 @@ export interface OptionCardsProviderProps {
8
8
  showTickIcon?: boolean;
9
9
  tickPosition?: TickPosition;
10
10
  onSelectionChange?: (selectedIds: Set<string>) => void;
11
+ selectionLimit?: number;
11
12
  }
12
13
  export interface OptionCardProps extends CardProps {
13
14
  id: string;
14
15
  children: ReactNode;
15
16
  disabled?: boolean;
16
17
  }
17
- export declare const OptionCardsGroup: React.FC<OptionCardsProviderProps>;
18
+ export interface OptionCardsGroupRef {
19
+ selectAllOptions: () => void;
20
+ clearAllOptions: () => void;
21
+ }
22
+ export declare const OptionCardsGroup: React.ForwardRefExoticComponent<OptionCardsProviderProps & React.RefAttributes<OptionCardsGroupRef>>;
18
23
  export declare const useOptionCard: (id: string) => {
19
24
  isSelected: boolean;
20
25
  toggleSelection: () => void;
21
26
  showTickIcon: boolean | undefined;
22
27
  };
28
+ export declare const useOptionCards: () => {
29
+ selectAllOptions: (() => void) | undefined;
30
+ clearAllOptions: (() => void) | undefined;
31
+ };
23
32
  export declare const OptionCard: React.FC<OptionCardProps>;
24
33
  //# sourceMappingURL=OptionCard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"OptionCard.d.ts","sourceRoot":"","sources":["../../../src/components/OptionCard/OptionCard.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAuC,SAAS,EAAe,MAAM,OAAO,CAAC;AAK3F,OAAO,EAAyB,SAAS,EAAE,MAAM,cAAc,CAAC;AAGhE,OAAO,mBAAmB,CAAC;AAG3B,MAAM,MAAM,YAAY,GAClB,UAAU,GACV,WAAW,GACX,aAAa,GACb,cAAc,GACd,aAAa,GACb,aAAa,GACb,cAAc,GACd,cAAc,GACd,YAAY,GACZ,YAAY,GACZ,eAAe,GACf,eAAe,GACf,QAAQ,GACR,QAAQ,CAAA;AAEd,MAAM,WAAW,wBAAwB;IACrC,QAAQ,EAAoB,SAAS,CAAC;IACtC,uBAAwB,CAAC,EAAG,OAAO,CAAC;IACpC,YAAwB,CAAC,EAAG,OAAO,CAAC;IACpC,YAAwB,CAAC,EAAG,YAAY,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,CAAC;IACpB,QAAQ,EAAK,SAAS,CAAC;IACvB,QAAS,CAAC,EAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAChC,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,eAAe,EAAE,MAAM,IAAI,CAAC;CAC/B;AAyBD,eAAO,MAAM,gBAAgB,sGAwG5B,CAAC;AAEF,eAAO,MAAM,aAAa,OAAQ,MAAM;;;;CAOvC,CAAC;AAEF,eAAO,MAAM,cAAc;6BArII,IAAI;4BACJ,IAAI;CAuIlC,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAqFhD,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  "use client;";
3
- import { A, g, h, B, i, b, a, C, c, s, t, d, _, f, e, D, E, q, F, l, m, n, H, ac, ad, ae, af, ag, ah, k, I, o, L, y, M, z, G, N, K, J, W, X, O, P, Q, U, r, R, x, w, V, S, p, a1, $, a0, Z, a2, a3, j, a4, u, v, a5, a6, ai, T, a7, aa, a9, ab, Y, a8 } from "../Heading-QR9QSn83.js";
3
+ import { A, g, h, B, i, b, a, C, c, s, t, d, _, f, e, D, E, q, F, l, m, n, H, ac, ad, ae, af, ag, ah, k, I, o, L, y, M, z, G, N, K, J, W, X, O, P, Q, U, r, R, x, w, V, S, p, a1, $, a0, Z, a2, a3, j, a4, u, v, a5, a6, ai, T, a7, aa, a9, ab, Y, a8 } from "../Heading-BSjpDrZx.js";
4
4
  export {
5
5
  A as Accordion,
6
6
  g as Article,