{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "native-internal-hook-use-resolved-style-property", "type": "registry:hook", "title": "Use Resolved Style Property", "description": "Use Resolved Style Property from @pitsi-ui/native for native projects.", "dependencies": [ "uniwind" ], "registryDependencies": [], "files": [ { "path": "registry/native-ui/src/helpers/internal/hooks/use-resolved-style-property.ts", "content": "import { useMemo } from \"react\";\nimport type { ImageStyle, StyleProp, TextStyle, ViewStyle } from \"react-native\";\nimport { StyleSheet } from \"react-native\";\nimport { useResolveClassNames } from \"uniwind\";\n\n/**\n * Combined style type from React Native\n */\ntype Style = ViewStyle | TextStyle | ImageStyle;\n\n/**\n * Parameters for single property resolution\n */\ninterface UseResolvedStylePropertyParamsSingle {\n /** The className string to resolve styles from */\n className?: string;\n /** The style prop (can be object, array, or null) */\n style?: StyleProp | StyleProp | StyleProp;\n /** The name of the style property to resolve */\n propertyName: K;\n}\n\n/**\n * Parameters for multiple properties resolution\n */\ninterface UseResolvedStylePropertyParamsMultiple {\n /** The className string to resolve styles from */\n className?: string;\n /** The style prop (can be object, array, or null) */\n style?: StyleProp | StyleProp | StyleProp;\n /** Array of style property names to resolve */\n propertyNames: readonly K[];\n}\n\n/**\n * A hook that resolves specific style properties from both className and style props.\n * The style prop takes precedence over className.\n *\n * This is useful when you need to extract specific style values (like width, height)\n * that might come from either Tailwind classes or inline styles.\n *\n * @param params - Configuration object with className, style, and propertyName(s)\n * @returns The resolved style property value(s) or undefined if not found\n *\n * @example Single property\n * ```tsx\n * const width = useResolvedStyleProperty({\n * className: 'w-10 h-8',\n * style: { width: 50 },\n * propertyName: 'width',\n * });\n * // Returns: 50 (from style, takes precedence)\n * ```\n *\n * @example Multiple properties\n * ```tsx\n * const [width, left] = useResolvedStyleProperty({\n * className: 'w-10 left-2',\n * propertyNames: ['width', 'left'],\n * });\n * // Returns: [40, 8] (from className)\n * ```\n */\nfunction useResolvedStyleProperty(\n params: UseResolvedStylePropertyParamsSingle,\n): Style[K] | undefined;\nfunction useResolvedStyleProperty(\n params: UseResolvedStylePropertyParamsMultiple,\n): (Style[K] | undefined)[];\nfunction useResolvedStyleProperty(\n params: UseResolvedStylePropertyParamsSingle | UseResolvedStylePropertyParamsMultiple,\n): Style[K] | undefined | (Style[K] | undefined)[] {\n const { className, style } = params;\n\n const resolvedClassName = useResolveClassNames(className ?? \"\");\n const resolvedStyle = useMemo(() => (style ? StyleSheet.flatten(style) : undefined), [style]);\n\n return useMemo(() => {\n // Check if we're resolving multiple properties\n if (\"propertyNames\" in params) {\n return params.propertyNames.map((propertyName) => {\n // Style prop takes precedence over className\n if (resolvedStyle && propertyName in resolvedStyle) {\n return resolvedStyle[propertyName];\n }\n\n // Fall back to className-resolved styles\n if (resolvedClassName && propertyName in resolvedClassName) {\n return resolvedClassName[propertyName];\n }\n\n return undefined;\n });\n }\n\n // Single property resolution\n const propertyName = params.propertyName;\n\n // Style prop takes precedence over className\n if (resolvedStyle && propertyName in resolvedStyle) {\n return resolvedStyle[propertyName];\n }\n\n // Fall back to className-resolved styles\n if (resolvedClassName && propertyName in resolvedClassName) {\n return resolvedClassName[propertyName];\n }\n\n return undefined;\n }, [resolvedStyle, resolvedClassName, params]);\n}\n\nexport { useResolvedStyleProperty };\n", "type": "registry:hook", "target": "@components/pitsi-ui/native-ui/src/helpers/internal/hooks/use-resolved-style-property.ts" } ], "categories": [ "native", "react-native", "internal-hooks" ], "meta": { "package": "@pitsi-ui/native", "packageSlug": "native-ui", "platform": "native" } }