From b228f30c52b56b0c4f20fdfd7cc911a957cbe637 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: Fri, 21 Apr 2023 16:24:22 +0300 Subject: [PATCH] Refactor #3879 - For Chip --- api-generator/components/chip.js | 6 ++++ components/lib/chip/Chip.d.ts | 60 ++++++++++++++++++++++++++++++++ components/lib/chip/Chip.vue | 14 ++++---- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/api-generator/components/chip.js b/api-generator/components/chip.js index 4d9022d64..894250b91 100644 --- a/api-generator/components/chip.js +++ b/api-generator/components/chip.js @@ -28,6 +28,12 @@ const ChipProps = [ type: 'string', default: 'pi pi-times-circle', description: 'Icon of the remove element.' + }, + { + name: 'pt', + type: 'any', + default: 'null', + description: 'Uses to pass attributes to DOM elements inside the component.' } ]; diff --git a/components/lib/chip/Chip.d.ts b/components/lib/chip/Chip.d.ts index ddf0b676f..38c3e908c 100644 --- a/components/lib/chip/Chip.d.ts +++ b/components/lib/chip/Chip.d.ts @@ -10,6 +10,61 @@ import { VNode } from 'vue'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; +export declare type ChipPassThroughOptionType = ChipPassThroughAttributes | ((options: ChipPassThroughMethodOptions) => ChipPassThroughAttributes) | null | undefined; + +/** + * Custom passthrough(pt) option method. + */ +export interface ChipPassThroughMethodOptions { + props: ChipProps; + state: ChipState; +} + +/** + * Custom passthrough(pt) options. + * @see {@link ChipProps.pt} + */ +export interface ChipPassThroughOptions { + /** + * Uses to pass attributes to the root's DOM element. + */ + root?: ChipPassThroughOptionType; + /** + * Uses to pass attributes to the image's DOM element. + */ + image?: ChipPassThroughOptionType; + /** + * Uses to pass attributes to the icon's DOM element. + */ + icon?: ChipPassThroughOptionType; + /** + * Uses to pass attributes to the label' DOM element. + */ + label?: ChipPassThroughOptionType; + /** + * Uses to pass attributes to the removeIcon's DOM element. + */ + removeIcon?: ChipPassThroughOptionType; +} + +/** + * Custom passthrough attributes for each DOM elements + */ +export interface ChipPassThroughAttributes { + [key: string]: any; +} + +/** + * Defines current inline state in Chip component. + */ +export interface ChipState { + /** + * Current visible state as a boolean. + * @defaultValue true + */ + visible: boolean; +} + /** * Defines valid properties in Chip component. */ @@ -37,6 +92,11 @@ export interface ChipProps { * @deprecated since v3.27.0. Use 'removeicon' slot. */ removeIcon?: string; + /** + * Uses to pass attributes to DOM elements inside the component. + * @type {ChipPassThroughOptions} + */ + pt?: ChipPassThroughOptions; } /** diff --git a/components/lib/chip/Chip.vue b/components/lib/chip/Chip.vue index e16447da4..668cbc5c1 100644 --- a/components/lib/chip/Chip.vue +++ b/components/lib/chip/Chip.vue @@ -1,23 +1,25 @@