How can I change the background of a custom modal? #1551
-
I want to change the props of the parent. Can you tell me how to do it? Thanks! const modalComponent: ModalComponent = {
ref: MyCustomComponent,
props: { background: 'bg-red-500' },
slot: '<p>Skeleton</p>'
};
const d: ModalSettings = {
type: 'component',
component: modalComponent,
title: 'HI',
body: `message`,
response: async (r: boolean) => {
console.log('ModalSettings', r);
}
};
modalStore.trigger(d); MyCustomComponent.svelte <script lang="ts">
import { modalStore } from '@skeletonlabs/skeleton';
// Props
/** Exposes parent props to this component. */
export let parent: any;
</script>
{#if $modalStore[0]}
<div class="modal-example-form {parent.background} ">
<!-- some content -->
</div>
{/if} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You need to define the background in the <Modal background="my-fancy-background-color-class"/> Helpful link to the Modal source to check for yourself: |
Beta Was this translation helpful? Give feedback.
-
@avecalme think of component modals as custom modals. There's a couple ways to go about this: Method 1 - using the
|
Beta Was this translation helpful? Give feedback.
@avecalme think of component modals as custom modals. There's a couple ways to go about this:
Method 1 - using the
props
objectWhen you're passing
props: { background: 'bg-red-500' }
, what we're doing is taking the component definition you've provided (reference, props, slot) and dynamically constructing that component for your within the Modal component on-demand using<svelte:component>
.In order to access the
props
value within your custom component, you have to setup your component to accept that prop as you would for any custom component:export let background: string = 'someDefaultValue'
Then you can use
background
as a proper within your custom generated component.To be honest, t…