From 74ae7588190a3b73c1aae6ca8f3b60f93320c290 Mon Sep 17 00:00:00 2001 From: lindsaym-fa Date: Mon, 16 Dec 2024 19:32:35 -0500 Subject: [PATCH] Add native input styles and share with `` --- docs/docs/components/input.md | 2 +- docs/docs/experimental/style-guide.md | 33 +++++++-- src/components/input/input.css | 84 +---------------------- src/components/input/input.ts | 19 +++--- src/styles/native.css | 2 + src/styles/native/form-control.css | 13 ++++ src/styles/native/input.css | 98 +++++++++++++++++++++++++++ src/styles/shadow/form-control.css | 6 +- 8 files changed, 158 insertions(+), 99 deletions(-) create mode 100644 src/styles/native/form-control.css create mode 100644 src/styles/native/input.css diff --git a/docs/docs/components/input.md b/docs/docs/components/input.md index 2e6442c7a..1ef889d49 100644 --- a/docs/docs/components/input.md +++ b/docs/docs/components/input.md @@ -157,7 +157,7 @@ Use [CSS parts](#css-parts) to customize the way form controls are drawn. This e text-align: right; } - .label-on-left::part(form-control-hint) { + .label-on-left::part(hint) { grid-column-start: 2; } diff --git a/docs/docs/experimental/style-guide.md b/docs/docs/experimental/style-guide.md index d3c0667ec..559cee802 100644 --- a/docs/docs/experimental/style-guide.md +++ b/docs/docs/experimental/style-guide.md @@ -22,9 +22,9 @@ The styles shown below can be all yours by adding Web Awesome's applied styleshe WA Button - + - + @@ -32,9 +32,34 @@ The styles shown below can be all yours by adding Web Awesome's applied styleshe - + - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/components/input/input.css b/src/components/input/input.css index 26e0c360f..4fec1fe57 100644 --- a/src/components/input/input.css +++ b/src/components/input/input.css @@ -1,63 +1,13 @@ :host { - --background-color: var(--wa-form-control-background-color); - --border-color: var(--wa-form-control-resting-color); - --border-radius: var(--wa-form-control-border-radius); - --border-style: var(--wa-form-control-border-style); - --border-width: var(--wa-form-control-border-width); - --box-shadow: initial; - display: block; } -:host([filled]) { - --background-color: var(--wa-color-neutral-fill-quiet); - --border-color: var(--background-color); -} - .input { - background-color: var(--background-color); - border-color: var(--border-color); - border-radius: var(--border-radius); - border-style: var(--border-style); - border-width: var(--border-width); - box-shadow: var(--box-shadow); flex: 1 1 auto; - display: inline-flex; + display: flex; align-items: stretch; justify-content: start; position: relative; - width: 100%; - font: inherit; - vertical-align: middle; - overflow: hidden; - cursor: text; - transition: - background var(--wa-transition-normal) var(--wa-transition-easing), - border var(--wa-transition-normal) var(--wa-transition-easing), - outline var(--wa-transition-fast) var(--wa-transition-easing); -} - -/* Standard inputs */ -.input--standard.input--focused:not(.input--disabled) { - outline: var(--wa-focus-ring); - outline-offset: var(--wa-focus-ring-offset); - border-color: var(--wa-form-control-activated-color); -} - -.input--standard.input--disabled { - opacity: 0.5; - cursor: not-allowed; -} - -/* Filled inputs */ -.input--filled.input--focused:not(.input--disabled) { - outline: var(--wa-focus-ring); - outline-offset: var(--wa-focus-ring-offset); -} - -.input--filled.input--disabled { - opacity: 0.5; - cursor: not-allowed; } .input__control { @@ -65,8 +15,6 @@ min-width: 0; height: 100%; font: inherit; - line-height: var(--wa-form-control-value-line-height); - color: var(--wa-form-control-value-color); border: none; /* prettier-ignore */ background-color: rgb(118 118 118 / 0); /* ensures proper placeholder styles in webkit's date input */ @@ -84,28 +32,6 @@ -webkit-appearance: none; } -.input__control:-webkit-autofill, -.input__control:-webkit-autofill:hover, -.input__control:-webkit-autofill:focus, -.input__control:-webkit-autofill:active { - box-shadow: none; - -webkit-text-fill-color: var(--wa-color-brand-on-normal); - caret-color: var(--wa-form-control-value-color); -} - -.input--filled .input__control:-webkit-autofill, -.input--filled .input__control:-webkit-autofill:hover, -.input--filled .input__control:-webkit-autofill:focus, -.input--filled .input__control:-webkit-autofill:active { - box-shadow: none; -} - -.input__control::placeholder { - color: var(--wa-form-control-placeholder-color); - user-select: none; - -webkit-user-select: none; -} - .input__control:focus { outline: none; } @@ -195,14 +121,6 @@ } } -/* - * Pill modifier - */ - -.input--pill { - border-radius: var(--wa-border-radius-pill); -} - /* * Clearable + Password Toggle */ diff --git a/src/components/input/input.ts b/src/components/input/input.ts index 6ec900581..132c02791 100644 --- a/src/components/input/input.ts +++ b/src/components/input/input.ts @@ -12,6 +12,7 @@ import { HasSlotController } from '../../internal/slot.js'; import { MirrorValidator } from '../../internal/validators/mirror-validator.js'; import { watch } from '../../internal/watch.js'; import { WebAwesomeFormAssociatedElement } from '../../internal/webawesome-element.js'; +import nativeStyles from '../../styles/native/input.css'; import formControlStyles from '../../styles/shadow/form-control.css'; import { LocalizeController } from '../../utilities/localize.js'; import type WaButton from '../button/button.js'; @@ -61,7 +62,7 @@ import styles from './input.css'; */ @customElement('wa-input') export default class WaInput extends WebAwesomeFormAssociatedElement { - static shadowStyle = [formControlStyles, styles]; + static shadowStyle = [formControlStyles, nativeStyles, styles]; static shadowRootOptions = { ...WebAwesomeFormAssociatedElement.shadowRootOptions, delegatesFocus: true }; @@ -206,8 +207,8 @@ export default class WaInput extends WebAwesomeFormAssociatedElement { converter: { // Allow "true|false" attribute values but keep the property boolean fromAttribute: value => (!value || value === 'false' ? false : true), - toAttribute: value => (value ? 'true' : 'false'), - }, + toAttribute: value => (value ? 'true' : 'false') + } }) spellcheck = true; @@ -289,7 +290,7 @@ export default class WaInput extends WebAwesomeFormAssociatedElement { } const button = formElements.find( - (el: HTMLButtonElement) => el.type === 'submit' && !el.matches(':disabled'), + (el: HTMLButtonElement) => el.type === 'submit' && !el.matches(':disabled') ) as undefined | HTMLButtonElement | WaButton; // No button found, don't submit. @@ -339,7 +340,7 @@ export default class WaInput extends WebAwesomeFormAssociatedElement { setSelectionRange( selectionStart: number, selectionEnd: number, - selectionDirection: 'forward' | 'backward' | 'none' = 'none', + selectionDirection: 'forward' | 'backward' | 'none' = 'none' ) { this.input.setSelectionRange(selectionStart, selectionEnd, selectionDirection); } @@ -349,7 +350,7 @@ export default class WaInput extends WebAwesomeFormAssociatedElement { replacement: string, start?: number, end?: number, - selectMode: 'select' | 'start' | 'end' | 'preserve' = 'preserve', + selectMode: 'select' | 'start' | 'end' | 'preserve' = 'preserve' ) { const selectionStart = start ?? this.input.selectionStart!; const selectionEnd = end ?? this.input.selectionEnd!; @@ -410,7 +411,7 @@ export default class WaInput extends WebAwesomeFormAssociatedElement { 'form-control--small': this.size === 'small', 'form-control--medium': this.size === 'medium', 'form-control--large': this.size === 'large', - 'form-control--has-label': hasLabel, + 'form-control--has-label': hasLabel })} >