native-variants
Version:
A library for handling variants in React Native components with theme support.
66 lines (65 loc) • 1.94 kB
TypeScript
import type { TextStyle } from "react-native";
import type { Styles } from "../types.js";
/**
* Extracts text-specific styles from a combined style object.
* Useful when you need to apply text styles to a Text component
* from a style object that may contain View styles.
*
* @param style - The combined style object to extract from
* @returns A new object containing only TextStyle properties
*
* @example
* ```ts
* const combinedStyles = {
* backgroundColor: "#fff",
* padding: 16,
* color: "#000",
* fontSize: 14,
* fontWeight: "600",
* };
*
* const textStyles = composeText(combinedStyles);
* // Result: { color: "#000", fontSize: 14, fontWeight: "600" }
*
* // Usage in components
* <View style={combinedStyles}>
* <Text style={composeText(combinedStyles)}>Hello</Text>
* </View>
* ```
*/
export declare function composeText(style?: Styles): Partial<TextStyle>;
/**
* Checks if a style object contains any text-specific styles.
*
* @param style - The style object to check
* @returns True if the style contains at least one text style property
*
* @example
* ```ts
* hasTextStyles({ padding: 10 }); // false
* hasTextStyles({ color: "red" }); // true
* hasTextStyles({ padding: 10, fontSize: 14 }); // true
* ```
*/
export declare function hasTextStyles(style?: Styles): boolean;
/**
* Extracts non-text styles (View styles) from a combined style object.
* Complement to composeText - returns everything except text styles.
*
* @param style - The combined style object to extract from
* @returns A new object containing only non-TextStyle properties
*
* @example
* ```ts
* const combinedStyles = {
* backgroundColor: "#fff",
* padding: 16,
* color: "#000",
* fontSize: 14,
* };
*
* const viewStyles = composeView(combinedStyles);
* // Result: { backgroundColor: "#fff", padding: 16 }
* ```
*/
export declare function composeView(style?: Styles): Styles;