@seed-design/lynx-react 0.0.0-alpha-20260622094810

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 (196) hide show
  1. package/lib/_virtual/_rolldown/runtime.js +13 -0
  2. package/lib/components/ActionButton/ActionButton.d.ts +49 -0
  3. package/lib/components/ActionButton/ActionButton.d.ts.map +1 -0
  4. package/lib/components/ActionButton/ActionButton.jsx +158 -0
  5. package/lib/components/ActionButton/index.d.ts +2 -0
  6. package/lib/components/ActionButton/index.d.ts.map +1 -0
  7. package/lib/components/AppBar/AppBar.d.ts +35 -0
  8. package/lib/components/AppBar/AppBar.d.ts.map +1 -0
  9. package/lib/components/AppBar/AppBar.jsx +132 -0
  10. package/lib/components/AppBar/AppBar.namespace.d.ts +2 -0
  11. package/lib/components/AppBar/AppBar.namespace.d.ts.map +1 -0
  12. package/lib/components/AppBar/AppBar.namespace.js +15 -0
  13. package/lib/components/AppBar/context.d.ts +13 -0
  14. package/lib/components/AppBar/context.d.ts.map +1 -0
  15. package/lib/components/AppBar/context.js +12 -0
  16. package/lib/components/AppBar/index.d.ts +3 -0
  17. package/lib/components/AppBar/index.d.ts.map +1 -0
  18. package/lib/components/AppBar/useAppBar.d.ts +15 -0
  19. package/lib/components/AppBar/useAppBar.d.ts.map +1 -0
  20. package/lib/components/AppBar/useAppBar.js +72 -0
  21. package/lib/components/Badge/Badge.d.ts +14 -0
  22. package/lib/components/Badge/Badge.d.ts.map +1 -0
  23. package/lib/components/Badge/Badge.jsx +15 -0
  24. package/lib/components/Badge/index.d.ts +2 -0
  25. package/lib/components/Badge/index.d.ts.map +1 -0
  26. package/lib/components/BottomSheet/BottomSheet.d.ts +87 -0
  27. package/lib/components/BottomSheet/BottomSheet.d.ts.map +1 -0
  28. package/lib/components/BottomSheet/BottomSheet.jsx +163 -0
  29. package/lib/components/BottomSheet/BottomSheet.namespace.d.ts +2 -0
  30. package/lib/components/BottomSheet/BottomSheet.namespace.d.ts.map +1 -0
  31. package/lib/components/BottomSheet/BottomSheet.namespace.js +18 -0
  32. package/lib/components/BottomSheet/index.d.ts +3 -0
  33. package/lib/components/BottomSheet/index.d.ts.map +1 -0
  34. package/lib/components/Box/Box.d.ts +20 -0
  35. package/lib/components/Box/Box.d.ts.map +1 -0
  36. package/lib/components/Box/Box.jsx +14 -0
  37. package/lib/components/Box/index.d.ts +2 -0
  38. package/lib/components/Box/index.d.ts.map +1 -0
  39. package/lib/components/Checkbox/Checkbox.d.ts +35 -0
  40. package/lib/components/Checkbox/Checkbox.d.ts.map +1 -0
  41. package/lib/components/Checkbox/Checkbox.jsx +130 -0
  42. package/lib/components/Checkbox/Checkbox.namespace.d.ts +2 -0
  43. package/lib/components/Checkbox/Checkbox.namespace.d.ts.map +1 -0
  44. package/lib/components/Checkbox/Checkbox.namespace.js +12 -0
  45. package/lib/components/Checkbox/index.d.ts +3 -0
  46. package/lib/components/Checkbox/index.d.ts.map +1 -0
  47. package/lib/components/Icon/Icon.d.ts +37 -0
  48. package/lib/components/Icon/Icon.d.ts.map +1 -0
  49. package/lib/components/Icon/Icon.jsx +143 -0
  50. package/lib/components/Icon/index.d.ts +2 -0
  51. package/lib/components/Icon/index.d.ts.map +1 -0
  52. package/lib/components/ProgressCircle/ProgressCircle.d.ts +25 -0
  53. package/lib/components/ProgressCircle/ProgressCircle.d.ts.map +1 -0
  54. package/lib/components/ProgressCircle/ProgressCircle.jsx +281 -0
  55. package/lib/components/ProgressCircle/ProgressCircle.namespace.d.ts +2 -0
  56. package/lib/components/ProgressCircle/ProgressCircle.namespace.d.ts.map +1 -0
  57. package/lib/components/ProgressCircle/ProgressCircle.namespace.js +9 -0
  58. package/lib/components/ProgressCircle/index.d.ts +3 -0
  59. package/lib/components/ProgressCircle/index.d.ts.map +1 -0
  60. package/lib/components/RadioGroup/RadioGroup.d.ts +34 -0
  61. package/lib/components/RadioGroup/RadioGroup.d.ts.map +1 -0
  62. package/lib/components/RadioGroup/RadioGroup.jsx +160 -0
  63. package/lib/components/RadioGroup/RadioGroup.namespace.d.ts +2 -0
  64. package/lib/components/RadioGroup/RadioGroup.namespace.d.ts.map +1 -0
  65. package/lib/components/RadioGroup/RadioGroup.namespace.js +12 -0
  66. package/lib/components/RadioGroup/index.d.ts +3 -0
  67. package/lib/components/RadioGroup/index.d.ts.map +1 -0
  68. package/lib/components/Stack/Stack.d.ts +33 -0
  69. package/lib/components/Stack/Stack.d.ts.map +1 -0
  70. package/lib/components/Stack/Stack.jsx +39 -0
  71. package/lib/components/Stack/index.d.ts +2 -0
  72. package/lib/components/Stack/index.d.ts.map +1 -0
  73. package/lib/components/Switch/Switch.d.ts +21 -0
  74. package/lib/components/Switch/Switch.d.ts.map +1 -0
  75. package/lib/components/Switch/Switch.jsx +101 -0
  76. package/lib/components/Switch/Switch.namespace.d.ts +2 -0
  77. package/lib/components/Switch/Switch.namespace.d.ts.map +1 -0
  78. package/lib/components/Switch/Switch.namespace.js +11 -0
  79. package/lib/components/Switch/index.d.ts +3 -0
  80. package/lib/components/Switch/index.d.ts.map +1 -0
  81. package/lib/components/TagGroup/TagGroup.d.ts +34 -0
  82. package/lib/components/TagGroup/TagGroup.d.ts.map +1 -0
  83. package/lib/components/TagGroup/TagGroup.jsx +57 -0
  84. package/lib/components/TagGroup/TagGroup.namespace.d.ts +2 -0
  85. package/lib/components/TagGroup/TagGroup.namespace.d.ts.map +1 -0
  86. package/lib/components/TagGroup/TagGroup.namespace.js +10 -0
  87. package/lib/components/TagGroup/index.d.ts +3 -0
  88. package/lib/components/TagGroup/index.d.ts.map +1 -0
  89. package/lib/components/Text/Text.d.ts +7 -0
  90. package/lib/components/Text/Text.d.ts.map +1 -0
  91. package/lib/components/Text/Text.jsx +28 -0
  92. package/lib/components/Text/index.d.ts +2 -0
  93. package/lib/components/Text/index.d.ts.map +1 -0
  94. package/lib/components/index.d.ts +14 -0
  95. package/lib/components/index.d.ts.map +1 -0
  96. package/lib/hooks/index.d.ts +5 -0
  97. package/lib/hooks/index.d.ts.map +1 -0
  98. package/lib/hooks/useControllableState.d.ts +15 -0
  99. package/lib/hooks/useControllableState.d.ts.map +1 -0
  100. package/lib/hooks/useControllableState.js +27 -0
  101. package/lib/hooks/useIconColor.d.ts +19 -0
  102. package/lib/hooks/useIconColor.d.ts.map +1 -0
  103. package/lib/hooks/useIconColor.js +38 -0
  104. package/lib/hooks/usePressTap.d.ts +27 -0
  105. package/lib/hooks/usePressTap.d.ts.map +1 -0
  106. package/lib/hooks/usePressTap.js +35 -0
  107. package/lib/hooks/useSafeArea.d.ts +19 -0
  108. package/lib/hooks/useSafeArea.d.ts.map +1 -0
  109. package/lib/hooks/useSafeArea.js +33 -0
  110. package/lib/index.d.ts +5 -0
  111. package/lib/index.d.ts.map +1 -0
  112. package/lib/index.js +29 -0
  113. package/lib/types.d.ts +51 -0
  114. package/lib/types.d.ts.map +1 -0
  115. package/lib/utils/children.d.ts +3 -0
  116. package/lib/utils/children.d.ts.map +1 -0
  117. package/lib/utils/children.js +8 -0
  118. package/lib/utils/create-slot-recipe-context.d.ts +27 -0
  119. package/lib/utils/create-slot-recipe-context.d.ts.map +1 -0
  120. package/lib/utils/create-slot-recipe-context.jsx +94 -0
  121. package/lib/utils/get-seed-class-name.d.ts +22 -0
  122. package/lib/utils/get-seed-class-name.d.ts.map +1 -0
  123. package/lib/utils/get-seed-class-name.js +28 -0
  124. package/lib/utils/index.d.ts +5 -0
  125. package/lib/utils/index.d.ts.map +1 -0
  126. package/lib/utils/resolve-recipe-token.d.ts +38 -0
  127. package/lib/utils/resolve-recipe-token.d.ts.map +1 -0
  128. package/lib/utils/resolve-recipe-token.js +49 -0
  129. package/lib/utils/split-multiple-variants-props.d.ts +29 -0
  130. package/lib/utils/split-multiple-variants-props.d.ts.map +1 -0
  131. package/lib/utils/split-multiple-variants-props.js +34 -0
  132. package/lib/utils/styled.d.ts +83 -0
  133. package/lib/utils/styled.d.ts.map +1 -0
  134. package/lib/utils/styled.js +144 -0
  135. package/package.json +54 -0
  136. package/src/components/ActionButton/ActionButton.test.tsx +167 -0
  137. package/src/components/ActionButton/ActionButton.tsx +363 -0
  138. package/src/components/ActionButton/index.ts +1 -0
  139. package/src/components/AppBar/AppBar.namespace.ts +18 -0
  140. package/src/components/AppBar/AppBar.test.tsx +270 -0
  141. package/src/components/AppBar/AppBar.tsx +288 -0
  142. package/src/components/AppBar/context.ts +27 -0
  143. package/src/components/AppBar/index.ts +21 -0
  144. package/src/components/AppBar/useAppBar.ts +100 -0
  145. package/src/components/Badge/Badge.test.tsx +54 -0
  146. package/src/components/Badge/Badge.tsx +32 -0
  147. package/src/components/Badge/index.ts +1 -0
  148. package/src/components/BottomSheet/BottomSheet.namespace.ts +24 -0
  149. package/src/components/BottomSheet/BottomSheet.test.tsx +219 -0
  150. package/src/components/BottomSheet/BottomSheet.tsx +423 -0
  151. package/src/components/BottomSheet/index.ts +27 -0
  152. package/src/components/Box/Box.test.tsx +85 -0
  153. package/src/components/Box/Box.tsx +39 -0
  154. package/src/components/Box/index.ts +1 -0
  155. package/src/components/Checkbox/Checkbox.namespace.ts +12 -0
  156. package/src/components/Checkbox/Checkbox.tsx +282 -0
  157. package/src/components/Checkbox/index.ts +14 -0
  158. package/src/components/Icon/Icon.tsx +265 -0
  159. package/src/components/Icon/index.ts +8 -0
  160. package/src/components/ProgressCircle/ProgressCircle.namespace.ts +5 -0
  161. package/src/components/ProgressCircle/ProgressCircle.tsx +424 -0
  162. package/src/components/ProgressCircle/index.ts +9 -0
  163. package/src/components/RadioGroup/RadioGroup.namespace.ts +12 -0
  164. package/src/components/RadioGroup/RadioGroup.tsx +320 -0
  165. package/src/components/RadioGroup/index.ts +14 -0
  166. package/src/components/Stack/Stack.tsx +97 -0
  167. package/src/components/Stack/index.ts +1 -0
  168. package/src/components/Switch/Switch.namespace.ts +10 -0
  169. package/src/components/Switch/Switch.tsx +200 -0
  170. package/src/components/Switch/index.ts +12 -0
  171. package/src/components/TagGroup/TagGroup.namespace.ts +8 -0
  172. package/src/components/TagGroup/TagGroup.tsx +127 -0
  173. package/src/components/TagGroup/index.ts +10 -0
  174. package/src/components/Text/Text.tsx +64 -0
  175. package/src/components/Text/index.ts +1 -0
  176. package/src/components/index.ts +13 -0
  177. package/src/hooks/index.ts +4 -0
  178. package/src/hooks/useControllableState.test.ts +120 -0
  179. package/src/hooks/useControllableState.ts +38 -0
  180. package/src/hooks/useIconColor.test.ts +13 -0
  181. package/src/hooks/useIconColor.ts +67 -0
  182. package/src/hooks/usePressTap.test.ts +129 -0
  183. package/src/hooks/usePressTap.ts +58 -0
  184. package/src/hooks/useSafeArea.test.ts +83 -0
  185. package/src/hooks/useSafeArea.ts +56 -0
  186. package/src/index.ts +4 -0
  187. package/src/types.ts +76 -0
  188. package/src/utils/children.ts +13 -0
  189. package/src/utils/create-slot-recipe-context.test.tsx +96 -0
  190. package/src/utils/create-slot-recipe-context.tsx +187 -0
  191. package/src/utils/get-seed-class-name.ts +47 -0
  192. package/src/utils/index.ts +4 -0
  193. package/src/utils/resolve-recipe-token.ts +47 -0
  194. package/src/utils/split-multiple-variants-props.test.ts +61 -0
  195. package/src/utils/split-multiple-variants-props.ts +59 -0
  196. package/src/utils/styled.ts +442 -0
