UNPKG

react-native-global-styler

Version:

Lightweight and developer-friendly React Native styling toolkit with prebuilt styled components and a powerful useGlobalStyler hook for shorthand props like m_10, radius_12, resize_cover, and more.

28 lines (27 loc) 1.09 kB
import { BaseMatcher } from "./types/BaseGlobalStyles"; import { detectStyleKeys, detectStyleValue } from "./styleDetector"; import { ImageGlobalMatcher, } from "./types/ImageGlobalStyles"; import { TextGlobalMatcher } from "./types/TextGlobalStyles"; export const GlobalMatcher = Object.assign(Object.assign(Object.assign({}, BaseMatcher), ImageGlobalMatcher), TextGlobalMatcher); const useGlobalStyler = (keys, prefix) => { const generatedStyles = {}; let activeKeys = Object.keys(keys).filter((k) => keys[k]); if (prefix) { activeKeys = activeKeys.map((e) => e.replace(prefix, '')); } activeKeys.forEach((k) => { if (GlobalMatcher[k]) { generatedStyles[GlobalMatcher[k].key] = GlobalMatcher[k].value; } else { const styles = detectStyleKeys(k); styles.forEach((gk) => { if (detectStyleValue(k) != gk) { generatedStyles[gk] = detectStyleValue(k); } }); } }); return generatedStyles; }; export default useGlobalStyler;