@seed-design/lynx-react 0.4.1 → 0.5.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 (92) hide show
  1. package/lib/components/Accordion/Accordion.d.ts +56 -0
  2. package/lib/components/Accordion/Accordion.d.ts.map +1 -0
  3. package/lib/components/Accordion/Accordion.jsx +210 -0
  4. package/lib/components/Accordion/Accordion.namespace.d.ts +2 -0
  5. package/lib/components/Accordion/Accordion.namespace.d.ts.map +1 -0
  6. package/lib/components/Accordion/Accordion.namespace.js +17 -0
  7. package/lib/components/Accordion/index.d.ts +3 -0
  8. package/lib/components/Accordion/index.d.ts.map +1 -0
  9. package/lib/components/ActionButton/ActionButton.jsx +6 -6
  10. package/lib/components/AppBar/AppBar.jsx +1 -1
  11. package/lib/components/Badge/Badge.jsx +1 -1
  12. package/lib/components/BottomSheet/BottomSheet.d.ts.map +1 -1
  13. package/lib/components/BottomSheet/BottomSheet.jsx +6 -3
  14. package/lib/components/Box/Box.jsx +1 -1
  15. package/lib/components/Callout/Callout.d.ts +32 -0
  16. package/lib/components/Callout/Callout.d.ts.map +1 -0
  17. package/lib/components/Callout/Callout.jsx +113 -0
  18. package/lib/components/Callout/Callout.namespace.d.ts +2 -0
  19. package/lib/components/Callout/Callout.namespace.d.ts.map +1 -0
  20. package/lib/components/Callout/Callout.namespace.js +13 -0
  21. package/lib/components/Callout/index.d.ts +3 -0
  22. package/lib/components/Callout/index.d.ts.map +1 -0
  23. package/lib/components/Checkbox/Checkbox.d.ts.map +1 -1
  24. package/lib/components/Checkbox/Checkbox.jsx +36 -5
  25. package/lib/components/Chip/Chip.d.ts +66 -0
  26. package/lib/components/Chip/Chip.d.ts.map +1 -0
  27. package/lib/components/Chip/Chip.jsx +159 -0
  28. package/lib/components/Chip/Chip.namespace.d.ts +2 -0
  29. package/lib/components/Chip/Chip.namespace.d.ts.map +1 -0
  30. package/lib/components/Chip/Chip.namespace.js +16 -0
  31. package/lib/components/Chip/index.d.ts +3 -0
  32. package/lib/components/Chip/index.d.ts.map +1 -0
  33. package/lib/components/Divider/Divider.d.ts +31 -0
  34. package/lib/components/Divider/Divider.d.ts.map +1 -0
  35. package/lib/components/Divider/Divider.jsx +26 -0
  36. package/lib/components/Divider/index.d.ts +2 -0
  37. package/lib/components/Divider/index.d.ts.map +1 -0
  38. package/lib/components/Field/Field.jsx +1 -1
  39. package/lib/components/Icon/Icon.jsx +2 -2
  40. package/lib/components/ProgressCircle/ProgressCircle.jsx +2 -2
  41. package/lib/components/RadioGroup/RadioGroup.jsx +2 -2
  42. package/lib/components/Stack/Stack.jsx +1 -1
  43. package/lib/components/Switch/Switch.jsx +2 -2
  44. package/lib/components/Tabs/Tabs.d.ts +59 -0
  45. package/lib/components/Tabs/Tabs.d.ts.map +1 -0
  46. package/lib/components/Tabs/Tabs.jsx +406 -0
  47. package/lib/components/Tabs/Tabs.namespace.d.ts +2 -0
  48. package/lib/components/Tabs/Tabs.namespace.d.ts.map +1 -0
  49. package/lib/components/Tabs/Tabs.namespace.js +14 -0
  50. package/lib/components/Tabs/index.d.ts +3 -0
  51. package/lib/components/Tabs/index.d.ts.map +1 -0
  52. package/lib/components/TagGroup/TagGroup.jsx +2 -2
  53. package/lib/components/Text/Text.jsx +2 -2
  54. package/lib/components/TextField/TextField.jsx +2 -2
  55. package/lib/components/index.d.ts +5 -0
  56. package/lib/components/index.d.ts.map +1 -1
  57. package/lib/hooks/useIconColor.d.ts +2 -1
  58. package/lib/hooks/useIconColor.d.ts.map +1 -1
  59. package/lib/hooks/useIconColor.js +29 -5
  60. package/lib/hooks/usePressTap.d.ts.map +1 -1
  61. package/lib/hooks/usePressTap.js +1 -0
  62. package/lib/index.js +14 -5
  63. package/lib/utils/create-slot-recipe-context.jsx +1 -1
  64. package/package.json +2 -2
  65. package/src/components/Accordion/Accordion.namespace.ts +22 -0
  66. package/src/components/Accordion/Accordion.test.tsx +129 -0
  67. package/src/components/Accordion/Accordion.tsx +453 -0
  68. package/src/components/Accordion/index.ts +24 -0
  69. package/src/components/BottomSheet/BottomSheet.test.tsx +24 -0
  70. package/src/components/BottomSheet/BottomSheet.tsx +14 -2
  71. package/src/components/Callout/Callout.namespace.ts +14 -0
  72. package/src/components/Callout/Callout.test.tsx +188 -0
  73. package/src/components/Callout/Callout.tsx +272 -0
  74. package/src/components/Callout/index.ts +16 -0
  75. package/src/components/Checkbox/Checkbox.test.tsx +176 -0
  76. package/src/components/Checkbox/Checkbox.tsx +36 -2
  77. package/src/components/Chip/Chip.namespace.ts +20 -0
  78. package/src/components/Chip/Chip.test.tsx +113 -0
  79. package/src/components/Chip/Chip.tsx +373 -0
  80. package/src/components/Chip/index.ts +22 -0
  81. package/src/components/Divider/Divider.test.tsx +73 -0
  82. package/src/components/Divider/Divider.tsx +76 -0
  83. package/src/components/Divider/index.ts +1 -0
  84. package/src/components/Icon/Icon.test.tsx +129 -0
  85. package/src/components/Tabs/Tabs.namespace.ts +16 -0
  86. package/src/components/Tabs/Tabs.test.tsx +181 -0
  87. package/src/components/Tabs/Tabs.tsx +706 -0
  88. package/src/components/Tabs/index.ts +2 -0
  89. package/src/components/index.ts +5 -0
  90. package/src/hooks/useIconColor.ts +43 -5
  91. package/src/hooks/usePressTap.test.ts +13 -0
  92. package/src/hooks/usePressTap.ts +1 -0
