From 3bae8de47e876cbdbda0a9bcd296bdb74f7f07b8 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, 28 Apr 2023 16:39:19 +0300 Subject: [PATCH] Refactor #3911 - For Toast --- api-generator/components/toast.js | 6 ++ components/lib/toast/Toast.d.ts | 79 +++++++++++++++++++++++++++ components/lib/toast/Toast.vue | 5 +- components/lib/toast/ToastMessage.vue | 20 ++++--- 4 files changed, 100 insertions(+), 10 deletions(-) diff --git a/api-generator/components/toast.js b/api-generator/components/toast.js index d9027d78b..e4dc9fe4c 100644 --- a/api-generator/components/toast.js +++ b/api-generator/components/toast.js @@ -28,6 +28,12 @@ const ToastProps = [ type: 'object', default: 'null', description: 'Object literal to define widths per screen size.' + }, + { + name: 'pt', + type: 'any', + default: 'null', + description: 'Uses to pass attributes to DOM elements inside the component.' } ]; diff --git a/components/lib/toast/Toast.d.ts b/components/lib/toast/Toast.d.ts index 6642b0bf2..9a012c6d1 100755 --- a/components/lib/toast/Toast.d.ts +++ b/components/lib/toast/Toast.d.ts @@ -10,6 +10,70 @@ import { ButtonHTMLAttributes, VNode } from 'vue'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; +export declare type ToastPassThroughOptionType = ToastPassThroughAttributes | ((options: ToastPassThroughMethodOptions) => ToastPassThroughAttributes) | null | undefined; + +/** + * Custom passthrough(pt) option method. + */ +export interface ToastPassThroughMethodOptions { + props: ToastProps; + state: ToastState; +} + +/** + * Custom passthrough(pt) options. + * @see {@link ToastProps.pt} + */ +export interface ToastPassThroughOptions { + /** + * Uses to pass attributes to the root's DOM element. + */ + root?: ToastPassThroughOptionType; + /** + * Uses to pass attributes to the container's DOM element. + */ + container?: ToastPassThroughOptionType; + /** + * Uses to pass attributes to the content's DOM element. + */ + content?: ToastPassThroughOptionType; + /** + * Uses to pass attributes to the icon's DOM element. + */ + icon?: ToastPassThroughOptionType; + /** + * Uses to pass attributes to the text's DOM element. + */ + text?: ToastPassThroughOptionType; + /** + * Uses to pass attributes to the summary's DOM element. + */ + summary?: ToastPassThroughOptionType; + /** + * Uses to pass attributes to the detail's DOM element. + */ + detail?: ToastPassThroughOptionType; + /** + * Uses to pass attributes to the button container's DOM element. + */ + buttonContainer?: ToastPassThroughOptionType; + /** + * Uses to pass attributes to the button's DOM element. + */ + button?: ToastPassThroughOptionType; + /** + * Uses to pass attributes to the button icon's DOM element. + */ + buttonIcon?: ToastPassThroughOptionType; +} + +/** + * Custom passthrough attributes for each DOM elements + */ +export interface ToastPassThroughAttributes { + [key: string]: any; +} + /** * Defines message options in Toast component. */ @@ -65,6 +129,16 @@ export interface ToastBreakpointsType { [key: string]: any; } +/** + * Defines current inline state in Toast component. + */ +export interface ToastState { + /** + * Current messages. + */ + messages: any[]; +} + /** * Defines valid properties in Toast component. */ @@ -123,6 +197,11 @@ export interface ToastProps { * @deprecated since v3.26.0. Use 'pt' property. */ closeButtonProps?: ButtonHTMLAttributes | undefined; + /** + * Uses to pass attributes to DOM elements inside the component. + * @type {ToastPassThroughOptions} + */ + pt?: ToastPassThroughOptions; } /** diff --git a/components/lib/toast/Toast.vue b/components/lib/toast/Toast.vue index ccb9fe08d..15d642724 100755 --- a/components/lib/toast/Toast.vue +++ b/components/lib/toast/Toast.vue @@ -1,6 +1,6 @@