@streamplace/components 0.7.27 → 0.7.29

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 (43) hide show
  1. package/dist/components/chat/chat-box.js +2 -2
  2. package/dist/components/chat/chat.js +1 -1
  3. package/dist/components/mobile-player/ui/autoplay-button.js +1 -0
  4. package/dist/components/mobile-player/ui/viewer-context-menu.js +1 -1
  5. package/dist/components/mobile-player/ui/viewer-loading-overlay.js +2 -2
  6. package/dist/components/mobile-player/use-webrtc.js +30 -0
  7. package/dist/components/ui/button.js +107 -155
  8. package/dist/components/ui/dialog.js +83 -116
  9. package/dist/components/ui/dropdown.js +41 -18
  10. package/dist/components/ui/input.js +53 -128
  11. package/dist/components/ui/primitives/button.js +0 -2
  12. package/dist/components/ui/primitives/modal.js +2 -2
  13. package/dist/components/ui/primitives/text.js +48 -8
  14. package/dist/components/ui/text.js +37 -66
  15. package/dist/components/ui/toast.js +78 -40
  16. package/dist/components/ui/view.js +28 -41
  17. package/dist/lib/theme/index.js +1 -2
  18. package/dist/lib/theme/theme.js +106 -54
  19. package/dist/lib/theme/tokens.js +94 -1
  20. package/dist/ui/index.js +2 -3
  21. package/node-compile-cache/v22.15.0-x64-efe9a9df-0/37be0eec +0 -0
  22. package/package.json +3 -2
  23. package/src/components/chat/chat-box.tsx +6 -3
  24. package/src/components/chat/chat.tsx +1 -0
  25. package/src/components/mobile-player/ui/autoplay-button.tsx +1 -0
  26. package/src/components/mobile-player/ui/viewer-context-menu.tsx +2 -2
  27. package/src/components/mobile-player/ui/viewer-loading-overlay.tsx +2 -2
  28. package/src/components/mobile-player/use-webrtc.tsx +31 -0
  29. package/src/components/ui/button.tsx +110 -172
  30. package/src/components/ui/dialog.tsx +96 -138
  31. package/src/components/ui/dropdown.tsx +60 -22
  32. package/src/components/ui/input.tsx +57 -144
  33. package/src/components/ui/primitives/button.tsx +0 -2
  34. package/src/components/ui/primitives/modal.tsx +0 -2
  35. package/src/components/ui/primitives/text.tsx +51 -8
  36. package/src/components/ui/text.tsx +42 -67
  37. package/src/components/ui/toast.tsx +108 -90
  38. package/src/components/ui/view.tsx +27 -41
  39. package/src/lib/theme/index.ts +0 -2
  40. package/src/lib/theme/theme.tsx +179 -72
  41. package/src/lib/theme/tokens.ts +97 -0
  42. package/src/ui/index.ts +0 -2
  43. package/tsconfig.tsbuildinfo +1 -1
@@ -1,7 +1,8 @@
1
1
  import { cva, type VariantProps } from "class-variance-authority";
2
2
  import React, { forwardRef } from "react";
3
- import { StyleSheet } from "react-native";
4
- import { colors, borderRadius as radius, spacing } from "../../lib/theme/atoms";
3
+ import { useTheme } from "../../lib/theme/theme";
4
+ import { fontFamilies } from "../../lib/theme/tokens";
5
+ import * as zero from "../../ui";
5
6
  import { TextPrimitive, TextPrimitiveProps } from "./primitives/text";
6
7
 
7
8
  // Text variants using class-variance-authority pattern
@@ -103,8 +104,7 @@ export const Text = forwardRef<any, TextProps>(
103
104
  },
104
105
  ref,
