@planetaexo/design-system 0.3.0 → 0.3.1

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.
package/dist/index.cjs CHANGED
@@ -1069,21 +1069,33 @@ function CountrySearchField({
1069
1069
  ] });
1070
1070
  }
1071
1071
  function AdventureCard({ adventure }) {
1072
- var _a, _b, _c;
1073
- const [checked, setChecked] = React18__namespace.useState(
1074
- new Set((_b = (_a = adventure.optionals) == null ? void 0 : _a.filter((o) => o.defaultChecked).map((o) => o.id)) != null ? _b : [])
1072
+ var _a, _b, _c, _d, _e;
1073
+ const isControlled = (_b = (_a = adventure.optionals) == null ? void 0 : _a.some((o) => o.onCheckedChange !== void 0)) != null ? _b : false;
1074
+ const [checkedInternal, setCheckedInternal] = React18__namespace.useState(
1075
+ new Set((_d = (_c = adventure.optionals) == null ? void 0 : _c.filter((o) => o.defaultChecked).map((o) => o.id)) != null ? _d : [])
1075
1076
  );
1076
- const toggleOptional = (id) => setChecked((prev) => {
1077
- const next = new Set(prev);
1078
- next.has(id) ? next.delete(id) : next.add(id);
1079
- return next;
1080
- });
1077
+ const isChecked = (opt) => {
1078
+ var _a2;
1079
+ return isControlled ? (_a2 = opt.checked) != null ? _a2 : false : checkedInternal.has(opt.id);
1080
+ };
1081
+ const toggleOptional = (opt) => {
1082
+ var _a2;
1083
+ if (isControlled) {
1084
+ (_a2 = opt.onCheckedChange) == null ? void 0 : _a2.call(opt, opt.id, !opt.checked);
1085
+ } else {
1086
+ setCheckedInternal((prev) => {
1087
+ const next = new Set(prev);
1088
+ next.has(opt.id) ? next.delete(opt.id) : next.add(opt.id);
1089
+ return next;
1090
+ });
1091
+ }
1092
+ };
1081
1093
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-2xl border border-border bg-card overflow-hidden", children: [
1082
1094
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aspect-[16/7] overflow-hidden bg-muted", children: /* @__PURE__ */ jsxRuntime.jsx(
1083
1095
  "img",
1084
1096
  {
1085
1097
  src: adventure.image,
1086
- alt: (_c = adventure.imageAlt) != null ? _c : adventure.title,
1098
+ alt: (_e = adventure.imageAlt) != null ? _e : adventure.title,
1087
1099
  className: "w-full h-full object-cover"
1088
1100
  }
1089
1101
  ) }),
@@ -1125,8 +1137,8 @@ function AdventureCard({ adventure }) {
1125
1137
  "input",
1126
1138
  {
1127
1139
  type: "checkbox",
1128
- checked: checked.has(opt.id),
1129
- onChange: () => toggleOptional(opt.id),
1140
+ checked: isChecked(opt),
1141
+ onChange: () => toggleOptional(opt),
1130
1142
  className: "h-4 w-4 shrink-0 rounded border-border accent-primary cursor-pointer"
1131
1143
  }
1132
1144
  ),