UNPKG

@atlaskit/datetime-picker

Version:

A date time picker allows the user to select an associated date and time.

51 lines (49 loc) 1.74 kB
import _extends from "@babel/runtime/helpers/extends"; import React, { forwardRef } from 'react'; /** * Gets all available ref types from two prop sets and returns * them in a ref prop * * @example * ``` * type P1 = { ref: Ref(HTMLDivElement), ... }; * type P2 = { ref: Ref(HTMLSpanElement), ... }; * * GetRefAttributes(P1, P2) // {ref: Ref(HTMLDivElement | HTMLSpanElement)} * ``` */ /** * Returns one of components depending on a boolean condition. * The result component will be a union of the two props and * an or on both ref types. * * @example * ``` * const Component = componentWithCondition( * isBooleanConditionMet, * ComponentWithConditionMet, * ComponentWithConditionNotMet, * ); * * @param condition Function returning boolean value * @param componentTrue Component that will be returned if conditionGetter is "true" * @param componentFalse Component that will be returned if conditionGetter is "false" * @returns Component Depending on a Condition result */ export function componentWithCondition(condition, ComponentTrue, ComponentFalse) { var ComponentWithCondition = /*#__PURE__*/forwardRef(function (props, ref) { return ( // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore: to unblock React 18.2.0 -> 18.3.1 version bump in Jira condition() ? /*#__PURE__*/React.createElement(ComponentTrue, _extends({}, props, { ref: ref })) : /*#__PURE__*/React.createElement(ComponentFalse, _extends({}, props, { ref: ref })) ); }); if (ComponentTrue.name !== '') { ComponentWithCondition.displayName = "ComponentWithCondition[".concat(condition.name, "]"); } return ComponentWithCondition; }