Refactor #5426 - For InputNumber
parent
898337667e
commit
586936fd95
|
@ -9,7 +9,6 @@
|
||||||
*/
|
*/
|
||||||
import { ButtonHTMLAttributes, InputHTMLAttributes, VNode } from 'vue';
|
import { ButtonHTMLAttributes, InputHTMLAttributes, VNode } from 'vue';
|
||||||
import { ComponentHooks } from '../basecomponent';
|
import { ComponentHooks } from '../basecomponent';
|
||||||
import { ButtonPassThroughOptions } from '../button';
|
|
||||||
import { InputTextPassThroughOptions } from '../inputtext';
|
import { InputTextPassThroughOptions } from '../inputtext';
|
||||||
import { PassThroughOptions } from '../passthrough';
|
import { PassThroughOptions } from '../passthrough';
|
||||||
import { ClassComponent, GlobalComponentConstructor, Nullable, PassThrough } from '../ts-helpers';
|
import { ClassComponent, GlobalComponentConstructor, Nullable, PassThrough } from '../ts-helpers';
|
||||||
|
@ -107,15 +106,13 @@ export interface InputNumberPassThroughOptions<T = any> {
|
||||||
*/
|
*/
|
||||||
buttonGroup?: InputNumberPassThroughOptionType<T>;
|
buttonGroup?: InputNumberPassThroughOptionType<T>;
|
||||||
/**
|
/**
|
||||||
* Used to pass attributes to the Button component.
|
* Used to pass attributes to the increment button's DOM element.
|
||||||
* @see {@link ButtonPassThroughOptions}
|
|
||||||
*/
|
*/
|
||||||
incrementButton?: ButtonPassThroughOptions<InputNumberSharedPassThroughMethodOptions>;
|
incrementButton?: InputNumberPassThroughOptionType<T>;
|
||||||
/**
|
/**
|
||||||
* Used to pass attributes to the Button component.
|
* Used to pass attributes to the decrement button's DOM element.
|
||||||
* @see {@link ButtonPassThroughOptions}
|
|
||||||
*/
|
*/
|
||||||
decrementButton?: ButtonPassThroughOptions<InputNumberSharedPassThroughMethodOptions>;
|
decrementButton?: InputNumberPassThroughOptionType<T>;
|
||||||
/**
|
/**
|
||||||
* Used to manage all lifecycle hooks.
|
* Used to manage all lifecycle hooks.
|
||||||
* @see {@link BaseComponent.ComponentHooks}
|
* @see {@link BaseComponent.ComponentHooks}
|
||||||
|
@ -240,7 +237,7 @@ export interface InputNumberProps {
|
||||||
*/
|
*/
|
||||||
roundingMode?: RoundingMode;
|
roundingMode?: RoundingMode;
|
||||||
/**
|
/**
|
||||||
* Mininum boundary value.
|
* Minimum boundary value.
|
||||||
*/
|
*/
|
||||||
min?: number | undefined;
|
min?: number | undefined;
|
||||||
/**
|
/**
|
||||||
|
@ -339,6 +336,66 @@ export interface InputNumberProps {
|
||||||
* Defines valid slots in InputNumber component.
|
* Defines valid slots in InputNumber component.
|
||||||
*/
|
*/
|
||||||
export interface InputNumberSlots {
|
export interface InputNumberSlots {
|
||||||
|
/**
|
||||||
|
* Custom increment button template.
|
||||||
|
*/
|
||||||
|
incrementbutton(scope: {
|
||||||
|
/**
|
||||||
|
* Mouse down event of increment button.
|
||||||
|
* @param {Event} event - Browser event
|
||||||
|
*/
|
||||||
|
onMousedown: (event: Event) => void;
|
||||||
|
/**
|
||||||
|
* Mouse up event of increment button.
|
||||||
|
* @param {Event} event - Browser event
|
||||||
|
*/
|
||||||
|
onMouseup: (event: Event) => void;
|
||||||
|
/**
|
||||||
|
* Mouse leave event of increment button.
|
||||||
|
* @param {Event} event - Browser event
|
||||||
|
*/
|
||||||
|
onMouseleave: (event: Event) => void;
|
||||||
|
/**
|
||||||
|
* Key down event of increment button.
|
||||||
|
* @param {Event} event - Browser event
|
||||||
|
*/
|
||||||
|
onKeydown: (event: Event) => void;
|
||||||
|
/**
|
||||||
|
* Key up event of increment button.
|
||||||
|
* @param {Event} event - Browser event
|
||||||
|
*/
|
||||||
|
onKeyup: (event: Event) => void;
|
||||||
|
}): VNode[];
|
||||||
|
/**
|
||||||
|
* Custom decrement button template.
|
||||||
|
*/
|
||||||
|
decrementbutton(scope: {
|
||||||
|
/**
|
||||||
|
* Mouse down event of decrement button.
|
||||||
|
* @param {Event} event - Browser event
|
||||||
|
*/
|
||||||
|
onMousedown: (event: Event) => void;
|
||||||
|
/**
|
||||||
|
* Mouse up event of decrement button.
|
||||||
|
* @param {Event} event - Browser event
|
||||||
|
*/
|
||||||
|
onMouseup: (event: Event) => void;
|
||||||
|
/**
|
||||||
|
* Mouse leave event of decrement button.
|
||||||
|
* @param {Event} event - Browser event
|
||||||
|
*/
|
||||||
|
onMouseleave: (event: Event) => void;
|
||||||
|
/**
|
||||||
|
* Key down event of decrement button.
|
||||||
|
* @param {Event} event - Browser event
|
||||||
|
*/
|
||||||
|
onKeydown: (event: Event) => void;
|
||||||
|
/**
|
||||||
|
* Key up event of decrement button.
|
||||||
|
* @param {Event} event - Browser event
|
||||||
|
*/
|
||||||
|
onKeyup: (event: Event) => void;
|
||||||
|
}): VNode[];
|
||||||
/**
|
/**
|
||||||
* Custom increment button icon template.
|
* Custom increment button icon template.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:aria-labelledby="ariaLabelledby"
|
:aria-labelledby="ariaLabelledby"
|
||||||
:aria-label="ariaLabel"
|
:aria-label="ariaLabel"
|
||||||
:aria-invalid="invalid || undefined"
|
:invalid="invalid"
|
||||||
|
:variant="variant"
|
||||||
@input="onUserInput"
|
@input="onUserInput"
|
||||||
@keydown="onInputKeyDown"
|
@keydown="onInputKeyDown"
|
||||||
@paste="onPaste"
|
@paste="onPaste"
|
||||||
|
@ -27,60 +28,55 @@
|
||||||
:unstyled="unstyled"
|
:unstyled="unstyled"
|
||||||
/>
|
/>
|
||||||
<span v-if="showButtons && buttonLayout === 'stacked'" :class="cx('buttonGroup')" v-bind="ptm('buttonGroup')">
|
<span v-if="showButtons && buttonLayout === 'stacked'" :class="cx('buttonGroup')" v-bind="ptm('buttonGroup')">
|
||||||
<INButton :class="[cx('incrementButton'), incrementButtonClass]" v-on="upButtonListeners" :disabled="disabled" :tabindex="-1" aria-hidden="true" v-bind="incrementButtonProps" :pt="ptm('incrementButton')" :unstyled="unstyled">
|
<slot name="incrementbutton" v-on="upButtonListeners">
|
||||||
<template #icon>
|
<button :class="[cx('incrementButton'), incrementButtonClass]" v-on="upButtonListeners" :disabled="disabled" :tabindex="-1" aria-hidden="true" v-bind="{ ...ptm('incrementButton'), ...incrementButtonProps }">
|
||||||
<slot name="incrementbuttonicon">
|
<slot name="incrementbuttonicon">
|
||||||
<component :is="incrementButtonIcon ? 'span' : 'AngleUpIcon'" :class="incrementButtonIcon" v-bind="ptm('incrementButton')['icon']" data-pc-section="incrementbuttonicon" />
|
<component :is="incrementButtonIcon ? 'span' : 'AngleUpIcon'" :class="incrementButtonIcon" v-bind="ptm('incrementButtonIcon')" data-pc-section="incrementbuttonicon" />
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</button>
|
||||||
</INButton>
|
</slot>
|
||||||
<INButton :class="[cx('decrementButton'), decrementButtonClass]" v-on="downButtonListeners" :disabled="disabled" :tabindex="-1" aria-hidden="true" v-bind="decrementButtonProps" :pt="ptm('decrementButton')" :unstyled="unstyled">
|
<slot name="decrementbutton" v-on="downButtonListeners">
|
||||||
<template #icon>
|
<button :class="[cx('decrementButton'), decrementButtonClass]" v-on="downButtonListeners" :disabled="disabled" :tabindex="-1" aria-hidden="true" v-bind="{ ...ptm('decrementButton'), ...decrementButtonProps }">
|
||||||
<slot name="decrementbuttonicon">
|
<slot name="decrementbuttonicon">
|
||||||
<component :is="decrementButtonIcon ? 'span' : 'AngleDownIcon'" :class="decrementButtonIcon" v-bind="ptm('decrementButton')['icon']" data-pc-section="decrementbuttonicon" />
|
<component :is="decrementButtonIcon ? 'span' : 'AngleDownIcon'" :class="decrementButtonIcon" v-bind="ptm('decrementButtonIcon')" data-pc-section="decrementbuttonicon" />
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</button>
|
||||||
</INButton>
|
</slot>
|
||||||
</span>
|
</span>
|
||||||
<INButton
|
<slot name="incrementbutton" v-on="upButtonListeners">
|
||||||
v-if="showButtons && buttonLayout !== 'stacked'"
|
<button
|
||||||
:class="[cx('incrementButton'), incrementButtonClass]"
|
v-if="showButtons && buttonLayout !== 'stacked'"
|
||||||
v-on="upButtonListeners"
|
:class="[cx('incrementButton'), incrementButtonClass]"
|
||||||
:disabled="disabled"
|
v-on="upButtonListeners"
|
||||||
:tabindex="-1"
|
:disabled="disabled"
|
||||||
aria-hidden="true"
|
:tabindex="-1"
|
||||||
v-bind="incrementButtonProps"
|
aria-hidden="true"
|
||||||
:pt="ptm('incrementButton')"
|
v-bind="{ ...ptm('incrementButton'), ...incrementButtonProps }"
|
||||||
:unstyled="unstyled"
|
>
|
||||||
>
|
|
||||||
<template #icon>
|
|
||||||
<slot name="incrementbuttonicon">
|
<slot name="incrementbuttonicon">
|
||||||
<component :is="incrementButtonIcon ? 'span' : 'AngleUpIcon'" :class="incrementButtonIcon" v-bind="ptm('incrementButton')['icon']" data-pc-section="incrementbuttonicon" />
|
<component :is="incrementButtonIcon ? 'span' : 'AngleUpIcon'" :class="incrementButtonIcon" v-bind="ptm('incrementButtonIcon')" data-pc-section="incrementbuttonicon" />
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</button>
|
||||||
</INButton>
|
</slot>
|
||||||
<INButton
|
<slot name="decrementbutton" v-on="downButtonListeners">
|
||||||
v-if="showButtons && buttonLayout !== 'stacked'"
|
<button
|
||||||
:class="[cx('decrementButton'), decrementButtonClass]"
|
v-if="showButtons && buttonLayout !== 'stacked'"
|
||||||
v-on="downButtonListeners"
|
:class="[cx('decrementButton'), decrementButtonClass]"
|
||||||
:disabled="disabled"
|
v-on="downButtonListeners"
|
||||||
:tabindex="-1"
|
:disabled="disabled"
|
||||||
aria-hidden="true"
|
:tabindex="-1"
|
||||||
v-bind="decrementButtonProps"
|
aria-hidden="true"
|
||||||
:pt="ptm('decrementButton')"
|
v-bind="{ ...ptm('decrementButton'), ...decrementButtonProps }"
|
||||||
:unstyled="unstyled"
|
>
|
||||||
>
|
|
||||||
<template #icon>
|
|
||||||
<slot name="decrementbuttonicon">
|
<slot name="decrementbuttonicon">
|
||||||
<component :is="decrementButtonIcon ? 'span' : 'AngleDownIcon'" :class="decrementButtonIcon" v-bind="ptm('decrementButton')['icon']" data-pc-section="decrementbuttonicon" />
|
<component :is="decrementButtonIcon ? 'span' : 'AngleDownIcon'" :class="decrementButtonIcon" v-bind="ptm('decrementButtonIcon')" data-pc-section="decrementbuttonicon" />
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</button>
|
||||||
</INButton>
|
</slot>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Button from 'primevue/button';
|
|
||||||
import AngleDownIcon from 'primevue/icons/angledown';
|
import AngleDownIcon from 'primevue/icons/angledown';
|
||||||
import AngleUpIcon from 'primevue/icons/angleup';
|
import AngleUpIcon from 'primevue/icons/angleup';
|
||||||
import InputText from 'primevue/inputtext';
|
import InputText from 'primevue/inputtext';
|
||||||
|
@ -988,7 +984,6 @@ export default {
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
INInputText: InputText,
|
INInputText: InputText,
|
||||||
INButton: Button,
|
|
||||||
AngleUpIcon: AngleUpIcon,
|
AngleUpIcon: AngleUpIcon,
|
||||||
AngleDownIcon: AngleDownIcon
|
AngleDownIcon: AngleDownIcon
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,16 +8,10 @@ const classes = {
|
||||||
'p-inputwrapper-focus': instance.focused,
|
'p-inputwrapper-focus': instance.focused,
|
||||||
'p-inputnumber-buttons-stacked': props.showButtons && props.buttonLayout === 'stacked',
|
'p-inputnumber-buttons-stacked': props.showButtons && props.buttonLayout === 'stacked',
|
||||||
'p-inputnumber-buttons-horizontal': props.showButtons && props.buttonLayout === 'horizontal',
|
'p-inputnumber-buttons-horizontal': props.showButtons && props.buttonLayout === 'horizontal',
|
||||||
'p-inputnumber-buttons-vertical': props.showButtons && props.buttonLayout === 'vertical',
|
'p-inputnumber-buttons-vertical': props.showButtons && props.buttonLayout === 'vertical'
|
||||||
'p-invalid': props.invalid
|
|
||||||
}
|
|
||||||
],
|
|
||||||
input: ({ props, instance }) => [
|
|
||||||
'p-inputnumber-input',
|
|
||||||
{
|
|
||||||
'p-variant-filled': props.variant ? props.variant === 'filled' : instance.$primevue.config.inputStyle === 'filled'
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
input: 'p-inputnumber-input',
|
||||||
buttonGroup: 'p-inputnumber-button-group',
|
buttonGroup: 'p-inputnumber-button-group',
|
||||||
incrementButton: ({ instance, props }) => [
|
incrementButton: ({ instance, props }) => [
|
||||||
'p-inputnumber-button p-inputnumber-button-up',
|
'p-inputnumber-button p-inputnumber-button-up',
|
||||||
|
|
Loading…
Reference in New Issue