@m3e/form-field 1.0.0-rc.2 → 1.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) 2025 matraic
4
4
  * See LICENSE file in the project root for full license text.
5
5
  */
6
- import{LitElement as t,nothing as e,html as i,unsafeCSS as o,css as s}from"lit";import{AttachInternals as r,MutationController as a,ResizeController as n,FocusController as l,HoverController as d,PressedController as h,isReadOnlyMixin as c,DesignToken as f,hasAssignedNodes as p,getTextContent as u}from"@m3e/core";import{M3eAriaDescriber as m}from"@m3e/core/a11y";
6
+ import{LitElement as t,nothing as e,html as i,css as o,unsafeCSS as s}from"lit";import{AttachInternals as r,MutationController as a,ResizeController as n,FocusController as l,HoverController as d,PressedController as h,isReadOnlyMixin as c,DesignToken as f,hasAssignedNodes as p,getTextContent as u}from"@m3e/core";import{M3eAriaDescriber as m}from"@m3e/core/a11y";
7
7
  /**
8
8
  * Adapted from Angular Material Form Field Control
9
9
  * Source: https://github.com/angular/components/blob/main/src/material/form-field/form-field-control.ts
@@ -88,7 +88,25 @@ function J(t,e){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Refl
88
88
  <span class="subscript" aria-hidden="true">
89
89
  <span class="error"><slot name="error">${this._validationMessage}</slot></span>
90
90
  <span class="hint"><slot name="hint"></slot></span>
91
- </span>`}};Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap,tt=new WeakMap,et=new WeakMap,it=new WeakMap,ot=new WeakMap,st=new WeakMap,rt=new WeakMap,at=new WeakMap,K=new WeakSet,nt=function(){return void 0!==w(this,Q,"f")?.shouldLabelFloat?!0===w(this,Q,"f").shouldLabelFloat:"string"==typeof w(this,Q,"f")?.value&&w(this,Q,"f").value.length>0},lt=function(t){t.stopImmediatePropagation(),t.stopPropagation()},dt=function(t){const e=t.target.assignedElements({flatten:!0});this.classList.toggle("-with-label",e.length>0),this._pseudoLabel=e[0]?.textContent??""},ht=function(t){this.classList.toggle("-with-prefix",p(t.target)),w(this,tt,"f").observe(this._prefix)},ct=function(t){this.classList.toggle("-with-suffix",p(t.target))},ft=function(){"outlined"===this.variant&&this._base.style.setProperty("--_prefix-width",`${this._prefix.clientWidth}px`)},pt=function(t){w(this,K,"m",gt).call(this,g(t.target))},ut=function(t){!w(this,Q,"f")||w(this,st,"f")||w(this,Q,"f").disabled||(w(this,Q,"f").onContainerClick?w(this,Q,"f").onContainerClick(t):w(this,Q,"f").focus())},mt=function(){this._invalid=!0,this.notifyControlStateChange()},bt=function(){this._invalid=!(w(this,Q,"f")?.checkValidity?.()??1),this.notifyControlStateChange()},vt=function(){this._invalid=!1,this.notifyControlStateChange()},gt=function(t){w(this,Q,"f")!==t&&(w(this,Q,"f")&&(w(this,rt,"f")&&m.removeDescription(w(this,Q,"f"),w(this,rt,"f")),w(this,at,"f")&&m.removeDescription(w(this,Q,"f"),w(this,at,"f")),w(this,Z,"f").unobserve(w(this,Q,"f")),w(this,Q,"f").removeEventListener("invalid",w(this,Y,"f")),w(this,Q,"f").form?.removeEventListener("reset",w(this,X,"f"))),_(this,Q,t,"f"),w(this,Q,"f")&&(w(this,Z,"f").observe(w(this,Q,"f")),w(this,Q,"f").addEventListener("invalid",w(this,Y,"f")),w(this,Q,"f").form?.addEventListener("reset",w(this,X,"f")),w(this,Q,"f").removeAttribute("aria-invalid"),w(this,rt,"f")&&m.describe(w(this,Q,"f"),w(this,rt,"f")),this.notifyControlStateChange()))},yt=function(){const t=u(this._hint,!0);t!==w(this,rt,"f")&&(w(this,Q,"f")&&w(this,rt,"f")&&m.removeDescription(w(this,Q,"f"),w(this,rt,"f")),_(this,rt,t,"f"),w(this,Q,"f")&&w(this,rt,"f")&&m.describe(w(this,Q,"f"),w(this,rt,"f")))},wt=function(){const t=u(this._error,!0);t!==w(this,at,"f")&&(w(this,Q,"f")&&w(this,at,"f")&&m.removeDescription(w(this,Q,"f"),w(this,at,"f")),_(this,at,t,"f"),w(this,Q,"f")&&w(this,at,"f")&&this._invalid&&m.describe(w(this,Q,"f"),w(this,at,"f")))},_t.styles=s`
91
+ </span>`}};Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap,tt=new WeakMap,et=new WeakMap,it=new WeakMap,ot=new WeakMap,st=new WeakMap,rt=new WeakMap,at=new WeakMap,K=new WeakSet,nt=function(){return void 0!==w(this,Q,"f")?.shouldLabelFloat?!0===w(this,Q,"f").shouldLabelFloat:"string"==typeof w(this,Q,"f")?.value&&w(this,Q,"f").value.length>0},lt=function(t){t.stopImmediatePropagation(),t.stopPropagation()},dt=function(t){const e=t.target.assignedElements({flatten:!0});this.classList.toggle("-with-label",e.length>0),this._pseudoLabel=e[0]?.textContent??""},ht=function(t){this.classList.toggle("-with-prefix",p(t.target)),w(this,tt,"f").observe(this._prefix)},ct=function(t){this.classList.toggle("-with-suffix",p(t.target))},ft=function(){"outlined"===this.variant&&this._base.style.setProperty("--_prefix-width",`${this._prefix.clientWidth}px`)},pt=function(t){w(this,K,"m",gt).call(this,g(t.target))},ut=function(t){!w(this,Q,"f")||w(this,st,"f")||w(this,Q,"f").disabled||(w(this,Q,"f").onContainerClick?w(this,Q,"f").onContainerClick(t):w(this,Q,"f").focus())},mt=function(){this._invalid=!0,this.notifyControlStateChange()},bt=function(){this._invalid=!(w(this,Q,"f")?.checkValidity?.()??1),this.notifyControlStateChange()},vt=function(){this._invalid=!1,this.notifyControlStateChange()},gt=function(t){w(this,Q,"f")!==t&&(w(this,Q,"f")&&(w(this,rt,"f")&&m.removeDescription(w(this,Q,"f"),w(this,rt,"f")),w(this,at,"f")&&m.removeDescription(w(this,Q,"f"),w(this,at,"f")),w(this,Z,"f").unobserve(w(this,Q,"f")),w(this,Q,"f").removeEventListener("invalid",w(this,Y,"f")),w(this,Q,"f").form?.removeEventListener("reset",w(this,X,"f"))),_(this,Q,t,"f"),w(this,Q,"f")&&(w(this,Z,"f").observe(w(this,Q,"f")),w(this,Q,"f").addEventListener("invalid",w(this,Y,"f")),w(this,Q,"f").form?.addEventListener("reset",w(this,X,"f")),w(this,Q,"f").removeAttribute("aria-invalid"),w(this,rt,"f")&&m.describe(w(this,Q,"f"),w(this,rt,"f")),this.notifyControlStateChange()))},yt=function(){const t=u(this._hint,!0);t!==w(this,rt,"f")&&(w(this,Q,"f")&&w(this,rt,"f")&&m.removeDescription(w(this,Q,"f"),w(this,rt,"f")),_(this,rt,t,"f"),w(this,Q,"f")&&w(this,rt,"f")&&m.describe(w(this,Q,"f"),w(this,rt,"f")))},wt=function(){const t=u(this._error,!0);t!==w(this,at,"f")&&(w(this,Q,"f")&&w(this,at,"f")&&m.removeDescription(w(this,Q,"f"),w(this,at,"f")),_(this,at,t,"f"),w(this,Q,"f")&&w(this,at,"f")&&this._invalid&&m.describe(w(this,Q,"f"),w(this,at,"f")))},(()=>{const t=new CSSStyleSheet;t.replaceSync(o`
92
+ m3e-form-field input::placeholder,
93
+ m3e-form-field textarea::placeholder {
94
+ user-select: none;
95
+ color: currentColor;
96
+ transition: opacity ${f.motion.duration.extraLong1};
97
+ }
98
+ m3e-form-field[float-label="auto"]:not(.-float-label).-with-label input::placeholder,
99
+ m3e-form-field[float-label="auto"]:not(.-float-label).-with-label textarea::placeholder {
100
+ opacity: 0;
101
+ transition: opacity 0s;
102
+ }
103
+ @media (prefers-reduced-motion) {
104
+ m3e-form-field input::placeholder,
105
+ m3e-form-field textarea::placeholder {
106
+ transition: none !important;
107
+ }
108
+ }
109
+ `.toString()),document.adoptedStyleSheets=[...document.adoptedStyleSheets,t]})(),_t.styles=o`
92
110
  :host {
93
111
  display: inline-flex;
94
112
  flex-direction: column;
@@ -157,10 +175,10 @@ function J(t,e){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Refl
157
175
  line-height: var(--m3e-form-field-label-line-height, ${f.typescale.standard.body.small.lineHeight});
158
176
  letter-spacing: var(--m3e-form-field-label-tracking, ${f.typescale.standard.body.small.tracking});
159
177
  color: var(--_form-field-label-color, inherit);
160
- transition: ${o(`top ${f.motion.duration.short4}, \n font-size ${f.motion.duration.short4}, \n line-height ${f.motion.duration.short4}`)};
178
+ transition: ${s(`top ${f.motion.duration.short4}, \n font-size ${f.motion.duration.short4}, \n line-height ${f.motion.duration.short4}`)};
161
179
  }
162
180
  :host(.-with-select) .label {
163
- margin-right: 1.5rem;
181
+ margin-inline-end: 1.5rem;
164
182
  }
165
183
  ::slotted([slot="label"]) {
166
184
  white-space: nowrap;
@@ -189,7 +207,7 @@ function J(t,e){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Refl
189
207
  opacity: 0;
190
208
  margin-top: 0px;
191
209
  margin-bottom: 0.25rem;
192
- transition: ${o(`opacity ${f.motion.duration.short4}, \n margin-top ${f.motion.duration.short4}, \n margin-bottom ${f.motion.duration.short4}`)};
210
+ transition: ${s(`opacity ${f.motion.duration.short4}, \n margin-top ${f.motion.duration.short4}, \n margin-bottom ${f.motion.duration.short4}`)};
193
211
  }
194
212
  :host([hide-subscript="auto"]:not(.-invalid):focus-within) .subscript,
195
213
  :host([hide-subscript="auto"]:not(.-invalid).-pressed) .subscript {
@@ -231,41 +249,27 @@ function J(t,e){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Refl
231
249
  :host([variant="outlined"]) ::slotted(m3e-input-chip-set) {
232
250
  margin-block: calc(calc(3.5rem + ${f.density.calc(-2)}) / 4);
233
251
  }
234
- ::slotted(:not([slot])::part(focus-ring)) {
235
- display: none;
236
- }
237
- ::slotted(input)::placeholder,
238
- ::slotted(textarea)::placeholder {
239
- user-select: none;
240
- color: currentColor;
241
- transition: opacity ${f.motion.duration.extraLong1};
242
- }
243
252
  :host([float-label="auto"]:not(.-float-label):not(.-pressed)) .label {
244
253
  font-size: inherit;
245
254
  }
246
- :host([float-label="auto"]:not(.-float-label).-with-label) ::slotted(input)::placeholder,
247
- :host([float-label="auto"]:not(.-float-label).-with-label) ::slotted(textarea)::placeholder,
255
+
248
256
  :host([float-label="auto"]:not(.-float-label).-with-label) .prefix-text,
249
257
  :host([float-label="auto"]:not(.-float-label).-with-label) .suffix-text {
250
258
  opacity: 0;
251
259
  transition: opacity 0s;
252
260
  }
253
261
  .prefix {
254
- margin-left: 1rem;
262
+ margin-inline-start: 1rem;
255
263
  }
256
264
  :host(.-with-prefix) .prefix {
257
- margin-right: 1rem;
258
- margin-left: 0.75rem;
259
- }
260
- .suffix {
261
- margin-right: 1rem;
265
+ margin-inline-end: 1rem;
266
+ margin-inline-start: 0.75rem;
262
267
  }
263
268
  :host(.-with-suffix) .suffix {
264
- margin-left: 1rem;
265
- margin-right: 0.75rem;
269
+ margin-inline-start: 0.25rem;
266
270
  }
267
271
  :host(.-with-suffix.-with-select) .suffix {
268
- margin-left: unset;
272
+ margin-inline-start: unset;
269
273
  }
270
274
  :host(.-with-select) .suffix-text {
271
275
  display: none;
@@ -284,17 +288,17 @@ function J(t,e){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Refl
284
288
  }
285
289
  :host([variant="outlined"]) .pseudo-label {
286
290
  visibility: hidden;
287
- margin-right: 0.25rem;
291
+ margin-inline-end: 0.25rem;
288
292
  font-size: var(--_form-field-label-font-size);
289
293
  line-height: var(--_form-field-label-line-height);
290
294
  letter-spacing: var(--_form-field-label-tracking);
291
295
  max-width: 100%;
292
- transition-property: max-width, margin-right;
296
+ transition-property: max-width, margin-inline-end;
293
297
  transition-duration: 1ms;
294
298
  }
295
299
  :host([variant="outlined"][float-label="auto"]:not(.-float-label):not(.-pressed)) .pseudo-label {
296
300
  max-width: 0;
297
- margin-right: 0px;
301
+ margin-inline-end: 0px;
298
302
  transition-delay: ${f.motion.duration.short2};
299
303
  }
300
304
  :host([variant="outlined"]) .outline-start,
@@ -308,9 +312,6 @@ function J(t,e){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Refl
308
312
  :host([variant="outlined"]:not(.-with-label)) .outline-notch {
309
313
  display: none;
310
314
  }
311
- :host([variant="outlined"].-with-suffix:not(.-with-select)) .outline-notch {
312
- margin-right: -0.75rem;
313
- }
314
315
  :host([variant="outlined"]) .outline-start {
315
316
  min-width: 0.75rem;
316
317
  border-top-style: solid;
@@ -494,9 +495,7 @@ function J(t,e){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Refl
494
495
  .outline-start,
495
496
  .outline-notch,
496
497
  .outline-end,
497
- .pseudo-label,
498
- ::slotted(input)::placeholder,
499
- ::slotted(textarea)::placeholder {
498
+ .pseudo-label {
500
499
  transition: none !important;
501
500
  }
502
501
  }