Skip to content

Commit

Permalink
Refactor #3922 - For InputSwitch
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed May 5, 2023
1 parent 6539ba2 commit 636bd1d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
6 changes: 6 additions & 0 deletions api-generator/components/inputswitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
}
];

Expand Down
2 changes: 2 additions & 0 deletions components/lib/config/PrimeVue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -110,6 +111,7 @@ interface PrimeVuePTOptions {
inplace?: InplacePassThroughOptions;
inputmask?: InputMaskPassThroughOptions;
inputnumber?: InputNumberPassThroughOptions;
inputswitch?: InputSwitchPassThroughOptions;
inputtext?: InputTextPassThroughOptions;
megamenu?: MegaMenuPassThroughOptions;
menu?: MenuPassThroughOptions;
Expand Down
51 changes: 51 additions & 0 deletions components/lib/inputswitch/InputSwitch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
11 changes: 7 additions & 4 deletions components/lib/inputswitch/InputSwitch.vue
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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: {
Expand Down

0 comments on commit 636bd1d

Please sign in to comment.