@tide-design/components 0.11.0 → 0.11.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.
Files changed (75) hide show
  1. package/dist/Accordion.js +1 -1
  2. package/dist/Alert.js +3 -2
  3. package/dist/Avatar.js +1 -1
  4. package/dist/Badge.js +1 -1
  5. package/dist/Breadcrumb.js +2 -2
  6. package/dist/Button.js +3 -2
  7. package/dist/Card.js +1 -1
  8. package/dist/Checkbox.d.ts +1 -1
  9. package/dist/Checkbox.js +4 -4
  10. package/dist/CheckboxGroup.js +3 -3
  11. package/dist/Combobox.d.ts +2 -2
  12. package/dist/Combobox.js +10 -7
  13. package/dist/Dialog.js +6 -4
  14. package/dist/Field.js +2 -2
  15. package/dist/IconButton.js +3 -2
  16. package/dist/Input.d.ts +1 -1
  17. package/dist/Input.js +3 -3
  18. package/dist/Link.js +1 -1
  19. package/dist/Menu.d.ts +2 -2
  20. package/dist/Menu.js +9 -5
  21. package/dist/Pagination.js +1 -1
  22. package/dist/Popover.d.ts +1 -1
  23. package/dist/Popover.js +7 -4
  24. package/dist/Progress.js +1 -1
  25. package/dist/Radio.d.ts +1 -1
  26. package/dist/Radio.js +4 -4
  27. package/dist/RadioGroup.js +3 -3
  28. package/dist/Select.d.ts +2 -2
  29. package/dist/Select.js +11 -7
  30. package/dist/Separator.js +1 -1
  31. package/dist/Skeleton.js +1 -1
  32. package/dist/Spinner.js +1 -1
  33. package/dist/Switch.js +2 -2
  34. package/dist/Table.js +1 -1
  35. package/dist/Tabs.d.ts +1 -1
  36. package/dist/Tabs.js +2 -2
  37. package/dist/Tag.d.ts +1 -1
  38. package/dist/Tag.js +2 -2
  39. package/dist/Textarea.js +3 -3
  40. package/dist/Toast.js +6 -4
  41. package/dist/Tooltip.d.ts +1 -1
  42. package/dist/Tooltip.js +7 -4
  43. package/dist/Typography.js +1 -1
  44. package/dist/VisuallyHidden.js +1 -1
  45. package/dist/{listbox.d.ts → components/ListBoxNodes.d.ts} +1 -1
  46. package/dist/{listbox.js → components/ListBoxNodes.js} +3 -3
  47. package/dist/components/OverlayPortal.js +21 -0
  48. package/dist/{alert-style.js → constants/alertClass.js} +2 -16
  49. package/dist/{choice-style.js → constants/choiceClass.js} +1 -1
  50. package/dist/{input-style.d.ts → constants/inputClass.d.ts} +1 -1
  51. package/dist/{input-style.js → constants/inputClass.js} +1 -1
  52. package/dist/{list-style.js → constants/listClass.js} +2 -2
  53. package/dist/{overlay-style.js → constants/overlayClass.js} +1 -1
  54. package/dist/constants/pressableClass.js +33 -0
  55. package/dist/{choice-group.js → hooks/useChoiceGroup.js} +2 -2
  56. package/dist/hooks/useCloseOnTab.js +29 -0
  57. package/dist/{field-context.js → hooks/useFieldControl.js} +1 -1
  58. package/dist/hooks/useOverlayPresence.js +46 -0
  59. package/dist/hooks/useOverlayTheme.js +20 -0
  60. package/dist/hooks/usePopoverOverlay.js +25 -0
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.js +1 -1
  63. package/dist/libs/alertStatusIcon.js +17 -0
  64. package/dist/{cn.js → libs/cn.js} +1 -1
  65. package/dist/{list-collection.js → libs/listCollection.js} +1 -1
  66. package/dist/{overlay.d.ts → libs/overlayPosition.d.ts} +0 -1
  67. package/dist/libs/overlayPosition.js +20 -0
  68. package/dist/libs/pressableState.js +43 -0
  69. package/dist/{render.js → libs/renderElement.js} +1 -1
  70. package/package.json +3 -3
  71. package/dist/overlay.js +0 -130
  72. package/dist/pressable.js +0 -70
  73. /package/dist/{choice-style.d.ts → constants/choiceClass.d.ts} +0 -0
  74. /package/dist/{cn.d.ts → libs/cn.d.ts} +0 -0
  75. /package/dist/{list-collection.d.ts → libs/listCollection.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- // src/overlay-style.ts
1
+ // src/constants/overlayClass.ts
2
2
  /**
3
3
  * 오버레이 표면. raised 표면(`bg-raised`), `shadow-md`, radius `lg`, 경계 `border-raised`(light 투명 / dark gray-800).
4
4
  * - 글자는 `text-default`다. `text-default × bg-raised` 4.5:1이 등록되어 있다.
@@ -0,0 +1,33 @@
1
+ // src/constants/pressableClass.ts
2
+ /**
3
+ * 기본 색(배경, 글자, 경계). 색 이름마다 Foundation이 같은 대비 규칙으로 검사한다.
4
+ * subtle 바탕 위 글자는 파스텔 글자 on-subtle이고(ADR 0022 §1), outline·ghost 글자는 바탕 없는 색 글자 text다.
5
+ */
6
+ const pressableColorClass = {
7
+ solid: "border-transparent bg-accent-solid text-accent-on-solid",
8
+ subtle: "border-transparent bg-accent-subtle text-accent-on-subtle",
9
+ outline: "border-accent text-accent",
10
+ ghost: "border-transparent text-accent"
11
+ };
12
+ /** outline·ghost의 hover·누름 색. 아래 `pressableInteractionClass` 주석 참고. */
13
+ const pressableTintClass = "[--pressable-hover:var(--tide-accent-faint)] [--pressable-active:var(--tide-accent-subtle)] data-[color=neutral]:[--pressable-hover:var(--tide-bg-hover)] data-[color=neutral]:[--pressable-active:var(--tide-bg-active)] hover:bg-(--pressable-hover) active:bg-(--pressable-active)";
14
+ /** hover·누름 색. 활성 상태일 때만 붙인다(비활성·로딩에는 붙이지 않아 CSS 순서에 기대지 않는다). */
15
+ const pressableInteractionClass = {
16
+ solid: "hover:bg-accent-solid-hover active:bg-accent-solid-active",
17
+ subtle: "hover:bg-accent-subtle-hover active:bg-accent-subtle-active",
18
+ outline: pressableTintClass,
19
+ ghost: pressableTintClass
20
+ };
21
+ /** 비활성 색. 색 이름과 관계없이 같다. disabled Token은 대비 검사 대상이 아니다. */
22
+ const pressableDisabledClass = {
23
+ solid: "cursor-not-allowed border-transparent bg-disabled text-disabled",
24
+ subtle: "cursor-not-allowed border-transparent bg-disabled text-disabled",
25
+ outline: "cursor-not-allowed border-default text-disabled",
26
+ ghost: "cursor-not-allowed border-transparent text-disabled"
27
+ };
28
+ /** 모양의 공통 부분. radius는 모든 size에서 `md`다. 높이·폭·padding은 Component가 정한다. */
29
+ const pressableBaseClass = "inline-flex shrink-0 items-center justify-center rounded-md border whitespace-nowrap select-none transition-colors focus-visible:focus-ring";
30
+ /** 누름 축소. motion-safe:일 때만 줄이고, 그때만 scale도 전환 대상에 넣는다(fast, out은 Tide 기본값). ADR 0010. */
31
+ const pressableScaleClass = "motion-safe:transition-[color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,scale] motion-safe:active:scale-96";
32
+
33
+ export { pressableBaseClass, pressableColorClass, pressableDisabledClass, pressableInteractionClass, pressableScaleClass };
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
 
3
- import { FieldContext } from "./field-context.js";
3
+ import { FieldContext } from "./useFieldControl.js";
4
4
  import { createContext, use } from "react";
5
5
 
6
- // src/choice-group.ts
6
+ // src/hooks/useChoiceGroup.ts
7
7
  /** CheckboxGroup 안에서만 값이 있다. */
8
8
  const CheckboxGroupContext = createContext(null);
9
9
  /** RadioGroup 안에서만 값이 있다. */
@@ -0,0 +1,29 @@
1
+ "use client";
2
+
3
+ import { useEffect } from "react";
4
+
5
+ // src/hooks/useCloseOnTab.ts
6
+ /**
7
+ * 오버레이 안에서 Tab을 누르면 기본 동작을 막고 닫는다(포커스는 `OverlayPortal`의 FocusScope가 트리거로 돌린다).
8
+ * 목록 오버레이(Menu, Select)가 쓴다(WAI-ARIA APG Menu Button·Select-Only Combobox: Tab은 목록을 닫는다).
9
+ *
10
+ * React Aria 목록 hook(useMenu·useListBox)은 Tab으로 닫지 않고, 항목의 keydown 처리가 전파를 멈추며 FocusScope가
11
+ * document capture에서 Tab을 먼저 다룬다. 열린 동안 바깥은 inert라 브라우저 기본 Tab은 갈 곳이 없다. 그래서 그보다
12
+ * 앞인 window capture에서 받는다.
13
+ * 전파도 멈춘다. listbox(useListBox 안의 useSelectableCollection)는 Tab에서 포커스를 목록 안 요소로 옮기는데, 그러면
14
+ * 닫힌 뒤 포커스가 트리거로 돌아오지 않았다(Select 테스트로 확인).
15
+ */
16
+ function useCloseOnTab(overlayRef, close) {
17
+ useEffect(() => {
18
+ const onKeyDown = (event) => {
19
+ if (event.key !== "Tab" || !overlayRef.current?.contains(event.target)) return;
20
+ event.preventDefault();
21
+ event.stopPropagation();
22
+ close();
23
+ };
24
+ window.addEventListener("keydown", onKeyDown, true);
25
+ return () => window.removeEventListener("keydown", onKeyDown, true);
26
+ }, [close, overlayRef]);
27
+ }
28
+
29
+ export { useCloseOnTab };
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { createContext, use } from "react";
4
4
 
5
- // src/field-context.ts
5
+ // src/hooks/useFieldControl.ts
6
6
  /** Field 밖에서는 `null`이다. */
7
7
  const FieldContext = createContext(null);
8
8
  /**
@@ -0,0 +1,46 @@
1
+ "use client";
2
+
3
+ import { useLayoutEffect, useState } from "react";
4
+
5
+ // src/hooks/useOverlayPresence.ts
6
+ /**
7
+ * 열림 상태가 꺼져도 퇴장 전환이 끝날 때까지 오버레이를 DOM에 남긴다. DOM에 둘지(`true`)를 돌려준다.
8
+ *
9
+ * 닫힌 뒤 요소의 `getAnimations()`(CSS transition 포함)가 모두 끝나면 뺀다. 전환이 없으면(지원하지 않는 브라우저,
10
+ * 전환이 없는 오버레이) 바로 뺀다. 퇴장 중에 다시 열리면 빼지 않는다. React Aria hooks에는 퇴장을 기다리는 hook이
11
+ * 없어서(react-aria-components의 `isExiting`은 Component 층에만 있다) 이 hook이 그 일을 한다.
12
+ */
13
+ function useOverlayPresence(isOpen, ref) {
14
+ const [present, setPresent] = useState(isOpen);
15
+ if (isOpen && !present) setPresent(true);
16
+ useLayoutEffect(() => {
17
+ if (isOpen || !present) return;
18
+ const element = ref.current;
19
+ if (!element || typeof element.getAnimations !== "function") {
20
+ setPresent(false);
21
+ return;
22
+ }
23
+ let cancelled = false;
24
+ const waitForExit = () => {
25
+ const animations = element.getAnimations();
26
+ if (animations.length === 0) {
27
+ setPresent(false);
28
+ return;
29
+ }
30
+ Promise.allSettled(animations.map((animation) => animation.finished)).then(() => {
31
+ if (!cancelled) waitForExit();
32
+ });
33
+ };
34
+ waitForExit();
35
+ return () => {
36
+ cancelled = true;
37
+ };
38
+ }, [
39
+ isOpen,
40
+ present,
41
+ ref
42
+ ]);
43
+ return isOpen || present;
44
+ }
45
+
46
+ export { useOverlayPresence };
@@ -0,0 +1,20 @@
1
+ "use client";
2
+
3
+ import { useLayoutEffect } from "react";
4
+
5
+ // src/hooks/useOverlayTheme.ts
6
+ /**
7
+ * 트리거가 놓인 Theme(`data-theme`)을 portal로 나간 오버레이에 옮긴다. Theme을 `<html>`이 아닌 일부 영역에
8
+ * 붙인 앱에서도 오버레이가 같은 색이 된다. 오버레이에 이미 `data-theme`이 있으면 두고, 트리거 위에 Theme이 없으면
9
+ * 붙이지 않는다(`:root` 기본값을 따른다). 위치를 계산하기 전(첫 스타일 계산 전)에 붙도록 위치 hook보다 먼저 부른다.
10
+ */
11
+ function useOverlayTheme(triggerRef, overlayRef) {
12
+ useLayoutEffect(() => {
13
+ const overlay = overlayRef.current;
14
+ if (!overlay || overlay.hasAttribute("data-theme")) return;
15
+ const theme = triggerRef.current?.closest("[data-theme]")?.getAttribute("data-theme");
16
+ if (theme) overlay.setAttribute("data-theme", theme);
17
+ }, [triggerRef, overlayRef]);
18
+ }
19
+
20
+ export { useOverlayTheme };
@@ -0,0 +1,25 @@
1
+ "use client";
2
+
3
+ import { overlayPositionProps } from "../libs/overlayPosition.js";
4
+ import { usePopover } from "react-aria";
5
+
6
+ // src/hooks/usePopoverOverlay.ts
7
+ /**
8
+ * 트리거에 붙는 오버레이(Popover, Menu, Select·Combobox 목록)의 위치·닫기 동작. React Aria `usePopover`를 감싼다.
9
+ * - 닫기: Esc, 바깥 누름, 포커스가 바깥으로 나감(`usePopover` 기본). 위에 쌓인 오버레이부터 닫힌다.
10
+ * - 모달: 기본은 바깥을 `inert`로 막고 스크롤을 잠근다. `nonModal`이면 둘 다 하지 않는다.
11
+ * - 위치: 공간이 모자라면 반대쪽으로 뒤집고, 주축 길이는 `max-height`로 줄여 트리거를 덮지 않는다(WCAG 2.4.11, Comments 참고).
12
+ * 돌려받은 `overlayProps`(style 포함)를 오버레이 요소에 펼친다. 쌓임 단계 class는 부르는 쪽이 붙인다.
13
+ */
14
+ function usePopoverOverlay({ triggerRef, popoverRef, placement, offset, nonModal = false }, state) {
15
+ const { popoverProps, placement: actual } = usePopover({
16
+ triggerRef,
17
+ popoverRef,
18
+ placement,
19
+ offset,
20
+ isNonModal: nonModal
21
+ }, state);
22
+ return { overlayProps: overlayPositionProps(popoverProps, actual, placement) };
23
+ }
24
+
25
+ export { usePopoverOverlay };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { cn } from "./cn.js";
1
+ import { cn } from "./libs/cn.js";
2
2
  import { VisuallyHidden, VisuallyHiddenProps } from "./VisuallyHidden.js";
3
3
  import { Typography, TypographyProps } from "./Typography.js";
4
4
  import { Spinner, SpinnerProps } from "./Spinner.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { cn } from "./cn.js";
1
+ import { cn } from "./libs/cn.js";
2
2
  import { VisuallyHidden } from "./VisuallyHidden.js";
3
3
  import { Typography } from "./Typography.js";
4
4
  import { Spinner } from "./Spinner.js";
@@ -0,0 +1,17 @@
1
+ import { CircleCheckIcon, InfoIcon, OctagonExclamationPointIcon, TriangleExclamationPointIcon } from "@tide-design/icons";
2
+
3
+ // src/libs/alertStatusIcon.ts
4
+ const statusIcons = {
5
+ neutral: InfoIcon,
6
+ primary: InfoIcon,
7
+ info: InfoIcon,
8
+ success: CircleCheckIcon,
9
+ warning: TriangleExclamationPointIcon,
10
+ danger: OctagonExclamationPointIcon
11
+ };
12
+ /** Role의 상태 아이콘. 앱이 더한 Role(예: `brand`)은 일반 알림으로 보고 i 아이콘을 쓴다. */
13
+ function alertStatusIcon(color) {
14
+ return Object.hasOwn(statusIcons, color) ? statusIcons[color] : InfoIcon;
15
+ }
16
+
17
+ export { alertStatusIcon };
@@ -2,7 +2,7 @@ import { tailwindMergeConfig } from "@tide-design/foundation/tailwind-merge";
2
2
  import { clsx } from "clsx";
3
3
  import { extendTailwindMerge } from "tailwind-merge";
4
4
 
5
- // src/cn.ts
5
+ // src/libs/cn.ts
6
6
  const twMerge = extendTailwindMerge(tailwindMergeConfig);
7
7
  /**
8
8
  * class를 합치고 충돌을 푼다. 뒤에 온 class가 이긴다.
@@ -1,6 +1,6 @@
1
1
  import { Children, Fragment, createElement, isValidElement } from "react";
2
2
 
3
- // src/list-collection.ts
3
+ // src/libs/listCollection.ts
4
4
  const lazyType = Symbol.for("react.lazy");
5
5
  const isLazy = (type) => typeof type === "object" && type !== null && type.$$typeof === lazyType;
6
6
  /**
@@ -1,5 +1,4 @@
1
1
  import "react";
2
- import "react-stately";
3
2
  /**
4
3
  * 트리거 기준 위치. 앞은 트리거의 어느 쪽에 놓을지(주축), 뒤는 그 변에서 어디에 맞출지(교차축)다.
5
4
  * 공간이 모자라면 반대쪽으로 뒤집는다(React Aria `shouldFlip` 기본값).
@@ -0,0 +1,20 @@
1
+ // src/libs/overlayPosition.ts
2
+ const isAxis = (value) => value === "top" || value === "bottom" || value === "left" || value === "right";
3
+ /**
4
+ * React Aria가 위치 style에 넣는 `zIndex: 100000`을 빼고 주축 방향을 `data-placement`로 붙인다.
5
+ * 쌓임은 쌓임 단계 class(`z-popover` 등)로만 정한다(spec 「오버레이」).
6
+ *
7
+ * `placement`가 아직 없으면(처음 렌더) 요청한 placement의 주축을 쓴다. 등장 전환의 시작 방향이 첫 스타일 계산에서
8
+ * 정해지기 때문이다. 공간이 없어 뒤집힌 경우에만 첫 프레임의 시작 방향이 요청한 쪽이 된다(4px).
9
+ */
10
+ function overlayPositionProps(props, placement, requested) {
11
+ const { zIndex: _zIndex, ...style } = props.style ?? {};
12
+ const fallback = requested.split(" ")[0];
13
+ return {
14
+ ...props,
15
+ style,
16
+ "data-placement": isAxis(placement) ? placement : fallback
17
+ };
18
+ }
19
+
20
+ export { overlayPositionProps };
@@ -0,0 +1,43 @@
1
+ import { pressableColorClass, pressableDisabledClass, pressableInteractionClass, pressableScaleClass } from "../constants/pressableClass.js";
2
+
3
+ // src/libs/pressableState.ts
4
+ /** `disabled`를 네이티브로 지원하는 요소인지. Button류가 렌더할 만한 요소 중에서는 `button`뿐이다. */
5
+ const supportsNativeDisabled = (render) => render === void 0 || render.type === "button";
6
+ /**
7
+ * 채움 방식·색·상태에서 class와 루트 props를 정한다.
8
+ * - disabled: 기본 요소와 `render={<button />}`는 네이티브 `disabled`, 그 밖의 요소는 `aria-disabled`·`data-disabled`와 클릭 차단
9
+ * - loading: 포커스를 남긴 채 `aria-disabled`·`data-loading`과 클릭 차단. disabled와 함께 오면 disabled가 이긴다
10
+ * - 커서: 활성 pointer, 로딩 wait, 비활성 not-allowed
11
+ * - hover·누름 색과 누름 축소는 활성 상태에서만 붙인다
12
+ */
13
+ function pressableState({ variant, color, disabled, loading, noPressScale, render, type, onClick, ariaDisabled }) {
14
+ const native = supportsNativeDisabled(render);
15
+ const softDisabled = disabled && !native;
16
+ const blocked = softDisabled || loading && !disabled;
17
+ const interactive = !disabled && !loading;
18
+ const showSpinner = loading && !disabled;
19
+ return {
20
+ className: [
21
+ disabled ? pressableDisabledClass[variant] : pressableColorClass[variant],
22
+ interactive ? pressableInteractionClass[variant] : void 0,
23
+ interactive && !noPressScale ? pressableScaleClass : void 0,
24
+ interactive ? "cursor-pointer" : void 0,
25
+ showSpinner ? "cursor-wait" : void 0
26
+ ].filter(Boolean).join(" "),
27
+ showSpinner,
28
+ rootProps: {
29
+ type: render === void 0 ? type ?? "button" : type,
30
+ disabled: native && disabled ? true : void 0,
31
+ "data-color": color,
32
+ "aria-disabled": blocked ? true : ariaDisabled,
33
+ "data-disabled": softDisabled ? "" : void 0,
34
+ "data-loading": showSpinner ? "" : void 0,
35
+ onClick: blocked ? (event) => {
36
+ event.preventDefault();
37
+ event.stopPropagation();
38
+ } : onClick
39
+ }
40
+ };
41
+ }
42
+
43
+ export { pressableState };
@@ -1,7 +1,7 @@
1
1
  import { cn } from "./cn.js";
2
2
  import { cloneElement, createElement } from "react";
3
3
 
4
- // src/render.ts
4
+ // src/libs/renderElement.ts
5
5
  const isHandlerName = (name) => /^on[A-Z]/.test(name);
6
6
  /** ref 여러 개를 하나로 합친다. React 19의 cleanup 함수 반환도 지원한다. */
7
7
  function mergeRefs(...refs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tide-design/components",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Tide 디자인 시스템의 React Component",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,8 +23,8 @@
23
23
  "./styles.css": "./dist/styles.css"
24
24
  },
25
25
  "dependencies": {
26
- "@tide-design/foundation": "0.11.0",
27
- "@tide-design/icons": "0.11.0",
26
+ "@tide-design/foundation": "0.11.1",
27
+ "@tide-design/icons": "0.11.1",
28
28
  "clsx": "^2.1.1",
29
29
  "react-aria": "^3.53.1",
30
30
  "react-stately": "^3.51.0",
package/dist/overlay.js DELETED
@@ -1,130 +0,0 @@
1
- "use client";
2
-
3
- import { jsx } from "react/jsx-runtime";
4
- import { useEffect, useLayoutEffect, useState } from "react";
5
- import { Overlay, usePopover } from "react-aria";
6
-
7
- // src/overlay.tsx
8
- const isAxis = (value) => value === "top" || value === "bottom" || value === "left" || value === "right";
9
- /**
10
- * 열림 상태가 꺼져도 퇴장 전환이 끝날 때까지 오버레이를 DOM에 남긴다. DOM에 둘지(`true`)를 돌려준다.
11
- *
12
- * 닫힌 뒤 요소의 `getAnimations()`(CSS transition 포함)가 모두 끝나면 뺀다. 전환이 없으면(지원하지 않는 브라우저,
13
- * 전환이 없는 오버레이) 바로 뺀다. 퇴장 중에 다시 열리면 빼지 않는다. React Aria hooks에는 퇴장을 기다리는 hook이
14
- * 없어서(react-aria-components의 `isExiting`은 Component 층에만 있다) 이 hook이 그 일을 한다.
15
- */
16
- function useOverlayPresence(isOpen, ref) {
17
- const [present, setPresent] = useState(isOpen);
18
- if (isOpen && !present) setPresent(true);
19
- useLayoutEffect(() => {
20
- if (isOpen || !present) return;
21
- const element = ref.current;
22
- if (!element || typeof element.getAnimations !== "function") {
23
- setPresent(false);
24
- return;
25
- }
26
- let cancelled = false;
27
- const waitForExit = () => {
28
- const animations = element.getAnimations();
29
- if (animations.length === 0) {
30
- setPresent(false);
31
- return;
32
- }
33
- Promise.allSettled(animations.map((animation) => animation.finished)).then(() => {
34
- if (!cancelled) waitForExit();
35
- });
36
- };
37
- waitForExit();
38
- return () => {
39
- cancelled = true;
40
- };
41
- }, [
42
- isOpen,
43
- present,
44
- ref
45
- ]);
46
- return isOpen || present;
47
- }
48
- /**
49
- * React Aria가 위치 style에 넣는 `zIndex: 100000`을 빼고 주축 방향을 `data-placement`로 붙인다.
50
- * 쌓임은 쌓임 단계 class(`z-popover` 등)로만 정한다(spec 「오버레이」).
51
- *
52
- * `placement`가 아직 없으면(처음 렌더) 요청한 placement의 주축을 쓴다. 등장 전환의 시작 방향이 첫 스타일 계산에서
53
- * 정해지기 때문이다. 공간이 없어 뒤집힌 경우에만 첫 프레임의 시작 방향이 요청한 쪽이 된다(4px).
54
- */
55
- function overlayPositionProps(props, placement, requested) {
56
- const { zIndex: _zIndex, ...style } = props.style ?? {};
57
- const fallback = requested.split(" ")[0];
58
- return {
59
- ...props,
60
- style,
61
- "data-placement": isAxis(placement) ? placement : fallback
62
- };
63
- }
64
- /**
65
- * 트리거에 붙는 오버레이(Popover, Menu, Select·Combobox 목록)의 위치·닫기 동작. React Aria `usePopover`를 감싼다.
66
- * - 닫기: Esc, 바깥 누름, 포커스가 바깥으로 나감(`usePopover` 기본). 위에 쌓인 오버레이부터 닫힌다.
67
- * - 모달: 기본은 바깥을 `inert`로 막고 스크롤을 잠근다. `nonModal`이면 둘 다 하지 않는다.
68
- * - 위치: 공간이 모자라면 반대쪽으로 뒤집고, 주축 길이는 `max-height`로 줄여 트리거를 덮지 않는다(WCAG 2.4.11, Comments 참고).
69
- * 돌려받은 `overlayProps`(style 포함)를 오버레이 요소에 펼친다. 쌓임 단계 class는 부르는 쪽이 붙인다.
70
- */
71
- function usePopoverOverlay({ triggerRef, popoverRef, placement, offset, nonModal = false }, state) {
72
- const { popoverProps, placement: actual } = usePopover({
73
- triggerRef,
74
- popoverRef,
75
- placement,
76
- offset,
77
- isNonModal: nonModal
78
- }, state);
79
- return { overlayProps: overlayPositionProps(popoverProps, actual, placement) };
80
- }
81
- /**
82
- * 트리거가 놓인 Theme(`data-theme`)을 portal로 나간 오버레이에 옮긴다. Theme을 `<html>`이 아닌 일부 영역에
83
- * 붙인 앱에서도 오버레이가 같은 색이 된다. 오버레이에 이미 `data-theme`이 있으면 두고, 트리거 위에 Theme이 없으면
84
- * 붙이지 않는다(`:root` 기본값을 따른다). 위치를 계산하기 전(첫 스타일 계산 전)에 붙도록 위치 hook보다 먼저 부른다.
85
- */
86
- function useOverlayTheme(triggerRef, overlayRef) {
87
- useLayoutEffect(() => {
88
- const overlay = overlayRef.current;
89
- if (!overlay || overlay.hasAttribute("data-theme")) return;
90
- const theme = triggerRef.current?.closest("[data-theme]")?.getAttribute("data-theme");
91
- if (theme) overlay.setAttribute("data-theme", theme);
92
- }, [triggerRef, overlayRef]);
93
- }
94
- /**
95
- * 오버레이 안에서 Tab을 누르면 기본 동작을 막고 닫는다(포커스는 `OverlayPortal`의 FocusScope가 트리거로 돌린다).
96
- * 목록 오버레이(Menu, Select)가 쓴다(WAI-ARIA APG Menu Button·Select-Only Combobox: Tab은 목록을 닫는다).
97
- *
98
- * React Aria 목록 hook(useMenu·useListBox)은 Tab으로 닫지 않고, 항목의 keydown 처리가 전파를 멈추며 FocusScope가
99
- * document capture에서 Tab을 먼저 다룬다. 열린 동안 바깥은 inert라 브라우저 기본 Tab은 갈 곳이 없다. 그래서 그보다
100
- * 앞인 window capture에서 받는다(티켓 27에서 Menu 안에 두었다가 티켓 28에서 이곳으로 옮겼다).
101
- * 전파도 멈춘다. listbox(useListBox 안의 useSelectableCollection)는 Tab에서 포커스를 목록 안 요소로 옮기는데, 그러면
102
- * 닫힌 뒤 포커스가 트리거로 돌아오지 않았다(Select 테스트로 확인).
103
- */
104
- function useCloseOnTab(overlayRef, close) {
105
- useEffect(() => {
106
- const onKeyDown = (event) => {
107
- if (event.key !== "Tab" || !overlayRef.current?.contains(event.target)) return;
108
- event.preventDefault();
109
- event.stopPropagation();
110
- close();
111
- };
112
- window.addEventListener("keydown", onKeyDown, true);
113
- return () => window.removeEventListener("keydown", onKeyDown, true);
114
- }, [close, overlayRef]);
115
- }
116
- /**
117
- * 오버레이를 `document.body`에 portal한다(React Aria `Overlay`). top-layer(`<dialog>`, popover API)는 쓰지 않는다.
118
- * 안을 `FocusScope`(`restoreFocus`)로 감싸서, DOM에서 빠질 때 포커스가 열기 전 요소(보통 트리거)로 돌아간다.
119
- * 역할 hook이 포커스 가두기를 요청하면(`useDialog` 등) Tab이 안에서 돈다. 서버 렌더에서는 아무것도 그리지 않는다.
120
- * `focusManagement={false}`면 FocusScope 없이 portal만 한다(Tooltip).
121
- */
122
- function OverlayPortal({ isExiting, focusManagement = true, children }) {
123
- return /* @__PURE__ */ jsx(Overlay, {
124
- isExiting,
125
- disableFocusManagement: !focusManagement,
126
- children
127
- });
128
- }
129
-
130
- export { OverlayPortal, overlayPositionProps, useCloseOnTab, useOverlayPresence, useOverlayTheme, usePopoverOverlay };
package/dist/pressable.js DELETED
@@ -1,70 +0,0 @@
1
- // src/pressable.ts
2
- /**
3
- * 기본 색(배경, 글자, 경계). 색 이름마다 Foundation이 같은 대비 규칙으로 검사한다.
4
- * subtle 바탕 위 글자는 파스텔 글자 on-subtle이고(ADR 0022 §1), outline·ghost 글자는 바탕 없는 색 글자 text다.
5
- */
6
- const colorClass = {
7
- solid: "border-transparent bg-accent-solid text-accent-on-solid",
8
- subtle: "border-transparent bg-accent-subtle text-accent-on-subtle",
9
- outline: "border-accent text-accent",
10
- ghost: "border-transparent text-accent"
11
- };
12
- /** outline·ghost의 hover·누름 색. 아래 `interactionClass` 주석 참고. */
13
- const pressableTintClass = "[--pressable-hover:var(--tide-accent-faint)] [--pressable-active:var(--tide-accent-subtle)] data-[color=neutral]:[--pressable-hover:var(--tide-bg-hover)] data-[color=neutral]:[--pressable-active:var(--tide-bg-active)] hover:bg-(--pressable-hover) active:bg-(--pressable-active)";
14
- /** hover·누름 색. 활성 상태일 때만 붙인다(비활성·로딩에는 붙이지 않아 CSS 순서에 기대지 않는다). */
15
- const interactionClass = {
16
- solid: "hover:bg-accent-solid-hover active:bg-accent-solid-active",
17
- subtle: "hover:bg-accent-subtle-hover active:bg-accent-subtle-active",
18
- outline: pressableTintClass,
19
- ghost: pressableTintClass
20
- };
21
- /** 비활성 색. 색 이름과 관계없이 같다. disabled Token은 대비 검사 대상이 아니다. */
22
- const disabledClass = {
23
- solid: "cursor-not-allowed border-transparent bg-disabled text-disabled",
24
- subtle: "cursor-not-allowed border-transparent bg-disabled text-disabled",
25
- outline: "cursor-not-allowed border-default text-disabled",
26
- ghost: "cursor-not-allowed border-transparent text-disabled"
27
- };
28
- /** 모양의 공통 부분. radius는 모든 size에서 `md`다. 높이·폭·padding은 Component가 정한다. */
29
- const pressableBaseClass = "inline-flex shrink-0 items-center justify-center rounded-md border whitespace-nowrap select-none transition-colors focus-visible:focus-ring";
30
- const pressScaleClass = "motion-safe:transition-[color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,scale] motion-safe:active:scale-96";
31
- /** `disabled`를 네이티브로 지원하는 요소인지. Button류가 렌더할 만한 요소 중에서는 `button`뿐이다. */
32
- const supportsNativeDisabled = (render) => render === void 0 || render.type === "button";
33
- /**
34
- * 채움 방식·색·상태에서 class와 루트 props를 정한다.
35
- * - disabled: 기본 요소와 `render={<button />}`는 네이티브 `disabled`, 그 밖의 요소는 `aria-disabled`·`data-disabled`와 클릭 차단
36
- * - loading: 포커스를 남긴 채 `aria-disabled`·`data-loading`과 클릭 차단. disabled와 함께 오면 disabled가 이긴다
37
- * - 커서: 활성 pointer, 로딩 wait, 비활성 not-allowed
38
- * - hover·누름 색과 누름 축소는 활성 상태에서만 붙인다
39
- */
40
- function pressableState({ variant, color, disabled, loading, noPressScale, render, type, onClick, ariaDisabled }) {
41
- const native = supportsNativeDisabled(render);
42
- const softDisabled = disabled && !native;
43
- const blocked = softDisabled || loading && !disabled;
44
- const interactive = !disabled && !loading;
45
- const showSpinner = loading && !disabled;
46
- return {
47
- className: [
48
- disabled ? disabledClass[variant] : colorClass[variant],
49
- interactive ? interactionClass[variant] : void 0,
50
- interactive && !noPressScale ? pressScaleClass : void 0,
51
- interactive ? "cursor-pointer" : void 0,
52
- showSpinner ? "cursor-wait" : void 0
53
- ].filter(Boolean).join(" "),
54
- showSpinner,
55
- rootProps: {
56
- type: render === void 0 ? type ?? "button" : type,
57
- disabled: native && disabled ? true : void 0,
58
- "data-color": color,
59
- "aria-disabled": blocked ? true : ariaDisabled,
60
- "data-disabled": softDisabled ? "" : void 0,
61
- "data-loading": showSpinner ? "" : void 0,
62
- onClick: blocked ? (event) => {
63
- event.preventDefault();
64
- event.stopPropagation();
65
- } : onClick
66
- }
67
- };
68
- }
69
-
70
- export { pressableBaseClass, pressableState };
File without changes