Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dialog]: **BREAKING** Replace 'size' property with media query #914

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions src/components/dialog/dialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import Button from '../button/button.svelte'
import Icon from '../icon/icon.svelte'

type DialogSizes = 'mobile' | 'normal'

type $$Props = Omit<Partial<SvelteHTMLElements['dialog']>, 'open'> & {
isOpen?: boolean
modal?: boolean
showClose?: boolean
showBack?: boolean
size?: DialogSizes
escapeCloses?: boolean
backdropClickCloses?: boolean
animate?: boolean
Expand All @@ -23,7 +20,6 @@
export let modal = true
export let showClose = false
export let showBack = false
export let size: DialogSizes = 'normal'
export let escapeCloses = true
export let backdropClickCloses = true
export let animate = true
Expand All @@ -49,7 +45,6 @@
transition:scale={{ duration: animate ? 60 : 0, start: 0.8 }}
{...$$restProps}
class="leo-dialog"
class:mobile={size === 'mobile'}
class:modal
class:hasHeader
class:hasActions={$$slots.actions}
Expand Down Expand Up @@ -122,7 +117,7 @@

<style lang="scss">
.leo-dialog {
--padding: var(--leo-dialog-padding, var(--leo-spacing-4xl));
--padding: var(--leo-dialog-padding, var(--leo-spacing-2xl));
--border-radius: var(--leo-dialog-border-radius, var(--leo-radius-xl));
--background: var(
--leo-dialog-background,
Expand All @@ -141,8 +136,8 @@
border: none;
display: grid;

width: var(--leo-dialog-width, 500px);
max-width: calc(100% - var(--leo-spacing-m) * 2);
width: calc(100% - var(--leo-spacing-m) * 2);
fallaciousreasoning marked this conversation as resolved.
Show resolved Hide resolved
max-width: var(--leo-dialog-width, 374px);

border-radius: var(--border-radius);

Expand All @@ -159,7 +154,7 @@
}

.leo-dialog.hasHeader {
grid-template-rows: auto 1fr;
grid-template-rows: auto auto;
}

/** Since Svelte 4 doesn't support conditional slots in the consumer,
Expand All @@ -168,17 +163,12 @@
* case the selector with :host. */
:host .leo-dialog.hasActions,
.leo-dialog.hasActions:has([slot='actions']:not(:empty)) {
grid-template-rows: 1fr auto;
grid-template-rows: auto auto;
}

:host .leo-dialog.hasHeader.hasActions,
.leo-dialog.hasHeader.hasActions:has(.actions [slot='actions']:not(:empty)) {
grid-template-rows: auto 1fr auto;
}

.leo-dialog.mobile {
--padding: var(--leo-dialog-padding, var(--leo-spacing-2xl));
width: var(--leo-dialog-width, 374px);
grid-template-rows: auto auto auto;
}

.leo-dialog:not(.modal) {
Expand Down Expand Up @@ -219,7 +209,6 @@
}

.leo-dialog .body {
overflow-y: auto;
background: var(--background);
color: var(--leo-color-text-secondary);
font: var(--leo-font-default-regular);
Expand Down Expand Up @@ -249,20 +238,21 @@
*
* The :global selector doesn't seem to be able to handle nesting, so we have
* two separate selectors for mobile & non-mobile layouts */
:global .leo-dialog.mobile .actions ::slotted(*),
:global .leo-dialog.mobile .actions [slot='actions']:not(:empty) {
:global .leo-dialog .actions ::slotted(*),
:global .leo-dialog .actions [slot='actions']:not(:empty) {
display: flex;
gap: var(--leo-spacing-xl);
flex-direction: column;
align-items: stretch;
justify-content: end;
}

:global .leo-dialog .actions ::slotted(*),
:global .leo-dialog [slot='actions']:not(:empty) {
display: flex;
flex-direction: row;
align-items: center;
justify-content: stretch;
gap: var(--leo-spacing-xl);
@media (orientation: portrait) {
:global .leo-dialog .actions ::slotted(*),
:global .leo-dialog .actions div[slot='actions'] {
flex-direction: column;
align-items: stretch;
}
}

.leo-dialog .title-row {
Expand All @@ -272,4 +262,24 @@
justify-content: stretch;
gap: var(--leo-spacing-l);
}

@media (min-width: 375px) and (min-height: 375px) {
.leo-dialog {
--padding: var(--leo-dialog-padding, var(--leo-spacing-4xl));
max-width: var(--leo-dialog-width, 500px);
}

:global .leo-dialog .actions ::slotted(*),
:global .leo-dialog [slot='actions']:not(:empty) {
flex-direction: row;
align-items: center;
justify-content: end;
}
}

@media (orientation: landscape) {
.leo-dialog {
max-width: var(--leo-dialog-width, 520px);
}
}
</style>
Loading