Skip to content

Commit

Permalink
Refactor #3922 - For TriStateCheckbox
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed May 9, 2023
1 parent f74d88c commit 77888cc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
48 changes: 35 additions & 13 deletions components/lib/tristatecheckbox/TriStateCheckbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export declare type TriStateCheckboxPassThroughOptionType = TriStateCheckboxPass
export interface TriStateCheckboxPassThroughMethodOptions {
props: TriStateCheckboxProps;
state: TriStateCheckboxState;
context: TriStateCheckboxContext;
}

/**
Expand All @@ -29,22 +30,10 @@ export interface TriStateCheckboxPassThroughOptions {
* Uses to pass attributes to the root's DOM element.
*/
root?: TriStateCheckboxPassThroughOptionType;
/**
* Uses to pass attributes to the input aria's DOM element.
*/
inputAria?: TriStateCheckboxPassThroughOptionType;
/**
* Uses to pass attributes to the input's DOM element.
*/
input?: TriStateCheckboxPassThroughOptionType;
/**
* Uses to pass attributes to the sr only aria's DOM element.
*/
srOnlyAria?: TriStateCheckboxPassThroughOptionType;
/**
* Uses to pass attributes to the checkbox box's DOM element.
*/
checboxBox?: TriStateCheckboxPassThroughOptionType;
checbox?: TriStateCheckboxPassThroughOptionType;
/**
* Uses to pass attributes to the check icon's DOM element.
*/
Expand All @@ -57,6 +46,18 @@ export interface TriStateCheckboxPassThroughOptions {
* Uses to pass attributes to the nullable icon's DOM element.
*/
nullableIcon?: TriStateCheckboxPassThroughOptionType;
/**
* Uses to pass attributes to the hidden input wrapper's DOM element.
*/
hiddenInputWrapper?: TriStateCheckboxPassThroughOptionType;
/**
* Uses to pass attributes to the hidden input's DOM element.
*/
hiddenInput?: TriStateCheckboxPassThroughOptionType;
/**
* Uses to pass attributes to the sr only aria's DOM element.
*/
srOnlyAria?: TriStateCheckboxPassThroughOptionType;
}

/**
Expand All @@ -76,6 +77,27 @@ export interface TriStateCheckboxState {
focused: boolean;
}

/**
* Defines current options in TriStateCheckbox component.
*/
export interface TriStateCheckboxContext {
/**
* Current active state as a boolean.
* @defaultValue false
*/
active: boolean;
/**
* Current focused state as a boolean.
* @defaultValue false
*/
focused: boolean;
/**
* Current disabled state as a boolean.
* @defaultValue false
*/
disabled: boolean;
}

/**
* Defines valid properties in TriStateCheckbox component.
*/
Expand Down
15 changes: 12 additions & 3 deletions components/lib/tristatecheckbox/TriStateCheckbox.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div :class="containerClass" @click="onClick($event)" v-bind="ptm('root')">
<div class="p-hidden-accessible" v-bind="ptm('inputAria')">
<div class="p-hidden-accessible" v-bind="ptm('hiddenInputWrapper')">
<input
ref="input"
:id="inputId"
Expand All @@ -13,11 +13,11 @@
@keydown="onKeyDown($event)"
@focus="onFocus($event)"
@blur="onBlur($event)"
v-bind="{ ...inputProps, ...ptm('input') }"
v-bind="{ ...inputProps, ...ptm('hiddenInput') }"
/>
</div>
<span class="p-sr-only" aria-live="polite" v-bind="ptm('srOnlyAria')">{{ ariaValueLabel }}</span>
<div ref="box" :class="['p-checkbox-box', { 'p-highlight': modelValue != null, 'p-disabled': disabled, 'p-focus': focused }]" v-bind="ptm('checboxBox')">
<div ref="box" :class="['p-checkbox-box', { 'p-highlight': modelValue != null, 'p-disabled': disabled, 'p-focus': focused }]" v-bind="getPTOptions('checbox')">
<slot v-if="modelValue === true" name="checkicon">
<component :is="'CheckIcon'" class="p-checkbox-icon" v-bind="ptm('checkIcon')" />
</slot>
Expand Down Expand Up @@ -73,6 +73,15 @@ export default {
};
},
methods: {
getPTOptions(key) {
return this.ptm(key, {
context: {
active: this.modelValue !== null,
focused: this.focused,
disabled: this.disabled
}
});
},
updateModel() {
if (!this.disabled) {
let newValue;
Expand Down

0 comments on commit 77888cc

Please sign in to comment.