@constructive-io/ui 0.1.0 → 0.2.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.
Files changed (59) hide show
  1. package/README.md +236 -0
  2. package/dist/components/alert-dialog.js.map +1 -1
  3. package/dist/components/autocomplete.js +11 -3
  4. package/dist/components/autocomplete.js.map +1 -1
  5. package/dist/components/avatar.js.map +1 -1
  6. package/dist/components/breadcrumb.js.map +1 -1
  7. package/dist/components/card.d.ts +1 -1
  8. package/dist/components/combobox.d.ts +1 -1
  9. package/dist/components/combobox.js +49 -13
  10. package/dist/components/combobox.js.map +1 -1
  11. package/dist/components/command.d.ts +16 -35
  12. package/dist/components/command.js +72 -508
  13. package/dist/components/command.js.map +1 -1
  14. package/dist/components/dialog.js.map +1 -1
  15. package/dist/components/drawer.js +1 -1
  16. package/dist/components/drawer.js.map +1 -1
  17. package/dist/components/dropdown-menu.js.map +1 -1
  18. package/dist/components/form-control.js.map +1 -1
  19. package/dist/components/form.js.map +1 -1
  20. package/dist/components/input-group.js +2 -2
  21. package/dist/components/input-group.js.map +1 -1
  22. package/dist/components/input.js +1 -1
  23. package/dist/components/input.js.map +1 -1
  24. package/dist/components/json-input.js.map +1 -1
  25. package/dist/components/multi-select.js.map +1 -1
  26. package/dist/components/pagination.js.map +1 -1
  27. package/dist/components/popover.js.map +1 -1
  28. package/dist/components/portal.js.map +1 -1
  29. package/dist/components/record-picker.js +1 -1
  30. package/dist/components/record-picker.js.map +1 -1
  31. package/dist/components/resizable.js.map +1 -1
  32. package/dist/components/responsive-diagram.js +6 -4
  33. package/dist/components/responsive-diagram.js.map +1 -1
  34. package/dist/components/select.d.ts +2 -2
  35. package/dist/components/select.js +3 -3
  36. package/dist/components/select.js.map +1 -1
  37. package/dist/components/sheet.js.map +1 -1
  38. package/dist/components/sidebar.js +1 -1
  39. package/dist/components/sidebar.js.map +1 -1
  40. package/dist/components/stack/index.d.ts +11 -0
  41. package/dist/components/stack/index.js +33 -6
  42. package/dist/components/stack/index.js.map +1 -1
  43. package/dist/components/stepper.js.map +1 -1
  44. package/dist/components/table.js.map +1 -1
  45. package/dist/components/tabs.js.map +1 -1
  46. package/dist/components/tags.d.ts +1 -3
  47. package/dist/components/tags.js +107 -388
  48. package/dist/components/tags.js.map +1 -1
  49. package/dist/components/textarea.js +1 -1
  50. package/dist/components/textarea.js.map +1 -1
  51. package/dist/components/tooltip.js.map +1 -1
  52. package/dist/index.cjs +348 -363
  53. package/dist/index.cjs.map +1 -1
  54. package/dist/index.d.cts +22 -24
  55. package/dist/index.d.ts +22 -24
  56. package/dist/index.js +235 -250
  57. package/dist/index.js.map +1 -1
  58. package/package.json +12 -15
  59. package/src/styles/globals.css +1 -1
@@ -30,6 +30,7 @@ type CardInjectedProps = {
30
30
  setTitle: (title?: string) => void;
31
31
  setDescription: (description?: string) => void;
32
32
  setWidth: (width?: string | number) => void;
33
+ setDismissable: (dismissable: boolean) => void;
33
34
  updateProps: <P>(patch: Partial<P> | ((prev: P) => P)) => void;
34
35
  };
35
36
  };
