diff --git a/README.md b/README.md index 33b33d2..218d51e 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,8 @@ A web component library for me to reuse components I otherwise often duplicate i # TODO -[ ] Set defaults for not provided CSS Variables to achieve components looking acceptable without configuration + +# Interesting Reads + +- [Pros and cons of using Shadow DOM and style encapsulation](https://www.matuzo.at/blog/2023/pros-and-cons-of-shadow-dom/) +- [Container Queries in Web Components](https://mxb.dev/blog/container-queries-web-components/) diff --git a/components/navigation-drawer/src/DimNavigationDrawer.ts b/components/navigation-drawer/src/DimNavigationDrawer.ts index 8a18153..5b74049 100644 --- a/components/navigation-drawer/src/DimNavigationDrawer.ts +++ b/components/navigation-drawer/src/DimNavigationDrawer.ts @@ -7,41 +7,73 @@ import { dimNavigationHostContext } from './DimNavigationHostContext.js'; //TODO use filled out icons for current destination //TODO only use expanded after > 1239dp https://m3.material.io/components/navigation-drawer/guidelines#81b637af-d1c6-4edd-84fd-487eb9860d76 /** + * It is recommended to use 3-7 destination items with the navigation * Remarks: For the component to properly work it needs to be registered before the navigation due to the context registration requiring the host provider to be initialized */ export class DimNavigationDrawer extends LitElement { static styles = // Only configure styles that are different between buttons css` - /* Compact: Width < 600 (Default in mobile first) */ - nav { - /* Color (modal) */ - background-color: var(--md-sys-color-surface-container-low); + :host { + /* Compact is default layout */ + display: block; + container-type: inline-size; + + position: fixed; + --_inset: auto auto 0 0; + inset: var(--_inset); + + --_width: 100dvw; + --_height: 80px; + + width: var(--_width); + height: var(--_height); + + background-color: var(--md-sys-color-surface); } - /* Medium: 600 < width < 840 */ + nav { + /* Compact Layout (default) */ + box-sizing: border-box; + padding: 0 8px; + z-index: var(--md-sys-elevation-level-2-z-index); + background-color: var(--md-sys-color-surface); + + /* Hide divider when not expanded */ + & slot::slotted(dim-divider) { + display: none; + visibility: hidden; + } - /* @media (600px < width < 840px) { */ - @media (min-width: 600px) and (max-width: 840px) { - nav { - /* Color (modal) */ + /* When width is expanded or modal open */ + @container (min-width: 360px) and (min-height: 100dvh) { background-color: var(--md-sys-color-surface-container-low); box-shadow: var(--md-sys-elevation-1-shadow); } - } - /* Expanded: 840 > width */ + /* Medium Layout (rail + modal drawer) */ + @media (min-width: 600px) and (max-width: 840px) { + /* Color (modal) */ - /* @media (width > 840px) { */ - /* Navigation drawer is visible in expanded layouts and a modal on compact and medium */ - @media (min-width: 840px) { - nav { - position: sticky; - top: 0; - height: 100dvh; - width: 360px; + border-radius: none; + } + + /* Expanded (rail + modal drawer) */ + @media (min-width: 840px) and (max-width: 1240px) { padding-inline: 12px; + width: var(--_rail-width); + border-radius: none; + + & slot::slotted(dim-divider) { + display: none; + } + } + + /* "Expandeder" for navigation drawer (expanded drawer) */ + @media (min-width: 1240px) { + width: 360px; box-sizing: border-box; + padding-inline: 12px; /* Color (standard) */ --_background-color: var(--md-sys-color-surface); @@ -52,6 +84,14 @@ export class DimNavigationDrawer extends LitElement { border-radius: var(--md-sys-shape-corner-large-end); } } + + /* Medium: 600 < width < 840 */ + + /* @media (600px < width < 840px) { */ + + /* Expanded: 840 > width */ + /* @media (width > 840px) { */ + /* Navigation drawer is visible in expanded layouts and a modal on compact and medium */ `; @provide({ context: dimNavigationHostContext }) @@ -130,172 +170,6 @@ export class DimNavigationDrawer extends LitElement { } } -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const _ = html`
-
Mail
- -
- -
-
Labels
- -
`; - declare global { interface HTMLElementTagNameMap { 'dim-navigation-drawer': DimNavigationDrawer; diff --git a/components/navigation-drawer/src/DimNavigationItem.ts b/components/navigation-drawer/src/DimNavigationItem.ts index 34cf067..837221f 100644 --- a/components/navigation-drawer/src/DimNavigationItem.ts +++ b/components/navigation-drawer/src/DimNavigationItem.ts @@ -6,127 +6,279 @@ import { DimNavigationDrawer } from './DimNavigationDrawer.js'; export class DimNavigationItem extends LitElement { static styles = css` + :host { + display: block; + container-type: inline-size; + + /* width: 70px; */ + width: 100%; + height: 56px; + box-sizing: border-box; + } + li a { all: unset; - vertical-align: middle; - box-sizing: border-box; + /* The rail */ + font-family: var(--md-sys-typescale-label-medium-font-family-name); + line-height: var(--md-sys-typescale-label-medium-line-height); + font-size: var(--md-sys-typescale-label-medium-font-size); + font-style: var(--md-sys-typescale-label-medium-font-family-style); + letter-spacing: var(--md-sys-typescale-label-medium-letter-spacing); + font-weight: var(--md-sys-typescale-label-medium-font-weight); + display: flex; - /* width 336 = 16 left padding + 296 w + 24 right padding */ - padding-inline: 16px 24px; - padding-block: 16px; + flex-direction: column; + gap: 4px; + padding: 12px 0 16px 0; + + height: 100%; + + cursor: pointer; + /* width: 56px; */ + align-items: center; - gap: 12px; + & slot[name^='icon-'] { + display: grid; + justify-content: center; + align-content: center; + width: 64; + height: 32px; + padding: 4px 20px; + box-sizing: border-box; - /* Inactive */ - font-family: var(--md-sys-typescale-label-large-font-family-name); - line-height: var(--md-sys-typescale-label-large-line-height); - font-size: var(--md-sys-typescale-label-large-font-size); - font-style: var(--md-sys-typescale-label-large-font-family-style); - letter-spacing: var(--md-sys-typescale-label-large-letter-spacing); - font-weight: var(--md-sys-typescale-label-large-font-weight); + border-radius: var(--md-sys-shape-corner-large); - border-radius: var(--md-sys-shape-corner-extra-large); + /* On the rail only the the area around the icon has a different color */ + --_background-color: var(--md-sys-color-surface); + background-color: var(--_background-color); + /* Text & icon color */ + --_color: var(--md-sys-color-on-surface-variant); + color: var(--_color); - cursor: pointer; + /* Inactive hover */ + &:hover { + background-color: color-mix( + in srgb, + var(--md-sys-color-on-surface-variant) + var(--md-sys-state-hover-state-layer-opacity), + var(--_background-color) + ); - /* Inactive hover */ - &:hover { - background-color: color-mix( - in srgb, - var(--md-sys-color-on-surface) - var(--md-sys-state-hover-state-layer-opacity), - var(--_background-color) - ); + color: var(--md-sys-color-on-surface-variant); + } - color: var(--md-sys-color-on-surface); - } + &:focus { + background-color: color-mix( + in srgb, + var(--md-sys-color-on-surface-variant) + var(--md-sys-state-focus-state-layer-opacity), + var(--_background-color) + ); - &:focus { - background-color: color-mix( - in srgb, - var(--md-sys-color-on-surface) - var(--md-sys-state-focus-state-layer-opacity), - var(--_background-color) - ); - color: var(--md-sys-color-on-surface); - } + color: var(--md-sys-color-on-surface-variant); + } - &:active { - background-color: color-mix( - in srgb, - var(--md-sys-color-on-secondary-container) - var(--md-sys-state-pressed-state-layer-opacity), - var(--_background-color) - ); - color: var(--md-sys-color-on-surface); + &:active { + background-color: color-mix( + in srgb, + var(--md-sys-color-on-surface-variant) + var(--md-sys-state-pressed-state-layer-opacity), + var(--_background-color) + ); + color: var(--md-sys-color-on-surface-variant); + } } /* Use outlined icon when inactive */ + &:not([active]) slot[name='icon-filled'] { + display: none; + } + + /* Icon size is always 24px */ + & slot[name^='icon-']::slotted(*) { + height: 24px; + width: 24px; + } - &:not([active]) slot[name='icon-filled']::slotted(*) { + /* Hide badge for now */ + & span:nth-of-type(2) { display: none; } - /* Active destination */ + /* States active destination */ &[active] { /* Active indicator is the link in our case so we change its background color */ - --_background-color: var(--md-sys-color-secondary-container); - --_color: var(--md-sys-color-on-secondary-container); - background-color: var(--_background-color); - color: var(--_color); + & slot[name^='icon-'] { + --_background-color: var(--md-sys-color-secondary-container); + --_color: var(--md-sys-color-on-surface); + + &::slotted(*) { + /* Icon color is different to label text color on active */ + color: var(--md-sys-color-on-secondary-container); + } + + /* Active hover */ + &:hover { + background-color: color-mix( + in srgb, + var(--md-sys-color-on-surface) + var(--md-sys-state-hover-state-layer-opacity), + var(--_background-color) + ); + + color: var(--md-sys-on-surface); + + &::slotted(*) { + color: var(--md-sys-color-on-secondary-container); + } + } + + &:focus { + background-color: color-mix( + in srgb, + var(--md-sys-color-on-secondary-container) + var(--md-sys-state-focus-state-layer-opacity), + var(--_background-color) + ); + + color: var(--md-sys-on-secondary-container); + + &::slotted(*) { + color: var(--md-sys-color-on-secondary-container); + } + } + + &:active { + background-color: color-mix( + in srgb, + var(--md-sys-color-on-secondary-container) + var(--md-sys-state-focus-state-layer-opacity), + var(--_background-color) + ); + + color: var(--md-sys-on-secondary-container); + + &::slotted(*) { + color: var(--md-sys-color-on-secondary-container); + } + } + } + + /* Use filled icon when active */ + & slot[name='icon-outlined'] { + display: none; + } + } - /* Active hover */ + /* The size when the drawer is expanded */ + @container (min-width: 336px) and (min-height: 100dvh) { + flex-direction: row; + vertical-align: middle; + box-sizing: border-box; + width: 336px; + /* width 336 = 16 left padding + 296 w + 24 right padding */ + padding-inline: 16px 24px; + padding-block: 16px; + align-items: center; + + gap: 12px; + + font-family: var(--md-sys-typescale-label-large-font-family-name); + line-height: var(--md-sys-typescale-label-large-line-height); + font-size: var(--md-sys-typescale-label-large-font-size); + font-style: var(--md-sys-typescale-label-large-font-family-style); + letter-spacing: var(--md-sys-typescale-label-large-letter-spacing); + font-weight: var(--md-sys-typescale-label-large-font-weight); + + border-radius: var(--md-sys-shape-corner-extra-large); + + /* Label */ + & span:first-of-type { + flex: 1 0 0; + } + + /* States inactive */ &:hover { background-color: color-mix( in srgb, - var(--md-sys-color-on-secondary-container) + var(--md-sys-color-on-surface) var(--md-sys-state-hover-state-layer-opacity), var(--_background-color) ); - color: var(--md-sys-on-secondary-container); + color: var(--md-sys-color-on-surface); } &:focus { background-color: color-mix( in srgb, - var(--md-sys-color-on-secondary-container) + var(--md-sys-color-on-surface) var(--md-sys-state-focus-state-layer-opacity), var(--_background-color) ); - - color: var(--md-sys-on-secondary-container); + color: var(--md-sys-color-on-surface); } &:active { background-color: color-mix( in srgb, var(--md-sys-color-on-secondary-container) - var(--md-sys-state-focus-state-layer-opacity), + var(--md-sys-state-pressed-state-layer-opacity), var(--_background-color) ); - - color: var(--md-sys-on-secondary-container); + color: var(--md-sys-color-on-surface); } - /* Use filled icon when active */ - & slot[name='icon-outlined']::slotted(*) { - display: none; + /* States active destination */ + &[active] { + /* Active indicator is the link in our case so we change its background color */ + --_background-color: var(--md-sys-color-secondary-container); + --_color: var(--md-sys-color-on-secondary-container); + background-color: var(--_background-color); + color: var(--_color); + + /* Active hover */ + &:hover { + background-color: color-mix( + in srgb, + var(--md-sys-color-on-secondary-container) + var(--md-sys-state-hover-state-layer-opacity), + var(--_background-color) + ); + + color: var(--md-sys-on-secondary-container); + } + + &:focus { + background-color: color-mix( + in srgb, + var(--md-sys-color-on-secondary-container) + var(--md-sys-state-focus-state-layer-opacity), + var(--_background-color) + ); + + color: var(--md-sys-on-secondary-container); + } + + &:active { + background-color: color-mix( + in srgb, + var(--md-sys-color-on-secondary-container) + var(--md-sys-state-focus-state-layer-opacity), + var(--_background-color) + ); + + color: var(--md-sys-on-secondary-container); + } + + /* Use filled icon when active */ + & slot[name='icon-outlined'] { + display: none; + } } } - - /* Icon */ - & slot[name^='icon-']::slotted(*) { - height: 24px; - width: 24px; - } - - /* Label */ - & span:first-of-type { - flex: 1 0 0; - } } `; diff --git a/components/navigation-drawer/src/DimNavigationSection.ts b/components/navigation-drawer/src/DimNavigationSection.ts index 61e66da..674dc46 100644 --- a/components/navigation-drawer/src/DimNavigationSection.ts +++ b/components/navigation-drawer/src/DimNavigationSection.ts @@ -4,26 +4,50 @@ import { LitElement, css, html } from 'lit'; */ export class DimNavigationSection extends LitElement { static styles = css` - ol { - all: unset; - list-style-type: none; + :host { + display: block; + + container-type: inline-size; + height: 80px; + } + + section { + height: 100%; + & ol { + all: unset; + + height: 100%; + list-style-type: none; + display: flex; + justify-content: space-between; + gap: 8px; + } } + /* Headline */ slot[name='headline']::slotted(*) { - padding-inline: 16px; - /* 18dp so we add up to 56 again due to no icon taking additional 2dp */ - padding-block: 18px; + /* Hide headline when not expanded */ + display: none; + } + + @container (min-width: 336px) and (min-height: 100dvh) { + slot[name='headline']::slotted(*) { + display: block; + padding-inline: 16px; + /* 18dp so we add up to 56 again due to no icon taking additional 2dp */ + padding-block: 18px; - margin: 0; + margin: 0; - color: var(--_color); + color: var(--_color); - font-family: var(--md-sys-typescale-title-small-font-family-name); - line-height: var(--md-sys-typescale-title-small-line-height); - font-size: var(--md-sys-typescale-title-small-font-size); - font-style: var(--md-sys-typescale-title-small-font-family-style); - letter-spacing: var(--md-sys-typescale-title-small-letter-spacing); - font-weight: var(--md-sys-typescale-title-small-font-weight); + font-family: var(--md-sys-typescale-title-small-font-family-name); + line-height: var(--md-sys-typescale-title-small-line-height); + font-size: var(--md-sys-typescale-title-small-font-size); + font-style: var(--md-sys-typescale-title-small-font-family-style); + letter-spacing: var(--md-sys-typescale-title-small-letter-spacing); + font-weight: var(--md-sys-typescale-title-small-font-weight); + } } `; diff --git a/page/index.html b/page/index.html index bec3a91..8f5ba2e 100644 --- a/page/index.html +++ b/page/index.html @@ -28,136 +28,6 @@ - - - -

Mail

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -

Labels

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-

Components

@@ -299,6 +169,123 @@ Label
+ + + + + +

Mail

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +

Labels

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ diff --git a/page/public/css/custom.tokens.css b/page/public/css/custom.tokens.css index fb539ca..8f923df 100644 --- a/page/public/css/custom.tokens.css +++ b/page/public/css/custom.tokens.css @@ -3,6 +3,7 @@ These tokens might not follow naming guidelines */ :root { --md-sys-elevation-0-shadow: none; + /* Elevation */ /* light */ /* Use --md-sys-color-shadow for shadow color maybe? */ --md-sys-elevation-light-1-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15), @@ -27,6 +28,15 @@ These tokens might not follow naming guidelines */ --md-sys-elevation-dark-5-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.3), 0px 8px 12px 6px rgba(0, 0, 0, 0.15); + /* https://m3.material.io/styles/elevation/tokens */ + --md-sys-elevation-level-0-z-index: 0; + --md-sys-elevation-level-1-z-index: 1; + --md-sys-elevation-level-2-z-index: 3; + --md-sys-elevation-level-3-z-index: 6; + --md-sys-elevation-level-4-z-index: 8; + --md-sys-elevation-level-5-z-index: 12; + + /* States */ /* https://m3.material.io/foundations/interaction/states/state-layers#bf9b84b2-690c-44b2-8429-8c42dc012d43 (there is a list for the states) */ --md-sys-state-hover-state-layer-opacity: 8%; --md-sys-state-focus-state-layer-opacity: 12%;