Skip to content

Commit

Permalink
feat(ld-modal): add modal component
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdiakur committed May 13, 2022
1 parent 5b4e63a commit 59f22ec
Show file tree
Hide file tree
Showing 13 changed files with 1,143 additions and 3 deletions.
78 changes: 78 additions & 0 deletions screenshot/builds/master.json
Original file line number Diff line number Diff line change
Expand Up @@ -7583,6 +7583,84 @@
"isLandscape": false,
"isMobile": false
},
{
"id": "9ef4f5a5",
"image": "80f03a4b95c03712bf4445f255ab129a.png",
"userAgent": "default",
"desc": "ld-modal renders as CSS Component",
"testPath": "./src/liquid/components/ld-modal/test/ld-modal.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "36fe5b6b",
"image": "fc03e0e8f65f45a09374af6c9ebdcd86.png",
"userAgent": "default",
"desc": "ld-modal renders as CSS Component with lots of content in scrollable container",
"testPath": "./src/liquid/components/ld-modal/test/ld-modal.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "f2519ea2",
"image": "a863b29419ccd361a6090e594c79dd05.png",
"userAgent": "default",
"desc": "ld-modal renders as CSS Component without header and footer",
"testPath": "./src/liquid/components/ld-modal/test/ld-modal.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "da147284",
"image": "80f03a4b95c03712bf4445f255ab129a.png",
"userAgent": "default",
"desc": "ld-modal renders as Web Component",
"testPath": "./src/liquid/components/ld-modal/test/ld-modal.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "a8abc56d",
"image": "fc03e0e8f65f45a09374af6c9ebdcd86.png",
"userAgent": "default",
"desc": "ld-modal renders as Web Component with lots of content in scrollable container",
"testPath": "./src/liquid/components/ld-modal/test/ld-modal.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "511a4558",
"image": "a863b29419ccd361a6090e594c79dd05.png",
"userAgent": "default",
"desc": "ld-modal renders as Web Component without header and footer",
"testPath": "./src/liquid/components/ld-modal/test/ld-modal.e2e.ts",
"width": 600,
"height": 600,
"deviceScaleFactor": 1,
"hasTouch": false,
"isLandscape": false,
"isMobile": false
},
{
"id": "754d17fa",
"image": "4a7e479dd27b53411e3cbc248927dc45.png",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/docs/components/docs-example/docs-example.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
padding: 0 0 var(--ld-sp-24);
}

> div > * {
> div > *:not(.ld-modal) {
margin: var(--ld-sp-24) var(--ld-sp-24) 0;
max-width: calc(100% - 2 * var(--ld-sp-24));
}
Expand Down
2 changes: 1 addition & 1 deletion src/docs/layouts/docs-layout/docs-layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ html {
}

body {
overscroll-behavior-x: none;
overscroll-behavior: none;
-webkit-text-size-adjust: none; /* stylelint-disable-line plugin/no-unsupported-browser-features */
--docs-header-height: 3.125rem;
--docs-max-width: 90rem;
Expand Down
5 changes: 4 additions & 1 deletion src/liquid/components/ld-button/ld-button.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
}
}

:where(.ld-button) {
margin: 0; /* margin reset for Safari must have zero specificity! */
}

