UNPKG

react-native-ios-utilities

Version:

Utilities for react-native + iOS and wrappers for using swift together with fabric/paper + JSI

121 lines (120 loc) 4.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CardRowColorPicker = void 0; var React = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _Colors = require("../misc/Colors.js"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const PALLETES = [_Colors.Colors.PINK, _Colors.Colors.RED, _Colors.Colors.ORANGE, _Colors.Colors.AMBER, _Colors.Colors.YELLOW, _Colors.Colors.LIGHT_GREEN, _Colors.Colors.GREEN, _Colors.Colors.BLUE, _Colors.Colors.INDIGO, _Colors.Colors.VIOLET, _Colors.Colors.PURPLE, _Colors.Colors.BLUE_GREY, _Colors.Colors.GREY]; const BASE_COLORS = PALLETES.reduce((acc, curr) => { if ('A700' in curr) acc[0].push(curr.A700); acc[1].push(curr['900']); acc[2].push(curr['600']); acc[3].push(curr['300']); return acc; }, [[], [], [], []]); const DEFAULT_COLORS = ['black', 'white', ...BASE_COLORS.flat()]; class CardRowColorPicker extends React.Component { constructor(props) { super(props); this.state = { selectedItem: undefined }; } _listRenderItem = ({ item }) => { const props = this.props; const state = this.state; const isSelected = item === state.selectedItem; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, { style: [styles.listItem, isSelected && styles.listItemSelected, { backgroundColor: item }], onPress: () => { // clear if already selected const selectedItem = isSelected ? undefined : item; this.setState({ selectedItem }); props.onSelectItem?.(selectedItem); } }); }; render() { const state = this.state; const hasSelection = state.selectedItem != null; return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.rootContainer, children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.selectedColorContainer, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.selectedColorLabel, children: 'Selected Color:' }), hasSelection ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.listItem, styles.selectedColorValueContainer, { backgroundColor: state.selectedItem }] }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.selectedColorValue, children: 'N/A' })] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.FlatList, { style: [styles.list], data: DEFAULT_COLORS, renderItem: this._listRenderItem, scrollIndicatorInsets: { left: 10, right: 10 }, keyExtractor: item => item, horizontal: true })] }); } } exports.CardRowColorPicker = CardRowColorPicker; ; const styles = _reactNative.StyleSheet.create({ rootContainer: { marginTop: 12 }, selectedColorContainer: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', minHeight: 25 }, selectedColorLabel: { fontSize: 12 }, selectedColorValue: { fontSize: 12, color: 'rgba(0,0,0,0.3)' }, list: { marginTop: 10, backgroundColor: _Colors.Colors.INDIGO[100], borderRadius: 10, paddingHorizontal: 10, paddingVertical: 10 }, listItem: { height: 25, minWidth: 25, backgroundColor: 'white', borderRadius: 25 / 2, marginRight: 10 }, listItemSelected: { width: 50 }, selectedColorValueContainer: { borderWidth: 3, borderColor: 'rgba(255,255,255,0.75)' } }); //# sourceMappingURL=CardRowColorPicker.js.map