@@ -0,0 +1,265 @@
1
+ import { useMainThreadRef } from "@lynx-js/react";
2
+ import type { CSSProperties, MainThread } from "@lynx-js/types";
3
+ import clsx from "clsx";
4
+ import * as React from "@lynx-js/react";
5
+ import {
6
+ cloneElement,
7
+ isValidElement,
8
+ type DependencyList,
9
+ type ReactElement,
10
+ } from "@lynx-js/react";
11
+
12
+ import { useIconColor } from "../../hooks/useIconColor";
13
+ import type { LynxIconElementProps, LynxStyledElementProps, LynxViewRef } from "../../types";
14
+ import { handleColor, handleDimension, type StyleProps } from "../../utils/styled";
15
+
16
+ export type IconSlotName = "icon" | "prefixIcon" | "suffixIcon";
17
+
18
+ ////////////////////////////////////////////////////////////////////////////////////
19
+
20
+ interface IconSlotContextValue {
21
+ classNames?: Partial<Record<IconSlotName, string>>;
22
+ deps?: DependencyList;
23
+ }
24
+
25
+ const IconSlotContext = React.createContext<IconSlotContextValue | null>(null);
26
+
27
+ interface IconRequiredContextValue {
28
+ register: () => void;
29
+ unregister: () => void;
30
+ }
31
+
32
+ const IconRequiredContext = React.createContext<IconRequiredContextValue | null>(null);
33
+
34
+ export function IconRequired({
35
+ children,
36
+ enabled,
37
+ }: {
38
+ children: React.ReactNode;
39
+ enabled: boolean;
40
+ }) {
41
+ const registeredCountRef = React.useRef(0);
42
+ const parentContext = React.useContext(IconRequiredContext);
43
+
44
+ const register = React.useCallback(() => {
45
+ registeredCountRef.current += 1;
46
+
47
+ if (process.env.NODE_ENV !== "production" && registeredCountRef.current > 1) {
48
+ throw new Error(
49
+ "Icon-only Component must render only one <Icon /> under children. Check if you are rendering multiple <Icon />.",
50
+ );
51
+ }
52
+ }, []);
53
+
54
+ const unregister = React.useCallback(() => {
55
+ registeredCountRef.current = Math.max(0, registeredCountRef.current - 1);
56
+ }, []);
57
+
58
+ React.useLayoutEffect(() => {
59
+ if (!enabled) return;
60
+
61
+ if (process.env.NODE_ENV !== "production") {
62
+ if (parentContext) {
63
+ throw new Error(
64
+ "Icon-only Component must not be nested within another Icon-Only. Check if you are using Icon-Only inside another Icon-Only.",
65
+ );
66
+ }
67
+ if (registeredCountRef.current === 0) {
68
+ throw new Error(
69
+ "Icon-only Component must render <Icon /> as a child. Check if you are using raw icon element instead of <Icon icon={} />.",
70
+ );
71
+ }
72
+ }
73
+ }, [enabled, parentContext]);
74
+
75
+ const value = React.useMemo<IconRequiredContextValue | null>(() => {
76
+ if (!enabled) return parentContext ?? null;
77
+ return { register, unregister };
78
+ }, [enabled, parentContext, register, unregister]);
79
+
80
+ return <IconRequiredContext.Provider value={value}>{children}</IconRequiredContext.Provider>;
81
+ }
82
+
83
+ export function IconSlotProvider({
84
+ value,
85
+ children,
86
+ }: {
87
+ value: IconSlotContextValue;
88
+ children: React.ReactNode;
89
+ }) {
90
+ return <IconSlotContext.Provider value={value}>{children}</IconSlotContext.Provider>;
91
+ }
92
+
93
+ ////////////////////////////////////////////////////////////////////////////////////
94
+
95
+ const iconSlotMarker = Symbol.for("@seed-design/lynx-react/icon-slot");
96
+
97
+ interface IconSlotComponent {
98
+ [iconSlotMarker]?: IconSlotName;
99
+ }
100
+
101
+ export function getIconSlotName(node: React.ReactNode): IconSlotName | null {
102
+ if (!isValidElement(node)) return null;
103
+
104
+ return ((node.type as IconSlotComponent)[iconSlotMarker] ?? null) as IconSlotName | null;
105
+ }
106
+
107
+ ////////////////////////////////////////////////////////////////////////////////////
108
+
109
+ export interface IconProps extends LynxStyledElementProps {
110
+ icon: ReactElement<LynxIconElementProps>;
111
+ size?: StyleProps["height"] | number;
112
+ color?: StyleProps["color"];
113
+ }
114
+
115
+ export interface PrefixIconProps extends IconProps {}
116
+
117
+ export interface SuffixIconProps extends IconProps {}
118
+
119
+ interface IconSlotBaseProps extends IconProps {
120
+ slot: IconSlotName | null;
121
+ baseClassName?: string;
122
+ }
123
+
124
+ function mergeWrapperStyle({
125
+ size,
126
+ color,
127
+ style,
128
+ }: Pick<IconProps, "size" | "color" | "style">): CSSProperties | undefined {
129
+ const dimension = handleDimension(size);
130
+ const resolvedColor = handleColor(color);
131
+
132
+ if (dimension == null && resolvedColor == null) return style;
133
+
134
+ return {
135
+ ...(dimension != null ? { width: dimension, height: dimension } : {}),
136
+ ...(resolvedColor != null ? { color: resolvedColor } : {}),
137
+ ...style,
138
+ };
139
+ }
140
+
141
+ function getStyleColor(style: CSSProperties | undefined): CSSProperties["color"] {
142
+ return style?.color;
143
+ }
144
+
145
+ const IconSlotBase = React.forwardRef<unknown, IconSlotBaseProps>((props, ref) => {
146
+ const {
147
+ icon,
148
+ slot,
149
+ baseClassName,
150
+ className,
151
+ style,
152
+ size,
153
+ color,
154
+ children: _children,
155
+ ...nativeProps
156
+ } = props;
157
+ const context = React.useContext(IconSlotContext);
158
+ const iconRequiredContext = React.useContext(IconRequiredContext);
159
+ const sourceRef = useMainThreadRef<MainThread.Element>(null);
160
+ const slotClassName = slot != null ? context?.classNames?.[slot] : undefined;
161
+ const styleColor = getStyleColor(style);
162
+ const iconColor = useIconColor(
163
+ [baseClassName, slotClassName, className, size, color, styleColor, ...(context?.deps ?? [])],
164
+ { sourceRef },
165
+ );
166
+ const hasValidIcon = isValidElement<LynxIconElementProps>(icon);
167
+
168
+ React.useLayoutEffect(() => {
169
+ if (slot !== "icon" || !hasValidIcon) return;
170
+
171
+ iconRequiredContext?.register();
172
+ return () => {
173
+ iconRequiredContext?.unregister();
174
+ };
175
+ }, [hasValidIcon, iconRequiredContext, slot]);
176
+
177
+ if (!hasValidIcon) return null;
178
+
179
+ return (
180
+ <view
181
+ {...(ref ? { ref: ref as LynxViewRef } : {})}
182
+ {...nativeProps}
183
+ main-thread:ref={sourceRef}
184
+ className={clsx(baseClassName, slotClassName, className)}
185
+ style={mergeWrapperStyle({ size, color, style })}
186
+ >
187
+ {cloneElement(icon, {
188
+ ...iconColor,
189
+ className: icon.props.className,
190
+ style: {
191
+ ...icon.props.style,
192
+ width: "100%",
193
+ height: "100%",
194
+ },
195
+ })}
196
+ </view>
197
+ );
198
+ });
199
+ IconSlotBase.displayName = "IconSlotBase";
200
+
201
+ ////////////////////////////////////////////////////////////////////////////////////
202
+
203
+ function createIconComponent<Props extends IconProps>(
204
+ displayName: string,
205
+ slot: IconSlotName,
206
+ baseClassName: string,
207
+ ) {
208
+ const Component = React.forwardRef<unknown, Props>((props, ref) => {
209
+ return <IconSlotBase ref={ref} slot={slot} baseClassName={baseClassName} {...props} />;
210
+ });
211
+
212
+ Component.displayName = displayName;
213
+ (Component as IconSlotComponent)[iconSlotMarker] = slot;
214
+
215
+ return Component;
216
+ }
217
+
218
+ export const Icon = createIconComponent<IconProps>("Icon", "icon", "seed-icon");
219
+ export const PrefixIcon = createIconComponent<PrefixIconProps>(
220
+ "PrefixIcon",
221
+ "prefixIcon",
222
+ "seed-prefix-icon",
223
+ );
224
+ export const SuffixIcon = createIconComponent<SuffixIconProps>(
225
+ "SuffixIcon",
226
+ "suffixIcon",
227
+ "seed-suffix-icon",
228
+ );
229
+
230
+ ////////////////////////////////////////////////////////////////////////////////////
231
+
232
+ export interface InternalIconProps extends LynxStyledElementProps {
233
+ icon: ReactElement<LynxIconElementProps>;
234
+ deps?: DependencyList;
235
+ }
236
+
237
+ export const InternalIcon = React.forwardRef<unknown, InternalIconProps>((props, ref) => {
238
+ const { icon, deps = [], className, style, children: _children, ...nativeProps } = props;
239
+ const sourceRef = useMainThreadRef<MainThread.Element>(null);
240
+ const styleColor = getStyleColor(style);
241
+ const iconColor = useIconColor([className, styleColor, ...(deps ?? [])], { sourceRef });
242
+
243
+ if (!isValidElement<LynxIconElementProps>(icon)) return null;
244
+
245
+ return (
246
+ <view
247
+ {...(ref ? { ref: ref as LynxViewRef } : {})}
248
+ {...nativeProps}
249
+ main-thread:ref={sourceRef}
250
+ className={className}
251
+ style={style}
252
+ >
253
+ {cloneElement(icon, {
254
+ ...iconColor,
255
+ className: icon.props.className,
256
+ style: {
257
+ ...icon.props.style,
258
+ width: "100%",
259
+ height: "100%",
260
+ },
261
+ })}
262
+ </view>
263
+ );
264
+ });
265
+ InternalIcon.displayName = "InternalIcon";
@@ -0,0 +1,8 @@
1
+ export {
2
+ Icon,
3
+ PrefixIcon,
4
+ SuffixIcon,
5
+ type IconProps,
6
+ type PrefixIconProps,
7
+ type SuffixIconProps,
8
+ } from "./Icon";
@@ -0,0 +1,5 @@
1
+ export {
2
+ ProgressCircleRange as Range,
3
+ ProgressCircleRoot as Root,
4
+ type ProgressCircleRootProps as RootProps,
5
+ } from "./ProgressCircle";