From 21c756ad96bf15aec92ef1ba2ace361e7bb325db Mon Sep 17 00:00:00 2001 From: Claas Date: Sun, 20 Aug 2023 19:09:11 +0200 Subject: [PATCH] Increase interaction target while keeping semantics of button --- README.md | 2 + .../buttons/common/button/src/DimButton.ts | 96 ++++++++++++------- .../common/text-button/src/DimTextButton.ts | 1 + 3 files changed, 67 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 5c5cd0b..c98be11 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # dim + A web component library for me to reuse components I otherwise often duplicate in different projects # Things to check out + - [lerna](https://lerna.js.org/docs/getting-started) for creating multiple libraries for each component in a single repository. Based on [Web Component Factory](https://www.npmjs.com/package/@wcfactory/cli) diff --git a/components/buttons/common/button/src/DimButton.ts b/components/buttons/common/button/src/DimButton.ts index 8a37ca0..5cacebe 100644 --- a/components/buttons/common/button/src/DimButton.ts +++ b/components/buttons/common/button/src/DimButton.ts @@ -26,12 +26,14 @@ export abstract class DimButton extends LitElement { render() { return html``; } @@ -96,8 +98,28 @@ export abstract class DimButton extends LitElement { } } + /* Make touch target at least 48dp. + Default otherwise at least 44dp. + https://m3.material.io/foundations/accessible-design/accessibility-basics#28032e45-c598-450c-b355-f9fe737b1cd8 + */ + button { + min-block-size: 44px; + min-inline-size: 44px; + } + + @media (any-pointer: coarse) { + button { + min-block-size: 48px; + min-inline-size: 48px; + } + } + button { outline: none; + background-color: transparent; + padding: 0; + border: none; + 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); @@ -105,35 +127,45 @@ export abstract class DimButton extends LitElement { letter-spacing: var(--md-sys-typescale-label-large-letter-spacing); font-weight: var(--md-sys-typescale-label-large-font-weight); - padding-inline: var(--_padding-inline, 24px); - padding-block: 10px; - height: 40px; - min-width: 48px; - border-radius: 20px; - text-align: center; - /* Have to use display flex to remove funky space between inline elements. As of 2023 there is no other viable solution */ - display: flex; - align-items: center; - gap: 8px; - - &:has(slot[name='icon'][slotted]) { - padding-inline: var(--_padding-inline-icon, 16px 24px); - } + cursor: default; - & [name='icon']::slotted(*) { - display: inline-block; - height: 18px; - width: 18px; - } + & div { + text-align: center; + /* Have to use display flex to remove funky space between inline elements. As of 2023 there is no other viable solution */ + display: flex; + align-items: center; + gap: 8px; + + height: 20px; + padding-block: 10px; + padding-inline: 24px; + &:has(slot[name='icon'][slotted]) { + padding-inline: var(--_padding-inline-icon, 16px 24px); + } - &:enabled { - border: var(--_border, none); background-color: var(--_background-color); color: var(--_color); - box-shadow: var(--_shadow-default); + + box-shadow: var(--_shadow--default); + + border-radius: 20px; + border: var(--_border, none); + + & slot { + &[name='icon'] { + &::slotted(*) { + display: inline-block; + height: 18px; + width: 18px; + } + } + } + } + + &:enabled { cursor: pointer; - &:hover { + &:hover div { background-color: color-mix( in srgb, var(--_color) var(--md-sys-state-hover-state-layer-opacity), @@ -142,7 +174,7 @@ export abstract class DimButton extends LitElement { box-shadow: var(--_shadow-elevated); } - &:focus { + &:focus div { background-color: color-mix( in srgb, var(--_color) var(--md-sys-state-focus-state-layer-opacity), @@ -151,7 +183,7 @@ export abstract class DimButton extends LitElement { border: var(--_border-focused, --_border, none); } - &:active { + &:active div { background-color: color-mix( in srgb, var(--_color) var(--md-sys-state-pressed-state-layer-opacity), @@ -160,7 +192,7 @@ export abstract class DimButton extends LitElement { } } - &:disabled { + &:disabled div { background-color: var( --_background-color-disabled, color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent) diff --git a/components/buttons/common/text-button/src/DimTextButton.ts b/components/buttons/common/text-button/src/DimTextButton.ts index 584bda9..19f04f7 100644 --- a/components/buttons/common/text-button/src/DimTextButton.ts +++ b/components/buttons/common/text-button/src/DimTextButton.ts @@ -7,6 +7,7 @@ export class DimTextButton extends DimButton { css` button { --_padding-inline: 12px; + /* Padding inline end when there is an icon slotted */ --_padding-inline-icon: 12px 16px; &:enabled { -- knotmirror 0.0.1