@seed-design/lynx-react 0.1.1-alpha.0 → 0.2.0-alpha.2
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/lib/components/ActionButton/ActionButton.d.ts +40 -9
- package/lib/components/ActionButton/ActionButton.d.ts.map +1 -1
- package/lib/components/ActionButton/ActionButton.jsx +132 -14
- package/lib/components/BottomSheet/BottomSheet.d.ts +92 -0
- package/lib/components/BottomSheet/BottomSheet.d.ts.map +1 -0
- package/lib/components/BottomSheet/BottomSheet.jsx +178 -0
- package/lib/components/BottomSheet/BottomSheet.namespace.d.ts +2 -0
- package/lib/components/BottomSheet/BottomSheet.namespace.d.ts.map +1 -0
- package/lib/components/BottomSheet/BottomSheet.namespace.js +1 -0
- package/lib/components/BottomSheet/index.d.ts +3 -0
- package/lib/components/BottomSheet/index.d.ts.map +1 -0
- package/lib/components/BottomSheet/index.js +2 -0
- package/lib/components/Checkbox/Checkbox.d.ts +51 -0
- package/lib/components/Checkbox/Checkbox.d.ts.map +1 -0
- package/lib/components/Checkbox/Checkbox.jsx +121 -0
- package/lib/components/Checkbox/Checkbox.namespace.d.ts +2 -0
- package/lib/components/Checkbox/Checkbox.namespace.d.ts.map +1 -0
- package/lib/components/Checkbox/Checkbox.namespace.js +1 -0
- package/lib/components/Checkbox/index.d.ts +3 -0
- package/lib/components/Checkbox/index.d.ts.map +1 -0
- package/lib/components/Checkbox/index.js +2 -0
- package/lib/components/ProgressCircle/ProgressCircle.d.ts +10 -9
- package/lib/components/ProgressCircle/ProgressCircle.d.ts.map +1 -1
- package/lib/components/ProgressCircle/ProgressCircle.jsx +8 -14
- package/lib/components/ProgressCircle/ProgressCircle.namespace.d.ts +2 -0
- package/lib/components/ProgressCircle/ProgressCircle.namespace.d.ts.map +1 -0
- package/lib/components/ProgressCircle/ProgressCircle.namespace.js +1 -0
- package/lib/components/ProgressCircle/index.d.ts +2 -1
- package/lib/components/ProgressCircle/index.d.ts.map +1 -1
- package/lib/components/ProgressCircle/index.js +2 -1
- package/lib/components/RadioGroup/RadioGroup.d.ts +50 -0
- package/lib/components/RadioGroup/RadioGroup.d.ts.map +1 -0
- package/lib/components/RadioGroup/RadioGroup.jsx +144 -0
- package/lib/components/RadioGroup/RadioGroup.namespace.d.ts +2 -0
- package/lib/components/RadioGroup/RadioGroup.namespace.d.ts.map +1 -0
- package/lib/components/RadioGroup/RadioGroup.namespace.js +1 -0
- package/lib/components/RadioGroup/index.d.ts +3 -0
- package/lib/components/RadioGroup/index.d.ts.map +1 -0
- package/lib/components/RadioGroup/index.js +2 -0
- package/lib/components/Switch/Switch.d.ts +27 -0
- package/lib/components/Switch/Switch.d.ts.map +1 -0
- package/lib/components/Switch/Switch.jsx +75 -0
- package/lib/components/Switch/Switch.namespace.d.ts +2 -0
- package/lib/components/Switch/Switch.namespace.d.ts.map +1 -0
- package/lib/components/Switch/Switch.namespace.js +1 -0
- package/lib/components/Switch/index.d.ts +3 -0
- package/lib/components/Switch/index.d.ts.map +1 -0
- package/lib/components/Switch/index.js +2 -0
- package/lib/components/TagGroup/TagGroup.d.ts +40 -0
- package/lib/components/TagGroup/TagGroup.d.ts.map +1 -0
- package/lib/components/TagGroup/TagGroup.jsx +54 -0
- package/lib/components/TagGroup/TagGroup.namespace.d.ts +2 -0
- package/lib/components/TagGroup/TagGroup.namespace.d.ts.map +1 -0
- package/lib/components/TagGroup/TagGroup.namespace.js +1 -0
- package/lib/components/TagGroup/index.d.ts +3 -0
- package/lib/components/TagGroup/index.d.ts.map +1 -0
- package/lib/components/TagGroup/index.js +2 -0
- package/lib/components/index.d.ts +8 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/components/index.js +7 -0
- package/lib/hooks/index.d.ts +4 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/index.js +3 -0
- package/lib/hooks/use-controllable-state.d.ts +15 -0
- package/lib/hooks/use-controllable-state.d.ts.map +1 -0
- package/lib/hooks/use-controllable-state.js +27 -0
- package/lib/hooks/use-icon-color.d.ts +15 -0
- package/lib/hooks/use-icon-color.d.ts.map +1 -0
- package/lib/hooks/use-icon-color.js +37 -0
- package/lib/hooks/use-press-tap.d.ts +24 -0
- package/lib/hooks/use-press-tap.d.ts.map +1 -0
- package/lib/hooks/use-press-tap.js +35 -0
- package/lib/index.d.ts +3 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -4
- package/lib/utils/create-slot-recipe-context.d.ts +26 -0
- package/lib/utils/create-slot-recipe-context.d.ts.map +1 -0
- package/lib/utils/create-slot-recipe-context.jsx +76 -0
- package/lib/utils/get-seed-class-name.d.ts.map +1 -0
- package/lib/utils/index.d.ts +5 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +4 -0
- package/lib/utils/resolve-recipe-token.d.ts +38 -0
- package/lib/utils/resolve-recipe-token.d.ts.map +1 -0
- package/lib/utils/resolve-recipe-token.js +47 -0
- package/lib/utils/split-multiple-variants-props.d.ts +29 -0
- package/lib/utils/split-multiple-variants-props.d.ts.map +1 -0
- package/lib/utils/split-multiple-variants-props.js +34 -0
- package/package.json +12 -9
- package/src/components/ActionButton/ActionButton.tsx +290 -31
- package/src/components/ActionButton/__tests__/ActionButton.test.tsx +35 -0
- package/src/components/BottomSheet/BottomSheet.namespace.ts +24 -0
- package/src/components/BottomSheet/BottomSheet.tsx +386 -0
- package/src/components/BottomSheet/__tests__/BottomSheet.test.tsx +119 -0
- package/src/components/BottomSheet/index.ts +27 -0
- package/src/components/Checkbox/Checkbox.namespace.ts +12 -0
- package/src/components/Checkbox/Checkbox.tsx +291 -0
- package/src/components/Checkbox/index.ts +14 -0
- package/src/components/ProgressCircle/ProgressCircle.namespace.ts +5 -0
- package/src/components/ProgressCircle/ProgressCircle.tsx +14 -13
- package/src/components/ProgressCircle/index.ts +9 -1
- package/src/components/RadioGroup/RadioGroup.namespace.ts +12 -0
- package/src/components/RadioGroup/RadioGroup.tsx +338 -0
- package/src/components/RadioGroup/index.ts +14 -0
- package/src/components/Switch/Switch.namespace.ts +10 -0
- package/src/components/Switch/Switch.tsx +191 -0
- package/src/components/Switch/index.ts +12 -0
- package/src/components/TagGroup/TagGroup.namespace.ts +8 -0
- package/src/components/TagGroup/TagGroup.tsx +125 -0
- package/src/components/TagGroup/index.ts +10 -0
- package/src/components/__tests__/ProgressCircle.test.ts +33 -0
- package/src/components/__tests__/exports.test.ts +38 -0
- package/src/components/__tests__/switch.test.ts +34 -0
- package/src/components/index.ts +7 -0
- package/src/hooks/__tests__/use-controllable-state.test.ts +120 -0
- package/src/hooks/__tests__/use-press-tap.test.ts +129 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/use-controllable-state.ts +38 -0
- package/src/hooks/use-icon-color.ts +51 -0
- package/src/hooks/use-press-tap.ts +54 -0
- package/src/index.ts +3 -4
- package/src/utils/__tests__/create-slot-recipe-context.test.tsx +228 -0
- package/src/utils/__tests__/split-multiple-variants-props.test.ts +61 -0
- package/src/utils/create-slot-recipe-context.tsx +147 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/resolve-recipe-token.ts +47 -0
- package/src/utils/split-multiple-variants-props.ts +59 -0
- package/lib/components/Box/Box.d.ts +0 -10
- package/lib/components/Box/Box.d.ts.map +0 -1
- package/lib/components/Box/Box.jsx +0 -19
- package/lib/components/Box/index.d.ts +0 -2
- package/lib/components/Box/index.d.ts.map +0 -1
- package/lib/components/Box/index.js +0 -1
- package/lib/components/Flex/Flex.d.ts +0 -33
- package/lib/components/Flex/Flex.d.ts.map +0 -1
- package/lib/components/Flex/Flex.jsx +0 -7
- package/lib/components/Flex/index.d.ts +0 -2
- package/lib/components/Flex/index.d.ts.map +0 -1
- package/lib/components/Flex/index.js +0 -1
- package/lib/components/List/List.d.ts +0 -9
- package/lib/components/List/List.d.ts.map +0 -1
- package/lib/components/List/List.jsx +0 -17
- package/lib/components/List/index.d.ts +0 -2
- package/lib/components/List/index.d.ts.map +0 -1
- package/lib/components/List/index.js +0 -1
- package/lib/components/ListItem/ListItem.d.ts +0 -8
- package/lib/components/ListItem/ListItem.d.ts.map +0 -1
- package/lib/components/ListItem/ListItem.jsx +0 -11
- package/lib/components/ListItem/index.d.ts +0 -2
- package/lib/components/ListItem/index.d.ts.map +0 -1
- package/lib/components/ListItem/index.js +0 -1
- package/lib/components/ScrollView/ScrollView.d.ts +0 -9
- package/lib/components/ScrollView/ScrollView.d.ts.map +0 -1
- package/lib/components/ScrollView/ScrollView.jsx +0 -17
- package/lib/components/ScrollView/index.d.ts +0 -2
- package/lib/components/ScrollView/index.d.ts.map +0 -1
- package/lib/components/ScrollView/index.js +0 -1
- package/lib/components/Stack/Stack.d.ts +0 -6
- package/lib/components/Stack/Stack.d.ts.map +0 -1
- package/lib/components/Stack/Stack.jsx +0 -10
- package/lib/components/Stack/index.d.ts +0 -2
- package/lib/components/Stack/index.d.ts.map +0 -1
- package/lib/components/Stack/index.js +0 -1
- package/lib/components/Text/Text.d.ts +0 -30
- package/lib/components/Text/Text.d.ts.map +0 -1
- package/lib/components/Text/Text.jsx +0 -49
- package/lib/components/Text/index.d.ts +0 -2
- package/lib/components/Text/index.d.ts.map +0 -1
- package/lib/components/Text/index.js +0 -1
- package/lib/get-seed-class-name.d.ts.map +0 -1
- package/lib/utils/dynamic-style.d.ts +0 -13
- package/lib/utils/dynamic-style.d.ts.map +0 -1
- package/lib/utils/dynamic-style.js +0 -26
- package/lib/utils/styled.d.ts +0 -120
- package/lib/utils/styled.d.ts.map +0 -1
- package/lib/utils/styled.jsx +0 -131
- package/src/utils/dynamic-style.ts +0 -26
- /package/lib/{get-seed-class-name.d.ts → utils/get-seed-class-name.d.ts} +0 -0
- /package/lib/{get-seed-class-name.js → utils/get-seed-class-name.js} +0 -0
- /package/src/{get-seed-class-name.ts → utils/get-seed-class-name.ts} +0 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bottomSheet,
|
|
3
|
+
type BottomSheetVariantProps,
|
|
4
|
+
} from "@seed-design/lynx-css/recipes/bottom-sheet";
|
|
5
|
+
import { bottomSheetHandle } from "@seed-design/lynx-css/recipes/bottom-sheet-handle";
|
|
6
|
+
import {
|
|
7
|
+
SheetBackdrop,
|
|
8
|
+
SheetContent,
|
|
9
|
+
SheetHandle,
|
|
10
|
+
SheetRoot,
|
|
11
|
+
SheetView,
|
|
12
|
+
type SheetBackdropProps,
|
|
13
|
+
type SheetContentProps,
|
|
14
|
+
type SheetHandleProps,
|
|
15
|
+
type SheetRootProps,
|
|
16
|
+
type SheetRootRef,
|
|
17
|
+
type SheetTransition,
|
|
18
|
+
type SheetViewProps,
|
|
19
|
+
} from "@lynx-js/lynx-ui-sheet";
|
|
20
|
+
import {
|
|
21
|
+
createContext,
|
|
22
|
+
forwardRef,
|
|
23
|
+
useCallback,
|
|
24
|
+
useContext,
|
|
25
|
+
useMemo,
|
|
26
|
+
useRef,
|
|
27
|
+
type ReactNode,
|
|
28
|
+
type Ref,
|
|
29
|
+
type RefObject,
|
|
30
|
+
} from "@lynx-js/react";
|
|
31
|
+
import type { CSSProperties } from "react";
|
|
32
|
+
import clsx from "clsx";
|
|
33
|
+
|
|
34
|
+
import { createSlotRecipeContext } from "../../utils/create-slot-recipe-context";
|
|
35
|
+
|
|
36
|
+
type BottomSheetClassNames = ReturnType<typeof bottomSheet>;
|
|
37
|
+
|
|
38
|
+
const { ClassNamesProvider, useClassNames, withContext } = createSlotRecipeContext(bottomSheet);
|
|
39
|
+
|
|
40
|
+
const DEFAULT_SNAP_POINTS: Array<number | string> = ["fit"];
|
|
41
|
+
const SKIP_ANIMATION_TRANSITION: SheetTransition = {
|
|
42
|
+
type: "tween",
|
|
43
|
+
duration: 0,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
47
|
+
// SEED Transitions — 웹 SEED BottomSheet (recipe: d6/d4 + enter-expressive/enter/exit)
|
|
48
|
+
// 의 감각을 lynx-ui-sheet의 spring으로 근사한 기본값.
|
|
49
|
+
//
|
|
50
|
+
// spring을 사용하는 이유:
|
|
51
|
+
// - lynx-ui-sheet 내장 main-thread 구현이라 stiffness/damping/mass만 JSON 직렬화로
|
|
52
|
+
// 안전 전달 (ease 함수 크로스스레드 문제 없음)
|
|
53
|
+
// - lynx-ui 공식 예제도 spring 기본 — 런타임 안정성 검증됨
|
|
54
|
+
//
|
|
55
|
+
// 튜닝 기준 (300ms 수준의 빠르고 약간의 탄성감):
|
|
56
|
+
// - 웹 d6 + enter-expressive ≈ stiffness 400, damping 35 (snap 드래그 settle)
|
|
57
|
+
// - 웹 d6 + enter ≈ stiffness 350, damping 32 (첫 open)
|
|
58
|
+
// - 웹 d4 + exit ≈ stiffness 400, damping 40 (close, critically damped)
|
|
59
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
60
|
+
|
|
61
|
+
const SEED_SNAP_ANIMATION: SheetTransition = {
|
|
62
|
+
type: "spring",
|
|
63
|
+
stiffness: 400,
|
|
64
|
+
damping: 35,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const SEED_ENTER_ANIMATION: SheetTransition = {
|
|
68
|
+
type: "spring",
|
|
69
|
+
stiffness: 350,
|
|
70
|
+
damping: 32,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const SEED_EXIT_ANIMATION: SheetTransition = {
|
|
74
|
+
type: "spring",
|
|
75
|
+
stiffness: 400,
|
|
76
|
+
damping: 40,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Trigger와 Content가 Root의 imperative API와 동작 옵션을 공유하는 내부 컨텍스트.
|
|
81
|
+
*/
|
|
82
|
+
interface BottomSheetContextValue {
|
|
83
|
+
rootRef: RefObject<SheetRootRef | null>;
|
|
84
|
+
options: {
|
|
85
|
+
skipAnimation: boolean;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const BottomSheetContext = createContext<BottomSheetContextValue | null>(null);
|
|
90
|
+
|
|
91
|
+
function useBottomSheetContext(): BottomSheetContextValue {
|
|
92
|
+
const ctx = useContext(BottomSheetContext);
|
|
93
|
+
if (!ctx) {
|
|
94
|
+
throw new Error("BottomSheet compound components must be used within BottomSheetRoot");
|
|
95
|
+
}
|
|
96
|
+
return ctx;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
100
|
+
// Root
|
|
101
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
102
|
+
|
|
103
|
+
export type BottomSheetRootRef = SheetRootRef;
|
|
104
|
+
|
|
105
|
+
export interface BottomSheetRootProps
|
|
106
|
+
extends BottomSheetVariantProps,
|
|
107
|
+
Omit<SheetRootProps, "show" | "defaultShow" | "onShowChange"> {
|
|
108
|
+
/**
|
|
109
|
+
* Whether the sheet is open (controlled mode).
|
|
110
|
+
* Internally mapped to `show` of `@lynx-js/lynx-ui-sheet`.
|
|
111
|
+
*/
|
|
112
|
+
open?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Whether the sheet is open by default (uncontrolled mode).
|
|
115
|
+
* Internally mapped to `defaultShow`.
|
|
116
|
+
* @defaultValue false
|
|
117
|
+
*/
|
|
118
|
+
defaultOpen?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Called when the sheet's open state is about to change.
|
|
121
|
+
* Internally mapped to `onShowChange`.
|
|
122
|
+
*/
|
|
123
|
+
onOpenChange?: (open: boolean) => void;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @platform Lynx — wraps `@lynx-js/lynx-ui-sheet`
|
|
128
|
+
*
|
|
129
|
+
* 웹 대비 미지원 기능:
|
|
130
|
+
* - `lazyMount`, `unmountOnExit`: lynx-ui-sheet의 `forceMount`로 대체
|
|
131
|
+
* - `BottomSheetPositioner`: lynx-ui-sheet의 `SheetView`가 자동 처리하므로 별도 슬롯 없음
|
|
132
|
+
* - `BottomSheetCloseButton`: Tier B (Lynx SVG 지원 후 추가 예정)
|
|
133
|
+
* - `BottomSheetTrigger`의 `asChild`: 미지원 (기본 `<view>`만)
|
|
134
|
+
*/
|
|
135
|
+
export const BottomSheetRoot = forwardRef<SheetRootRef, BottomSheetRootProps>(
|
|
136
|
+
(props, forwardedRef) => {
|
|
137
|
+
const [variantProps, restProps] = bottomSheet.splitVariantProps(props);
|
|
138
|
+
const { open, defaultOpen, onOpenChange, snapPoints, children, ...nativeProps } = restProps;
|
|
139
|
+
const { headerAlign, skipAnimation } = variantProps;
|
|
140
|
+
|
|
141
|
+
const internalRef = useRef<SheetRootRef | null>(null);
|
|
142
|
+
|
|
143
|
+
// `SheetRoot`에 직접 ref를 넘겨 Trigger 컨텍스트와 외부 ref에 같은 인스턴스를 동기화한다.
|
|
144
|
+
// `useImperativeHandle([])`은 마운트 시점 값(null)을 고정시키는 함정이 있어 사용하지 않는다.
|
|
145
|
+
const mergedRef = useCallback(
|
|
146
|
+
(value: SheetRootRef | null) => {
|
|
147
|
+
internalRef.current = value;
|
|
148
|
+
if (typeof forwardedRef === "function") {
|
|
149
|
+
forwardedRef(value);
|
|
150
|
+
} else if (forwardedRef) {
|
|
151
|
+
forwardedRef.current = value;
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
[forwardedRef],
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const classNames = useMemo(
|
|
158
|
+
() => bottomSheet(variantProps),
|
|
159
|
+
// variantProps 객체는 매 렌더 새로 생성되므로 개별 variant 값으로 의존성을 고정한다.
|
|
160
|
+
[headerAlign, skipAnimation],
|
|
161
|
+
);
|
|
162
|
+
const shouldSkipAnimation = skipAnimation === true;
|
|
163
|
+
const context = useMemo(
|
|
164
|
+
() => ({
|
|
165
|
+
rootRef: internalRef,
|
|
166
|
+
options: {
|
|
167
|
+
skipAnimation: shouldSkipAnimation,
|
|
168
|
+
},
|
|
169
|
+
}),
|
|
170
|
+
[shouldSkipAnimation],
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<BottomSheetContext.Provider value={context}>
|
|
175
|
+
<ClassNamesProvider value={classNames}>
|
|
176
|
+
<SheetRoot
|
|
177
|
+
ref={mergedRef}
|
|
178
|
+
show={open}
|
|
179
|
+
defaultShow={defaultOpen}
|
|
180
|
+
onShowChange={onOpenChange}
|
|
181
|
+
snapPoints={snapPoints ?? DEFAULT_SNAP_POINTS}
|
|
182
|
+
{...nativeProps}
|
|
183
|
+
>
|
|
184
|
+
{children}
|
|
185
|
+
</SheetRoot>
|
|
186
|
+
</ClassNamesProvider>
|
|
187
|
+
</BottomSheetContext.Provider>
|
|
188
|
+
);
|
|
189
|
+
},
|
|
190
|
+
);
|
|
191
|
+
BottomSheetRoot.displayName = "BottomSheetRoot";
|
|
192
|
+
|
|
193
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
194
|
+
// Trigger
|
|
195
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
196
|
+
|
|
197
|
+
export interface BottomSheetTriggerProps {
|
|
198
|
+
children?: ReactNode;
|
|
199
|
+
className?: string;
|
|
200
|
+
style?: CSSProperties;
|
|
201
|
+
bindtap?: () => void;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export const BottomSheetTrigger = forwardRef<unknown, BottomSheetTriggerProps>((props, ref) => {
|
|
205
|
+
const { children, className, style, bindtap: userBindtap } = props;
|
|
206
|
+
const { rootRef, options } = useBottomSheetContext();
|
|
207
|
+
|
|
208
|
+
// `bindtap`을 직접 prop으로 쓰면 React DOM `<view>` 타입(SVG)이 적용되어 TS가 거부한다.
|
|
209
|
+
// Lynx JSX 런타임은 이 prop을 올바르게 처리하므로 spread로 우회한다 (ActionButton과 동일 패턴).
|
|
210
|
+
const handlers = {
|
|
211
|
+
bindtap: () => {
|
|
212
|
+
if (options.skipAnimation) {
|
|
213
|
+
rootRef.current?.open({ animate: false });
|
|
214
|
+
} else {
|
|
215
|
+
rootRef.current?.open();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
userBindtap?.();
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<view
|
|
224
|
+
{...(ref ? { ref: ref as Ref<SVGViewElement> } : {})}
|
|
225
|
+
{...handlers}
|
|
226
|
+
className={className}
|
|
227
|
+
style={style}
|
|
228
|
+
>
|
|
229
|
+
{children}
|
|
230
|
+
</view>
|
|
231
|
+
);
|
|
232
|
+
});
|
|
233
|
+
BottomSheetTrigger.displayName = "BottomSheetTrigger";
|
|
234
|
+
|
|
235
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
236
|
+
// Positioner — SheetView를 래핑해 mount gating 담당 (웹 BottomSheetPositioner에 대응)
|
|
237
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
238
|
+
|
|
239
|
+
export interface BottomSheetPositionerProps extends SheetViewProps {}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Backdrop/Content는 반드시 `BottomSheetPositioner` 안에 배치해야 한다.
|
|
243
|
+
*
|
|
244
|
+
* `SheetView`는 `mounted || forceMount` 조건으로 자식을 gating하므로 시트가 처음
|
|
245
|
+
* 열리기 전까지는 SheetBackdrop/SheetContent가 마운트되지 않아 motion value
|
|
246
|
+
* 초기화 레이스를 피할 수 있다. Trigger는 이 컴포넌트 밖에 두어야 탭 가능하다.
|
|
247
|
+
*
|
|
248
|
+
* recipe의 `positioner` slot className을 자동 적용해 `position: fixed` + 전체
|
|
249
|
+
* 뷰포트 커버 레이아웃을 보장한다.
|
|
250
|
+
*/
|
|
251
|
+
export const BottomSheetPositioner = withContext<unknown, BottomSheetPositionerProps>(
|
|
252
|
+
SheetView,
|
|
253
|
+
"positioner",
|
|
254
|
+
);
|
|
255
|
+
BottomSheetPositioner.displayName = "BottomSheetPositioner";
|
|
256
|
+
|
|
257
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
258
|
+
// Backdrop / Content — lynx-ui-sheet 컴포넌트를 감싸서 recipe 슬롯 className 적용
|
|
259
|
+
//
|
|
260
|
+
// lynx-ui-sheet의 컴포넌트는 React 함수 컴포넌트이므로 `withContext`로 래핑해도
|
|
261
|
+
// `React.createElement(Component, ...)`가 정상 동작한다.
|
|
262
|
+
// (반면 네이티브 `<view>`/`<text>` intrinsic은 리터럴 JSX가 아니면 Lynx 컴파일러의
|
|
263
|
+
// BackgroundSnapshot 정적 분석을 우회해 런타임 에러가 발생한다 — 하단 slot 참고.)
|
|
264
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
265
|
+
|
|
266
|
+
export interface BottomSheetBackdropProps extends SheetBackdropProps {}
|
|
267
|
+
|
|
268
|
+
export const BottomSheetBackdrop = withContext<unknown, BottomSheetBackdropProps>(
|
|
269
|
+
SheetBackdrop,
|
|
270
|
+
"backdrop",
|
|
271
|
+
);
|
|
272
|
+
BottomSheetBackdrop.displayName = "BottomSheetBackdrop";
|
|
273
|
+
|
|
274
|
+
export interface BottomSheetContentProps extends SheetContentProps {}
|
|
275
|
+
|
|
276
|
+
export const BottomSheetContent = forwardRef<unknown, BottomSheetContentProps>((props, ref) => {
|
|
277
|
+
const { className, snapAnimation, enterAnimation, exitAnimation, ...restProps } = props;
|
|
278
|
+
const classNames = useClassNames();
|
|
279
|
+
const { options } = useBottomSheetContext();
|
|
280
|
+
|
|
281
|
+
const defaultAnimation = options.skipAnimation ? SKIP_ANIMATION_TRANSITION : undefined;
|
|
282
|
+
|
|
283
|
+
return (
|
|
284
|
+
<SheetContent
|
|
285
|
+
{...(ref ? { ref } : {})}
|
|
286
|
+
{...restProps}
|
|
287
|
+
className={clsx(classNames.content, className)}
|
|
288
|
+
snapAnimation={snapAnimation ?? defaultAnimation ?? SEED_SNAP_ANIMATION}
|
|
289
|
+
enterAnimation={enterAnimation ?? defaultAnimation ?? SEED_ENTER_ANIMATION}
|
|
290
|
+
exitAnimation={exitAnimation ?? defaultAnimation ?? SEED_EXIT_ANIMATION}
|
|
291
|
+
/>
|
|
292
|
+
);
|
|
293
|
+
});
|
|
294
|
+
BottomSheetContent.displayName = "BottomSheetContent";
|
|
295
|
+
|
|
296
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
297
|
+
// Handle — 자체 bottomSheetHandle recipe 사용 (Root context 비의존)
|
|
298
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
299
|
+
|
|
300
|
+
export interface BottomSheetHandleProps extends SheetHandleProps {}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* @remarks
|
|
304
|
+
* `SheetHandle`은 forwardRef가 아니므로 ref 시그니처는 제공하지 않는다. touchArea 슬롯은
|
|
305
|
+
* `SheetHandle` JSX가 정적으로 children을 받지 않는 구조라 적용하지 않는다 (Lynx
|
|
306
|
+
* BackgroundSnapshot이 정적 slot 외의 동적 children 삽입을 허용하지 않음).
|
|
307
|
+
*/
|
|
308
|
+
export function BottomSheetHandle(props: BottomSheetHandleProps) {
|
|
309
|
+
const { className, style, ...rest } = props;
|
|
310
|
+
const classNames = bottomSheetHandle();
|
|
311
|
+
|
|
312
|
+
return <SheetHandle className={clsx(classNames.root, className)} style={style} {...rest} />;
|
|
313
|
+
}
|
|
314
|
+
BottomSheetHandle.displayName = "BottomSheetHandle";
|
|
315
|
+
|
|
316
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
317
|
+
// Header / Body / Footer / Title / Description — 네이티브 view/text + 슬롯 className
|
|
318
|
+
//
|
|
319
|
+
// 주의: 네이티브 `<view>`/`<text>` 슬롯은 `withContext`를 사용하면 안 된다.
|
|
320
|
+
// `withContext("view", ...)`는 `React.createElement(Component)` 형태로 컴파일되어
|
|
321
|
+
// Lynx 컴파일러의 리터럴 `<view>` 정적 분석을 우회하고 `BackgroundSnapshot not found`
|
|
322
|
+
// 런타임 에러를 유발한다. 반드시 리터럴 JSX로 `<view>`/`<text>`를 작성해야 한다.
|
|
323
|
+
// (lynx-ui-sheet 같은 외부 컴포넌트 감싸기엔 withContext를 그대로 사용해도 안전.)
|
|
324
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
325
|
+
|
|
326
|
+
export interface BottomSheetSlotProps {
|
|
327
|
+
children?: ReactNode;
|
|
328
|
+
className?: string;
|
|
329
|
+
style?: CSSProperties;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function createViewSlot(slotName: keyof BottomSheetClassNames) {
|
|
333
|
+
const Slot = forwardRef<unknown, BottomSheetSlotProps>((props, ref) => {
|
|
334
|
+
const { children, className, style } = props;
|
|
335
|
+
const classNames = useClassNames();
|
|
336
|
+
|
|
337
|
+
return (
|
|
338
|
+
<view
|
|
339
|
+
{...(ref ? { ref: ref as Ref<SVGViewElement> } : {})}
|
|
340
|
+
className={clsx(classNames[slotName], className)}
|
|
341
|
+
style={style}
|
|
342
|
+
>
|
|
343
|
+
{children}
|
|
344
|
+
</view>
|
|
345
|
+
);
|
|
346
|
+
});
|
|
347
|
+
return Slot;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function createTextSlot(slotName: keyof BottomSheetClassNames) {
|
|
351
|
+
const Slot = forwardRef<unknown, BottomSheetSlotProps>((props, ref) => {
|
|
352
|
+
const { children, className, style } = props;
|
|
353
|
+
const classNames = useClassNames();
|
|
354
|
+
|
|
355
|
+
return (
|
|
356
|
+
<text
|
|
357
|
+
{...(ref ? { ref: ref as Ref<SVGTextElement> } : {})}
|
|
358
|
+
className={clsx(classNames[slotName], className)}
|
|
359
|
+
style={style}
|
|
360
|
+
>
|
|
361
|
+
{children}
|
|
362
|
+
</text>
|
|
363
|
+
);
|
|
364
|
+
});
|
|
365
|
+
return Slot;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export interface BottomSheetHeaderProps extends BottomSheetSlotProps {}
|
|
369
|
+
export const BottomSheetHeader = createViewSlot("header");
|
|
370
|
+
BottomSheetHeader.displayName = "BottomSheetHeader";
|
|
371
|
+
|
|
372
|
+
export interface BottomSheetBodyProps extends BottomSheetSlotProps {}
|
|
373
|
+
export const BottomSheetBody = createViewSlot("body");
|
|
374
|
+
BottomSheetBody.displayName = "BottomSheetBody";
|
|
375
|
+
|
|
376
|
+
export interface BottomSheetFooterProps extends BottomSheetSlotProps {}
|
|
377
|
+
export const BottomSheetFooter = createViewSlot("footer");
|
|
378
|
+
BottomSheetFooter.displayName = "BottomSheetFooter";
|
|
379
|
+
|
|
380
|
+
export interface BottomSheetTitleProps extends BottomSheetSlotProps {}
|
|
381
|
+
export const BottomSheetTitle = createTextSlot("title");
|
|
382
|
+
BottomSheetTitle.displayName = "BottomSheetTitle";
|
|
383
|
+
|
|
384
|
+
export interface BottomSheetDescriptionProps extends BottomSheetSlotProps {}
|
|
385
|
+
export const BottomSheetDescription = createTextSlot("description");
|
|
386
|
+
BottomSheetDescription.displayName = "BottomSheetDescription";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { fireEvent, render } from "@lynx-js/react/testing-library";
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
const sheetMocks = vi.hoisted(() => ({
|
|
5
|
+
contentProps: [] as Array<Record<string, unknown>>,
|
|
6
|
+
rootRef: {
|
|
7
|
+
open: vi.fn(),
|
|
8
|
+
},
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
vi.mock("@lynx-js/lynx-ui-sheet", async () => {
|
|
12
|
+
const React = await vi.importActual<typeof import("@lynx-js/react")>("@lynx-js/react");
|
|
13
|
+
|
|
14
|
+
const SheetRoot = React.forwardRef<unknown, { children?: React.ReactNode }>((props, ref) => {
|
|
15
|
+
React.useImperativeHandle(ref, () => sheetMocks.rootRef);
|
|
16
|
+
return <>{props.children}</>;
|
|
17
|
+
});
|
|
18
|
+
SheetRoot.displayName = "MockSheetRoot";
|
|
19
|
+
|
|
20
|
+
const SheetView = React.forwardRef<unknown, { children?: React.ReactNode }>((props) => {
|
|
21
|
+
return <>{props.children}</>;
|
|
22
|
+
});
|
|
23
|
+
SheetView.displayName = "MockSheetView";
|
|
24
|
+
|
|
25
|
+
const SheetContent = React.forwardRef<unknown, Record<string, unknown>>((props) => {
|
|
26
|
+
sheetMocks.contentProps.push(props);
|
|
27
|
+
return <>{props.children as React.ReactNode}</>;
|
|
28
|
+
});
|
|
29
|
+
SheetContent.displayName = "MockSheetContent";
|
|
30
|
+
|
|
31
|
+
const passthrough = (displayName: string) => {
|
|
32
|
+
const Component = React.forwardRef<unknown, { children?: React.ReactNode }>((props) => {
|
|
33
|
+
return <>{props.children}</>;
|
|
34
|
+
});
|
|
35
|
+
Component.displayName = displayName;
|
|
36
|
+
return Component;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
SheetBackdrop: passthrough("MockSheetBackdrop"),
|
|
41
|
+
SheetContent,
|
|
42
|
+
SheetHandle: passthrough("MockSheetHandle"),
|
|
43
|
+
SheetRoot,
|
|
44
|
+
SheetView,
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
import * as BottomSheet from "../BottomSheet.namespace";
|
|
49
|
+
|
|
50
|
+
describe("BottomSheet", () => {
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
sheetMocks.contentProps = [];
|
|
53
|
+
sheetMocks.rootRef.open.mockClear();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("skips motion-engine animations when Root has skipAnimation", () => {
|
|
57
|
+
render(
|
|
58
|
+
<BottomSheet.Root skipAnimation>
|
|
59
|
+
<BottomSheet.Content />
|
|
60
|
+
</BottomSheet.Root>,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(sheetMocks.contentProps.at(-1)).toMatchObject({
|
|
64
|
+
snapAnimation: { type: "tween", duration: 0 },
|
|
65
|
+
enterAnimation: { type: "tween", duration: 0 },
|
|
66
|
+
exitAnimation: { type: "tween", duration: 0 },
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("preserves user-provided animations when Root has skipAnimation", () => {
|
|
71
|
+
const snapAnimation = { type: "tween", duration: 120 };
|
|
72
|
+
const enterAnimation = { type: "tween", duration: 140 };
|
|
73
|
+
const exitAnimation = { type: "tween", duration: 90 };
|
|
74
|
+
|
|
75
|
+
render(
|
|
76
|
+
<BottomSheet.Root skipAnimation>
|
|
77
|
+
<BottomSheet.Content
|
|
78
|
+
snapAnimation={snapAnimation}
|
|
79
|
+
enterAnimation={enterAnimation}
|
|
80
|
+
exitAnimation={exitAnimation}
|
|
81
|
+
/>
|
|
82
|
+
</BottomSheet.Root>,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect(sheetMocks.contentProps.at(-1)).toMatchObject({
|
|
86
|
+
snapAnimation,
|
|
87
|
+
enterAnimation,
|
|
88
|
+
exitAnimation,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("opens with default animation when Root does not skip animation", () => {
|
|
93
|
+
const { getByText } = render(
|
|
94
|
+
<BottomSheet.Root>
|
|
95
|
+
<BottomSheet.Trigger>
|
|
96
|
+
<text>Open sheet</text>
|
|
97
|
+
</BottomSheet.Trigger>
|
|
98
|
+
</BottomSheet.Root>,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
fireEvent.tap(getByText("Open sheet").parentElement!);
|
|
102
|
+
|
|
103
|
+
expect(sheetMocks.rootRef.open).toHaveBeenCalledWith();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("opens without animation when Trigger is tapped inside a skipping Root", () => {
|
|
107
|
+
const { getByText } = render(
|
|
108
|
+
<BottomSheet.Root skipAnimation>
|
|
109
|
+
<BottomSheet.Trigger>
|
|
110
|
+
<text>Open sheet</text>
|
|
111
|
+
</BottomSheet.Trigger>
|
|
112
|
+
</BottomSheet.Root>,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
fireEvent.tap(getByText("Open sheet").parentElement!);
|
|
116
|
+
|
|
117
|
+
expect(sheetMocks.rootRef.open).toHaveBeenCalledWith({ animate: false });
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export {
|
|
2
|
+
BottomSheetBackdrop,
|
|
3
|
+
type BottomSheetBackdropProps,
|
|
4
|
+
BottomSheetBody,
|
|
5
|
+
type BottomSheetBodyProps,
|
|
6
|
+
BottomSheetContent,
|
|
7
|
+
type BottomSheetContentProps,
|
|
8
|
+
BottomSheetDescription,
|
|
9
|
+
type BottomSheetDescriptionProps,
|
|
10
|
+
BottomSheetFooter,
|
|
11
|
+
type BottomSheetFooterProps,
|
|
12
|
+
BottomSheetHandle,
|
|
13
|
+
type BottomSheetHandleProps,
|
|
14
|
+
BottomSheetHeader,
|
|
15
|
+
type BottomSheetHeaderProps,
|
|
16
|
+
BottomSheetPositioner,
|
|
17
|
+
type BottomSheetPositionerProps,
|
|
18
|
+
BottomSheetRoot,
|
|
19
|
+
type BottomSheetRootProps,
|
|
20
|
+
type BottomSheetRootRef,
|
|
21
|
+
BottomSheetTitle,
|
|
22
|
+
type BottomSheetTitleProps,
|
|
23
|
+
BottomSheetTrigger,
|
|
24
|
+
type BottomSheetTriggerProps,
|
|
25
|
+
} from "./BottomSheet";
|
|
26
|
+
|
|
27
|
+
export * as BottomSheet from "./BottomSheet.namespace";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export {
|
|
2
|
+
CheckboxControl as Control,
|
|
3
|
+
CheckboxGroup as Group,
|
|
4
|
+
CheckboxIndicator as Indicator,
|
|
5
|
+
CheckboxLabel as Label,
|
|
6
|
+
CheckboxRoot as Root,
|
|
7
|
+
type CheckboxControlProps as ControlProps,
|
|
8
|
+
type CheckboxGroupProps as GroupProps,
|
|
9
|
+
type CheckboxIndicatorProps as IndicatorProps,
|
|
10
|
+
type CheckboxLabelProps as LabelProps,
|
|
11
|
+
type CheckboxRootProps as RootProps,
|
|
12
|
+
} from "./Checkbox";
|