.ld-button {
--ld-button-icon-size-sm: 1rem;
--ld-button-icon-size-md: 1.25rem;
Expand All @@ -25,7 +29,6 @@
--ld-button-gap-lg: 1.1875rem;
background-color: var(--ld-button-bg-color, var(--ld-thm-primary));
box-sizing: border-box;
margin: 0;
position: relative;
font: var(--ld-typo-body-m);
border: 0;
Expand Down
203 changes: 203 additions & 0 deletions src/liquid/components/ld-modal/ld-modal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
:host {
display: contents;
}

@keyframes ld-modal-in {
from {
transform: translateY(2rem);
}

to {
transform: translateY(0rem);
}
}

@keyframes ld-modal-out {
from {
transform: scale(1);
}

to {
transform: scale(0.9);
}
}

@keyframes ld-modal-out-mobile {
from {
transform: translateY(0rem);
}

to {
transform: translateY(2rem);
}
}

dialog.ld-modal,
:host dialog {
--ld-modal-bg-col: var(--ld-col-wht);
--ld-modal-fixed-padding-x: var(--ld-sp-16);
--ld-modal-fixed-padding-y: var(--ld-sp-16);
--ld-modal-padding-x: var(--ld-sp-16);
--ld-modal-padding-y: var(--ld-sp-24);
--ld-modal-fixed-bg-col: var(--ld-col-neutral-010);
--ld-modal-transition-duration: 0.001s;
--ld-modal-max-inline-size: 30rem;
--ld-modal-max-block-size: 70rem;
--ld-modal-min-inline-size: 18rem;

@media (prefers-reduced-motion: no-preference) {
--ld-modal-transition-duration: 0.2s;
}

/* overwrites */
border: 0;
display: flex; /* allows for transitions */
flex-direction: column;
inset: 0; /* keeps the dialog positioned correctly during closing transition */
margin: auto;
overflow: visible; /* required due to scalehack */
padding: 0;
position: fixed; /* makes sure it stays fixed during closing transition */
z-index: 2147483647; /* makes sure it is not overlapped during closing transition */

animation: ld-modal-in var(--ld-modal-transition-duration) ease-out forwards;
border-radius: var(--ld-br-l);
box-shadow: var(--ld-shadow-active);

/* dimensions */
max-block-size: min(
/* account for additional margin bottom on mobile */
calc(100% - var(--ld-sp-24) - var(--ld-sp-40)),
var(--ld-modal-max-block-size)
);
max-inline-size: min(
calc(100% - var(--ld-sp-32)),
var(--ld-modal-max-inline-size)
);
min-inline-size: var(--ld-modal-min-inline-size);

transition: opacity var(--ld-modal-transition-duration) linear,
transform var(--ld-modal-transition-duration) ease;

@media (max-width: 32rem) {
/*
On mobile we place the dialog at the bottom of the screen
so that it is easier for the user to interact with it. */
margin-bottom: var(--ld-sp-40);
}

&:not([open]) {
animation: ld-modal-out var(--ld-modal-transition-duration) ease-in forwards;
opacity: 0;
pointer-events: none;
transition: opacity var(--ld-modal-transition-duration) linear,
visibility 0s var(--ld-modal-transition-duration) linear,
transform var(--ld-modal-transition-duration) ease;
visibility: hidden;

@media (max-width: 32rem) {
/*
On mobile, since the dialog is placed at the bottom of the screen,
we transition it out slightly differently than on wide view ports. */
animation-name: ld-modal-out-mobile;
}
}

&::after {
background-color: var(--ld-modal-bg-col);
border-radius: inherit;
content: '';
inset: 0;
position: absolute;
z-index: -1;
}

&::before {
background-color: var(--ld-thm-primary-active);
content: '';
inset: 0;
opacity: 0.3;
position: fixed;
transform: scale(99); /* scalehack required due to animation */
z-index: -2;
}
}

dialog.ld-modal--blurry-backdrop,
:host(.ld-modal--blurry-backdrop) dialog {
&::backdrop {
backdrop-filter: blur(5px);
}
}

.ld-modal__x {
align-self: flex-start;
appearance: none;
aspect-ratio: 1;
background-color: transparent;
border: solid transparent var(--ld-sp-8);
box-sizing: border-box;
cursor: pointer;
display: inline-flex;
justify-self: flex-end;
margin: var(--ld-sp-8) calc(var(--ld-sp-8) * -1) var(--ld-sp-8) auto;
position: relative;
width: var(--ld-sp-32);

&::before,
&::after {
border-radius: 1rem;
background-color: var(--ld-col-neutral-900);
content: '';
display: block;
height: 125%;
left: 50%;
position: absolute;
top: 50%;
width: 0.15rem;
}

&::before {
transform: translateX(-50%) translateY(-50%) rotate(45deg);
}

&::after {
transform: translateX(-50%) translateY(-50%) rotate(-45deg);
}
}

.ld-modal__content {
flex-grow: 1;
overflow: hidden auto;
overscroll-behavior: none;
padding: var(--ld-modal-padding-y) var(--ld-modal-padding-x);
}

.ld-modal__header,
.ld-modal__footer {
align-items: center;
background-color: var(--ld-modal-fixed-bg-col);
display: grid;
grid-auto-flow: column;
gap: var(--ld-modal-fixed-padding-x);
padding: 0 var(--ld-modal-fixed-padding-x);
}

.ld-modal__header {
border-radius: var(--ld-br-l) var(--ld-br-l) 0 0;

> *:not(.ld-modal__x),
> ::slotted(*:not(.ld-modal__x)) {
padding: var(--ld-sp-12) 0;
}
}

.ld-modal__footer {
border-radius: 0 0 var(--ld-br-l) var(--ld-br-l);
justify-content: flex-end;

> *,
> ::slotted(*) {
margin: var(--ld-modal-fixed-padding-y) 0;
}
}
Loading

0 comments on commit 59f22ec

Please sign in to comment.