@quidone/react-native-wheel-picker
Version:
Picker is a UI component for selecting an item from a list of options.
57 lines (56 loc) • 2.3 kB
JavaScript
;
import React, { createContext, forwardRef, memo, useContext } from 'react';
import { useMemoObject } from '@rozhkov/react-useful-hooks';
import { jsx as _jsx } from "react/jsx-runtime";
const DatePickerCommonPropsContext = /*#__PURE__*/createContext(undefined);
const DatePickerCommonPropsProvider = ({
children,
...restProps
}) => {
const memoizedValue = useMemoObject(restProps);
return /*#__PURE__*/_jsx(DatePickerCommonPropsContext.Provider, {
value: memoizedValue,
children: children
});
};
export default DatePickerCommonPropsProvider;
const useDatePickerCommonProps = () => {
const value = useContext(DatePickerCommonPropsContext);
if (value === undefined) {
throw new Error('useDatePickerCommonProps must be called from within DatePickerCommonPropsContext.Provider!');
}
return useContext(DatePickerCommonPropsContext);
};
export const withCommonProps = WheelPickerComponent => {
const WrappedWheelPicker = ({
style: pickerStyleProp,
contentContainerStyle: contentContainerStyleProp,
itemTextStyle: itemTextStyleProp,
overlayItemStyle: overlayItemStyleProp,
...restProps
}, forwardedRef) => {
const {
pickerStyle: pickerStyleCommon,
contentContainerStyle: contentContainerStyleCommon,
itemTextStyle: itemTextStyleCommon,
overlayItemStyle: overlayItemStyleCommon,
...restCommonProps
} = useDatePickerCommonProps();
const style = useMemoObject([pickerStyleCommon, pickerStyleProp]);
const contentContainerStyle = useMemoObject([contentContainerStyleCommon, contentContainerStyleProp]);
const itemTextStyle = useMemoObject([itemTextStyleCommon, itemTextStyleProp]);
const overlayItemStyle = useMemoObject([overlayItemStyleCommon, overlayItemStyleProp]);
return /*#__PURE__*/_jsx(WheelPickerComponent, {
...restCommonProps,
...restProps,
style: style,
contentContainerStyle: contentContainerStyle,
itemTextStyle: itemTextStyle,
overlayItemStyle: overlayItemStyle,
ref: forwardedRef
});
};
WrappedWheelPicker.displayName = `withDateCommonProps(${WheelPickerComponent.displayName})`;
return /*#__PURE__*/memo(/*#__PURE__*/forwardRef(WrappedWheelPicker));
};
//# sourceMappingURL=DatePickerCommonPropsProvider.js.map