Skip to content

Commit

Permalink
Refactor #3832 Refactor #3833 - For TriStateCheckbox
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Apr 4, 2023
1 parent 6672378 commit 5ea5069
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
18 changes: 17 additions & 1 deletion api-generator/components/tristatecheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,26 @@ const TriStateCheckboxProps = [
}
];

const TriStateCheckboxSlots = [
{
name: 'checkicon',
description: 'Custom check icon template.'
},
{
name: 'uncheckicon',
description: 'Custom uncheck icon template.'
},
{
name: 'nullableicon',
description: 'Custom nullable icon template.'
}
];

module.exports = {
tristatecheckbox: {
name: 'TriStateCheckbox',
description: 'TriStateCheckbox is used to select either "true", "false" or "null" as the value.',
props: TriStateCheckboxProps
props: TriStateCheckboxProps,
slots: TriStateCheckboxSlots
}
};
17 changes: 15 additions & 2 deletions components/lib/tristatecheckbox/TriStateCheckbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @module tristatecheckbox
*
*/
import { InputHTMLAttributes } from 'vue';
import { InputHTMLAttributes, VNode } from 'vue';
import { ClassComponent, GlobalComponentConstructor, Nullable } from '../ts-helpers';

/**
Expand Down Expand Up @@ -49,7 +49,20 @@ export interface TriStateCheckboxProps {
/**
* Defines valid slots in TriStateCheckbox component.
*/
export interface TriStateCheckboxSlots {}
export interface TriStateCheckboxSlots {
/**
* Custom check icon template.
*/
checkicon(): VNode[];
/**
* Custom uncheck icon template.
*/
uncheckicon(): VNode[];
/**
* Custom nullable icon template.
*/
nullableicon(): VNode[];
}

/**
* Defines valid emits in TriStateCheckbox component.
Expand Down
15 changes: 14 additions & 1 deletion components/lib/tristatecheckbox/TriStateCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@
</div>
<span class="p-sr-only" aria-live="polite">{{ ariaValueLabel }}</span>
<div ref="box" :class="['p-checkbox-box', { 'p-highlight': modelValue != null, 'p-disabled': disabled, 'p-focus': focused }]">
<span :class="['p-checkbox-icon', icon]"></span>
<slot v-if="modelValue === true" name="checkicon">
<component :is="'CheckIcon'" class="p-checkbox-icon" />
</slot>
<slot v-else-if="modelValue === false" name="uncheckicon">
<component :is="'TimesIcon'" class="p-checkbox-icon" />
</slot>
<slot v-else name="nullableicon" />
</div>
</div>
</template>

<script>
import CheckIcon from 'primevue/icon/check';
import TimesIcon from 'primevue/icon/times';
export default {
name: 'TriStateCheckbox',
emits: ['click', 'update:modelValue', 'change', 'keydown', 'focus', 'blur'],
Expand Down Expand Up @@ -136,6 +145,10 @@ export default {
ariaValueLabel() {
return this.modelValue ? this.$primevue.config.locale.aria.trueLabel : this.modelValue === false ? this.$primevue.config.locale.aria.falseLabel : this.$primevue.config.locale.aria.nullLabel;
}
},
components: {
CheckIcon: CheckIcon,
TimesIcon: TimesIcon
}
};
</script>

0 comments on commit 5ea5069

Please sign in to comment.