noph-ui 0.2.7 → 0.2.9

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.
@@ -14,9 +14,9 @@
14
14
  label,
15
15
  noAsterisk = false,
16
16
  variant = 'filled',
17
+ placeholder = ' ',
17
18
  ...attributes
18
19
  }: TextFieldProps | TextAreaFieldProps = $props()
19
- let focused = $state(false)
20
20
 
21
21
  let contentEl: HTMLInputElement | HTMLTextAreaElement | undefined = $state()
22
22
  let errorTextRaw = $state(errorText)
@@ -40,15 +40,6 @@
40
40
  currentTarget.focus()
41
41
  }
42
42
  })
43
- contentEl.addEventListener('focus', () => {
44
- if (!attributes.disabled) {
45
- focused = true
46
- }
47
- })
48
-
49
- contentEl.addEventListener('blur', () => {
50
- focused = false
51
- })
52
43
 
53
44
  contentEl.addEventListener('change', (event) => {
54
45
  const { currentTarget } = event as Event & {
@@ -61,7 +52,6 @@
61
52
  })
62
53
  }
63
54
  })
64
- let emptyValue = $derived(value === undefined || value === null || value === '')
65
55
  </script>
66
56
 
67
57
  <!-- svelte-ignore a11y_click_events_have_key_events -->
@@ -77,15 +67,12 @@
77
67
  if (attributes.disabled) {
78
68
  return
79
69
  }
80
- focused = true
81
70
  contentEl?.focus()
82
71
  }}
83
72
  >
84
73
  <div
85
74
  class="field"
86
- class:populated={!emptyValue}
87
75
  class:error
88
- class:focused
89
76
  class:resizable={attributes.type === 'textarea'}
90
77
  class:no-label={!label?.length}
91
78
  class:with-start={start}
@@ -121,12 +108,7 @@
121
108
  <div class="middle">
122
109
  <div class="label-wrapper">
123
110
  {#if label?.length}
124
- <span
125
- class="label"
126
- class:resting={!focused && emptyValue}
127
- class:floating={focused || !emptyValue}
128
- >{label}{noAsterisk || !attributes.required ? '' : '*'}
129
- </span>
111
+ <span class="label">{label}{noAsterisk || !attributes.required ? '' : '*'} </span>
130
112
  {/if}
131
113
  </div>
132
114
  <div class="content">
@@ -137,6 +119,7 @@
137
119
  bind:this={contentEl}
138
120
  class="input"
139
121
  aria-label={label}
122
+ {placeholder}
140
123
  rows={attributes.rows || 2}
141
124
  ></textarea>
142
125
  {:else}
@@ -151,6 +134,7 @@
151
134
  bind:value
152
135
  bind:this={contentEl}
153
136
  class="input"
137
+ {placeholder}
154
138
  aria-label={label}
155
139
  aria-invalid={error}
156
140
  />
@@ -191,7 +175,8 @@
191
175
  width: 100%;
192
176
  z-index: 1;
193
177
  }
