@viktorvojtek/react-native-simple-components
Version:
Collection of essential UI components based on react-native components
42 lines (41 loc) • 1.81 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const ThemeProvider_1 = require("../ThemeProvider");
const useColoredProps = (props) => {
const theme = (0, ThemeProvider_1.useTheme)();
const coloredPropItems = (0, react_1.useMemo)(() => {
var _a, _b, _c;
if (!props)
return [];
const entries = (_c = (_b = (_a = [
{ color: props.color },
{ borderColor: props.borderColor },
{ bgColor: props.bgColor },
{ backgroundColor: props.backgroundColor },
{ placeholderTextColor: props.placeholderTextColor },
]) === null || _a === void 0 ? void 0 : _a.filter((item) => !!Object.values(item)[0])) === null || _b === void 0 ? void 0 : _b.map((item) => {
var _a, _b;
const itemColor = Object.values(item)[0];
const isThemeColor = Object.keys((_a = theme === null || theme === void 0 ? void 0 : theme.colors) !== null && _a !== void 0 ? _a : {}).includes(itemColor);
if (isThemeColor) {
return {
[Object.keys(item)[0] === "bgColor"
? "backgroundColor"
: Object.keys(item)[0]]: (_b = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _b === void 0 ? void 0 : _b[itemColor],
};
}
return item;
})) !== null && _c !== void 0 ? _c : [];
return entries;
}, [
theme === null || theme === void 0 ? void 0 : theme.colors,
props.backgroundColor,
props.color,
props.borderColor,
props.bgColor,
props.placeholderTextColor,
]);
return coloredPropItems;
};
exports.default = useColoredProps;
;