Skip to content

Commit

Permalink
Apply BEM refactor for drawer (#7196)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdvg authored Dec 16, 2024
2 parents d37732f + 4ee4c17 commit efccdbc
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 82 deletions.
17 changes: 13 additions & 4 deletions packages/components/src/components/drawer/shadow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { setState, validateLabel, validateOpen, validateAlign, validateModal } f
import { Component, Host, Method, Prop, State, Watch, h } from '@stencil/core';

import type { JSX } from '@stencil/core';
import clsx from 'clsx';

/**
* @slot - The Content of drawer.
Expand Down Expand Up @@ -55,10 +56,13 @@ export class KolDrawer implements DrawerAPI {
return (
<div
ref={this.getWrapperRef}
class={`drawer__wrapper drawer__wrapper--${align} ${this.state._open ? 'drawer__wrapper--open' : 'is-closing'}`}
class={clsx(`kol-drawer__wrapper`, `kol-drawer__wrapper--${align}`, {
'kol-drawer__wrapper--open': this.state._open,
'kol-drawer__wrapper--is-closing': this.state._open === false,
})}
aria-label={this.state._label}
>
<div class="drawer__content">
<div class="kol-drawer__content">
<slot />
</div>
</div>
Expand All @@ -69,8 +73,13 @@ export class KolDrawer implements DrawerAPI {
public render(): JSX.Element {
const isModal = this.state._modal;
return (
<Host class={`kol-drawer drawer ${isModal ? 'drawer--modal' : ''}`} ref={(el) => (this.hostElement = el as HTMLElement)}>
<dialog class="drawer__dialog" ref={this.getRef}>
<Host
class={clsx('kol-drawer--modal', {
'kol-drawer--modal': isModal,
})}
ref={(el) => (this.hostElement = el as HTMLElement)}
>
<dialog class="kol-drawer__dialog" ref={this.getRef}>
{this.renderDialogContent()}
</dialog>
</Host>
Expand Down
4 changes: 1 addition & 3 deletions packages/components/src/components/drawer/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
@import '../style';

@layer kol-component {
:host {
.kol-drawer {
font-size: rem(16);
}

.drawer {
&__dialog {
padding: 0;
border: none;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`kol-drawer should render with _label="Label" _modal=false _open=false 1`] = `
<kol-drawer class="drawer kol-drawer">
<kol-drawer class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--top is-closing">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--is-closing kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -15,11 +15,11 @@ exports[`kol-drawer should render with _label="Label" _modal=false _open=false 1
`;

exports[`kol-drawer should render with _label="Label" _modal=false _open=true _variant="bottom" 1`] = `
<kol-drawer _variant="bottom" class="drawer kol-drawer">
<kol-drawer _variant="bottom" class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--open drawer__wrapper--top">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--open kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -29,11 +29,11 @@ exports[`kol-drawer should render with _label="Label" _modal=false _open=true _v
`;

exports[`kol-drawer should render with _label="Label" _modal=false _open=true _variant="left" 1`] = `
<kol-drawer _variant="left" class="drawer kol-drawer">
<kol-drawer _variant="left" class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--open drawer__wrapper--top">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--open kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -43,11 +43,11 @@ exports[`kol-drawer should render with _label="Label" _modal=false _open=true _v
`;

exports[`kol-drawer should render with _label="Label" _modal=false _open=true _variant="right" 1`] = `
<kol-drawer _variant="right" class="drawer kol-drawer">
<kol-drawer _variant="right" class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--open drawer__wrapper--top">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--open kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -57,11 +57,11 @@ exports[`kol-drawer should render with _label="Label" _modal=false _open=true _v
`;

exports[`kol-drawer should render with _label="Label" _modal=false _open=true _variant="top" 1`] = `
<kol-drawer _variant="top" class="drawer kol-drawer">
<kol-drawer _variant="top" class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--open drawer__wrapper--top">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--open kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -71,11 +71,11 @@ exports[`kol-drawer should render with _label="Label" _modal=false _open=true _v
`;

exports[`kol-drawer should render with _label="Label" _modal=true _open=false 1`] = `
<kol-drawer class="drawer drawer--modal kol-drawer">
<kol-drawer class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--top is-closing">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--is-closing kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -85,11 +85,11 @@ exports[`kol-drawer should render with _label="Label" _modal=true _open=false 1`
`;

exports[`kol-drawer should render with _label="Label" _modal=true _open=true _variant="bottom" 1`] = `
<kol-drawer _variant="bottom" class="drawer drawer--modal kol-drawer">
<kol-drawer _variant="bottom" class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--open drawer__wrapper--top">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--open kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -99,11 +99,11 @@ exports[`kol-drawer should render with _label="Label" _modal=true _open=true _va
`;

exports[`kol-drawer should render with _label="Label" _modal=true _open=true _variant="left" 1`] = `
<kol-drawer _variant="left" class="drawer drawer--modal kol-drawer">
<kol-drawer _variant="left" class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--open drawer__wrapper--top">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--open kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -113,11 +113,11 @@ exports[`kol-drawer should render with _label="Label" _modal=true _open=true _va
`;

exports[`kol-drawer should render with _label="Label" _modal=true _open=true _variant="right" 1`] = `
<kol-drawer _variant="right" class="drawer drawer--modal kol-drawer">
<kol-drawer _variant="right" class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--open drawer__wrapper--top">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--open kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -127,11 +127,11 @@ exports[`kol-drawer should render with _label="Label" _modal=true _open=true _va
`;

exports[`kol-drawer should render with _label="Label" _modal=true _open=true _variant="top" 1`] = `
<kol-drawer _variant="top" class="drawer drawer--modal kol-drawer">
<kol-drawer _variant="top" class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--open drawer__wrapper--top">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--open kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -141,11 +141,11 @@ exports[`kol-drawer should render with _label="Label" _modal=true _open=true _va
`;

exports[`kol-drawer should render with _label="Label" _open=false 1`] = `
<kol-drawer class="drawer kol-drawer">
<kol-drawer class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--top is-closing">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--is-closing kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand All @@ -155,11 +155,11 @@ exports[`kol-drawer should render with _label="Label" _open=false 1`] = `
`;

exports[`kol-drawer should render with _label="Label" 1`] = `
<kol-drawer class="drawer kol-drawer">
<kol-drawer class="kol-drawer--modal">
<template shadowrootmode="open">
<dialog class="drawer__dialog">
<div aria-label="Label" class="drawer__wrapper drawer__wrapper--top is-closing">
<div class="drawer__content">
<dialog class="kol-drawer__dialog">
<div aria-label="Label" class="kol-drawer__wrapper kol-drawer__wrapper--is-closing kol-drawer__wrapper--top">
<div class="kol-drawer__content">
<slot></slot>
</div>
</div>
Expand Down
44 changes: 23 additions & 21 deletions packages/themes/default/src/components/drawer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@

$duration: 0.4s;
@layer kol-theme-component {
.drawer__wrapper {
box-shadow: 0 0 rem(4) var(--color-subtle);
.kol-drawer {
&__wrapper {
box-shadow: 0 0 rem(4) var(--color-subtle);

&--left {
animation: slideInLeft $duration forwards;
&--left {
animation: slideInLeft $duration forwards;

&.is-closing {
animation: slideOutLeft $duration forwards;
&.kol-drawer__wrapper--is-closing {
animation: slideOutLeft $duration forwards;
}
}
}

&--right {
animation: slideInRight $duration forwards;
&--right {
animation: slideInRight $duration forwards;

&.is-closing {
animation: slideOutRight $duration forwards;
&.kol-drawer__wrapper--is-closing {
animation: slideOutRight $duration forwards;
}
}
}

&--top {
animation: slideInTop $duration forwards;
&--top {
animation: slideInTop $duration forwards;

&.is-closing {
animation: slideOutTop $duration forwards;
&.kol-drawer__wrapper--is-closing {
animation: slideOutTop $duration forwards;
}
}
}

&--bottom {
animation: slideInBottom $duration forwards;
&--bottom {
animation: slideInBottom $duration forwards;

&.is-closing {
animation: slideOutBottom $duration forwards;
&.kol-drawer__wrapper--is-closing {
animation: slideOutBottom $duration forwards;
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions packages/themes/ecl/src/ecl-ec/components/drawer.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@layer kol-theme-component {
:host .drawer__wrapper {
box-shadow: 0 0 calc(var(--spacing-2xs) / 2) var(--color-black);
.kol-drawer {
&__wrapper {
box-shadow: 0 0 calc(var(--spacing-2xs) / 2) var(--color-black);
}
}
}
6 changes: 4 additions & 2 deletions packages/themes/ecl/src/ecl-eu/components/drawer.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@layer kol-theme-component {
:host .drawer__wrapper {
box-shadow: 0 0 calc(var(--spacing-2xs) / 2) var(--color-black);
.kol-drawer {
&__wrapper {
box-shadow: 0 0 calc(var(--spacing-2xs) / 2) var(--color-black);
}
}
}
6 changes: 4 additions & 2 deletions packages/themes/itzbund/src/components/drawer.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@layer kol-theme-component {
:host .drawer__wrapper {
box-shadow: 0 0 0.25em gray;
.kol-drawer {
&__wrapper {
box-shadow: 0 0 0.25em gray;
}
}
}

0 comments on commit efccdbc

Please sign in to comment.