194
- .field:has(input:focus-visible) .active-indicator::after {
178
+ .field:has(input:focus-visible) .active-indicator::after,
179
+ .field:has(textarea:focus-visible) .active-indicator::after {
195
180
  opacity: 1;
196
181
  }
197
182
  .active-indicator::after {
@@ -356,7 +341,9 @@
356
341
 
357
342
  .no-label .content,
358
343
  .field:has(input:focus-visible) .content,
359
- .populated .content {
344
+ .field:has(textarea:focus-visible) .content,
345
+ .field:has(input:not(:placeholder-shown)) .content,
346
+ .field:has(textarea:not(:placeholder-shown)) .content {
360
347
  opacity: 1;
361
348
  }
362
349
 
@@ -481,22 +468,31 @@
481
468
  .label.np-hidden {
482
469
  opacity: 0;
483
470
  }
484
- .label.resting {
471
+
472
+ .field:has(input:not(:focus-visible):placeholder-shown) .label,
473
+ .field:has(textarea:not(:focus-visible):placeholder-shown) .label {
485
474
  position: absolute;
486
475
  top: 1rem;
487
476
  left: 0rem;
488
477
  }
489
-
490
- .label.floating {
478
+ .field:has(input:focus-visible:not(:placeholder-shown)) .label,
479
+ .field:has(input:focus-visible) .label,
480
+ .field:has(input:not(:placeholder-shown)) .label,
481
+ .field:has(textarea:focus-visible:not(:placeholder-shown)) .label,
482
+ .field:has(textarea:focus-visible) .label,
483
+ .field:has(textarea:not(:placeholder-shown)) .label {
491
484
  font-size: 0.75rem;
492
485
  line-height: 1rem;
493
486
  transform-origin: top left;
494
- }
495
- .label.floating {
496
487
  position: absolute;
497
488
  top: var(--floating-label-top, 0.5rem);
498
489
  }
499
- .with-start .label.floating {
490
+ .with-start:has(input:focus-visible:not(:placeholder-shown)) .label,
491
+ .with-start:has(input:focus-visible) .label,
492
+ .with-start:has(input:not(:placeholder-shown)) .label,
493
+ .with-start:has(textarea:focus-visible:not(:placeholder-shown)) .label,
494
+ .with-start:has(textarea:focus-visible) .label,
495
+ .with-start:has(textarea:not(:placeholder-shown)) .label {
500
496
  left: var(--floating-label-left, 0);
501
497
  }
502
498
  .label {
@@ -514,11 +510,13 @@
514
510
  line-height: 1.5rem;
515
511
  width: min-content;
516
512
  }
517
- .field:has(input:focus-visible) .label {
513
+ .field:has(input:focus-visible) .label,
514
+ .field:has(textarea:focus-visible) .label {
518
515
  color: var(--np-color-primary);
519
516
  }
520
517
  .error .label,
521
- .error:has(input:focus-visible) .label {
518
+ .error:has(input:focus-visible) .label,
519
+ .error:has(textarea:focus-visible) .label {
522
520
  color: var(--np-color-error);
523
521
  }
524
522
  .disabled .label {
@@ -532,7 +530,8 @@
532
530
  overflow: hidden;
533
531
  }
534
532
  .disabled.no-label .content,
535
- .disabled.populated .content {
533
+ .disabled:has(input:not(:placeholder-shown)) .content,
534
+ .disabled:has(textarea:not(:placeholder-shown)) .content {
536
535
  opacity: 0.38;
537
536
  }
538
537
  .field,
@@ -598,14 +597,19 @@
598
597
  border-bottom-style: solid;
599
598
  border-top-style: solid;
600
599
  }
601
- .outline-notch::before,
602
600
  .outline-notch::after {
603
601
  border-bottom-style: solid;
604
602
  border-top-style: none;
605
603
  }
606
- .field:not(:has(input:focus-visible)):not(.populated) .outline-notch::before {
604
+ .outline-notch::before {
605
+ border-bottom-style: solid;
607
606
  border-top-style: solid;
608
607
  }
608
+ .field:has(input:focus-visible) .outline-notch::before,
609
+ .field:has(textarea:focus-visible) .outline-notch::before,
610
+ .field:has(input:not(:placeholder-shown)) .outline-notch::before {
611
+ border-top-style: none;
612
+ }
609
613
 
610
614
  .outline-notch::before,
611
615
  .outline-notch::after {
@@ -643,7 +647,10 @@
643
647
  }
644
648
  .field:has(input:focus-visible) .outline-start::after,
645
649
  .field:has(input:focus-visible) .outline-end::after,
646
- .field:has(input:focus-visible) .outline-notch::after {
650
+ .field:has(input:focus-visible) .outline-notch::after,
651
+ .field:has(textarea:focus-visible) .outline-start::after,
652
+ .field:has(textarea:focus-visible) .outline-end::after,
653
+ .field:has(textarea:focus-visible) .outline-notch::after {
647
654
  opacity: 1;
648
655
  }
649
656
  .np-outline {
@@ -657,12 +664,14 @@
657
664
  z-index: 1;
658
665
  }
659
666
 
660
- .field:has(input:focus-visible) .np-outline {
667
+ .field:has(input:focus-visible) .np-outline,
668
+ .field:has(textarea:focus-visible) .np-outline {
661
669
  border-color: var(--np-color-primary);
662
670
  color: var(--np-color-primary);
663
671
  }
664
672
  .error .np-outline,
665
- .error:has(input:focus-visible) .np-outline {
673
+ .error:has(input:focus-visible) .np-outline,
674
+ .error:has(textarea:focus-visible) .np-outline {
666
675
  border-color: var(--np-color-error);
667
676
  }
668
677
  .disabled .np-outline {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noph-ui",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "license": "MIT",
5
5
  "homepage": "https://noph.dev",
6
6
  "repository": {