@pedidopago/ui 1.12.13 → 1.12.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/TimeInput/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,mBAAmB,EAKpB,MAAM,OAAO,CAAC;AA4Bf,OAAO,EAAE,cAAc,EAAc,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKjD,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/TimeInput/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,mBAAmB,EAKpB,MAAM,OAAO,CAAC;AA4Bf,OAAO,EAAE,cAAc,EAAc,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKjD,eAAO,MAAM,SAAS,uKAkRrB,CAAC"}
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
// Styles
|
|
6
6
|
// Types
|
|
7
7
|
// Constants
|
|
8
|
-
function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})),keys.push.apply(keys,symbols)}return keys}function _objectSpread(target){for(var source,i=1;i<arguments.length;i++)source=null==arguments[i]?{}:arguments[i],i%2?ownKeys(Object(source),!0).forEach(function(key){_defineProperty(target,key,source[key])}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))});return target}function _defineProperty(obj,key,value){return key=_toPropertyKey(key),key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}function _toPropertyKey(arg){var key=_toPrimitive(arg,"string");return"symbol"===_typeof(key)?key:key+""}function _toPrimitive(input,hint){if("object"!==_typeof(input)||null===input)return input;var prim=input[Symbol.toPrimitive];if(prim!==void 0){var res=prim.call(input,hint||"default");if("object"!==_typeof(res))return res;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===hint?String:Number)(input)}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(o){if("string"==typeof o)return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,minLen):void 0}}function _arrayLikeToArray(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_x,_r,_arr=[],_n=!0,_d=!1;try{if(_x=(_i=_i.call(arr)).next,0===i){if(Object(_i)!==_i)return;_n=!1}else for(;!(_n=(_s=_x.call(_i)).done)&&(_arr.push(_s.value),_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{if(!_n&&null!=_i.return&&(_r=_i.return(),Object(_r)!==_r))return}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}function _objectWithoutProperties(source,excluded){if(null==source)return{};var key,i,target=_objectWithoutPropertiesLoose(source,excluded);if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++)key=sourceSymbolKeys[i],0<=excluded.indexOf(key)||Object.prototype.propertyIsEnumerable.call(source,key)&&(target[key]=source[key])}return target}function _objectWithoutPropertiesLoose(source,excluded){if(null==source)return{};var key,i,target={},sourceKeys=Object.keys(source);for(i=0;i<sourceKeys.length;i++)key=sourceKeys[i],0<=excluded.indexOf(key)||(target[key]=source[key]);return target}var TimeInput=/*#__PURE__*/(0,_react.forwardRef)(function(_ref,ref){function handleOnClose(){setIsModalOpen(function(oldState){return!oldState})}function handleReset(){setTimeValue(""),setSelectedTime(""),(0,_utils.handleSetNativeInputValue)(timeInputRef,"")}var _ref$label=_ref.label,label=void 0===_ref$label?"":_ref$label,_ref$placeholder=_ref.placeholder,placeholder=void 0===_ref$placeholder?"":_ref$placeholder,helperText=_ref.helperText,alert=_ref.alert,_ref$variant=_ref.variant,variant=void 0===_ref$variant?"24_hours":_ref$variant,showRemoveButton=_ref.showRemoveButton,rest=_objectWithoutProperties(_ref,_excluded),_useState=(0,_react.useState)(!1),_useState2=_slicedToArray(_useState,2),isModalOpen=_useState2[0],setIsModalOpen=_useState2[1],timeInputRef=(0,_react.useRef)(null),mainContainer=(0,_react.useRef)(null),hourContainerRef=(0,_react.useRef)(null),minuteContainerRef=(0,_react.useRef)(null),hourElementRef=(0,_react.useRef)(null),minuteElementRef=(0,_react.useRef)(null),timePeriodContainerRef=(0,_react.useRef)(null),_useState3=(0,_react.useState)("00:00"),_useState4=_slicedToArray(_useState3,2),selectedTime=_useState4[0],setSelectedTime=_useState4[1],_useState5=(0,_react.useState)(),_useState6=_slicedToArray(_useState5,2),timeValue=_useState6[0],setTimeValue=_useState6[1],_useState7=(0,_react.useState)("PM"),_useState8=_slicedToArray(_useState7,2),selectedPeriod=_useState8[0],setSelectedPeriod=_useState8[1],_useState9=(0,_react.useState)(),_useState10=_slicedToArray(_useState9,2),periodValue=_useState10[0],setPeriodValue=_useState10[1],HOUR_LIST="24_hours"===variant?_constants.TWENTY_FOUR_HOUR_LIST:_constants.AM_PM_HOUR_LIST,observerOptions=(0,_utils.setObserverOptions)(mainContainer),isAmPmVariant="am_pm"===variant,_useDraggableScroll=(0,_useDraggableScroll4.useDraggableScroll)(hourContainerRef,{direction:"vertical"}),onMouseDownHour=_useDraggableScroll.onMouseDown,_useDraggableScroll2=(0,_useDraggableScroll4.useDraggableScroll)(minuteContainerRef,{direction:"vertical"}),onMouseDownMinute=_useDraggableScroll2.onMouseDown,_useDraggableScroll3=(0,_useDraggableScroll4.useDraggableScroll)(timePeriodContainerRef,{direction:"vertical"}),onMouseDownTimePeriod=_useDraggableScroll3.onMouseDown;return(0,_react.useImperativeHandle)(ref,function(){return timeInputRef.current}),(0,_react.useEffect)(function(){hourContainerRef.current&&minuteContainerRef.current&&timeValue&&(0,_utils.handleScrollIntoView)(hourContainerRef,minuteContainerRef,timeValue,timePeriodContainerRef)},[isModalOpen]),/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles.TimeInputContainer,{children:[/*#__PURE__*/(0,_jsxRuntime.jsx)(_Input.default,_objectSpread(_objectSpread({"data-testid":"time-input",ref:timeInputRef,leftIcon:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Icon.default,{name:"clock",color:"neutral.neutral5"}),onLeftIconClick:function(){var _timeInputRef$current,_timeInputRef$current2;setSelectedTime(null===(_timeInputRef$current=timeInputRef.current)||void 0===_timeInputRef$current?void 0:_timeInputRef$current.value),setTimeValue(null===(_timeInputRef$current2=timeInputRef.current)||void 0===_timeInputRef$current2?void 0:_timeInputRef$current2.value),rest.disabled||setIsModalOpen(function(oldState){return!oldState})},rightIcon:showRemoveButton&&/*#__PURE__*/(0,_jsxRuntime.jsx)(_framerMotion.AnimatePresence,{mode:"wait",children:timeValue?/*#__PURE__*/(0,_jsxRuntime.jsx)(_framerMotion.motion.div,{initial:{opacity:0,x:10},animate:{opacity:1,x:0},exit:{opacity:0,x:10},transition:{duration:.2,ease:"easeInOut"},children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Icon.default,{name:"trash-2",color:"error.default"})}):void 0}),onRightIconClick:function onRightIconClick(){showRemoveButton&&handleReset()},label:label,type:"24_hours"===variant?"tel":"text",placeholder:placeholder||"HH:MM ".concat("am_pm"===variant?"AM/PM":""),helperText:helperText,alert:alert,disabled:!!rest.disabled,tabIndex:rest.disabled?-1:0,className:rest.className,style:rest.style},rest),{},{onChange:function onChange(event){var _rest$onChange;event.currentTarget.value=(0,_utils.onChangeFormatter)(event,isAmPmVariant),setTimeValue(event.currentTarget.value),setSelectedTime(event.currentTarget.value),(0,_utils.handleSetNativeInputValue)(timeInputRef,event.currentTarget.value),null===(_rest$onChange=rest.onChange)||void 0===_rest$onChange?void 0:_rest$onChange.call(rest,event)},onBlur:function onBlur(event){event.currentTarget.value=(0,_utils.onBlurTimeInputFormatter)(event,rest.onChange)}})),/*#__PURE__*/(0,_jsxRuntime.jsx)(_Modal.Modal,{maxWidth:"min(400px, 90%)",maxHeight:"370px",open:isModalOpen,onClose:handleOnClose,children:/*#__PURE__*/(0,_jsxRuntime.jsxs)(_Flex.default,{direction:"column",alignItems:"center",spacing:"8",style:{padding:"2em",width:"100%"},children:[/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles.ClockContent,{ref:mainContainer,variant:variant,children:[/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles.DigitContainer,{ref:hourContainerRef,onMouseDown:onMouseDownHour,children:[/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:"hour_separator",ref:hourElementRef}),HOUR_LIST.map(function(hour,index){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_Observer.Observer,{onObserved:function onObserved(){setSelectedTime(function(state){var _state$split=state.split(":"),_state$split2=_slicedToArray(_state$split,2),minute=_state$split2[1];return"".concat(hour,":").concat(minute)})},observerOptions:observerOptions,children:/*#__PURE__*/(0,_jsxRuntime.jsx)("li",{children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Typography.default,{fontSize:"xl",fontWeight:"600",color:"neutral.neutral6","data-input-hour":hour,children:hour})})},"hour-".concat(index))})]}),/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:"comma",children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Typography.default,{fontSize:"xl",fontWeight:"600",color:"neutral.neutral6",children:":"})}),/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles.DigitContainer,{ref:minuteContainerRef,onMouseDown:onMouseDownMinute,children:[/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:"minutes_separator",ref:minuteElementRef}),_constants.MINUTE_LIST.map(function(minute,index){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_Observer.Observer,{onObserved:function onObserved(){setSelectedTime(function(state){var _state$split3=state.split(":"),_state$split4=_slicedToArray(_state$split3,1),hour=_state$split4[0];return"".concat(hour,":").concat(minute)})},observerOptions:observerOptions,children:/*#__PURE__*/(0,_jsxRuntime.jsx)("li",{children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Typography.default,{fontSize:"xl",fontWeight:"600",color:"neutral.neutral6","data-input-minute":minute,children:minute})})},"minute-".concat(index))})]}),isAmPmVariant&&/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles.DigitContainer,{ref:timePeriodContainerRef,onMouseDown:onMouseDownTimePeriod,children:[/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:"ampm_separator",ref:minuteElementRef}),_constants.TIME_PERIODS.map(function(period,index){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_Observer.Observer,{onObserved:function onObserved(){setSelectedPeriod(period)},observerOptions:observerOptions,children:/*#__PURE__*/(0,_jsxRuntime.jsx)("li",{children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Typography.default,{fontSize:"xl",fontWeight:"600",color:"neutral.neutral6","data-input-period":period,children:period})})},"am-pm-".concat(index))})]})]}),/*#__PURE__*/(0,_jsxRuntime.jsxs)(_Flex.default,{direction:"row",alignItems:"center",spacing:"4",style:{width:"100%"},children:[/*#__PURE__*/(0,_jsxRuntime.jsx)(_Button.default,{variant:"outline",bgColor:"tertiary.default",textColor:"tertiary.focus",fullWidth:!0,onClick:handleOnClose,children:"Cancelar"}),/*#__PURE__*/(0,_jsxRuntime.jsx)(_Button.default,{fullWidth:!0,onClick:function(){var timeFormatted=selectedTime;if(isAmPmVariant?(setPeriodValue(periodValue),timeFormatted="".concat(selectedTime," ").concat(selectedPeriod),setTimeValue(timeFormatted)):setTimeValue(timeFormatted),timeInputRef.current){var _nativeInputValueSett,nativeInputValueSetter=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value");null===nativeInputValueSetter||void 0===nativeInputValueSetter||null===(_nativeInputValueSett=nativeInputValueSetter.set)||void 0===_nativeInputValueSett?void 0:_nativeInputValueSett.call(timeInputRef.current,timeFormatted);var event=new Event("input",{bubbles:!0});timeInputRef.current.dispatchEvent(event)}setIsModalOpen(!1)},"data-testid":"time-input-confirm-button",children:"Ok"})]})]})})]})});exports.TimeInput=TimeInput,TimeInput.displayName="TimeInput";
|
|
8
|
+
function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})),keys.push.apply(keys,symbols)}return keys}function _objectSpread(target){for(var source,i=1;i<arguments.length;i++)source=null==arguments[i]?{}:arguments[i],i%2?ownKeys(Object(source),!0).forEach(function(key){_defineProperty(target,key,source[key])}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))});return target}function _defineProperty(obj,key,value){return key=_toPropertyKey(key),key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}function _toPropertyKey(arg){var key=_toPrimitive(arg,"string");return"symbol"===_typeof(key)?key:key+""}function _toPrimitive(input,hint){if("object"!==_typeof(input)||null===input)return input;var prim=input[Symbol.toPrimitive];if(prim!==void 0){var res=prim.call(input,hint||"default");if("object"!==_typeof(res))return res;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===hint?String:Number)(input)}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(o){if("string"==typeof o)return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,minLen):void 0}}function _arrayLikeToArray(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_x,_r,_arr=[],_n=!0,_d=!1;try{if(_x=(_i=_i.call(arr)).next,0===i){if(Object(_i)!==_i)return;_n=!1}else for(;!(_n=(_s=_x.call(_i)).done)&&(_arr.push(_s.value),_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{if(!_n&&null!=_i.return&&(_r=_i.return(),Object(_r)!==_r))return}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}function _objectWithoutProperties(source,excluded){if(null==source)return{};var key,i,target=_objectWithoutPropertiesLoose(source,excluded);if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++)key=sourceSymbolKeys[i],0<=excluded.indexOf(key)||Object.prototype.propertyIsEnumerable.call(source,key)&&(target[key]=source[key])}return target}function _objectWithoutPropertiesLoose(source,excluded){if(null==source)return{};var key,i,target={},sourceKeys=Object.keys(source);for(i=0;i<sourceKeys.length;i++)key=sourceKeys[i],0<=excluded.indexOf(key)||(target[key]=source[key]);return target}var TimeInput=/*#__PURE__*/(0,_react.forwardRef)(function(_ref,ref){function handleOnClose(){setIsModalOpen(function(oldState){return!oldState})}function handleReset(){setTimeValue(""),setSelectedTime(""),(0,_utils.handleSetNativeInputValue)(timeInputRef,"")}var _ref$label=_ref.label,label=void 0===_ref$label?"":_ref$label,_ref$placeholder=_ref.placeholder,placeholder=void 0===_ref$placeholder?"":_ref$placeholder,helperText=_ref.helperText,alert=_ref.alert,_ref$variant=_ref.variant,variant=void 0===_ref$variant?"24_hours":_ref$variant,showRemoveButton=_ref.showRemoveButton,rest=_objectWithoutProperties(_ref,_excluded),_useState=(0,_react.useState)(!1),_useState2=_slicedToArray(_useState,2),isModalOpen=_useState2[0],setIsModalOpen=_useState2[1],timeInputRef=(0,_react.useRef)(null),mainContainer=(0,_react.useRef)(null),hourContainerRef=(0,_react.useRef)(null),minuteContainerRef=(0,_react.useRef)(null),hourElementRef=(0,_react.useRef)(null),minuteElementRef=(0,_react.useRef)(null),timePeriodContainerRef=(0,_react.useRef)(null),_useState3=(0,_react.useState)("00:00"),_useState4=_slicedToArray(_useState3,2),selectedTime=_useState4[0],setSelectedTime=_useState4[1],_useState5=(0,_react.useState)(),_useState6=_slicedToArray(_useState5,2),timeValue=_useState6[0],setTimeValue=_useState6[1],_useState7=(0,_react.useState)("PM"),_useState8=_slicedToArray(_useState7,2),selectedPeriod=_useState8[0],setSelectedPeriod=_useState8[1],_useState9=(0,_react.useState)(),_useState10=_slicedToArray(_useState9,2),periodValue=_useState10[0],setPeriodValue=_useState10[1],HOUR_LIST="24_hours"===variant?_constants.TWENTY_FOUR_HOUR_LIST:_constants.AM_PM_HOUR_LIST,observerOptions=(0,_utils.setObserverOptions)(mainContainer),isAmPmVariant="am_pm"===variant,_useDraggableScroll=(0,_useDraggableScroll4.useDraggableScroll)(hourContainerRef,{direction:"vertical"}),onMouseDownHour=_useDraggableScroll.onMouseDown,_useDraggableScroll2=(0,_useDraggableScroll4.useDraggableScroll)(minuteContainerRef,{direction:"vertical"}),onMouseDownMinute=_useDraggableScroll2.onMouseDown,_useDraggableScroll3=(0,_useDraggableScroll4.useDraggableScroll)(timePeriodContainerRef,{direction:"vertical"}),onMouseDownTimePeriod=_useDraggableScroll3.onMouseDown;return(0,_react.useImperativeHandle)(ref,function(){return timeInputRef.current}),(0,_react.useEffect)(function(){hourContainerRef.current&&minuteContainerRef.current&&timeValue&&(0,_utils.handleScrollIntoView)(hourContainerRef,minuteContainerRef,timeValue,timePeriodContainerRef)},[isModalOpen]),/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles.TimeInputContainer,{children:[/*#__PURE__*/(0,_jsxRuntime.jsx)(_Input.default,_objectSpread(_objectSpread({"data-testid":"time-input",ref:timeInputRef,leftIcon:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Icon.default,{name:"clock",color:"neutral.neutral5"}),onLeftIconClick:function(){var _timeInputRef$current,_timeInputRef$current2;setSelectedTime(null===(_timeInputRef$current=timeInputRef.current)||void 0===_timeInputRef$current?void 0:_timeInputRef$current.value),setTimeValue(null===(_timeInputRef$current2=timeInputRef.current)||void 0===_timeInputRef$current2?void 0:_timeInputRef$current2.value),rest.disabled||setIsModalOpen(function(oldState){return!oldState})},rightIcon:showRemoveButton&&/*#__PURE__*/(0,_jsxRuntime.jsx)(_framerMotion.AnimatePresence,{mode:"wait",children:timeValue?/*#__PURE__*/(0,_jsxRuntime.jsx)(_framerMotion.motion.div,{initial:{opacity:0,x:10},animate:{opacity:1,x:0},exit:{opacity:0,x:10},transition:{duration:.2,ease:"easeInOut"},children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Icon.default,{name:"trash-2",color:"error.default"})}):void 0}),onRightIconClick:function onRightIconClick(){showRemoveButton&&handleReset()},label:label,type:"24_hours"===variant?"tel":"text",placeholder:placeholder||"HH:MM ".concat("am_pm"===variant?"AM/PM":""),helperText:helperText,alert:alert,disabled:!!rest.disabled,tabIndex:rest.disabled?-1:0,className:rest.className,style:rest.style},rest),{},{onChange:function onChange(event){var _rest$onChange;event.currentTarget.value=(0,_utils.onChangeFormatter)(event,isAmPmVariant),setTimeValue(event.currentTarget.value),setSelectedTime(event.currentTarget.value),(0,_utils.handleSetNativeInputValue)(timeInputRef,event.currentTarget.value),null===(_rest$onChange=rest.onChange)||void 0===_rest$onChange?void 0:_rest$onChange.call(rest,event)},onBlur:function onBlur(event){var formattedValue=(0,_utils.onBlurTimeInputFormatter)(event),isFormattedValue=event.currentTarget.value!==formattedValue;isFormattedValue&&(0,_utils.handleSetNativeInputValue)(timeInputRef,formattedValue),event.currentTarget.value=formattedValue}})),/*#__PURE__*/(0,_jsxRuntime.jsx)(_Modal.Modal,{maxWidth:"min(400px, 90%)",maxHeight:"370px",open:isModalOpen,onClose:handleOnClose,children:/*#__PURE__*/(0,_jsxRuntime.jsxs)(_Flex.default,{direction:"column",alignItems:"center",spacing:"8",style:{padding:"2em",width:"100%"},children:[/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles.ClockContent,{ref:mainContainer,variant:variant,children:[/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles.DigitContainer,{ref:hourContainerRef,onMouseDown:onMouseDownHour,children:[/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:"hour_separator",ref:hourElementRef}),HOUR_LIST.map(function(hour,index){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_Observer.Observer,{onObserved:function onObserved(){setSelectedTime(function(state){var _state$split=state.split(":"),_state$split2=_slicedToArray(_state$split,2),minute=_state$split2[1];return"".concat(hour,":").concat(minute)})},observerOptions:observerOptions,children:/*#__PURE__*/(0,_jsxRuntime.jsx)("li",{children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Typography.default,{fontSize:"xl",fontWeight:"600",color:"neutral.neutral6","data-input-hour":hour,children:hour})})},"hour-".concat(index))})]}),/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:"comma",children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Typography.default,{fontSize:"xl",fontWeight:"600",color:"neutral.neutral6",children:":"})}),/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles.DigitContainer,{ref:minuteContainerRef,onMouseDown:onMouseDownMinute,children:[/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:"minutes_separator",ref:minuteElementRef}),_constants.MINUTE_LIST.map(function(minute,index){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_Observer.Observer,{onObserved:function onObserved(){setSelectedTime(function(state){var _state$split3=state.split(":"),_state$split4=_slicedToArray(_state$split3,1),hour=_state$split4[0];return"".concat(hour,":").concat(minute)})},observerOptions:observerOptions,children:/*#__PURE__*/(0,_jsxRuntime.jsx)("li",{children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Typography.default,{fontSize:"xl",fontWeight:"600",color:"neutral.neutral6","data-input-minute":minute,children:minute})})},"minute-".concat(index))})]}),isAmPmVariant&&/*#__PURE__*/(0,_jsxRuntime.jsxs)(_styles.DigitContainer,{ref:timePeriodContainerRef,onMouseDown:onMouseDownTimePeriod,children:[/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{className:"ampm_separator",ref:minuteElementRef}),_constants.TIME_PERIODS.map(function(period,index){return/*#__PURE__*/(0,_jsxRuntime.jsx)(_Observer.Observer,{onObserved:function onObserved(){setSelectedPeriod(period)},observerOptions:observerOptions,children:/*#__PURE__*/(0,_jsxRuntime.jsx)("li",{children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_Typography.default,{fontSize:"xl",fontWeight:"600",color:"neutral.neutral6","data-input-period":period,children:period})})},"am-pm-".concat(index))})]})]}),/*#__PURE__*/(0,_jsxRuntime.jsxs)(_Flex.default,{direction:"row",alignItems:"center",spacing:"4",style:{width:"100%"},children:[/*#__PURE__*/(0,_jsxRuntime.jsx)(_Button.default,{variant:"outline",bgColor:"tertiary.default",textColor:"tertiary.focus",fullWidth:!0,onClick:handleOnClose,children:"Cancelar"}),/*#__PURE__*/(0,_jsxRuntime.jsx)(_Button.default,{fullWidth:!0,onClick:function(){var timeFormatted=selectedTime;if(isAmPmVariant?(setPeriodValue(periodValue),timeFormatted="".concat(selectedTime," ").concat(selectedPeriod),setTimeValue(timeFormatted)):setTimeValue(timeFormatted),timeInputRef.current){var _nativeInputValueSett,nativeInputValueSetter=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value");null===nativeInputValueSetter||void 0===nativeInputValueSetter||null===(_nativeInputValueSett=nativeInputValueSetter.set)||void 0===_nativeInputValueSett?void 0:_nativeInputValueSett.call(timeInputRef.current,timeFormatted);var event=new Event("input",{bubbles:!0});timeInputRef.current.dispatchEvent(event)}setIsModalOpen(!1)},"data-testid":"time-input-confirm-button",children:"Ok"})]})]})})]})});exports.TimeInput=TimeInput,TimeInput.displayName="TimeInput";
|
|
@@ -7,5 +7,5 @@ export declare function setObserverOptions(mainContainer: RefObject<HTMLDivEleme
|
|
|
7
7
|
rootMargin: string;
|
|
8
8
|
};
|
|
9
9
|
export declare function onChangeFormatter(event: React.FormEvent<HTMLInputElement> | React.ChangeEvent<HTMLInputElement>, isAmPmVariant: boolean): string;
|
|
10
|
-
export declare function onBlurTimeInputFormatter(event: React.FormEvent<HTMLInputElement
|
|
10
|
+
export declare function onBlurTimeInputFormatter(event: React.FormEvent<HTMLInputElement>): string;
|
|
11
11
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/TimeInput/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAUlC,wBAAgB,oBAAoB,CAClC,gBAAgB,EAAE,SAAS,CAAC,cAAc,CAAC,EAC3C,kBAAkB,EAAE,SAAS,CAAC,cAAc,CAAC,EAC7C,UAAU,EAAE,MAAM,EAClB,sBAAsB,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,QAkCnD;AAED,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,SAAS,CAAC,gBAAgB,CAAC,EACzC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,QAU5C;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,cAAc,CAAC;;;;EAM1E;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAC9E,aAAa,EAAE,OAAO,UAiDvB;AAED,wBAAgB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/TimeInput/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAUlC,wBAAgB,oBAAoB,CAClC,gBAAgB,EAAE,SAAS,CAAC,cAAc,CAAC,EAC3C,kBAAkB,EAAE,SAAS,CAAC,cAAc,CAAC,EAC7C,UAAU,EAAE,MAAM,EAClB,sBAAsB,CAAC,EAAE,SAAS,CAAC,cAAc,CAAC,QAkCnD;AAED,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,SAAS,CAAC,gBAAgB,CAAC,EACzC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,QAU5C;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,cAAc,CAAC;;;;EAM1E;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAC9E,aAAa,EAAE,OAAO,UAiDvB;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,UA8BhF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use strict";var _constants=require("./constants");Object.defineProperty(exports,"__esModule",{value:!0}),exports.handleScrollIntoView=handleScrollIntoView,exports.handleSetNativeInputValue=handleSetNativeInputValue,exports.onBlurTimeInputFormatter=onBlurTimeInputFormatter,exports.onChangeFormatter=onChangeFormatter,exports.setObserverOptions=setObserverOptions;function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(o){if("string"==typeof o)return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,minLen):void 0}}function _arrayLikeToArray(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_x,_r,_arr=[],_n=!0,_d=!1;try{if(_x=(_i=_i.call(arr)).next,0===i){if(Object(_i)!==_i)return;_n=!1}else for(;!(_n=(_s=_x.call(_i)).done)&&(_arr.push(_s.value),_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{if(!_n&&null!=_i.return&&(_r=_i.return(),Object(_r)!==_r))return}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}// Libs
|
|
2
2
|
// Constants
|
|
3
|
-
function handleScrollIntoView(hourContainerRef,minuteContainerRef,inputValue,timePeriodContainerRef){var _hourContainerRef$cur,_minuteContainerRef$c,_inputValue$split=inputValue.split(/:| /),_inputValue$split2=_slicedToArray(_inputValue$split,3),hour=_inputValue$split2[0],minute=_inputValue$split2[1],period=_inputValue$split2[2],targetHourEl=null===(_hourContainerRef$cur=hourContainerRef.current)||void 0===_hourContainerRef$cur?void 0:_hourContainerRef$cur.querySelector("[data-input-hour=\"".concat(null===hour||void 0===hour?void 0:hour.padStart(2,"0"),"\"]")),targetMinuteEl=null===(_minuteContainerRef$c=minuteContainerRef.current)||void 0===_minuteContainerRef$c?void 0:_minuteContainerRef$c.querySelector("[data-input-minute=\"".concat(null===minute||void 0===minute?void 0:minute.padEnd(2,"0"),"\"]"));if((targetHourEl||targetMinuteEl)&&(null===targetHourEl||void 0===targetHourEl?void 0:targetHourEl.scrollIntoView({behavior:"auto",block:"center"}),null===targetMinuteEl||void 0===targetMinuteEl?void 0:targetMinuteEl.scrollIntoView({behavior:"auto",block:"center"})),timePeriodContainerRef&&period){var _timePeriodContainerR,targetTimePeriodEl=null===(_timePeriodContainerR=timePeriodContainerRef.current)||void 0===_timePeriodContainerR?void 0:_timePeriodContainerR.querySelector("[data-input-period=\"".concat(period,"\"]"));targetTimePeriodEl&&targetTimePeriodEl.scrollIntoView({behavior:"auto",block:"center"})}}function handleSetNativeInputValue(timeInputRef,value){var _nativeInputValueSett;if(timeInputRef.current){var nativeInputValueSetter=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value");null===nativeInputValueSetter||void 0===nativeInputValueSetter||null===(_nativeInputValueSett=nativeInputValueSetter.set)||void 0===_nativeInputValueSett?void 0:_nativeInputValueSett.call(timeInputRef.current,value);var event=new Event("input",{bubbles:!0});timeInputRef.current.dispatchEvent(event)}}function setObserverOptions(mainContainer){return{root:null===mainContainer||void 0===mainContainer?void 0:mainContainer.current,threshold:1,rootMargin:"-40px"}}function onChangeFormatter(event,isAmPmVariant){return void 0===event.currentTarget.value||":"===event.currentTarget.value?"":isAmPmVariant?(event.currentTarget.value=(event.currentTarget.value+"").replace(/(\d{2})(\d{2})/,function(match,hours,minutes){var formattedHours=hours,formattedMinutes=minutes;return 2===formattedHours.length&&(formattedHours=Math.min(parseInt(formattedHours,10),12).toString().padStart(2,"0")),2===formattedMinutes.length&&(formattedMinutes=Math.min(parseInt(formattedMinutes,10),59).toString().padStart(2,"0")),"".concat(formattedHours,":").concat(formattedMinutes)}).replace(/(:\d{2})\d*$/,function(match){var minutesMatch=match.substring(1),formattedMinutes=Math.min(parseInt(minutesMatch,10),59).toString().padStart(2,"0");return":".concat(formattedMinutes)}).substring(0,11),event.currentTarget.value):(event.currentTarget.value+"").replace(/\D/g,"").replace(/(\d{2})(\d)/,function(match,hours,minutes){var formattedHours=hours;return 2===formattedHours.length&&(formattedHours=Math.min(parseInt(formattedHours,10),23).toString().padStart(2,"0")),"".concat(formattedHours,":").concat(minutes)}).replace(/(:\d{2})\d*$/,function(match){var minutesMatch=match.substring(1),formattedMinutes=Math.min(parseInt(minutesMatch,10),59).toString().padStart(2,"0");return":".concat(formattedMinutes)}).substring(0,5)}function onBlurTimeInputFormatter(event
|
|
3
|
+
function handleScrollIntoView(hourContainerRef,minuteContainerRef,inputValue,timePeriodContainerRef){var _hourContainerRef$cur,_minuteContainerRef$c,_inputValue$split=inputValue.split(/:| /),_inputValue$split2=_slicedToArray(_inputValue$split,3),hour=_inputValue$split2[0],minute=_inputValue$split2[1],period=_inputValue$split2[2],targetHourEl=null===(_hourContainerRef$cur=hourContainerRef.current)||void 0===_hourContainerRef$cur?void 0:_hourContainerRef$cur.querySelector("[data-input-hour=\"".concat(null===hour||void 0===hour?void 0:hour.padStart(2,"0"),"\"]")),targetMinuteEl=null===(_minuteContainerRef$c=minuteContainerRef.current)||void 0===_minuteContainerRef$c?void 0:_minuteContainerRef$c.querySelector("[data-input-minute=\"".concat(null===minute||void 0===minute?void 0:minute.padEnd(2,"0"),"\"]"));if((targetHourEl||targetMinuteEl)&&(null===targetHourEl||void 0===targetHourEl?void 0:targetHourEl.scrollIntoView({behavior:"auto",block:"center"}),null===targetMinuteEl||void 0===targetMinuteEl?void 0:targetMinuteEl.scrollIntoView({behavior:"auto",block:"center"})),timePeriodContainerRef&&period){var _timePeriodContainerR,targetTimePeriodEl=null===(_timePeriodContainerR=timePeriodContainerRef.current)||void 0===_timePeriodContainerR?void 0:_timePeriodContainerR.querySelector("[data-input-period=\"".concat(period,"\"]"));targetTimePeriodEl&&targetTimePeriodEl.scrollIntoView({behavior:"auto",block:"center"})}}function handleSetNativeInputValue(timeInputRef,value){var _nativeInputValueSett;if(timeInputRef.current){var nativeInputValueSetter=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value");null===nativeInputValueSetter||void 0===nativeInputValueSetter||null===(_nativeInputValueSett=nativeInputValueSetter.set)||void 0===_nativeInputValueSett?void 0:_nativeInputValueSett.call(timeInputRef.current,value);var event=new Event("input",{bubbles:!0});timeInputRef.current.dispatchEvent(event)}}function setObserverOptions(mainContainer){return{root:null===mainContainer||void 0===mainContainer?void 0:mainContainer.current,threshold:1,rootMargin:"-40px"}}function onChangeFormatter(event,isAmPmVariant){return void 0===event.currentTarget.value||":"===event.currentTarget.value?"":isAmPmVariant?(event.currentTarget.value=(event.currentTarget.value+"").replace(/(\d{2})(\d{2})/,function(match,hours,minutes){var formattedHours=hours,formattedMinutes=minutes;return 2===formattedHours.length&&(formattedHours=Math.min(parseInt(formattedHours,10),12).toString().padStart(2,"0")),2===formattedMinutes.length&&(formattedMinutes=Math.min(parseInt(formattedMinutes,10),59).toString().padStart(2,"0")),"".concat(formattedHours,":").concat(formattedMinutes)}).replace(/(:\d{2})\d*$/,function(match){var minutesMatch=match.substring(1),formattedMinutes=Math.min(parseInt(minutesMatch,10),59).toString().padStart(2,"0");return":".concat(formattedMinutes)}).substring(0,11),event.currentTarget.value):(event.currentTarget.value+"").replace(/\D/g,"").replace(/(\d{2})(\d)/,function(match,hours,minutes){var formattedHours=hours;return 2===formattedHours.length&&(formattedHours=Math.min(parseInt(formattedHours,10),23).toString().padStart(2,"0")),"".concat(formattedHours,":").concat(minutes)}).replace(/(:\d{2})\d*$/,function(match){var minutesMatch=match.substring(1),formattedMinutes=Math.min(parseInt(minutesMatch,10),59).toString().padStart(2,"0");return":".concat(formattedMinutes)}).substring(0,5)}function onBlurTimeInputFormatter(event){var value=event.currentTarget.value,sanitizedValue=value.replace(/\D/g,"");if(4===sanitizedValue.length||!value)return value;var numericValue=+sanitizedValue;if(numericValue>_constants.MAX_VALID_TIME)return"23:59";var shouldPadEndWithZero=3===sanitizedValue.length&&numericValue<_constants.MAX_TIME_TO_PAD_END_WITH_ZERO;if(shouldPadEndWithZero){var hours=sanitizedValue.substring(0,2),minutes=+sanitizedValue[2]>=_constants.MAX_MINUTE_FIRST_DIGIT?"59":sanitizedValue.substring(2).padEnd(2,"0");return"".concat(hours,":").concat(minutes)}return numericValue>_constants.MAX_VALID_HOUR?"23:59":1===sanitizedValue.length?"0".concat(value,":00"):2===sanitizedValue.length?"".concat(value,":00"):value}
|