@idealyst/theme 1.2.59 → 1.2.61

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idealyst/theme",
3
- "version": "1.2.59",
3
+ "version": "1.2.61",
4
4
  "description": "Theming system for Idealyst Framework",
5
5
  "readme": "README.md",
6
6
  "main": "src/index.ts",
package/src/index.ts CHANGED
@@ -25,6 +25,9 @@ export * from './responsive';
25
25
  export * from './breakpoints';
26
26
  export * from './useResponsiveStyle';
27
27
 
28
+ // Style props hook (platform-specific via .native.ts)
29
+ export { useStyleProps, type StyleProps } from './useStyleProps';
30
+
28
31
  // Animation tokens and utilities
29
32
  // Note: Use '@idealyst/theme/animation' for full animation API
30
33
  export { durations, easings, presets } from './animation/tokens';
@@ -0,0 +1,62 @@
1
+ /**
2
+ * useStyleProps - Native implementation
3
+ *
4
+ * Unified hook for applying styles across platforms.
5
+ * On native, combines Unistyles and additional styles into an array.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { View } from '@idealyst/components';
10
+ * import { useStyleProps } from '@idealyst/theme';
11
+ *
12
+ * function MyComponent({ style }: { style?: StyleProp<ViewStyle> }) {
13
+ * const styleProps = useStyleProps(
14
+ * (myStyles.container as any)({}), // Unistyles
15
+ * [style, { marginTop: 16 }] // Additional styles (array or single)
16
+ * );
17
+ *
18
+ * // Native: spreads { style: [unistyles, ...inlineStyles] }
19
+ * return <View {...styleProps}>Content</View>;
20
+ * }
21
+ * ```
22
+ */
23
+
24
+ import { useMemo } from 'react';
25
+ import type { StyleProp, ViewStyle, TextStyle, ImageStyle } from 'react-native';
26
+
27
+ type AnyStyle = ViewStyle | TextStyle | ImageStyle;
28
+ type StyleInput = AnyStyle | StyleProp<AnyStyle> | undefined | null | false;
29
+
30
+ export interface StyleProps {
31
+ /** Style array to pass to React Native components */
32
+ style?: StyleInput[];
33
+ }
34
+
35
+ /**
36
+ * Hook that returns style props for native components.
37
+ *
38
+ * @param unistyles - Unistyles style (from stylesheet)
39
+ * @param inlineStyles - Additional inline styles (single style or array)
40
+ * @returns Object with style array to spread onto element
41
+ */
42
+ export function useStyleProps(
43
+ unistyles: StyleInput,
44
+ inlineStyles?: StyleInput | StyleInput[]
45
+ ): StyleProps {
46
+ return useMemo(() => {
47
+ // Combine unistyles with inline styles into array
48
+ const styles: StyleInput[] = [unistyles];
49
+
50
+ if (inlineStyles) {
51
+ if (Array.isArray(inlineStyles)) {
52
+ for (const s of inlineStyles) {
53
+ styles.push(s as StyleInput);
54
+ }
55
+ } else {
56
+ styles.push(inlineStyles);
57
+ }
58
+ }
59
+
60
+ return { style: styles };
61
+ }, [unistyles, inlineStyles]);
62
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * useStyleProps - Web implementation
3
+ *
4
+ * Unified hook for applying styles across platforms.
5
+ * On web, wraps Unistyles with getWebProps to generate CSS class names,
6
+ * and passes additional styles for the style prop.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { View } from '@idealyst/components';
11
+ * import { useStyleProps } from '@idealyst/theme';
12
+ *
13
+ * function MyComponent({ style }: { style?: StyleProp<ViewStyle> }) {
14
+ * const styleProps = useStyleProps(
15
+ * (myStyles.container as any)({}), // Unistyles (goes through getWebProps)
16
+ * [style, { marginTop: 16 }] // Additional styles (array or single)
17
+ * );
18
+ *
19
+ * // Web: spreads { className, ref, style }
20
+ * return <View {...styleProps}>Content</View>;
21
+ * }
22
+ * ```
23
+ */
24
+
25
+ import { useMemo } from 'react';
26
+ import type { StyleProp, ViewStyle, TextStyle, ImageStyle } from 'react-native';
27
+ import { getWebProps } from 'react-native-unistyles/web';
28
+
29
+ type AnyStyle = ViewStyle | TextStyle | ImageStyle | React.CSSProperties;
30
+ type StyleInput = AnyStyle | StyleProp<AnyStyle> | undefined | null | false;
31
+
32
+ export interface StyleProps {
33
+ /** CSS class name(s) for the element (from Unistyles) */
34
+ className?: string;
35
+ /** Ref to attach to the element (required for Unistyles on web) */
36
+ ref?: React.Ref<any>;
37
+ /** Additional inline styles */
38
+ style?: StyleInput | StyleInput[];
39
+ }
40
+
41
+ /**
42
+ * Hook that returns style props for web components.
43
+ *
44
+ * @param unistyles - Unistyles style (from stylesheet), passed to getWebProps
45
+ * @param inlineStyles - Additional inline styles (single style or array)
46
+ * @returns Object with className, ref, and style to spread onto element
47
+ */
48
+ export function useStyleProps(
49
+ unistyles: StyleInput,
50
+ inlineStyles?: StyleInput | StyleInput[]
51
+ ): StyleProps {
52
+ return useMemo(() => {
53
+ // Process Unistyles through getWebProps
54
+ const webProps = getWebProps(unistyles as any);
55
+
56
+ return {
57
+ ...webProps,
58
+ style: inlineStyles,
59
+ };
60
+ }, [unistyles, inlineStyles]);
61
+ }