From f8bffa473dccbf582482d116fbe81b460aa933d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Mon, 31 Jul 2023 14:24:02 +0300 Subject: [PATCH] Refactor #4211 - For Badge Directive --- .../lib/badgedirective/BadgeDirective.d.ts | 32 ++++++++++++++++++- .../lib/badgedirective/BadgeDirective.js | 4 ++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/components/lib/badgedirective/BadgeDirective.d.ts b/components/lib/badgedirective/BadgeDirective.d.ts index 518e3144a..b86c7baee 100644 --- a/components/lib/badgedirective/BadgeDirective.d.ts +++ b/components/lib/badgedirective/BadgeDirective.d.ts @@ -9,7 +9,14 @@ import { DirectiveBinding, ObjectDirective } from 'vue'; import { DirectiveHooks } from '../basedirective'; -export declare type BadgeDirectivePassThroughOptionType = BadgeDirectivePassThroughAttributes | null | undefined; +export declare type BadgeDirectivePassThroughOptionType = BadgeDirectivePassThroughAttributes | ((options: BadgePassThroughMethodOptions) => BadgeDirectivePassThroughAttributes) | null | undefined; + +/** + * Custom passthrough(pt) option method. + */ +export interface BadgePassThroughMethodOptions { + context: BadgeContext; +} /** * Defines options of Badge. @@ -50,6 +57,29 @@ export interface BadgeDirectivePassThroughAttributes { [key: string]: any; } +/** + * Defines current options in Badge directive. + */ +export interface BadgeContext { + /** + * Current info state as a boolean. + * @defaultValue true + */ + info: boolean; + /** + * Current success state as a boolean. + */ + success: boolean; + /** + * Current warning state as a boolean. + */ + warning: boolean; + /** + * Current danger state as a boolean. + */ + danger: boolean; +} + /** * Defines modifiers of Badge directive. */ diff --git a/components/lib/badgedirective/BadgeDirective.js b/components/lib/badgedirective/BadgeDirective.js index dbc1bf433..c30a4d454 100644 --- a/components/lib/badgedirective/BadgeDirective.js +++ b/components/lib/badgedirective/BadgeDirective.js @@ -10,7 +10,9 @@ const BadgeDirective = BaseBadgeDirective.extend('badge', { const badge = DomHandler.createElement('span', { id, class: !el.unstyled && this.cx('root'), - 'p-bind': this.ptm('root') + 'p-bind': this.ptm('root', { + context: binding.modifiers + }) }); el.$_pbadgeId = badge.getAttribute('id');