|
| 1 | +<script lang="ts"> |
| 2 | + import type { ParamsType } from '$lib/types'; |
| 3 | + import CloseButton from '$lib/utils/CloseButton.svelte'; |
| 4 | + import { type ModalProps as Props, modal } from '.'; |
| 5 | + import { fade } from 'svelte/transition'; |
| 6 | + import { sineIn } from 'svelte/easing'; |
| 7 | +
|
| 8 | + let { children, header, footer, title, modalStatus, dismissable = true, closeModal, divClass, contentClass, closeBtnClass, h3Class, headerClass, bodyClass, footerClass, outsideClose = true, size = 'md', backdrop = true, backdropClass, position = 'center', class: className, params = { duration: 100, easing: sineIn }, transition = fade, rounded = true, shadow = true, ...restProps }: Props = $props(); |
| 9 | +
|
| 10 | + const { base, div, content, backdrop: backdropCls, header: headerCls, footer: footerCls, body, closeBtn, h3 } = $derived( |
| 11 | + modal({ |
| 12 | + position, |
| 13 | + size, |
| 14 | + backdrop, |
| 15 | + rounded |
| 16 | + }) |
| 17 | + ); |
| 18 | + |
| 19 | +</script> |
| 20 | + |
| 21 | +{#if modalStatus} |
| 22 | + {#if backdrop && outsideClose} |
| 23 | + <div role="presentation" class={backdropCls({ class: backdropClass })} onclick={closeModal}></div> |
| 24 | + {:else if backdrop && !outsideClose} |
| 25 | + <div role="presentation" class={backdropCls({ class: backdropClass })}></div> |
| 26 | + {:else if !backdrop && outsideClose} |
| 27 | + <div role="presentation" class="fixed start-0 top-0 z-50 h-full w-full" onclick={closeModal}></div> |
| 28 | + {:else if !backdrop && !outsideClose} |
| 29 | + <div role="presentation" class="fixed start-0 top-0 z-50 h-full w-full"></div> |
| 30 | + {/if} |
| 31 | + <div {...restProps} class={base({ className })} transition:transition={params as ParamsType} tabindex="-1"> |
| 32 | + <div class={div({ class: divClass })}> |
| 33 | + <div class={content({ class: contentClass })}> |
| 34 | + {#if title || header} |
| 35 | + <div class={headerCls({ class: headerClass })}> |
| 36 | + {#if title} |
| 37 | + <h3 class={h3({ class: h3Class })}> |
| 38 | + {title} |
| 39 | + </h3> |
| 40 | + {:else if header} |
| 41 | + {@render header()} |
| 42 | + {/if} |
| 43 | + {#if dismissable} |
| 44 | + <CloseButton onclick={closeModal} class={closeBtn({ class: closeBtnClass })}/> |
| 45 | + {/if} |
| 46 | + </div> |
| 47 | + {/if} |
| 48 | + <div class={body({ class: bodyClass })}> |
| 49 | + {#if dismissable && !title && !header} |
| 50 | + <CloseButton onclick={closeModal} class={closeBtn({ class: closeBtnClass })}/> |
| 51 | + {/if} |
| 52 | + {@render children()} |
| 53 | + </div> |
| 54 | + {#if footer} |
| 55 | + <div class={footerCls({ class: footerClass })}> |
| 56 | + {@render footer()} |
| 57 | + </div> |
| 58 | + {/if} |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | +{/if} |
| 63 | + |
| 64 | +<!-- |
| 65 | +@component |
| 66 | +[Go to docs](https://svelte-5-ui-lib.codewithshin.com/) |
| 67 | +## Props |
| 68 | +@prop children |
| 69 | +@prop drawerStatus |
| 70 | +@prop toggleDrawer |
| 71 | +@prop closeDrawer |
| 72 | +@prop outsideClose = true |
| 73 | +@prop position |
| 74 | +@prop width |
| 75 | +@prop backdrop = true |
| 76 | +@prop backdropClass |
| 77 | +@prop placement = 'left' |
| 78 | +@prop class: divClass |
| 79 | +@prop transitionParams |
| 80 | +@prop transitionType = 'fly' |
| 81 | +@prop ...restProps |
| 82 | +--> |
0 commit comments