Skip to content

Commit

Permalink
feat: Globally define custom icon by type
Browse files Browse the repository at this point in the history
  • Loading branch information
wuchao committed Dec 18, 2024
1 parent 5d8bf46 commit 9ec9491
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
22 changes: 21 additions & 1 deletion docs/docs/usage/icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,30 @@ import { VNodeIcon } from './icons.tsx';
import Vue3Toasity from 'vue3-toastify';
import 'vue3-toastify/dist/index.css';

const ResolveCustomIcon = (props: IconProps) => {
switch (props.type) {
case 'default':
return '👌';
case 'loading':
return '...';
case 'info':
return '🎈';
case 'success':
return '✌️';
case 'error':
return '🤣';
case 'warning':
return '😢';
default:
return undefined;
}
};

createApp(App).use(
Vue3Toasity,
{
icon: VNodeIcon,
icon: ResolveCustomIcon, // use function
// icon: VNodeIcon, // use Unified icon
},
).mount('#app');
```
Expand Down
39 changes: 36 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type IconType =
| string
| number
| VNode
| ((props: IconProps) => VNode)
| ((props: IconProps) => VNode | string | undefined | null)
| DefineComponent<IconProps, {}, {}>;

export type CloseBtnType =
Expand Down Expand Up @@ -165,6 +165,41 @@ export interface Options {
* @default -
*/
icon?: IconType;
/** props of custom component */
contentProps?: Record<string, any>;
/**
* use with `contentProps`, allow to pass custom props to the custom component
* @default false
*
* how to receive custom props in the custom component:
*
* - expandCustomProps: false
*
* ```ts
* defineProps({
* contentProps: {
* type: Object as PropType<{ title: string; color: String }>,
* default: () => ({}),
* },
* });
* ```
*
* - expandCustomProps: true
*
* ```ts
* defineProps({
* title: {
* type: String,
* default: '',
* },
* color: {
* type: String,
* default: '',
* },
* });
* ```
*/
expandCustomProps?: boolean;
/** app use hander */
useHandler?: (app: App<Element>) => void;
}
Expand Down Expand Up @@ -264,8 +299,6 @@ export interface ToastOptions<Data = {}> extends Options {

/** Only available when using `toast.loading' */
isLoading?: boolean;

contentProps?: Object;
}

/**
Expand Down

0 comments on commit 9ec9491

Please sign in to comment.