@seed-design/react-drawer 1.0.1 → 1.0.3

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.
@@ -72,6 +72,21 @@ const WINDOW_TOP_OFFSET = 26;
72
72
  const DRAG_CLASS = "seed-dragging";
73
73
 
74
74
  const cache = new WeakMap();
75
+ // HTML input types that do not cause the software keyboard to appear.
76
+ const nonTextInputTypes = new Set([
77
+ "checkbox",
78
+ "radio",
79
+ "range",
80
+ "color",
81
+ "file",
82
+ "image",
83
+ "button",
84
+ "submit",
85
+ "reset"
86
+ ]);
87
+ function isInput(target) {
88
+ return target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
89
+ }
75
90
  function set(el, styles, ignoreCache = false) {
76
91
  if (!el || !(el instanceof HTMLElement)) return;
77
92
  let originalStyles = {};
@@ -246,255 +261,10 @@ let previousBodyPosition = null;
246
261
  };
247
262
  }
248
263
 
249
- // This code comes from https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/overlays/src/usePreventScroll.ts
250
- const KEYBOARD_BUFFER = 24;
251
- const useIsomorphicLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
252
- function chain(...callbacks) {
253
- return (...args)=>{
254
- for (let callback of callbacks){
255
- if (typeof callback === "function") {
256
- callback(...args);
257
- }
258
- }
259
- };
260
- }
261
- // @ts-ignore
262
- const visualViewport = typeof document !== "undefined" && window.visualViewport;
263
- function isScrollable(node) {
264
- let style = window.getComputedStyle(node);
265
- return /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
266
- }
267
- function getScrollParent(node) {
268
- if (isScrollable(node)) {
269
- node = node.parentElement;
270
- }
271
- while(node && !isScrollable(node)){
272
- node = node.parentElement;
273
- }
274
- return node || document.scrollingElement || document.documentElement;
275
- }
276
- // HTML input types that do not cause the software keyboard to appear.
277
- const nonTextInputTypes = new Set([
278
- "checkbox",
279
- "radio",
280
- "range",
281
- "color",
282
- "file",
283
- "image",
284
- "button",
285
- "submit",
286
- "reset"
287
- ]);
288
- // The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
289
- let preventScrollCount = 0;
290
- let restore;
291
- /**
292
- * Prevents scrolling on the document body on mount, and
293
- * restores it on unmount. Also ensures that content does not
294
- * shift due to the scrollbars disappearing.
295
- */ function usePreventScroll(options = {}) {
296
- let { isDisabled } = options;
297
- useIsomorphicLayoutEffect(()=>{
298
- if (isDisabled) {
299
- return;
300
- }
301
- preventScrollCount++;
302
- if (preventScrollCount === 1) {
303
- if (isIOS()) {
304
- restore = preventScrollMobileSafari();
305
- }
306
- }
307
- return ()=>{
308
- preventScrollCount--;
309
- if (preventScrollCount === 0) {
310
- restore?.();
311
- }
312
- };
313
- }, [
314
- isDisabled
315
- ]);
316
- }
317
- // Mobile Safari is a whole different beast. Even with overflow: hidden,
318
- // it still scrolls the page in many situations:
319
- //
320
- // 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
321
- // 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
322
- // it, so it becomes scrollable.
323
- // 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
324
- // This may cause even fixed position elements to scroll off the screen.
325
- // 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
326
- // scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
327
- //
328
- // In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
329
- //
330
- // 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
331
- // on the window.
332
- // 2. Prevent default on `touchmove` events inside a scrollable element when the scroll position is at the
333
- // top or bottom. This avoids the whole page scrolling instead, but does prevent overscrolling.
334
- // 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
335
- // 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top
336
- // of the page, which prevents it from scrolling the page. After the input is focused, scroll the element
337
- // into view ourselves, without scrolling the whole page.
338
- // 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the
339
- // same visually, but makes the actual scroll position always zero. This is required to make all of the
340
- // above work or Safari will still try to scroll the page when focusing an input.
341
- // 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting
342
- // to navigate to an input with the next/previous buttons that's outside a modal.
343
- function preventScrollMobileSafari() {
344
- let scrollable;
345
- let lastY = 0;
346
- let onTouchStart = (e)=>{
347
- // Store the nearest scrollable parent element from the element that the user touched.
348
- scrollable = getScrollParent(e.target);
349
- if (scrollable === document.documentElement && scrollable === document.body) {
350
- return;
351
- }
352
- lastY = e.changedTouches[0].pageY;
353
- };
354
- let onTouchMove = (e)=>{
355
- // Prevent scrolling the window.
356
- if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
357
- e.preventDefault();
358
- return;
359
- }
360
- // Prevent scrolling up when at the top and scrolling down when at the bottom
361
- // of a nested scrollable area, otherwise mobile Safari will start scrolling
362
- // the window instead. Unfortunately, this disables bounce scrolling when at
363
- // the top but it's the best we can do.
364
- let y = e.changedTouches[0].pageY;
365
- let scrollTop = scrollable.scrollTop;
366
- let bottom = scrollable.scrollHeight - scrollable.clientHeight;
367
- if (bottom === 0) {
368
- return;
369
- }
370
- if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) {
371
- e.preventDefault();
372
- }
373
- lastY = y;
374
- };
375
- let onTouchEnd = (e)=>{
376
- let target = e.target;
377
- // Apply this change if we're not already focused on the target element
378
- if (isInput(target) && target !== document.activeElement) {
379
- e.preventDefault();
380
- // Apply a transform to trick Safari into thinking the input is at the top of the page
381
- // so it doesn't try to scroll it into view. When tapping on an input, this needs to
382
- // be done before the "focus" event, so we have to focus the element ourselves.
383
- target.style.transform = "translateY(-2000px)";
384
- target.focus();
385
- requestAnimationFrame(()=>{
386
- target.style.transform = "";
387
- });
388
- }
389
- };
390
- let onFocus = (e)=>{
391
- let target = e.target;
392
- if (isInput(target)) {
393
- // Transform also needs to be applied in the focus event in cases where focus moves
394
- // other than tapping on an input directly, e.g. the next/previous buttons in the
395
- // software keyboard. In these cases, it seems applying the transform in the focus event
396
- // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️
397
- target.style.transform = "translateY(-2000px)";
398
- requestAnimationFrame(()=>{
399
- target.style.transform = "";
400
- // This will have prevented the browser from scrolling the focused element into view,
401
- // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.
402
- if (visualViewport) {
403
- if (visualViewport.height < window.innerHeight) {
404
- // If the keyboard is already visible, do this after one additional frame
405
- // to wait for the transform to be removed.
406
- requestAnimationFrame(()=>{
407
- scrollIntoView(target);
408
- });
409
- } else {
410
- // Otherwise, wait for the visual viewport to resize before scrolling so we can
411
- // measure the correct position to scroll to.
412
- visualViewport.addEventListener("resize", ()=>scrollIntoView(target), {
413
- once: true
414
- });
415
- }
416
- }
417
- });
418
- }
419
- };
420
- let onWindowScroll = ()=>{
421
- // Last resort. If the window scrolled, scroll it back to the top.
422
- // It should always be at the top because the body will have a negative margin (see below).
423
- window.scrollTo(0, 0);
424
- };
425
- // Record the original scroll position so we can restore it.
426
- // Then apply a negative margin to the body to offset it by the scroll position. This will
427
- // enable us to scroll the window to the top, which is required for the rest of this to work.
428
- let scrollX = window.pageXOffset;
429
- let scrollY = window.pageYOffset;
430
- let restoreStyles = chain(setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`));
431
- // Scroll to the top. The negative margin on the body will make this appear the same.
432
- window.scrollTo(0, 0);
433
- let removeEvents = chain(addEvent(document, "touchstart", onTouchStart, {
434
- passive: false,
435
- capture: true
436
- }), addEvent(document, "touchmove", onTouchMove, {
437
- passive: false,
438
- capture: true
439
- }), addEvent(document, "touchend", onTouchEnd, {
440
- passive: false,
441
- capture: true
442
- }), addEvent(document, "focus", onFocus, true), addEvent(window, "scroll", onWindowScroll));
443
- return ()=>{
444
- // Restore styles and scroll the page back to where it was.
445
- restoreStyles();
446
- removeEvents();
447
- window.scrollTo(scrollX, scrollY);
448
- };
449
- }
450
- // Sets a CSS property on an element, and returns a function to revert it to the previous value.
451
- function setStyle(element, style, value) {
452
- // https://github.com/microsoft/TypeScript/issues/17827#issuecomment-391663310
453
- // @ts-ignore
454
- let cur = element.style[style];
455
- // @ts-ignore
456
- element.style[style] = value;
457
- return ()=>{
458
- // @ts-ignore
459
- element.style[style] = cur;
460
- };
461
- }
462
- // Adds an event listener to an element, and returns a function to remove it.
463
- function addEvent(target, event, handler, options) {
464
- // @ts-ignore
465
- target.addEventListener(event, handler, options);
466
- return ()=>{
467
- // @ts-ignore
468
- target.removeEventListener(event, handler, options);
469
- };
470
- }
471
- function scrollIntoView(target) {
472
- let root = document.scrollingElement || document.documentElement;
473
- while(target && target !== root){
474
- // Find the parent scrollable element and adjust the scroll position if the target is not already in view.
475
- let scrollable = getScrollParent(target);
476
- if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
477
- let scrollableTop = scrollable.getBoundingClientRect().top;
478
- let targetTop = target.getBoundingClientRect().top;
479
- let targetBottom = target.getBoundingClientRect().bottom;
480
- // Buffer is needed for some edge cases
481
- const keyboardHeight = scrollable.getBoundingClientRect().bottom + KEYBOARD_BUFFER;
482
- if (targetBottom > keyboardHeight) {
483
- scrollable.scrollTop += targetTop - scrollableTop;
484
- }
485
- }
486
- // @ts-ignore
487
- target = scrollable.parentElement;
488
- }
489
- }
490
- function isInput(target) {
491
- return target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
492
- }
493
-
494
264
  function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints, drawerRef, overlayRef, fadeFromIndex, onSnapPointChange, direction = "bottom", container, snapToSequentialPoint }) {
495
265
  const [activeSnapPoint, setActiveSnapPoint] = reactUseControllableState.useControllableState({
496
266
  prop: activeSnapPointProp,
497
- defaultProp: snapPoints?.[0],
267
+ defaultProp: snapPoints?.[0] ?? null,
498
268
  onChange: setActiveSnapPointProp
499
269
  });
500
270
  const [windowDimensions, setWindowDimensions] = React__default.default.useState(typeof window !== "undefined" ? {
@@ -532,6 +302,11 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
532
302
  height: 0
533
303
  };
534
304
  return snapPoints?.map((snapPoint)=>{
305
+ // FIXME
306
+ // 1 -> container 100% << expected
307
+ // 0.5 -> container 50% << expected
308
+ // 300px -> 300 -> 300px << expected
309
+ // 15rem -> 15 -> 15px << this makes no sense, should fix or disallow
535
310
  const isPx = typeof snapPoint === "string";
536
311
  let snapPointAsNumber = 0;
537
312
  if (isPx) {
@@ -553,7 +328,8 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
553
328
  }, [
554
329
  snapPoints,
555
330
  windowDimensions,
556
- container
331
+ container,
332
+ direction
557
333
  ]);
558
334
  const activeSnapPointOffset = React__default.default.useMemo(()=>activeSnapPointIndex !== null ? snapPointsOffset?.[activeSnapPointIndex] : null, [
559
335
  snapPointsOffset,
@@ -704,7 +480,7 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
704
480
  }
705
481
 
706
482
  function useDrawer(props) {
707
- const { open: openProp, onOpenChange, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, closeThreshold = CLOSE_THRESHOLD, scrollLockTimeout = SCROLL_LOCK_TIMEOUT, dismissible = true, handleOnly = false, fadeFromIndex = snapPoints && snapPoints.length - 1, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal = true, onClose, nested, noBodyStyles = false, direction = "bottom", defaultOpen = false, disablePreventScroll = true, snapToSequentialPoint = false, preventScrollRestoration = false, repositionInputs = true, onAnimationEnd, container, autoFocus = false, closeOnInteractOutside = true, closeOnEscape = true } = props;
483
+ const { open: openProp, onOpenChange, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, closeThreshold = CLOSE_THRESHOLD, scrollLockTimeout = SCROLL_LOCK_TIMEOUT, dismissible = true, handleOnly = false, fadeFromIndex = snapPoints && snapPoints.length - 1, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal = true, onClose, nested, noBodyStyles = true, direction = "bottom", defaultOpen = false, snapToSequentialPoint = false, preventScrollRestoration = false, repositionInputs = true, onAnimationEnd, container, autoFocus = false, closeOnInteractOutside = true, closeOnEscape = true } = props;
708
484
  const [isOpen = false, setIsOpen] = reactUseControllableState.useControllableState({
709
485
  defaultProp: defaultOpen,
710
486
  prop: openProp,
@@ -730,7 +506,6 @@ function useDrawer(props) {
730
506
  });
731
507
  const [hasBeenOpened, setHasBeenOpened] = React.useState(false);
732
508
  const [isDragging, setIsDragging] = React.useState(false);
733
- const [justReleased, setJustReleased] = React.useState(false);
734
509
  const [shouldOverlayAnimate, setShouldOverlayAnimate] = React.useState(false);
735
510
  const overlayRef = React.useRef(null);
736
511
  const openTime = React.useRef(null);
@@ -764,9 +539,6 @@ function useDrawer(props) {
764
539
  direction,
765
540
  snapToSequentialPoint
766
541
  });
767
- usePreventScroll({
768
- isDisabled: !isOpen || isDragging || !modal || justReleased || !hasBeenOpened || !repositionInputs || !disablePreventScroll
769
- });
770
542
  const { restorePositionSetting } = usePositionFixed({
771
543
  isOpen,
772
544
  modal,
@@ -783,7 +555,9 @@ function useDrawer(props) {
783
555
  setIsDragging(true);
784
556
  dragStartTime.current = new Date();
785
557
  if (isIOS()) {
786
- window.addEventListener("touchend", ()=>isAllowedToDrag.current = false, {
558
+ window.addEventListener("touchend", ()=>{
559
+ isAllowedToDrag.current = false;
560
+ }, {
787
561
  once: true
788
562
  });
789
563
  }
@@ -950,12 +724,6 @@ function useDrawer(props) {
950
724
  const timeTaken = dragEndTime.current.getTime() - dragStartTime.current.getTime();
951
725
  const distMoved = pointerStart.current - (isVertical(direction) ? event.pageY : event.pageX);
952
726
  const velocity = Math.abs(distMoved) / timeTaken;
953
- if (velocity > 0.05) {
954
- setJustReleased(true);
955
- setTimeout(()=>{
956
- setJustReleased(false);
957
- }, 200);
958
- }
959
727
  if (snapPoints) {
960
728
  const directionMultiplier = direction === "bottom" || direction === "right" ? 1 : -1;
961
729
  onReleaseSnapPoints({
@@ -1043,7 +811,7 @@ function useDrawer(props) {
1043
811
  drawerRef.current.style.height = `${initialDrawerHeight.current}px`;
1044
812
  }
1045
813
  if (snapPoints && snapPoints.length > 0 && !keyboardIsOpen.current) {
1046
- drawerRef.current.style.bottom = `0px`;
814
+ drawerRef.current.style.bottom = "0px";
1047
815
  } else {
1048
816
  drawerRef.current.style.bottom = `${Math.max(diffFromInitial, 0)}px`;
1049
817
  }
@@ -1081,9 +849,8 @@ function useDrawer(props) {
1081
849
  setShouldOverlayAnimate(false);
1082
850
  }, TRANSITIONS.ENTER_DURATION * 1000);
1083
851
  return ()=>clearTimeout(timeoutId);
1084
- } else {
1085
- setShouldOverlayAnimate(false);
1086
852
  }
853
+ setShouldOverlayAnimate(false);
1087
854
  }, [
1088
855
  isOpen,
1089
856
  snapPoints,
@@ -1158,7 +925,7 @@ function useDrawerContext() {
1158
925
  }
1159
926
 
1160
927
  const DrawerRoot = (props)=>{
1161
- const { children, defaultOpen, dismissible, onOpenChange, modal } = props;
928
+ const { children, defaultOpen, dismissible, modal } = props;
1162
929
  const api = useDrawer(props);
1163
930
  return /*#__PURE__*/ jsxRuntime.jsx(DialogPrimitive__namespace.Root, {
1164
931
  defaultOpen: defaultOpen,
@@ -1171,7 +938,6 @@ const DrawerRoot = (props)=>{
1171
938
  api.closeDrawer(true);
1172
939
  }
1173
940
  api.setIsOpen(open);
1174
- onOpenChange?.(open);
1175
941
  },
1176
942
  modal: modal,
1177
943
  children: /*#__PURE__*/ jsxRuntime.jsx(DrawerProvider, {
@@ -1187,7 +953,8 @@ const DrawerPositioner = /*#__PURE__*/ React.forwardRef((props, ref)=>{
1187
953
  ref: ref,
1188
954
  ...props,
1189
955
  style: {
1190
- pointerEvents: api.isOpen ? undefined : "none"
956
+ pointerEvents: api.isOpen ? undefined : "none",
957
+ ...props.style
1191
958
  }
1192
959
  });
1193
960
  });
package/lib/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- var Drawer12s = require('./Drawer-12s-BXSK15mB.cjs');
1
+ var Drawer12s = require('./Drawer-12s-D1dD-wen.cjs');
2
2
 
3
3
  var Drawer_namespace = {
4
4
  __proto__: null,
package/lib/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
3
3
  import { PrimitiveProps } from '@seed-design/react-primitive';
4
4
  import * as react from 'react';
5
5
 
6
- interface DialogProps {
6
+ interface UseDrawerProps {
7
7
  activeSnapPoint?: number | string | null;
8
8
  setActiveSnapPoint?: (snapPoint: number | string | null) => void;
9
9
  children?: React.ReactNode;
@@ -15,7 +15,8 @@ interface DialogProps {
15
15
  */
16
16
  closeThreshold?: number;
17
17
  /**
18
- * When `true` the `body` doesn't get any styles assigned from Vaul
18
+ * When `true` the `body` doesn't get any styles assigned from Drawer
19
+ * @default true
19
20
  */
20
21
  noBodyStyles?: boolean;
21
22
  onOpenChange?: (open: boolean) => void;
@@ -35,7 +36,7 @@ interface DialogProps {
35
36
  handleOnly?: boolean;
36
37
  /**
37
38
  * When `false` dragging, clicking outside, pressing esc, etc. will not close the drawer.
38
- * Use this in comination with the `open` prop, otherwise you won't be able to open/close the drawer.
39
+ * Use this in combination with the `open` prop, otherwise you won't be able to open/close the drawer.
39
40
  * @default true
40
41
  */
41
42
  dismissible?: boolean;
@@ -58,11 +59,6 @@ interface DialogProps {
58
59
  * @default false
59
60
  */
60
61
  defaultOpen?: boolean;
61
- /**
62
- * When set to `true` prevents scrolling on the document body on mount, and restores it on unmount.
63
- * @default false
64
- */
65
- disablePreventScroll?: boolean;
66
62
  /**
67
63
  * When `true` Vaul will reposition inputs rather than scroll then into view if the keyboard is in the way.
68
64
  * Setting it to `false` will fall back to the default browser behavior.
@@ -86,7 +82,7 @@ interface DialogProps {
86
82
  autoFocus?: boolean;
87
83
  /**
88
84
  * Array of snap points to use.
89
- * Example: snapPoints={[0, 100, 200]} will use the first snap point at 0px, the second at 100px, and the third at 200px.
85
+ * Example: snapPoints={["100px", "200px", 1]} will use the snap points 100px, 200px and fully open (1 = 100% of the container).
90
86
  * @default undefined
91
87
  */
92
88
  snapPoints?: (number | string)[];
@@ -107,7 +103,7 @@ interface DialogProps {
107
103
  */
108
104
  closeOnEscape?: boolean;
109
105
  }
110
- declare function useDrawer(props: DialogProps): {
106
+ declare function useDrawer(props: UseDrawerProps): {
111
107
  activeSnapPoint: string | number | null;
112
108
  snapPoints: (string | number)[] | undefined;
113
109
  setActiveSnapPoint: (value: react.SetStateAction<string | number | null>) => void;
@@ -139,7 +135,7 @@ declare function useDrawer(props: DialogProps): {
139
135
  closeOnEscape: boolean;
140
136
  };
141
137
 
142
- interface DrawerRootProps extends DialogProps {
138
+ interface DrawerRootProps extends UseDrawerProps {
143
139
  children?: react.ReactNode;
144
140
  }
145
141
  declare const DrawerRoot: (props: DrawerRootProps) => react_jsx_runtime.JSX.Element;
@@ -208,4 +204,4 @@ declare namespace Drawer_namespace {
208
204
  }
209
205
 
210
206
  export { Drawer_namespace as Drawer, DrawerBackdrop, DrawerCloseButton, DrawerContent, DrawerDescription, DrawerHandle, DrawerPositioner, DrawerRoot, DrawerTitle, DrawerTrigger, useDrawer, useDrawerContext };
211
- export type { DialogProps, DrawerBackdropProps, DrawerCloseButtonProps, DrawerContentProps, DrawerContextValue, DrawerDescriptionProps, DrawerHandleProps, DrawerPositionerProps, DrawerRootProps, DrawerTitleProps, DrawerTriggerProps };
207
+ export type { DrawerBackdropProps, DrawerCloseButtonProps, DrawerContentProps, DrawerContextValue, DrawerDescriptionProps, DrawerHandleProps, DrawerPositionerProps, DrawerRootProps, DrawerTitleProps, DrawerTriggerProps, UseDrawerProps };
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DrawerBackdrop, a as DrawerCloseButton, b as DrawerContent, c as DrawerDescription, d as DrawerHandle, e as DrawerPositioner, f as DrawerRoot, g as DrawerTitle, h as DrawerTrigger } from './Drawer-12s-CAlIg6sU.js';
2
- export { u as useDrawer, i as useDrawerContext } from './Drawer-12s-CAlIg6sU.js';
1
+ import { D as DrawerBackdrop, a as DrawerCloseButton, b as DrawerContent, c as DrawerDescription, d as DrawerHandle, e as DrawerPositioner, f as DrawerRoot, g as DrawerTitle, h as DrawerTrigger } from './Drawer-12s-Cg9AJtdN.js';
2
+ export { u as useDrawer, i as useDrawerContext } from './Drawer-12s-Cg9AJtdN.js';
3
3
 
4
4
  var Drawer_namespace = {
5
5
  __proto__: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-design/react-drawer",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/daangn/seed-design.git",
package/src/Drawer.tsx CHANGED
@@ -8,15 +8,15 @@ import { Primitive, type PrimitiveProps } from "@seed-design/react-primitive";
8
8
  import type * as React from "react";
9
9
  import { forwardRef, useEffect, useRef, useState } from "react";
10
10
  import type { DrawerDirection } from "./types";
11
- import { useDrawer, type DialogProps } from "./useDrawer";
11
+ import { useDrawer, type UseDrawerProps } from "./useDrawer";
12
12
  import { DrawerProvider, useDrawerContext } from "./useDrawerContext";
13
13
 
14
- export interface DrawerRootProps extends DialogProps {
14
+ export interface DrawerRootProps extends UseDrawerProps {
15
15
  children?: React.ReactNode;
16
16
  }
17
17
 
18
18
  export const DrawerRoot = (props: DrawerRootProps) => {
19
- const { children, defaultOpen, dismissible, onOpenChange, modal } = props;
19
+ const { children, defaultOpen, dismissible, modal } = props;
20
20
  const api = useDrawer(props);
21
21
  return (
22
22
  <DialogPrimitive.Root
@@ -31,7 +31,6 @@ export const DrawerRoot = (props: DrawerRootProps) => {
31
31
  }
32
32
 
33
33
  api.setIsOpen(open);
34
- onOpenChange?.(open);
35
34
  }}
36
35
  modal={modal}
37
36
  >
@@ -54,7 +53,7 @@ export const DrawerPositioner = forwardRef<HTMLDivElement, DrawerPositionerProps
54
53
  <Primitive.div
55
54
  ref={ref}
56
55
  {...props}
57
- style={{ pointerEvents: api.isOpen ? undefined : "none" }}
56
+ style={{ pointerEvents: api.isOpen ? undefined : "none", ...props.style }}
58
57
  />
59
58
  );
60
59
  });
package/src/helpers.ts CHANGED
@@ -6,6 +6,27 @@ interface Style {
6
6
 
7
7
  const cache = new WeakMap();
8
8
 
9
+ // HTML input types that do not cause the software keyboard to appear.
10
+ const nonTextInputTypes = new Set([
11
+ "checkbox",
12
+ "radio",
13
+ "range",
14
+ "color",
15
+ "file",
16
+ "image",
17
+ "button",
18
+ "submit",
19
+ "reset",
20
+ ]);
21
+
22
+ export function isInput(target: Element) {
23
+ return (
24
+ (target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type)) ||
25
+ target instanceof HTMLTextAreaElement ||
26
+ (target instanceof HTMLElement && target.isContentEditable)
27
+ );
28
+ }
29
+
9
30
  export function isInView(el: HTMLElement): boolean {
10
31
  const rect = el.getBoundingClientRect();
11
32
 
package/src/index.ts CHANGED
@@ -19,7 +19,7 @@ export {
19
19
  type DrawerTriggerProps,
20
20
  } from "./Drawer";
21
21
 
22
- export { useDrawer, type DialogProps } from "./useDrawer";
22
+ export { useDrawer, type UseDrawerProps } from "./useDrawer";
23
23
  export { useDrawerContext, type DrawerContextValue } from "./useDrawerContext";
24
24
 
25
25
  export * as Drawer from "./Drawer.namespace";
@@ -20,8 +20,8 @@ export function useSnapPoints({
20
20
  setActiveSnapPointProp?(snapPoint: number | null | string): void;
21
21
  snapPoints?: (number | string)[];
22
22
  fadeFromIndex?: number;
23
- drawerRef: React.RefObject<HTMLDivElement>;
24
- overlayRef: React.RefObject<HTMLDivElement>;
23
+ drawerRef: React.RefObject<HTMLDivElement | null>;
24
+ overlayRef: React.RefObject<HTMLDivElement | null>;
25
25
  onSnapPointChange(activeSnapPointIndex: number): void;
26
26
  direction?: DrawerDirection;
27
27
  container?: HTMLElement | null | undefined;
@@ -29,7 +29,7 @@ export function useSnapPoints({
29
29
  }) {
30
30
  const [activeSnapPoint, setActiveSnapPoint] = useControllableState<string | number | null>({
31
31
  prop: activeSnapPointProp,
32
- defaultProp: snapPoints?.[0],
32
+ defaultProp: snapPoints?.[0] ?? null,
33
33
  onChange: setActiveSnapPointProp,
34
34
  });
35
35
 
@@ -84,6 +84,12 @@ export function useSnapPoints({
84
84
 
85
85
  return (
86
86
  snapPoints?.map((snapPoint) => {
87
+ // FIXME
88
+ // 1 -> container 100% << expected
89
+ // 0.5 -> container 50% << expected
90
+ // 300px -> 300 -> 300px << expected
91
+ // 15rem -> 15 -> 15px << this makes no sense, should fix or disallow
92
+
87
93
  const isPx = typeof snapPoint === "string";
88
94
  let snapPointAsNumber = 0;
89
95
 
@@ -119,7 +125,7 @@ export function useSnapPoints({
119
125
  return width;
120
126
  }) ?? []
121
127
  );
122
- }, [snapPoints, windowDimensions, container]);
128
+ }, [snapPoints, windowDimensions, container, direction]);
123
129
 
124
130
  const activeSnapPointOffset = React.useMemo(
125
131
  () => (activeSnapPointIndex !== null ? snapPointsOffset?.[activeSnapPointIndex] : null),