-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(web): Introduce Drawer component #DS-1580
- Loading branch information
Showing
8 changed files
with
209 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Drawer |
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,40 @@ | ||
@use '../../tools/typography'; | ||
@use 'theme'; | ||
|
||
.Drawer { | ||
@include typography.generate(theme.$drawer-typography); | ||
|
||
all: unset; | ||
position: fixed; | ||
inset: 0; | ||
z-index: 1; | ||
display: flex; | ||
width: 100%; | ||
max-width: none; | ||
height: 100%; | ||
max-height: none; | ||
border: none; | ||
background-color: theme.$drawer-backdrop-background-color; | ||
visibility: hidden; | ||
|
||
&::backdrop { | ||
background-color: transparent; | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
transition-property: visibility, opacity; | ||
transition-duration: theme.$drawer-transition-duration; | ||
} | ||
} | ||
|
||
.Drawer--left { | ||
justify-content: start; | ||
} | ||
|
||
.Drawer--right { | ||
justify-content: end; | ||
} | ||
|
||
.Drawer[open] { | ||
visibility: visible; | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/web/src/scss/components/Drawer/_DrawerCloseButton.scss
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,11 @@ | ||
@use '../../tools/accessibility'; | ||
@use '../../tools/reset'; | ||
@use 'theme'; | ||
|
||
.DrawerCloseButton { | ||
@include accessibility.min-tap-target(theme.$drawer-close-button-size); | ||
|
||
align-self: flex-end; | ||
margin-inline-end: theme.$drawer-close-button-padding-x; | ||
margin-block-start: theme.$drawer-close-button-padding-y; | ||
} |
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,43 @@ | ||
@use 'sass:map'; | ||
@use 'theme'; | ||
|
||
.DrawerPanel { | ||
--drawer-translate-x: 0%; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
box-sizing: border-box; | ||
width: theme.$drawer-panel-width; | ||
height: theme.$drawer-panel-height; | ||
max-height: theme.$drawer-panel-max-height; | ||
color: theme.$drawer-panel-text-color; | ||
background-color: theme.$drawer-panel-background-color; | ||
box-shadow: theme.$drawer-panel-shadow; | ||
transform: translateX(var(--drawer-translate-x)); | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
transition-property: transform; | ||
transition-duration: theme.$drawer-transition-duration; | ||
transition-timing-function: theme.$drawer-transition-timing; | ||
} | ||
} | ||
|
||
.Drawer--left .DrawerPanel { | ||
--drawer-translate-x: -100%; | ||
} | ||
|
||
.Drawer--right .DrawerPanel { | ||
--drawer-translate-x: 100%; | ||
} | ||
|
||
.Drawer[open] .DrawerPanel { | ||
--drawer-translate-x: 0%; | ||
} | ||
|
||
.DrawerPanel__content { | ||
display: flex; | ||
flex-grow: 1; | ||
flex-direction: column; | ||
overflow-y: auto; | ||
overscroll-behavior: contain; | ||
} |
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,22 @@ | ||
@use '@tokens' as tokens; | ||
@use '../../settings/transitions'; | ||
|
||
$drawer-typography: tokens.$body-medium-semibold; | ||
|
||
// Transition | ||
$drawer-transition-duration: transitions.$duration-200; | ||
$drawer-transition-timing: transitions.$timing-eased-in-out; | ||
$drawer-backdrop-background-color: tokens.$background-backdrop; | ||
|
||
// DrawerPanel | ||
$drawer-panel-width: 288px; | ||
$drawer-panel-height: auto; | ||
$drawer-panel-max-height: none; | ||
$drawer-panel-text-color: tokens.$text-primary; | ||
$drawer-panel-background-color: tokens.$background-primary; | ||
$drawer-panel-shadow: tokens.$shadow-400; | ||
|
||
// DrawerCloseButton | ||
$drawer-close-button-size: tokens.$space-1200; | ||
$drawer-close-button-padding-x: tokens.$space-900; | ||
$drawer-close-button-padding-y: tokens.$space-700; |
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,88 @@ | ||
{{#> web/layout/default title="Drawer" parentPageName="Components" }} | ||
|
||
<script> | ||
document.addEventListener("DOMContentLoaded", () => { | ||
const radios = document.querySelectorAll('input[name="drawer-alignment"]'); | ||
const drawer = document.getElementById("drawer-example-1"); | ||
|
||
radios.forEach(radio => { | ||
radio.addEventListener("change", () => { | ||
if (radio.checked) { | ||
if (radio.value === "left") { | ||
drawer.classList.remove("Drawer--right"); | ||
drawer.classList.add("Drawer--left"); | ||
} else if (radio.value === "right") { | ||
drawer.classList.remove("Drawer--left"); | ||
drawer.classList.add("Drawer--right"); | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
</script> | ||
|
||
<section class="UNSTABLE_Section"> | ||
|
||
<div class="Container"> | ||
<h2 class="docs-Heading">Drawer</h2> | ||
|
||
<div class="docs-Stack docs-Stack--start"> | ||
|
||
<form class="mb-600"> | ||
<div>Drawer alignment:</div> | ||
<label for="drawer-alignment-top" class="Radio mr-600"> | ||
<input name="drawer-alignment" autocomplete="off" aria-describedby="drawer-alignment-top__helperText" type="radio" id="drawer-alignment-top" class="Radio__input" value="left"> | ||
<span class="Radio__text"> | ||
<span class="Radio__label">Left</span> | ||
</span> | ||
</label> | ||
<label for="drawer-alignment-bottom" class="Radio mr-600"> | ||
<input name="drawer-alignment" autocomplete="off" aria-describedby="drawer-alignment-bottom__helperText" type="radio" id="drawer-alignment-bottom" class="Radio__input" value="right" checked=""> | ||
<span class="Radio__text"> | ||
<span class="Radio__label">Right</span> | ||
</span> | ||
</label> | ||
</form> | ||
<button | ||
type="button" | ||
data-test-id="drawer-basic" | ||
class="Button Button--primary Button--medium" | ||
data-spirit-toggle="offcanvas" | ||
data-spirit-target="#drawer-example-1" | ||
aria-controls="drawer-example-1" | ||
aria-expanded="false" | ||
> | ||
Open Drawer | ||
</button> | ||
|
||
<!-- Drawer: start --> | ||
<dialog id="drawer-example-1" class="Drawer Drawer--right" aria-labelledby="example-basic__title"> | ||
<div class="DrawerPanel"> | ||
<div class="DrawerPanel__content"> | ||
<button | ||
type="button" | ||
aria-expanded="false" | ||
class="Button Button--tertiary Button--medium Button--symmetrical DrawerCloseButton" | ||
data-spirit-dismiss="offcanvas" | ||
data-spirit-target="#drawer-example-1" | ||
aria-controls="drawer-example-1"> | ||
<svg viewBox="0 0 24 24" fill="none" width="24" height="24" aria-hidden="true"> | ||
<path d="M18.3 5.70997C17.91 5.31997 17.28 5.31997 16.89 5.70997L12 10.59L7.11 5.69997C6.72 5.30997 6.09 5.30997 5.7 | ||
5.69997C5.31 6.08997 5.31 6.71997 5.7 7.10997L10.59 12L5.7 16.89C5.31 17.28 5.31 17.91 5.7 18.3C6.09 18.69 6.72 18.69 | ||
7.11 18.3L12 13.41L16.89 18.3C17.28 18.69 17.91 18.69 18.3 18.3C18.69 17.91 18.69 17.28 18.3 16.89L13.41 12L18.3 | ||
7.10997C18.68 6.72997 18.68 6.08997 18.3 5.70997Z" fill="currentColor"> | ||
</path> | ||
</svg> | ||
<span class="accessibility-hidden">Close</span> | ||
</button> | ||
<div class="p-800">Drawer content</div> | ||
</div> | ||
</div> | ||
</dialog> | ||
<!-- Drawer: end --> | ||
|
||
</div> | ||
</div> | ||
</section> | ||
|
||
{{/web/layout/default }} |
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,3 @@ | ||
@forward 'Drawer'; | ||
@forward 'DrawerPanel'; | ||
@forward 'DrawerCloseButton'; |
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