@sofyan/glass 0.1.6 → 0.3.0

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/glass.css CHANGED
@@ -38,6 +38,13 @@
38
38
  --lg-sheet-fill default rgb(var(--lg-c-paper)), the <dialog> sheet's fill */
39
39
  --lg-danger: #ff3b30; /* iOS system red */
40
40
  --lg-danger-strong: #e5352b;
41
+ /* Danger as a fill under white text (buttons, error toasts): 5.4:1 and 7.4:1 (WCAG 1.4.3).
42
+ White on --lg-danger is only 3.6:1, so that one stays for edges and rings. */
43
+ --lg-danger-fill: #d70015;
44
+ --lg-danger-fill-strong: #b00012;
45
+ /* Danger as text (field errors). --lg-danger is a fill and too light for text; this one
46
+ has 4.5:1 or more on the paper and canvas neutrals (WCAG 1.4.3). dark.css retunes it. */
47
+ --lg-danger-text: #d70015;
41
48
 
42
49
  /* Theme-aware neutrals as RGB triplets, so `rgb(var(--lg-c-ink) / 0.5)` works.
43
50
  tailwind.css maps them to `lg-*` colours. Redefine them for dark mode. */
@@ -145,7 +152,7 @@
145
152
  @layer components {
146
153
  /* ── Base material ──────────────────────────────────────────────────── */
147
154
  /* Every class in this list is a glass surface; the composites below add to it. */
148
- :where(.glass, .glass-btn, .glass-menu, .glass-sheet, .glass-chip) {
155
+ :where(.glass, .glass-btn, .glass-menu, .glass-sheet, .glass-chip, .glass-toast, .glass-tabs) {
149
156
  --lg-fill: var(--lg-light-fill);
150
157
  --lg-fill-hover: var(--lg-light-fill-hover);
151
158
  --lg-rim: var(--lg-light-rim);
@@ -160,7 +167,9 @@
160
167
  .glass-btn,
161
168
  .glass-menu,
162
169
  .glass-sheet,
163
- .glass-chip {
170
+ .glass-chip,
171
+ .glass-toast,
172
+ .glass-tabs {
164
173
  position: relative;
165
174
  isolation: isolate;
166
175
  color: var(--lg-light-text);
@@ -175,8 +184,9 @@
175
184
  }
176
185
 
177
186
  /* Specular rim: a 1px gradient ring that follows the border radius. Light catches the
178
- top edge only, then fades. */
179
- :is(.glass, .glass-btn, .glass-menu, .glass-sheet, .glass-chip)::before {
187
+ top edge only, then fades. Not on the tab track: it scrolls, and the ring would scroll
188
+ away with the tabs. */
189
+ :is(.glass, .glass-btn, .glass-menu, .glass-sheet, .glass-chip, .glass-toast)::before {
180
190
  content: '';
181
191
  position: absolute;
182
192
  inset: 0;
@@ -364,6 +374,119 @@
364
374
  0 0 0 4px color-mix(in srgb, var(--lg-accent, var(--color-primary, #0a84ff)) 16%, transparent);
365
375
  }
366
376
 
377
+ /* Invalid (aria-invalid, which the field components set once there is an error): a danger
378
+ ring, 3:1 against paper. The error text is the cue that does not rely on colour. */
379
+ .glass-input[aria-invalid='true'] {
380
+ box-shadow: inset 0 0 0 1.5px var(--lg-danger);
381
+ }
382
+
383
+ /* The first box-shadow is for engines without color-mix(). */
384
+ .glass-input[aria-invalid='true']:focus {
385
+ box-shadow: inset 0 0 0 2px var(--lg-danger);
386
+ box-shadow:
387
+ inset 0 0 0 1.5px var(--lg-danger),
388
+ 0 0 0 4px color-mix(in srgb, var(--lg-danger) 16%, transparent);
389
+ }
390
+
391
+ textarea.glass-input {
392
+ min-height: 5.5rem;
393
+ resize: vertical;
394
+ }
395
+
396
+ /* Fields (<GlassInput />, <GlassTextarea />, <GlassSelect />): label, control, hint and
397
+ error, one under the other. Margins, not flex gap, which needs Safari 14.1. */
398
+ .glass-field .glass-input {
399
+ display: block;
400
+ }
401
+
402
+ .glass-field .glass-input:disabled {
403
+ cursor: not-allowed;
404
+ opacity: 0.5;
405
+ }
406
+
407
+ .glass-field-label {
408
+ display: block;
409
+ margin-bottom: 0.375rem;
410
+ font-size: 0.875rem;
411
+ line-height: 1.25rem;
412
+ font-weight: 500;
413
+ color: rgb(var(--lg-c-ink));
414
+ }
415
+
416
+ /* hideLabel: out of sight, still read. */
417
+ .glass-field-label-hidden {
418
+ position: absolute;
419
+ width: 1px;
420
+ height: 1px;
421
+ margin: -1px;
422
+ padding: 0;
423
+ overflow: hidden;
424
+ clip: rect(0 0 0 0);
425
+ clip-path: inset(50%);
426
+ white-space: nowrap;
427
+ }
428
+
429
+ /* The asterisk is decoration (aria-hidden): the control's `required` carries the meaning. */
430
+ .glass-field-required {
431
+ margin-inline-start: 0.125rem;
432
+ color: var(--lg-danger-text);
433
+ }
434
+
435
+ .glass-field-hint,
436
+ .glass-field-error {
437
+ margin-top: 0.375rem;
438
+ font-size: 0.8125rem;
439
+ line-height: 1.125rem;
440
+ }
441
+
442
+ .glass-field-hint {
443
+ color: rgb(var(--lg-c-ink-2));
444
+ }
445
+
446
+ .glass-field-error {
447
+ font-weight: 500;
448
+ color: var(--lg-danger-text);
449
+ }
450
+
451
+ /* A drop-down <select> in a .glass-select wrapper: the native arrow goes, and a chevron
452
+ drawn in the ink colour takes its place, so it follows the theme. Physical `right` first
453
+ for engines without inset-inline (before Safari 14.1). */
454
+ .glass-select {
455
+ position: relative;
456
+ }
457
+
458
+ .glass-select > select {
459
+ -webkit-appearance: none;
460
+ appearance: none;
461
+ padding-inline-end: 2.5rem;
462
+ cursor: pointer;
463
+ }
464
+
465
+ .glass-select::after {
466
+ content: '';
467
+ position: absolute;
468
+ top: 50%;
469
+ right: 1rem;
470
+ inset-inline-start: auto;
471
+ inset-inline-end: 1rem;
472
+ width: 0.5rem;
473
+ height: 0.5rem;
474
+ margin-top: -0.375rem;
475
+ border-right: 1.5px solid;
476
+ border-bottom: 1.5px solid;
477
+ color: rgb(var(--lg-c-ink-2));
478
+ transform: rotate(45deg);
479
+ pointer-events: none;
480
+ }
481
+
482
+ /* iOS zooms into a focused control whose text is under 16px. */
483
+ @media (pointer: coarse) {
484
+ .glass-field .glass-input {
485
+ font-size: 1rem;
486
+ line-height: 1.5rem;
487
+ }
488
+ }
489
+
367
490
  /* Small chip / badge: thin, pill. */
368
491
  .glass-chip {
369
492
  --lg-surface-blur: var(--lg-blur-thin);
@@ -378,6 +501,204 @@
378
501
  font-weight: 600;
379
502
  }
380
503
 
504
+ /* Toasts (<GlassToasts />): a stack at the top (or bottom) of the viewport, clear of the
505
+ notch and the home indicator. The stack lets taps through to the page; only the toasts
506
+ take them. Margins, not flex gap, which needs Safari 14.1. */
507
+ .glass-toasts {
508
+ position: fixed;
509
+ top: 0;
510
+ left: 0;
511
+ right: 0;
512
+ z-index: 9999;
513
+ display: flex;
514
+ flex-direction: column;
515
+ align-items: center;
516
+ padding: max(env(safe-area-inset-top), 0.75rem) max(env(safe-area-inset-right), 1rem) 0
517
+ max(env(safe-area-inset-left), 1rem);
518
+ pointer-events: none;
519
+ }
520
+
521
+ .glass-toasts-bottom {
522
+ top: auto;
523
+ bottom: 0;
524
+ padding-top: 0;
525
+ padding-bottom: max(env(safe-area-inset-bottom), 0.75rem);
526
+ }
527
+
528
+ /* The two live regions (status, then alert). Never display: none, even when empty: a live
529
+ region that is not rendered is not listening. */
530
+ .glass-toasts-region {
531
+ display: flex;
532
+ flex-direction: column;
533
+ align-items: center;
534
+ width: 100%;
535
+ }
536
+
537
+ .glass-toast + .glass-toast,
538
+ .glass-toasts-region:not(:empty) + .glass-toasts-region:not(:empty) {
539
+ margin-top: 0.5rem;
540
+ }
541
+
542
+ /* A pill while it holds one line; a rounded box when the message wraps. */
543
+ .glass-toast {
544
+ --lg-surface-blur: var(--lg-blur-thick);
545
+ --lg-shadow: var(--lg-shadow-lg);
546
+ display: flex;
547
+ align-items: center;
548
+ max-width: 28rem;
549
+ min-height: 44px;
550
+ padding: 0.625rem 1.25rem;
551
+ border-radius: 22px;
552
+ font-size: 0.875rem;
553
+ line-height: 1.25rem;
554
+ font-weight: 500;
555
+ pointer-events: auto;
556
+ animation: lg-pop var(--lg-duration) var(--lg-ease-spring) both;
557
+ transform-origin: top center;
558
+ }
559
+
560
+ .glass-toasts-bottom .glass-toast {
561
+ transform-origin: bottom center;
562
+ }
563
+
564
+ /* Danger: the solid danger fill. */
565
+ .glass-toast-danger {
566
+ --lg-fill: var(--lg-danger-fill);
567
+ --lg-rim: rgba(255, 255, 255, 0.28);
568
+ --lg-rim-low: rgba(255, 255, 255, 0);
569
+ --lg-edge: transparent;
570
+ --lg-surface-sheen: none;
571
+ color: #fff;
572
+ }
573
+
574
+ .glass-toast-message {
575
+ flex: 1 1 auto;
576
+ min-width: 0;
577
+ overflow-wrap: break-word;
578
+ }
579
+
580
+ /* 44px target, pulled into the padding so the toast stays 44px tall. */
581
+ .glass-toast-dismiss {
582
+ display: flex;
583
+ flex-shrink: 0;
584
+ align-items: center;
585
+ justify-content: center;
586
+ width: 44px;
587
+ height: 44px;
588
+ margin-top: -0.625rem;
589
+ margin-bottom: -0.625rem;
590
+ margin-inline-start: 0.25rem;
591
+ margin-inline-end: -1rem;
592
+ padding: 0;
593
+ border: 0;
594
+ border-radius: 9999px;
595
+ color: inherit;
596
+ background-color: transparent;
597
+ cursor: pointer;
598
+ transition: background-color var(--lg-duration-fast) ease;
599
+ }
600
+
601
+ .glass-toast-dismiss:hover {
602
+ background-color: rgba(127, 127, 127, 0.18);
603
+ }
604
+
605
+ .glass-toast-dismiss:focus-visible {
606
+ outline: 2px solid var(--lg-accent, var(--color-primary, #0a84ff));
607
+ outline-offset: -2px;
608
+ }
609
+
610
+ .glass-toast-danger .glass-toast-dismiss:focus-visible {
611
+ outline-color: currentColor;
612
+ }
613
+
614
+ /* Tabs (<GlassTabList />): a pill track that scrolls sideways, without a scrollbar, when
615
+ the tabs do not fit. The selected tab is a raised pill. Focus rings sit inside the tabs,
616
+ where the scrolling track cannot clip them. */
617
+ .glass-tabs {
618
+ --lg-surface-blur: var(--lg-blur-thin);
619
+ --lg-shadow: var(--lg-shadow-sm);
620
+ display: flex;
621
+ width: max-content;
622
+ max-width: 100%;
623
+ padding: 0.25rem;
624
+ border-radius: 9999px;
625
+ overflow-x: auto;
626
+ overscroll-behavior-x: contain;
627
+ scrollbar-width: none;
628
+ }
629
+
630
+ .glass-tabs::-webkit-scrollbar {
631
+ display: none;
632
+ }
633
+
634
+ .glass-tabs[aria-orientation='vertical'] {
635
+ flex-direction: column;
636
+ border-radius: var(--lg-radius-lg);
637
+ }
638
+
639
+ .glass-tab {
640
+ display: inline-flex;
641
+ flex-shrink: 0;
642
+ align-items: center;
643
+ justify-content: center;
644
+ gap: 0.375rem;
645
+ min-height: 44px;
646
+ padding: 0.5rem 1rem;
647
+ border: 0;
648
+ border-radius: 9999px;
649
+ font-family: inherit;
650
+ font-size: 0.875rem;
651
+ line-height: 1.25rem;
652
+ font-weight: 500;
653
+ white-space: nowrap;
654
+ color: inherit;
655
+ background-color: transparent;
656
+ cursor: pointer;
657
+ transition:
658
+ background-color var(--lg-duration-fast) ease,
659
+ box-shadow var(--lg-duration-fast) ease;
660
+ }
661
+
662
+ /* Concentric with the track's corners. */
663
+ .glass-tabs[aria-orientation='vertical'] .glass-tab {
664
+ justify-content: flex-start;
665
+ border-radius: calc(var(--lg-radius-lg) - 0.25rem);
666
+ }
667
+
668
+ .glass-tab:not(:disabled):hover {
669
+ background-color: rgb(var(--lg-c-line) / 0.06);
670
+ }
671
+
672
+ /* Selected: raised, outlined and bolder, not only a different colour. */
673
+ .glass-tab[aria-selected='true'] {
674
+ font-weight: 600;
675
+ color: rgb(var(--lg-c-ink));
676
+ background-color: rgb(var(--lg-c-raised));
677
+ box-shadow:
678
+ inset 0 0 0 1px rgb(var(--lg-c-line) / 0.08),
679
+ 0 1px 3px rgb(0 0 0 / 0.12);
680
+ }
681
+
682
+ .glass-tab:focus-visible {
683
+ outline: 2px solid var(--lg-accent, var(--color-primary, #0a84ff));
684
+ outline-offset: -2px;
685
+ }
686
+
687
+ .glass-tab:disabled {
688
+ cursor: not-allowed;
689
+ opacity: 0.4;
690
+ }
691
+
692
+ .glass-tab-panel:focus-visible {
693
+ outline: 2px solid var(--lg-accent, var(--color-primary, #0a84ff));
694
+ outline-offset: 2px;
695
+ }
696
+
697
+ /* Stays hidden even if a class of yours sets `display` on the panel. */
698
+ .glass-tab-panel[hidden] {
699
+ display: none;
700
+ }
701
+
381
702
  /* ── Tones ──────────────────────────────────────────────────────────── */
382
703
  .glass-dark {
383
704
  --lg-fill: var(--lg-dark-fill);
@@ -432,8 +753,8 @@
432
753
  }
433
754
 
434
755
  .glass-danger {
435
- --lg-fill: var(--lg-danger);
436
- --lg-fill-hover: var(--lg-danger-strong);
756
+ --lg-fill: var(--lg-danger-fill);
757
+ --lg-fill-hover: var(--lg-danger-fill-strong);
437
758
  }
438
759
 
439
760
  /* ── Thickness ──────────────────────────────────────────────────────── */
@@ -669,6 +990,71 @@
669
990
  user-select: none;
670
991
  }
671
992
 
993
+ /* ── Confirm (<GlassConfirm />, or a <dialog class="glass-confirm">) ─── */
994
+ /* A centred box on every width: a question has to be answered, so it is never a sheet to
995
+ swipe away. The vh line is for engines without dvh (before Safari 15.4). */
996
+ dialog.glass-confirm {
997
+ width: 100%;
998
+ max-width: min(28rem, calc(100% - 2rem));
999
+ max-height: calc(100vh - 2rem);
1000
+ max-height: calc(100dvh - 2rem);
1001
+ margin: auto;
1002
+ padding: 1.5rem;
1003
+ border: 0;
1004
+ overflow-y: auto;
1005
+ overscroll-behavior: contain;
1006
+ border-radius: var(--lg-radius-xl);
1007
+ color: rgb(var(--lg-c-ink));
1008
+ background-color: var(--lg-sheet-fill, rgb(var(--lg-c-paper)));
1009
+ box-shadow:
1010
+ inset 0 0 0 1px rgb(var(--lg-c-line) / 0.1),
1011
+ var(--lg-shadow-lg);
1012
+ }
1013
+
1014
+ dialog.glass-confirm[open] {
1015
+ animation: lg-sheet-in var(--lg-duration) var(--lg-ease-spring) both;
1016
+ }
1017
+
1018
+ dialog.glass-confirm:focus {
1019
+ outline: none;
1020
+ }
1021
+
1022
+ /* With a fallback: before Chrome 122, ::backdrop inherits no custom properties. */
1023
+ dialog.glass-confirm::backdrop {
1024
+ background-color: var(--lg-scrim, rgba(0, 0, 0, 0.4));
1025
+ }
1026
+
1027
+ .glass-confirm-title {
1028
+ margin: 0;
1029
+ font-size: 1.125rem;
1030
+ line-height: 1.5rem;
1031
+ font-weight: 600;
1032
+ color: rgb(var(--lg-c-ink));
1033
+ }
1034
+
1035
+ .glass-confirm-message {
1036
+ margin-top: 0.5rem;
1037
+ font-size: 0.9375rem;
1038
+ line-height: 1.375rem;
1039
+ color: rgb(var(--lg-c-ink-2));
1040
+ }
1041
+
1042
+ .glass-confirm-details {
1043
+ margin-top: 1rem;
1044
+ }
1045
+
1046
+ /* Side by side when they fit, one above the other when they do not. */
1047
+ .glass-confirm-actions {
1048
+ display: flex;
1049
+ flex-wrap: wrap;
1050
+ gap: 0.75rem;
1051
+ margin-top: 1.5rem;
1052
+ }
1053
+
1054
+ .glass-confirm-actions > * {
1055
+ flex: 1 1 8rem;
1056
+ }
1057
+
672
1058
  /* ── Keyframes ──────────────────────────────────────────────────────── */
673
1059
  /* Pop-ins animate transform only: an element with opacity < 1 can't sample its
674
1060
  backdrop in Chromium, so fading would show unblurred content until it settles. */
@@ -711,8 +1097,12 @@
711
1097
  .glass-menu-item,
712
1098
  .glass-sheet,
713
1099
  .glass-scrim,
1100
+ .glass-toast,
1101
+ .glass-toast-dismiss,
1102
+ .glass-tab,
714
1103
  dialog.glass-dialog[open],
715
- dialog.glass-dialog::backdrop {
1104
+ dialog.glass-dialog::backdrop,
1105
+ dialog.glass-confirm[open] {
716
1106
  animation: none;
717
1107
  transition: none;
718
1108
  }