Refactor #3922 - For InputSwitch

pull/3938/head
Tuğçe Küçükoğlu 2023-05-05 16:10:07 +03:00
parent 6539ba296d
commit 636bd1de8f
4 changed files with 66 additions and 4 deletions

View File

@ -40,6 +40,12 @@ const InputSwitchProps = [
type: 'object',
default: 'null',
description: 'Uses to pass all properties of the HTMLInputElement to the focusable input element inside the component.'
},
{
name: 'pt',
type: 'any',
default: 'null',
description: 'Uses to pass attributes to DOM elements inside the component.'
}
];

View File

@ -32,6 +32,7 @@ import { InlineMessagePassThroughOptions } from '../inlinemessage';
import { InplacePassThroughOptions } from '../inplace';
import { InputMaskPassThroughOptions } from '../inputmask';
import { InputNumberPassThroughOptions } from '../inputnumber';
import { InputSwitchPassThroughOptions } from '../inputswitch';
import { InputTextPassThroughOptions } from '../inputtext';
import { MegaMenuPassThroughOptions } from '../megamenu';
import { MenuPassThroughOptions } from '../menu';
@ -110,6 +111,7 @@ interface PrimeVuePTOptions {
inplace?: InplacePassThroughOptions;
inputmask?: InputMaskPassThroughOptions;
inputnumber?: InputNumberPassThroughOptions;
inputswitch?: InputSwitchPassThroughOptions;
inputtext?: InputTextPassThroughOptions;
megamenu?: MegaMenuPassThroughOptions;
menu?: MenuPassThroughOptions;

View File

@ -10,6 +10,57 @@
import { InputHTMLAttributes } from 'vue';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type InputSwitchPassThroughOptionType = InputSwitchPassThroughAttributes | ((options: InputSwitchPassThroughMethodOptions) => InputSwitchPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface InputSwitchPassThroughMethodOptions {
props: InputSwitchProps;
state: InputSwitchState;
}
/**
* Custom passthrough(pt) options.
* @see {@link InputSwitchProps.pt}
*/
export interface InputSwitchPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: InputSwitchPassThroughOptionType;
/**
* Uses to pass attributes to the slider's DOM element.
*/
slider?: InputSwitchPassThroughOptionType;
/**
* Uses to pass attributes to the hidden accessible DOM element.
*/
hiddenAccessible?: InputSwitchPassThroughOptionType;
/**
* Uses to pass attributes to the input aria's DOM element.
*/
inputAria?: InputSwitchPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface InputSwitchPassThroughAttributes {
[key: string]: any;
}
/**
* Defines current inline state in InputSwitch component.
*/
export interface InputSwitchState {
/**
* Current focus state as a boolean.
* @defaultValue false
*/
focused: boolean;
}
/**
* Defines valid properties in InputSwitch component.
*/

View File

@ -1,6 +1,6 @@
<template>
<div :class="containerClass" @click="onClick($event)">
<div class="p-hidden-accessible">
<div :class="containerClass" @click="onClick($event)" v-bind="ptm('root')">
<div class="p-hidden-accessible" v-bind="ptm('hiddenAccessible')">
<input
ref="input"
:id="inputId"
@ -15,16 +15,19 @@
:aria-label="ariaLabel"
@focus="onFocus($event)"
@blur="onBlur($event)"
v-bind="inputProps"
v-bind="ptm('inputAria')"
/>
</div>
<span class="p-inputswitch-slider"></span>
<span class="p-inputswitch-slider" v-bind="{ ...inputProps, ...ptm('slider') }"></span>
</div>
</template>
<script>
import BaseComponent from 'primevue/basecomponent';
export default {
name: 'InputSwitch',
extends: BaseComponent,
emits: ['click', 'update:modelValue', 'change', 'input', 'focus', 'blur'],
props: {
modelValue: {