@@ -63,6 +64,9 @@ type CardSpec<P = unknown> = {
63
64
  * Pass an object to configure blur and styling.
64
65
  */
65
66
  backdrop?: boolean | BackdropConfig;
67
+ /** Whether user interactions (close button, Escape, backdrop click, gestures) can dismiss this card.
68
+ * Programmatic dismissal via card.close() / api.dismiss() always works. Default: true */
69
+ dismissable?: boolean;
66
70
  /**
67
71
  * Callback fired when this card is removed from the stack.
68
72
  * Fires regardless of how the card was closed (swipe, backdrop, escape, api.dismiss, etc.)
@@ -153,6 +157,8 @@ type CardStackApi = {
153
157
  setDescription: (id: CardId, description?: string) => void;
154
158
  /** Update the width for a specific card */
155
159
  setWidth: (id: CardId, width?: string | number) => void;
160
+ /** Update the dismissable state for a specific card */
161
+ setDismissable: (id: CardId, dismissable: boolean) => void;
156
162
  /**
157
163
  * Remove a card from the stack.
158
164
  * By default (cascade: true), also removes all cards above it.
@@ -277,6 +283,10 @@ type StackAction = {
277
283
  type: 'SET_WIDTH';
278
284
  id: CardId;
279
285
  width?: string | number;
286
+ } | {
287
+ type: 'SET_DISMISSABLE';
288
+ id: CardId;
289
+ dismissable: boolean;
280
290
  } | {
281
291
  type: 'DISMISS';
282
292
  id: CardId;
@@ -320,6 +330,7 @@ declare function useCardInjectedProps(id: CardId): {
320
330
  setTitle: (title?: string) => void;
321
331
  setDescription: (description?: string) => void;
322
332
  setWidth: (width?: string | number) => void;
333
+ setDismissable: (dismissable: boolean) => void;
323
334
  updateProps: <P>(patch: Partial<P> | ((prev: P) => P)) => void;
324
335
  };
325
336
  };
@@ -74,6 +74,13 @@ function stackReducer(state, action) {
74
74
  newCards[index] = { ...newCards[index], width: action.width };
75
75
  return { cards: newCards };
76
76
  }
77
+ case "SET_DISMISSABLE": {
78
+ const index = state.cards.findIndex((c) => c.id === action.id);
79
+ if (index === -1) return state;
80
+ const newCards = [...state.cards];
81
+ newCards[index] = { ...newCards[index], dismissable: action.dismissable };
82
+ return { cards: newCards };
83
+ }
77
84
  case "DISMISS": {
78
85
  const index = state.cards.findIndex((c) => c.id === action.id);
79
86
  if (index === -1) return state;
@@ -190,6 +197,9 @@ function CardStackProvider({
190
197
  const setWidth = (id, width) => {
191
198
  dispatch({ type: "SET_WIDTH", id, width });
192
199
  };
200
+ const setDismissable = (id, dismissable) => {
201
+ dispatch({ type: "SET_DISMISSABLE", id, dismissable });
202
+ };
193
203
  const dismiss = (id, options) => {
194
204
  const cascade = options?.cascade ?? true;
195
205
  dispatch({ type: "DISMISS", id, cascade });
@@ -217,6 +227,7 @@ function CardStackProvider({
217
227
  setTitle,
218
228
  setDescription,
219
229
  setWidth,
230
+ setDismissable,
220
231
  dismiss,
221
232
  insertAt
222
233
  };
@@ -226,7 +237,10 @@ function CardStackProvider({
226
237
  if (event.key === "Escape" && stateRef.current.cards.length > 0) {
227
238
  event.preventDefault();
228
239
  event.stopPropagation();
229
- api.pop();
240
+ const topCard = stateRef.current.cards[stateRef.current.cards.length - 1];
241
+ if (topCard.dismissable !== false) {
242
+ api.pop();
243
+ }
230
244
  }
231
245
  };
232
246
  document.addEventListener("keydown", handleEscape, true);
@@ -298,6 +312,7 @@ function useCardInjectedProps(id) {
298
312
  setTitle: (title) => api.setTitle(id, title),
299
313
  setDescription: (description) => api.setDescription(id, description),
300
314
  setWidth: (width) => api.setWidth(id, width),
315
+ setDismissable: (dismissable) => api.setDismissable(id, dismissable),
301
316
  updateProps: (patch) => api.updateProps(id, patch)
302
317
  }
303
318
  }),
@@ -460,16 +475,17 @@ var reducedMotionBackdropVariants = {
460
475
  exit: { opacity: 0, transition: { duration: 0 } }
461
476
  };
462
477
  function StackBackdrop({ className, onClick, config: backdropConfig }) {
463
- const { config } = useStackContext();
478
+ const { config, state } = useStackContext();
464
479
  const api = useCardStack();
465
480
  const prefersReducedMotion = useReducedMotion();
466
481
  const handleClick = React.useCallback(() => {
482
+ if (state.cards.some((c) => c.dismissable === false)) return;
467
483
  if (onClick) {
468
484
  onClick();
469
485
  } else {
470
486
  api.clear();
471
487
  }
472
- }, [onClick, api]);
488
+ }, [onClick, api, state.cards]);
473
489
  const variants = prefersReducedMotion ? reducedMotionBackdropVariants : backdropVariants;
474
490
  const useBlur = backdropConfig?.blur ?? false;
475
491
  return /* @__PURE__ */ jsx(
@@ -538,7 +554,7 @@ function StackHeader({ card, onClose, className, renderTitle }) {
538
554
  title && /* @__PURE__ */ jsx("h2", { className: cn("text-foreground truncate", styles.title), children: title }),
539
555
  card.description && /* @__PURE__ */ jsx("p", { className: cn("text-muted-foreground truncate", styles.description), children: card.description })
540
556
  ] }),