@@ -1,9 +1,13 @@
1
+ export * from "./Accordion";
1
2
  export * from "./ActionButton";
2
3
  export * from "./AppBar";
3
4
  export * from "./Badge";
4
5
  export * from "./Box";
5
6
  export * from "./BottomSheet";
7
+ export * from "./Callout";
6
8
  export * from "./Checkbox";
9
+ export * from "./Chip";
10
+ export * from "./Divider";
7
11
  export * from "./Field";
8
12
  export * from "./Icon";
9
13
  export * from "./KeyboardAvoidingScrollView";
@@ -11,6 +15,7 @@ export * from "./ProgressCircle";
11
15
  export * from "./RadioGroup";
12
16
  export * from "./Stack";
13
17
  export * from "./Switch";
18
+ export * from "./Tabs";
14
19
  export * from "./TagGroup";
15
20
  export * from "./Text";
16
21
  export * from "./TextField";
@@ -14,7 +14,7 @@ export interface UseIconColorOptions {
14
14
  // Lynx `<image>` 의 `tint-color` attribute 에 CSS variable 문자열을 직접 넣는 경로는
15
15
  // 안정적으로 동작하지 않는다. CSS `color` 는 computed style 로 resolved color 를 읽을 수
16
16
  // 있으므로 main-thread 에서 한 번 읽어 `tint-color` 로 mirror 한다.
17
- function syncTintColor(targetRef: RefObject<IconElement>, sourceRef?: RefObject<IconElement>) {
17
+ function syncTintColorOnce(targetRef: RefObject<IconElement>, sourceRef?: RefObject<IconElement>) {
18
18
  "main thread";
19
19
 
20
20
  const target = targetRef.current;
@@ -29,14 +29,48 @@ function syncTintColor(targetRef: RefObject<IconElement>, sourceRef?: RefObject<
29
29
  color = source.getComputedCssProperty("color");
30
30
  }
31
31
 
32
- if (color) {
32
+ if (color && target.getAttribute("tint-color") !== color) {
33
33
  target.setAttribute("tint-color", color);
34
34
  }
35
35
  }
36
36
 
37
+ function scheduleTintColorSync(
38
+ targetRef: RefObject<IconElement>,
39
+ sourceRef: RefObject<IconElement> | undefined,
40
+ frameRef: RefObject<number>,
41
+ ) {
42
+ "main thread";
43
+
44
+ if (frameRef.current && typeof cancelAnimationFrame === "function") {
45
+ cancelAnimationFrame(frameRef.current);
46
+ frameRef.current = 0;
47
+ }
48
+
49
+ // ReactLynx는 effect worklet을 native class patch flush보다 먼저 실행할 수 있다.
50
+ // 다음 frame에서 class patch가 반영된 computed color를 읽는다.
51
+ if (typeof requestAnimationFrame === "function") {
52
+ frameRef.current = requestAnimationFrame(() => {
53
+ frameRef.current = 0;
54
+ syncTintColorOnce(targetRef, sourceRef);
55
+ });
56
+ } else {
57
+ syncTintColorOnce(targetRef, sourceRef);
58
+ }
59
+ }
60
+
61
+ function cancelTintColorSync(frameRef: RefObject<number>) {
62
+ "main thread";
63
+
64
+ if (frameRef.current && typeof cancelAnimationFrame === "function") {
65
+ cancelAnimationFrame(frameRef.current);
66
+ frameRef.current = 0;
67
+ }
68
+ }
69
+
37
70
  /**
38
71
  * Lynx `<image>` 의 tint color 를 recipe 의 CSS `color` 로부터 main-thread 에서 읽어
39
- * `tint-color` attribute 로 mirror. `deps` 가 바뀌면 재동기화.
72
+ * `tint-color` attribute 로 mirror. `deps` 가 바뀌면 native class patch가 반영된
73
+ * 다음 frame에 재동기화하고, UI 표시 이벤트에서는 즉시 동기화.
40
74
  *
41
75
  * ```tsx
42
76
  * const iconColorProps = useIconColor([variant, disabled, loading]);
@@ -52,15 +86,19 @@ export function useIconColor(
52
86
  } {
53
87
  const ref = useMainThreadRef<IconElement>(null);
54
88
  const sourceRef = options?.sourceRef as RefObject<IconElement> | undefined;
89
+ const frameRef = useMainThreadRef<number>(0);
55
90
 
56
91
  function syncOnUiAppear() {
57
92
  "main thread";
58
- syncTintColor(ref, sourceRef);
93
+ syncTintColorOnce(ref, sourceRef);
59
94
  }
60
95
 
61
96
  // deps 는 caller 가 책임.
62
97
  useEffect(() => {
63
- runOnMainThread(syncTintColor)(ref, sourceRef);
98
+ runOnMainThread(scheduleTintColorSync)(ref, sourceRef, frameRef);
99
+ return () => {
100
+ runOnMainThread(cancelTintColorSync)(frameRef);
101
+ };
64
102
  }, deps);
65
103
 
66
104
  return { ref, "main-thread:binduiappear": syncOnUiAppear };
@@ -60,6 +60,19 @@ describe("usePressTap", () => {
60
60
  expect(onTap).toHaveBeenCalledTimes(1);
61
61
  });
62
62
 
63
+ it("clears pressed when bindtap fires before touchend", () => {
64
+ const { result } = renderHook(() => usePressTap({ onTap: vi.fn() }));
65
+
66
+ act(() => {
67
+ result.current.bindtouchstart(fakeEvent);
68
+ });
69
+ act(() => {
70
+ result.current.bindtap(fakeEvent);
71
+ });
72
+
73
+ expect(result.current.pressed).toBe(false);
74
+ });
75
+
63
76
  it("can be omitted without error", () => {
64
77
  const { result } = renderHook(() => usePressTap());
65
78
 
@@ -44,6 +44,7 @@ export function usePressTap(options: UsePressTapOptions = {}): UsePressTapReturn
44
44
 
45
45
  const handleTap = useMemoizedFn((...args: Parameters<TouchHandler>) => {
46
46
  if (disabled) return;
47
+ setPressed(false);
47
48
  onTap?.(...args);
48
49
  });
49
50