UNPKG

@progress/kendo-vue-dateinputs

Version:
9 lines (8 loc) 4.82 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue"),d=require("@progress/kendo-vue-buttons"),u=require("@progress/kendo-date-math"),l=require("@progress/kendo-vue-common"),m=require("@progress/kendo-vue-intl"),a=require("../messages/main.js"),s=require("../utils.js"),r=require("./utils.js"),y=require("./TimePart.js");function p(e){return typeof e=="function"||Object.prototype.toString.call(e)==="[object Object]"&&!n.isVNode(e)}const V=n.defineComponent({name:"KendoTimeSelector",emits:{change:e=>!0,focus:e=>!0,blur:e=>!0,keydown:e=>!0,reject:e=>!0},props:{cancelButton:{type:Boolean,default:!0},boundRange:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},format:{type:[String,Object],default:function(){return"t"}},max:{type:Date,default:function(){return s.MAX_TIME}},min:{type:Date,default:function(){return s.MIN_TIME}},nowButton:Boolean,steps:{type:Object,default:function(){return{}}},smoothScroll:{type:Boolean,default:!0},tabIndex:Number,value:{type:Date,default:function(){return null}},onChange:Function,onReject:Function,onKeydown:Function},created(){this.dateFormatParts=this.intl.splitDateFormat(this.$props.format),this.mergeValue=r.valueMerger(r.generateGetters(this.dateFormatParts)),this.hasActiveButton=this.hasActiveButton.bind(this),this.currentState=this.$props.value||s.MIDNIGHT_DATE,this.currentValue=this.$props.value},inject:{kendoIntlService:{default:null},kendoLocalizationService:{default:null}},data(){return{currentState:null,currentValue:null,valueDuringOnChange:void 0}},computed:{computedValue(){const e=this.valueDuringOnChange!==void 0?this.valueDuringOnChange:this.$props.value!==null?this.$props.value:this.currentValue;return e!==null?u.cloneDate(e):null},intl(){return m.provideIntlService(this)},current(){return this.currentState!==null?u.cloneDate(this.currentState):null}},mounted(){this.timePart=this.$refs.timePart,this._acceptButton=this.$refs.acceptButton,this._cancelButton=this.$refs.cancelButton},setup(){const e=n.inject("kendoIntlService",{}),t=n.inject("kendoLocalizationService",{});return{kendoIntlService:e,kendoLocalizationService:t}},render(){const{format:e,cancelButton:t,disabled:c,tabIndex:f,smoothScroll:g,min:v,max:S,boundRange:k,nowButton:B,steps:b}=this.$props,h=m.provideLocalizationService(this),i=h.toLanguageString(a.timePickerCancel,a.messages[a.timePickerCancel]),o=h.toLanguageString(a.timePickerSet,a.messages[a.timePickerSet]);return n.createVNode("div",{tabindex:c?void 0:f||0,class:l.classNames("k-timeselector",{"k-disabled":c}),onKeydown:this.handleKeyDown},[n.createVNode(y.TimePart,{ref:"timePart",value:this.current,onChange:this.handleChange,onNowclick:this.handleNowClick,format:e,smoothScroll:g,min:v,max:S,onFocus:this.handleFocus,onBlur:this.handleBlur,boundRange:k,disabled:c,nowButton:B,steps:b},null),n.createVNode("div",{class:"k-time-footer k-actions k-actions-stretched"},[t&&n.createVNode(d.Button,{type:"button",ref:"cancelButton",class:"k-time-cancel",onClick:this.handleReject,title:i,"aria-label":i},p(i)?i:{default:()=>[i]}),n.createVNode(d.Button,{type:"button",ref:"acceptButton",themeColor:"primary",class:"k-time-accept",onClick:this.handleAccept,title:o,"aria-label":o},p(o)?o:{default:()=>[o]})])])},methods:{handleBlur(e){this.$emit("blur",e)},handleFocus(e){this.$emit("focus",e)},focusActiveList(){this.timePart&&this.timePart.focus({preventScroll:!0})},hasActiveButton(){return this._acceptButton?l.canUseDOM&&(document.activeElement===this._acceptButton.$el||document.activeElement===this._cancelButton.$el):!1},handleKeyDown(e){const{keyCode:t}=e;switch(this.$emit("keydown",e),t){case l.Keys.enter:this.hasActiveButton()||this.handleAccept(e);return;default:return}},handleAccept(e){const t=this.mergeValue(u.cloneDate(this.computedValue||r.getNow()),this.timePart?this.timePart.computedValue:this.current);this.currentValue=t,this.valueDuringOnChange=t,this.$emit("change",{event:e,value:this.computedValue,target:this}),this.valueDuringOnChange=void 0},handleReject(e){this.currentState=this.computedValue,this.$emit("reject",e)},handleNowClick(e){const t=this.mergeValue(u.cloneDate(this.computedValue||r.getNow()),r.getNow());this.currentState=t,this.currentValue=t,this.valueDuringOnChange=t,this.$emit("change",{event:e,value:this.computedValue,target:this}),this.valueDuringOnChange=void 0},handleChange(e){this.currentState=e}}});exports.TimeSelector=V;