Refactor #3922 - For Checkbox
parent
8e6068e26b
commit
9dcb0daa01
|
@ -88,6 +88,12 @@ const CheckboxProps = [
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: 'null',
|
default: 'null',
|
||||||
description: 'Used to define a string that labels the element.'
|
description: 'Used to define a string that labels the element.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'pt',
|
||||||
|
type: 'any',
|
||||||
|
default: 'null',
|
||||||
|
description: 'Uses to pass attributes to DOM elements inside the component.'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,57 @@
|
||||||
import { InputHTMLAttributes, VNode } from 'vue';
|
import { InputHTMLAttributes, VNode } from 'vue';
|
||||||
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
||||||
|
|
||||||
|
export declare type CheckboxPassThroughOptionType = CheckboxPassThroughAttributes | ((options: CheckboxPassThroughMethodOptions) => CheckboxPassThroughAttributes) | null | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom passthrough(pt) option method.
|
||||||
|
*/
|
||||||
|
export interface CheckboxPassThroughMethodOptions {
|
||||||
|
props: CheckboxProps;
|
||||||
|
state: CheckboxState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom passthrough(pt) options.
|
||||||
|
* @see {@link CheckboxProps.pt}
|
||||||
|
*/
|
||||||
|
export interface CheckboxPassThroughOptions {
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the root's DOM element.
|
||||||
|
*/
|
||||||
|
root?: CheckboxPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the input's DOM element.
|
||||||
|
*/
|
||||||
|
input?: CheckboxPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the icon's DOM element.
|
||||||
|
*/
|
||||||
|
icon?: CheckboxPassThroughOptionType;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to the input aria's DOM element.
|
||||||
|
*/
|
||||||
|
inputAria?: CheckboxPassThroughOptionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom passthrough attributes for each DOM elements
|
||||||
|
*/
|
||||||
|
export interface CheckboxPassThroughAttributes {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines current inline state in Checkbox component.
|
||||||
|
*/
|
||||||
|
export interface CheckboxState {
|
||||||
|
/**
|
||||||
|
* Current focus state as a boolean.
|
||||||
|
* @defaultValue false
|
||||||
|
*/
|
||||||
|
focused: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines valid properties in Checkbox component.
|
* Defines valid properties in Checkbox component.
|
||||||
*/
|
*/
|
||||||
|
@ -84,6 +135,11 @@ export interface CheckboxProps {
|
||||||
* Establishes a string value that labels the component.
|
* Establishes a string value that labels the component.
|
||||||
*/
|
*/
|
||||||
'aria-label'?: string | undefined;
|
'aria-label'?: string | undefined;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to DOM elements inside the component.
|
||||||
|
* @type {CheckboxPassThroughOptions}
|
||||||
|
*/
|
||||||
|
pt?: CheckboxPassThroughOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CheckboxSlots {
|
export interface CheckboxSlots {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="containerClass" @click="onClick($event)">
|
<div :class="containerClass" @click="onClick($event)" v-bind="ptm('root')">
|
||||||
<div class="p-hidden-accessible">
|
<div class="p-hidden-accessible">
|
||||||
<input
|
<input
|
||||||
ref="input"
|
ref="input"
|
||||||
|
@ -16,23 +16,25 @@
|
||||||
:aria-label="ariaLabel"
|
:aria-label="ariaLabel"
|
||||||
@focus="onFocus($event)"
|
@focus="onFocus($event)"
|
||||||
@blur="onBlur($event)"
|
@blur="onBlur($event)"
|
||||||
v-bind="inputProps"
|
v-bind="ptm('inputAria')"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div ref="box" :class="['p-checkbox-box', inputClass, { 'p-highlight': checked, 'p-disabled': disabled, 'p-focus': focused }]" :style="inputStyle">
|
<div ref="box" :class="['p-checkbox-box', inputClass, { 'p-highlight': checked, 'p-disabled': disabled, 'p-focus': focused }]" :style="inputStyle" v-bind="{ ...inputProps, ...ptm('input') }">
|
||||||
<slot name="icon" :checked="checked">
|
<slot name="icon" :checked="checked">
|
||||||
<component :is="checked ? 'CheckIcon' : null" class="p-checkbox-icon" />
|
<component :is="checked ? 'CheckIcon' : null" class="p-checkbox-icon" v-bind="ptm('icon')" />
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import BaseComponent from 'primevue/basecomponent';
|
||||||
import CheckIcon from 'primevue/icons/check';
|
import CheckIcon from 'primevue/icons/check';
|
||||||
import { ObjectUtils } from 'primevue/utils';
|
import { ObjectUtils } from 'primevue/utils';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Checkbox',
|
name: 'Checkbox',
|
||||||
|
extends: BaseComponent,
|
||||||
emits: ['click', 'update:modelValue', 'change', 'input', 'focus', 'blur'],
|
emits: ['click', 'update:modelValue', 'change', 'input', 'focus', 'blur'],
|
||||||
props: {
|
props: {
|
||||||
value: null,
|
value: null,
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { CardPassThroughOptions } from '../card';
|
||||||
import { CarouselPassThroughOptions } from '../carousel';
|
import { CarouselPassThroughOptions } from '../carousel';
|
||||||
import { CascadeSelectPassThroughOptions } from '../cascadeselect';
|
import { CascadeSelectPassThroughOptions } from '../cascadeselect';
|
||||||
import { ChartPassThroughOptions } from '../chart';
|
import { ChartPassThroughOptions } from '../chart';
|
||||||
|
import { CheckboxPassThroughOptions } from '../checkbox';
|
||||||
import { ChipPassThroughOptions } from '../chip';
|
import { ChipPassThroughOptions } from '../chip';
|
||||||
import { ConfirmDialogPassThroughOptions } from '../confirmdialog';
|
import { ConfirmDialogPassThroughOptions } from '../confirmdialog';
|
||||||
import { ConfirmPopupPassThroughOptions } from '../confirmpopup';
|
import { ConfirmPopupPassThroughOptions } from '../confirmpopup';
|
||||||
|
@ -82,6 +83,7 @@ interface PrimeVuePTOptions {
|
||||||
carousel?: CarouselPassThroughOptions;
|
carousel?: CarouselPassThroughOptions;
|
||||||
cascadeselect?: CascadeSelectPassThroughOptions;
|
cascadeselect?: CascadeSelectPassThroughOptions;
|
||||||
chart?: ChartPassThroughOptions;
|
chart?: ChartPassThroughOptions;
|
||||||
|
checkbox?: CheckboxPassThroughOptions;
|
||||||
chip?: ChipPassThroughOptions;
|
chip?: ChipPassThroughOptions;
|
||||||
confirmdialog?: ConfirmDialogPassThroughOptions;
|
confirmdialog?: ConfirmDialogPassThroughOptions;
|
||||||
confirmpopup?: ConfirmPopupPassThroughOptions;
|
confirmpopup?: ConfirmPopupPassThroughOptions;
|
||||||
|
|
Loading…
Reference in New Issue