-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Pass porps to your custom compoonent
- Loading branch information
wuchao
committed
Dec 18, 2024
1 parent
9ec9491
commit 9189a1f
Showing
6 changed files
with
166 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Pass porps to your custom compoonent. | ||
|
||
> `expandCustomProps` default is false. | ||
- `expandCustomProps`: true | ||
|
||
::: sandbox | ||
```vue /src/App.vue | ||
<script setup lang="ts"> | ||
import { toast } from 'vue3-toastify'; | ||
import CustomComp from './CustomComp.vue'; | ||
import 'vue3-toastify/dist/index.css'; | ||
const notify = () => { | ||
toast(CustomComp, { | ||
type: 'warning', | ||
expandCustomProps: true, | ||
contentProps: { | ||
title: 'hello world', | ||
color: '#00a2ed', | ||
}, | ||
}); | ||
}; | ||
</script> | ||
<template> | ||
<div> | ||
<button @click="notify">Notify !</button> | ||
</div> | ||
</template> | ||
``` | ||
|
||
```vue /src/CustomComp.vue | ||
<template> | ||
<div :style="`color: ${color}`"> | ||
{{ title }} | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
defineProps({ | ||
title: { | ||
type: String, | ||
default: '', | ||
}, | ||
color: { | ||
type: String, | ||
default: '', | ||
}, | ||
}); | ||
</script> | ||
``` | ||
::: | ||
|
||
- disable globally | ||
|
||
```ts | ||
app.use( | ||
Vue3Toasity, | ||
{ | ||
expandCustomProps: true, // default is false | ||
} as ToastContainerOptions, | ||
); | ||
``` | ||
|
||
- `expandCustomProps`: false | ||
|
||
::: sandbox | ||
```vue /src/App.vue | ||
<script setup lang="ts"> | ||
import { toast } from 'vue3-toastify'; | ||
import CustomComp from './CustomComp.vue'; | ||
import 'vue3-toastify/dist/index.css'; | ||
const notify = () => { | ||
toast(CustomComp, { | ||
type: 'warning', | ||
contentProps: { | ||
title: 'hello world', | ||
color: '#00a2ed', | ||
}, | ||
}); | ||
}; | ||
</script> | ||
<template> | ||
<div> | ||
<button @click="notify">Notify !</button> | ||
</div> | ||
</template> | ||
``` | ||
|
||
```vue /src/CustomComp.vue | ||
<template> | ||
<div :style="`color: ${contentProps.color}`"> | ||
{{ contentProps.title }} | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { PropType } from 'vue'; | ||
defineProps({ | ||
contentProps: { | ||
type: Object as PropType<{ title: string; color: String }>, | ||
default: () => ({}), | ||
}, | ||
}); | ||
</script> | ||
``` | ||
::: | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters