From 17075f485544d186e82c1d93bd441a658f0ccf49 Mon Sep 17 00:00:00 2001 From: Material Web Team Date: Mon, 1 Aug 2022 01:11:23 -0700 Subject: [PATCH] feat(form-field): Added theme styles to form field PiperOrigin-RevId: 464479156 --- formfield/lib/_formfield-theme.scss | 41 +++++++++++++ formfield/lib/_formfield.scss | 59 ++++++------------- formfield/lib/formfield-styles.scss | 8 +++ .../lib/{formfield-base.ts => formfield.ts} | 12 ++-- 4 files changed, 74 insertions(+), 46 deletions(-) create mode 100644 formfield/lib/_formfield-theme.scss rename formfield/lib/{formfield-base.ts => formfield.ts} (79%) diff --git a/formfield/lib/_formfield-theme.scss b/formfield/lib/_formfield-theme.scss new file mode 100644 index 0000000000..3f022c7bc0 --- /dev/null +++ b/formfield/lib/_formfield-theme.scss @@ -0,0 +1,41 @@ +// +// Copyright 2022 Google LLC +// SPDX-License-Identifier: Apache-2.0 +// + +// stylelint-disable selector-class-pattern -- +// Selector '.md3-*' should only be used in this project. + +@use 'sass:map'; + +@use '@material/web/sass/theme'; +@use '@material/web/tokens'; + +$custom-property-prefix: 'formfield'; + +$light-theme: ( + label-text-color: + map.get(tokens.md-sys-color-values-light-dynamic(), on-surface), + disabled-label-text-color: + map.get(tokens.md-sys-color-values-light-dynamic(), on-surface-variant), +); + +@mixin theme($theme) { + $theme: theme.validate-theme($light-theme, $theme); + @include theme.emit-theme-vars( + theme.create-theme-vars($theme, $custom-property-prefix) + ); +} + +@mixin theme-styles($theme) { + $theme: theme.validate-theme($light-theme, $theme); + $theme: theme.create-theme-vars($theme, $prefix: $custom-property-prefix); + + .md3-formfield__label { + color: map.get($theme, label-text-color); + } + + &.md3-formfield--disabled .md3-formfield__label { + color: map.get($theme, disabled-label-text-color); + } +} diff --git a/formfield/lib/_formfield.scss b/formfield/lib/_formfield.scss index d28f3b7654..dc26d5bcf3 100644 --- a/formfield/lib/_formfield.scss +++ b/formfield/lib/_formfield.scss @@ -4,58 +4,37 @@ // // stylelint-disable selector-class-pattern -- -// Selector '.mdc-*' should only be used in this project. +// Selector '.md3-*' should only be used in this project. @mixin static-styles() { :host { - @include host-root; + display: inline-flex; } - .mdc-formfield { - @include root; - - .mdc-formfield__label { - @include label; - } + .md3-formfield { + align-items: center; + display: inline-flex; + vertical-align: middle; + width: 100%; } - .mdc-formfield--align-end .mdc-formfield__label { - @include align-end; + .md3-formfield__label { + margin-inline: 0 auto; + order: 0; + padding-inline: 4px 0; } - .mdc-formfield--space-between { - @include space-between; + .md3-formfield--align-end .md3-formfield__label { + margin-inline: auto 0; + order: -1; + padding-inline: 0 4px; } -} - -@mixin host-root() { - display: inline-flex; -} - -@mixin root() { - align-items: center; - display: inline-flex; - vertical-align: middle; - width: 100%; -} -@mixin label() { - margin-inline: 0 auto; - padding-inline: 4px 0; - - order: 0; -} -@mixin align-end() { - margin-inline: auto 0; - padding-inline: 0 4px; - - order: -1; -} - -@mixin space-between() { - justify-content: space-between; + .md3-formfield--space-between { + justify-content: space-between; + } - .mdc-formfield__label { + .md3-formfield--space-between .md3-formfield__label { margin: 0; } } diff --git a/formfield/lib/formfield-styles.scss b/formfield/lib/formfield-styles.scss index cc29ea50c7..a1884b66de 100644 --- a/formfield/lib/formfield-styles.scss +++ b/formfield/lib/formfield-styles.scss @@ -3,6 +3,14 @@ // SPDX-License-Identifier: Apache-2.0 // +// stylelint-disable selector-class-pattern -- +// Selector '.md3-*' should only be used in this project. + @use './formfield'; +@use './formfield-theme'; @include formfield.static-styles(); + +.md3-formfield { + @include formfield-theme.theme-styles(formfield-theme.$light-theme); +} diff --git a/formfield/lib/formfield-base.ts b/formfield/lib/formfield.ts similarity index 79% rename from formfield/lib/formfield-base.ts rename to formfield/lib/formfield.ts index 4477474b25..61023cdd28 100644 --- a/formfield/lib/formfield-base.ts +++ b/formfield/lib/formfield.ts @@ -13,10 +13,9 @@ import {ifDefined} from 'lit/directives/if-defined'; export class Formfield extends LitElement { @property({type: Boolean}) alignEnd = false; @property({type: Boolean}) spaceBetween = false; - @property({type: String}) label = ''; - @property({type: String}) inputId?: string; + @property({type: Boolean}) disabled = false; @queryAssignedElements() protected slottedInputs!: HTMLElement[]|null; @@ -27,9 +26,9 @@ export class Formfield extends LitElement { /** @soyTemplate */ protected override render(): TemplateResult { return html` -
+
-
`; @@ -38,8 +37,9 @@ export class Formfield extends LitElement { /** @soyTemplate */ protected getRenderClasses(): ClassInfo { return { - 'mdc-formfield--align-end': this.alignEnd, - 'mdc-formfield--space-between': this.spaceBetween, + 'md3-formfield--align-end': this.alignEnd, + 'md3-formfield--space-between': this.spaceBetween, + 'md3-formfield--disabled': this.disabled, }; }