105
106
  ) => {
106
- // Create dynamic styles based on atoms
107
- const styles = React.useMemo(() => createStyles(), []);
107
+ const { zero: zt } = useTheme();
108
108
 
109
109
  // Override props based on convenience props
110
110
  const finalColor = customColor ? customColor : muted ? "muted" : color;
@@ -134,8 +134,31 @@ export const Text = forwardRef<any, TextProps>(
134
134
  ? "justify"
135
135
  : "left";
136
136
 
137
- // Get variant-specific styles
138
- const variantStyle = styles[`${variant}Style` as keyof typeof styles] || {};
137
+ // Get variant-specific styles using theme.zero
138
+ const variantStyle = React.useMemo(() => {
139
+ switch (variant) {
140
+ case "h1":
141
+ return zero.my[6];
142
+ case "h2":
143
+ case "h3":
144
+ return zero.my[4];
145
+ case "h4":
146
+ case "h5":
147
+ case "h6":
148
+ case "subtitle1":
149
+ return zero.my[2];
150
+ case "subtitle2":
151
+ case "caption":
152
+ case "overline":
153
+ return zero.my[1];
154
+ case "body1":
155
+ return zero.my[4];
156
+ case "body2":
157
+ return zero.my[2];
158
+ default:
159
+ return {};
160
+ }
161
+ }, [variant, zt]);
139
162
 
140
163
  const styleArr = (
141
164
  Array.isArray(style) ? style : [style || undefined]
@@ -209,13 +232,24 @@ export const Label = forwardRef<any, Omit<TextProps, "variant">>(
209
232
  Label.displayName = "Label";
210
233
 
211
234
  export const Code = forwardRef<any, TextProps>(({ style, ...props }, ref) => {
212
- const styles = React.useMemo(() => createStyles(), []);
235
+ const { zero: zt } = useTheme();
236
+
237
+ const codeStyle = React.useMemo(
238
+ () => [
239
+ {
240
+ borderRadius: zero.borderRadius.sm,
241
+ fontFamily: fontFamilies.monoRegular,
242
+ },
243
+ ],
244
+ [zt],
245
+ );
246
+
213
247
  // if style is not an array, convert it to an array
214
248
  const styleArr = (Array.isArray(style) ? style : [style || undefined]).filter(
215
249
  (s) => s !== undefined,
216
250
  );
217
251
 
218
- return <Text ref={ref} style={[styles.codeStyle, ...styleArr]} {...props} />;
252
+ return <Text ref={ref} style={[...codeStyle, ...styleArr]} {...props} />;
219
253
  });
220
254
 
221
255
  Code.displayName = "Code";
@@ -264,65 +298,6 @@ export const Span = forwardRef<
264
298
 
265
299
  Span.displayName = "Span";
266
300
 
267
- // Create atom-based styles
268
- function createStyles() {
269
- return StyleSheet.create({
270
- // Variant-specific styles
271
- h1Style: {
272
- marginBottom: spacing[4],
273
- },
274
- h2Style: {
275
- marginBottom: spacing[3],
276
- },
277
- h3Style: {
278
- marginBottom: spacing[3],
279
- },
280
- h4Style: {
281
- marginBottom: spacing[2],
282
- },
283
- h5Style: {
284
- marginBottom: spacing[2],
285
- },
286
- h6Style: {
287
- marginBottom: spacing[2],
288
- },
289
- subtitle1Style: {
290
- marginBottom: spacing[2],
291
- },
292
- subtitle2Style: {
293
- marginBottom: spacing[1],
294
- },
295
- body1Style: {
296
- marginBottom: spacing[3],
297
- },
298
- body2Style: {
299
- marginBottom: spacing[2],
300
- },
301
- captionStyle: {
302
- marginBottom: spacing[1],
303
- },
304
- overlineStyle: {
305
- marginBottom: spacing[1],
306
- textTransform: "uppercase",
307
- letterSpacing: 1,
308
- },
309
- labelStyle: {
310
- marginBottom: spacing[1],
311
- },
312
- buttonStyle: {
313
- textAlign: "center",
314
- },
315
- codeStyle: {
316
- fontFamily: "monospace",
317
- backgroundColor: colors["muted"],
318
- paddingHorizontal: spacing[1],
319
- paddingVertical: 2,
320
- borderRadius: radius.sm,
321
- fontSize: 14,
322
- },
323
- });
324
- }
325
-
326
301
  // Export text variants for external use
327
302
  export { textVariants };
328
303
 
@@ -11,11 +11,81 @@ import {
11
11
  ViewStyle,
12
12
  } from "react-native";
13
13
  import { useSafeAreaInsets } from "react-native-safe-area-context";
14
- import { useTheme } from "../../lib/theme/theme";
15
14
 
16
- import { useCallback } from "react";
15
+ import { useTheme } from "../../ui";
17
16
 
18
- type ToastController = {
17
+ type ToastConfig = {
18
+ title: string;
19
+ description?: string;
20
+ duration?: number;
21
+ actionLabel?: string;
22
+ onAction?: () => void;
23
+ };
24
+
25
+ type ToastState = {
26
+ id: string;
27
+ open: boolean;
28
+ title: string;
29
+ description?: string;
30
+ duration: number;
31
+ actionLabel?: string;
32
+ onAction?: () => void;
33
+ };
34
+
35
+ class ToastManager {
36
+ private listeners: Set<(state: ToastState | null) => void> = new Set();
37
+ private currentToast: ToastState | null = null;
38
+ private timeoutId: ReturnType<typeof setTimeout> | null = null;
39
+
40
+ show(config: ToastConfig) {
41
+ if (this.timeoutId) {
42
+ clearTimeout(this.timeoutId);
43
+ }
44
+
45
+ const toast: ToastState = {
46
+ id: Math.random().toString(36).substr(2, 9),
47
+ open: true,
48
+ title: config.title,
49
+ description: config.description,
50
+ duration: config.duration ?? 3,
51
+ actionLabel: config.actionLabel,
52
+ onAction: config.onAction,
53
+ };
54
+
55
+ this.currentToast = toast;
56
+ this.notifyListeners();
57
+
58
+ if (toast.duration > 0) {
59
+ this.timeoutId = setTimeout(() => {
60
+ this.hide();
61
+ }, toast.duration * 1000);
62
+ }
63
+ }
64
+
65
+ hide() {
66
+ if (this.timeoutId) {
67
+ clearTimeout(this.timeoutId);
68
+ this.timeoutId = null;
69
+ }
70
+ this.currentToast = null;
71
+ this.notifyListeners();
72
+ }
73
+
74
+ subscribe(listener: (state: ToastState | null) => void) {
75
+ this.listeners.add(listener);
76
+ return () => {
77
+ this.listeners.delete(listener);
78
+ };
79
+ }
80
+
81
+ private notifyListeners() {
82
+ this.listeners.forEach((listener) => listener(this.currentToast));
83
+ }
84
+ }
85
+
86
+ const toastManager = new ToastManager();
87
+
88
+ export const toast = {
19
89
  show: (
20
90
  title: string,
21
91
  description?: string,
@@ -24,103 +94,51 @@ type ToastController = {
24
94
  actionLabel?: string;
25
95
  onAction?: () => void;
26
96
  },
27
- ) => void;
28
- hide: () => void;
97
+ ) => {
98
+ toastManager.show({
99
+ title,
100
+ description,
101
+ ...options,
102
+ });
103
+ },
104
+ hide: () => toastManager.hide(),
29
105
  };
30
106
 
31
- type UseToastReturn = {
32
- open: boolean;
33
- title: string;
34
- description?: string;
35
- actionLabel?: string;
36
- onAction?: () => void;
37
- duration?: number;
38
- setOpen: (open: boolean) => void;
39
- setTitle: (title: string) => void;
40
- setDescription: (description: string) => void;
41
- setActionLabel: (label: string) => void;
42
- setOnAction: (cb?: () => void) => void;
43
- setDuration: (duration: number) => void;
44
- toastController: ToastController;
45
- };
107
+ export function useToast() {
108
+ const [toastState, setToastState] = useState<ToastState | null>(null);
46
109
 
47
- /**
48
- * useToast - a hook to manage Toast state and provide a toastController.
49
- * Returns a ready-to-render ToastComponent.
50
- */
51
- export function useToast(
52
- initial: {
53
- title?: string;
54
- description?: string;
55
- duration?: number;
56
- actionLabel?: string;
57
- onAction?: () => void;
58
- } = {},
59
- ) {
60
- const [open, setOpen] = useState(false);
61
- const [title, setTitle] = useState(initial.title ?? "");
62
- const [description, setDescription] = useState(initial.description ?? "");
63
- const [duration, setDuration] = useState(initial.duration ?? 3);
64
- const [actionLabel, setActionLabel] = useState(
65
- initial.actionLabel ?? "Action",
66
- );
67
- const [onAction, setOnAction] = useState<(() => void) | undefined>(
68
- initial.onAction,
69
- );
110
+ useEffect(() => {
111
+ return toastManager.subscribe(setToastState);
112
+ }, []);
70
113
 
71
- const show = useCallback(
72
- (
73
- toastTitle: string,
74
- toastDescription?: string,
75
- options?: {
76
- duration?: number;
77
- actionLabel?: string;
78
- onAction?: () => void;
79
- },
80
- ) => {
81
- setTitle(toastTitle);
82
- setDescription(toastDescription ?? "");
83
- setDuration(options?.duration ?? 3);
84
- setActionLabel(options?.actionLabel ?? "Action");
85
- setOnAction(options?.onAction);
86
- setOpen(true);
87
- },
88
- [],
89
- );
114
+ return {
115
+ toast: toastState,
116
+ ...toast,
117
+ };
118
+ }
119
+
120
+ export function ToastProvider() {
121
+ const [toastState, setToastState] = useState<ToastState | null>(null);
90
122
 
91
- const hide = useCallback(() => {
92
- setOpen(false);
123
+ useEffect(() => {
124
+ return toastManager.subscribe(setToastState);
93
125
  }, []);
94
126
 
95
- // Ready-to-render Toast component
96
- const ToastComponent = (
127
+ if (!toastState?.open) return null;
128
+
129
+ return (
97
130
  <Toast
98
- open={open}
99
- onOpenChange={setOpen}
100
- title={title}
101
- description={description}
102
- actionLabel={actionLabel}
103
- onAction={onAction}
104
- duration={duration}
131
+ open={toastState.open}
132
+ onOpenChange={(open) => {
133
+ if (!open) toastManager.hide();
134
+ }}
135
+ title={toastState.title}
136
+ description={toastState.description}
137
+ actionLabel={toastState.actionLabel}
138
+ onAction={toastState.onAction}
139
+ duration={toastState.duration}
105
140
  />
106
141
  );
107
-
108
- return {
109
- open,
110
- title,
111
- description,
112
- actionLabel,
113
- onAction,
114
- duration,
115
- setOpen,
116
- setTitle,
117
- setDescription,
118
- setActionLabel,
119
- setOnAction,
120
- setDuration,
121
- toastController: { show, hide },
122
- ToastComponent,
123
- };
124
142
  }
125
143
 
126
144
  type ToastProps = {
@@ -5,8 +5,8 @@ import {
5
5
  ViewProps as RNViewProps,
6
6
  ViewStyle,
7
7
  } from "react-native";
8
- import { borderRadius as radius, spacing } from "../../lib/theme/atoms";
9
8
  import { useTheme } from "../../lib/theme/theme";
9
+ import * as zero from "../../ui";
10
10
 
11
11
  // View variants using class-variance-authority pattern
12
12
  const viewVariants = cva("", {
@@ -121,72 +121,64 @@ export const View = forwardRef<RNView, ViewProps>(
121
121
  },
122
122
  ref,
123
123
  ) => {
124
- const { theme } = useTheme();
124
+ const { zero: zt } = useTheme();
125
125
 
126
- // Map variant to styles
126
+ // Map variant to styles using theme.zero
127
127
  const variantStyles: ViewStyle = (() => {
128
128
  switch (variant) {
129
129
  case "card":
130
130
  return {
131
- backgroundColor: theme.colors.card,
132
- borderRadius: radius.lg,
133
- shadowColor: "#000",
134
- shadowOffset: { width: 0, height: 2 },
135
- shadowOpacity: 0.1,
136
- shadowRadius: 4,
137
- elevation: 3,
131
+ ...zt.bg.card,
132
+ borderRadius: zero.borderRadius.lg,
133
+ ...zero.shadows.md,
138
134
  };
139
135
  case "overlay":
140
- return {
141
- backgroundColor: "rgba(0, 0, 0, 0.5)",
142
- };
136
+ return zt.bg.overlay;
143
137
  case "surface":
144
- return {
145
- backgroundColor: theme.colors.background,
146
- };
138
+ return zt.bg.background;
147
139
  case "container":
148
140
  return {
149
- backgroundColor: theme.colors.background,
150
- padding: spacing[4],
141
+ ...zt.bg.background,
142
+ ...zero.p[8],
151
143
  };
152
144
  default:
153
145
  return {};
154
146
  }
155
147
  })();
156
148
 
157
- // Map padding to numeric values
149
+ // Map padding to zero tokens
158
150
  const paddingValue = (() => {
159
151
  switch (padding) {
160
152
  case "xs":
161
- return spacing[1];
153
+ return zero.p[1];
162
154
  case "sm":
163
- return spacing[2];
155
+ return zero.p[2];
164
156
  case "md":
165
- return spacing[3];
157
+ return zero.p[4];
166
158
  case "lg":
167
- return spacing[4];
159
+ return zero.p[6];
168
160
  case "xl":
169
- return spacing[5];
161
+ return zero.p[8];
170
162
  default:
171
- return undefined;
163
+ return {};
172
164
  }
173
165
  })();
174
166
 
175
- // Map margin to numeric values
167
+ // Map margin to zero tokens
176
168
  const marginValue = (() => {
177
169
  switch (margin) {
178
170
  case "xs":
179
- return spacing[1];
171
+ return zero.m[1];
180
172
  case "sm":
181
- return spacing[2];
173
+ return zero.m[2];
182
174
  case "md":
183
- return spacing[3];
175
+ return zero.m[4];
184
176
  case "lg":
185
- return spacing[4];
177
+ return zero.m[6];
186
178
  case "xl":
187
- return spacing[5];
179
+ return zero.m[8];
188
180
  default:
189
- return undefined;
181
+ return {};
190
182
  }
191
183
  })();
192
184
 
@@ -262,8 +254,8 @@ export const View = forwardRef<RNView, ViewProps>(
262
254
 
263
255
  const computedStyle: ViewStyle = {
264
256
  ...variantStyles,
265
- ...(paddingValue !== undefined && { padding: paddingValue }),
266
- ...(marginValue !== undefined && { margin: marginValue }),
257
+ ...paddingValue,
258
+ ...marginValue,
267
259
  flexDirection,
268
260
  alignItems,
269
261
  justifyContent,
@@ -278,13 +270,7 @@ export const View = forwardRef<RNView, ViewProps>(
278
270
  ...(borderColor && { borderColor }),
279
271
  ...(borderWidth !== undefined && { borderWidth }),
280
272
  ...(borderRadius !== undefined && { borderRadius }),
281
- ...(shadow && {
282
- shadowColor: "#000",
283
- shadowOffset: { width: 0, height: 2 },
284
- shadowOpacity: 0.1,
285
- shadowRadius: 4,
286
- elevation: 3,
287
- }),
273
+ ...(shadow && zero.shadows.md),
288
274
  };
289
275
 
290
276
  const finalStyle = Array.isArray(style)
@@ -3,7 +3,6 @@ export {
3
3
  ThemeProvider,
4
4
  createThemeColors,
5
5
  createThemeIcons,
6
- createThemeStyles,
7
6
  createThemedStyles,
8
7
  darkTheme,
9
8
  lightTheme,
@@ -11,7 +10,6 @@ export {
11
10
  useTheme,
12
11
  type Theme,
13
12
  type ThemeIcons,
14
- type ThemeStyles,
15
13
  } from "./theme";
16
14
 
17
15
  // Design tokens