541
- /* @__PURE__ */ jsx(
557
+ card.dismissable !== false && /* @__PURE__ */ jsx(
542
558
  "button",
543
559
  {
544
560
  type: "button",
@@ -929,11 +945,15 @@ function StackCardInner({
929
945
  api.dismiss(card.id);
930
946
  }, [api, card.id]);
931
947
  const handlePeekClick = useCallback(() => {
948
+ const cardsAbove = state.cards.slice(index + 1);
949
+ if (cardsAbove.some((c) => c.dismissable === false)) return;
932
950
  api.popTo(card.id);
933
- }, [api, card.id]);
951
+ }, [api, card.id, state.cards, index]);
934
952
  const handlePeekDragDismiss = useCallback(() => {
953
+ const cardsAbove = state.cards.slice(index + 1);
954
+ if (cardsAbove.some((c) => c.dismissable === false)) return;
935
955
  onPeekDragEnd?.(index, true);
936
- }, [index, onPeekDragEnd]);
956
+ }, [index, onPeekDragEnd, state.cards]);
937
957
  const handlePeekDrag = useCallback(
938
958
  (offset) => {
939
959
  onPeekDrag?.(index, offset);
@@ -1226,6 +1246,8 @@ function CardStackViewport({
1226
1246
  }, [viewportWidth, cardWidths, cards.length, config.defaultPeekOffset, config.layoutMode]);
1227
1247
  const useFullScreen = isMobile || responsiveOffset.shouldCollapse;
1228
1248
  const handleDismiss = useCallback(() => {
1249
+ const topCard = api.top();
1250
+ if (topCard?.dismissable === false) return;
1229
1251
  api.pop();
1230
1252
  }, [api]);
1231
1253
  const swipeThreshold = mobile?.gestures?.swipeThreshold ?? Math.max(120, Math.round(viewportWidth * 0.35));
@@ -1259,6 +1281,11 @@ function CardStackViewport({
1259
1281
  const handlePeekDragEnd = useCallback(
1260
1282
  (cardIndex, shouldDismiss) => {
1261
1283
  if (shouldDismiss) {
1284
+ const cardsAbove = cards.slice(cardIndex + 1);
1285
+ if (cardsAbove.some((c) => c.dismissable === false)) {
1286
+ setPeekDrag({ sourceIndex: -1, offset: 0 });
1287
+ return;
1288
+ }
1262
1289
  const card = cards[cardIndex];
1263
1290
  if (card) {
1264
1291
  api.popTo(card.id);