@gridkitjs/theme-tailwind 0.3.2 → 0.5.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.
Files changed (3) hide show
  1. package/README.md +34 -3
  2. package/package.json +1 -1
  3. package/src/styles.css +333 -39
package/README.md CHANGED
@@ -23,13 +23,33 @@ them directly. Nothing needs to scan the component source.
23
23
 
24
24
  ## Dark mode
25
25
 
26
- The `dark:` variant is bound to a `.dark` class rather than the OS preference,
27
- so you drive the theme yourself:
26
+ GridKit doesn't register its own `dark:` variant — it follows whatever your
27
+ app's Tailwind build already resolves `dark:` to. Out of the box that's the
28
+ OS preference. For the common class-toggle pattern, declare it yourself,
29
+ same as any Tailwind v4 app would:
30
+
31
+ ```css
32
+ @import "tailwindcss";
33
+ @custom-variant dark (&:where(.dark, .dark *));
34
+ @import "@gridkitjs/theme-tailwind/styles.css";
35
+ ```
28
36
 
29
37
  ```js
30
38
  document.documentElement.classList.toggle("dark", isDark);
31
39
  ```
32
40
 
41
+ ### Forcing a theme on one grid
42
+
43
+ `.gridkit-light` / `.gridkit-dark` pin a grid to one palette regardless of
44
+ the ambient `dark:` state. Put either on any ancestor of the grid, including
45
+ the grid's own root:
46
+
47
+ ```tsx
48
+ <div className="gridkit-dark">
49
+ <DataGridComponent ... />
50
+ </div>
51
+ ```
52
+
33
53
  ## Theming
34
54
 
35
55
  Every colour is a CSS custom property, so overriding one is plain CSS — no
@@ -54,7 +74,18 @@ Tailwind config:
54
74
  | `--gridkit-selected` | Selected row, column or cell |
55
75
  | `--gridkit-selected-strong` | A selected row or cell also hovered |
56
76
 
57
- Redefine them under `.dark` to change the dark palette too.
77
+ Redefine them inside `@variant dark { }` (or under `.gridkit-dark`) to change
78
+ the dark palette too:
79
+
80
+ ```css
81
+ :root {
82
+ --gridkit-accent: oklch(0.6 0.17 145);
83
+
84
+ @variant dark {
85
+ --gridkit-accent: oklch(0.7 0.15 145);
86
+ }
87
+ }
88
+ ```
58
89
 
59
90
  `--gridkit-selected-strong` earns its place because hover already claims
60
91
  `--gridkit-surface-muted`: with one token a selected row would lose its
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridkitjs/theme-tailwind",
3
- "version": "0.3.2",
3
+ "version": "0.5.0",
4
4
  "description": "Tailwind v4 theme for GridKit — palette tokens, dark mode and grid styles.",
5
5
  "license": "MIT",
6
6
  "author": "Blagoja Blazhevski",
package/src/styles.css CHANGED
@@ -4,50 +4,103 @@
4
4
  */
5
5
 
6
6
  /*
7
- * Tailwind's `dark:` variant follows the OS preference by default. Bind it to
8
- * a `.dark` class instead so consumers can drive the theme themselves.
9
- */
10
- @custom-variant dark (&:where(.dark, .dark *));
11
-
12
- /*
13
- * The palette. Light is the default; `.dark` redefines the same names, so a
14
- * token means "the header background", not "light grey".
7
+ * The palette. Each token is a raw `--gridkit-<name>-light` / `-dark` pair,
8
+ * defined once below; every rule in this file reads the live
9
+ * `--gridkit-<name>` name instead, which gets pointed at one pair by
10
+ * whichever of these applies:
11
+ *
12
+ * - `:root`, by default — light.
13
+ * - `@variant dark` nested inside it — whatever the app's own `dark:`
14
+ * variant currently resolves to. GridKit does not register a
15
+ * `@custom-variant dark` of its own, so it never conflicts with an app
16
+ * that already has one (a class, a `data-` attribute, anything) —
17
+ * absent one, this falls back to Tailwind's own `prefers-color-scheme`
18
+ * default.
19
+ * - `.gridkit-light` / `.gridkit-dark` — an explicit, per-instance
20
+ * override. Put either on any ancestor of the grid, including the
21
+ * grid's own root, to pin one grid to a palette regardless of the
22
+ * ambient state. No specificity trick needed: custom properties inherit
23
+ * from the nearest matching ancestor, so a wrapper closer to the grid
24
+ * than `:root` simply wins.
15
25
  */
16
26
  :root {
27
+ --gridkit-surface-light: oklch(1 0 0);
28
+ --gridkit-surface-dark: oklch(0.21 0.01 250);
29
+ --gridkit-surface-muted-light: oklch(0.97 0.003 250);
30
+ --gridkit-surface-muted-dark: oklch(0.26 0.012 250);
31
+ --gridkit-line-light: oklch(0.92 0.005 250);
32
+ --gridkit-line-dark: oklch(0.33 0.014 250);
33
+ --gridkit-hover-line-light: oklch(0.65 0.09 255);
34
+ --gridkit-hover-line-dark: oklch(0.75 0.09 255);
35
+ --gridkit-fg-light: oklch(0.21 0.01 250);
36
+ --gridkit-fg-dark: oklch(0.97 0.003 250);
37
+ --gridkit-fg-muted-light: oklch(0.55 0.015 250);
38
+ --gridkit-fg-muted-dark: oklch(0.7 0.015 250);
39
+ --gridkit-accent-light: oklch(0.6 0.17 255);
40
+ --gridkit-accent-dark: oklch(0.7 0.15 255);
41
+ --gridkit-selected-light: oklch(0.94 0.03 255);
42
+ --gridkit-selected-dark: oklch(0.32 0.05 255);
43
+ --gridkit-selected-strong-light: oklch(0.9 0.05 255);
44
+ --gridkit-selected-strong-dark: oklch(0.38 0.07 255);
45
+
17
46
  color-scheme: light;
47
+ --gridkit-surface: var(--gridkit-surface-light);
48
+ --gridkit-surface-muted: var(--gridkit-surface-muted-light);
49
+ --gridkit-line: var(--gridkit-line-light);
50
+ --gridkit-hover-line: var(--gridkit-hover-line-light);
51
+ --gridkit-fg: var(--gridkit-fg-light);
52
+ --gridkit-fg-muted: var(--gridkit-fg-muted-light);
53
+ --gridkit-accent: var(--gridkit-accent-light);
54
+ --gridkit-selected: var(--gridkit-selected-light);
55
+ --gridkit-selected-strong: var(--gridkit-selected-strong-light);
56
+
57
+ @variant dark {
58
+ color-scheme: dark;
59
+ --gridkit-surface: var(--gridkit-surface-dark);
60
+ --gridkit-surface-muted: var(--gridkit-surface-muted-dark);
61
+ --gridkit-line: var(--gridkit-line-dark);
62
+ --gridkit-hover-line: var(--gridkit-hover-line-dark);
63
+ --gridkit-fg: var(--gridkit-fg-dark);
64
+ --gridkit-fg-muted: var(--gridkit-fg-muted-dark);
65
+ --gridkit-accent: var(--gridkit-accent-dark);
66
+ --gridkit-selected: var(--gridkit-selected-dark);
67
+ --gridkit-selected-strong: var(--gridkit-selected-strong-dark);
68
+ }
69
+ }
18
70
 
19
- --gridkit-surface: oklch(1 0 0);
20
- --gridkit-surface-muted: oklch(0.97 0.003 250);
21
- --gridkit-line: oklch(0.92 0.005 250);
22
- --gridkit-hover-line: oklch(0.65 0.09 255);
23
- --gridkit-fg: oklch(0.21 0.01 250);
24
- --gridkit-fg-muted: oklch(0.55 0.015 250);
25
- --gridkit-accent: oklch(0.6 0.17 255);
26
- --gridkit-selected: oklch(0.94 0.03 255);
27
- --gridkit-selected-strong: oklch(0.9 0.05 255);
71
+ .gridkit-light {
72
+ color-scheme: light;
73
+ --gridkit-surface: var(--gridkit-surface-light);
74
+ --gridkit-surface-muted: var(--gridkit-surface-muted-light);
75
+ --gridkit-line: var(--gridkit-line-light);
76
+ --gridkit-hover-line: var(--gridkit-hover-line-light);
77
+ --gridkit-fg: var(--gridkit-fg-light);
78
+ --gridkit-fg-muted: var(--gridkit-fg-muted-light);
79
+ --gridkit-accent: var(--gridkit-accent-light);
80
+ --gridkit-selected: var(--gridkit-selected-light);
81
+ --gridkit-selected-strong: var(--gridkit-selected-strong-light);
28
82
  }
29
83
 
30
- .dark {
84
+ .gridkit-dark {
31
85
  color-scheme: dark;
32
-
33
- --gridkit-surface: oklch(0.21 0.01 250);
34
- --gridkit-surface-muted: oklch(0.26 0.012 250);
35
- --gridkit-line: oklch(0.33 0.014 250);
36
- --gridkit-hover-line: oklch(0.75 0.09 255);
37
- --gridkit-fg: oklch(0.97 0.003 250);
38
- --gridkit-fg-muted: oklch(0.7 0.015 250);
39
- --gridkit-accent: oklch(0.7 0.15 255);
40
- --gridkit-selected: oklch(0.32 0.05 255);
41
- --gridkit-selected-strong: oklch(0.38 0.07 255);
86
+ --gridkit-surface: var(--gridkit-surface-dark);
87
+ --gridkit-surface-muted: var(--gridkit-surface-muted-dark);
88
+ --gridkit-line: var(--gridkit-line-dark);
89
+ --gridkit-hover-line: var(--gridkit-hover-line-dark);
90
+ --gridkit-fg: var(--gridkit-fg-dark);
91
+ --gridkit-fg-muted: var(--gridkit-fg-muted-dark);
92
+ --gridkit-accent: var(--gridkit-accent-dark);
93
+ --gridkit-selected: var(--gridkit-selected-dark);
94
+ --gridkit-selected-strong: var(--gridkit-selected-strong-dark);
42
95
  }
43
96
 
44
97
  /*
45
98
  * `inline` is what makes the swap work. Without it Tailwind emits
46
99
  * `--color-surface: var(--gridkit-surface)` on `:root`, which resolves once
47
- * against the light values and is then inherited already-resolved — a `.dark`
48
- * further down the tree would have nothing left to override. `inline`
49
- * substitutes the var into each utility instead, so it resolves at the element
50
- * the class sits on.
100
+ * against the light values and is then inherited already-resolved — a
101
+ * dark-mode switch further down the tree would have nothing left to
102
+ * override. `inline` substitutes the var into each utility instead, so it
103
+ * resolves at the element the class sits on.
51
104
  */
52
105
  @theme inline {
53
106
  --color-surface: var(--gridkit-surface);
@@ -342,6 +395,41 @@
342
395
  background-color: var(--gridkit-surface-muted);
343
396
  }
344
397
 
398
+ /*
399
+ * Docked before the label, in normal flow rather than absolutely
400
+ * positioned like the sort toggle and resize handle — see the component's
401
+ * own note on why. Faint until grouped, hovered, or focused, the same
402
+ * restraint `.header-sort-toggle` uses for an unsorted header.
403
+ */
404
+ .gridkit-data-grid .header-group-toggle {
405
+ display: inline-flex;
406
+ align-items: center;
407
+ vertical-align: middle;
408
+ margin-right: 0.375rem;
409
+ cursor: pointer;
410
+ color: var(--gridkit-fg-muted);
411
+ }
412
+
413
+ .gridkit-data-grid .header-group-toggle svg {
414
+ width: 14px;
415
+ height: 14px;
416
+ flex-shrink: 0;
417
+ }
418
+
419
+ .gridkit-data-grid .header-group-toggle:not(.is-grouped) {
420
+ opacity: 0.35;
421
+ }
422
+
423
+ .gridkit-data-grid .grid-header .header-cell:hover .header-group-toggle,
424
+ .gridkit-data-grid .header-cell:focus-visible .header-group-toggle {
425
+ opacity: 1;
426
+ }
427
+
428
+ .gridkit-data-grid .header-group-toggle.is-grouped {
429
+ opacity: 1;
430
+ color: var(--gridkit-accent);
431
+ }
432
+
345
433
  .gridkit-data-grid .grid-cell {
346
434
  padding: 0.5rem;
347
435
  }
@@ -355,6 +443,62 @@
355
443
  background-color: var(--gridkit-surface-muted);
356
444
  }
357
445
 
446
+ /*
447
+ * A group header — one cell spanning every column, not a `.grid-cell` — so
448
+ * it gets its own rules rather than sharing the data-cell ones above.
449
+ */
450
+ .gridkit-data-grid .grid-group-row {
451
+ cursor: pointer;
452
+ background-color: var(--gridkit-surface-muted);
453
+ }
454
+
455
+ .gridkit-data-grid .grid-group-row:hover {
456
+ background-color: var(--gridkit-selected);
457
+ }
458
+
459
+ /*
460
+ * Padding lives on `.grid-group-cell-content` (the inner `div`), not here:
461
+ * see that component's own note on why the flex layout is one level in
462
+ * rather than on the `<td>` itself.
463
+ */
464
+ .gridkit-data-grid .grid-group-cell {
465
+ padding: 0;
466
+ }
467
+
468
+ .gridkit-data-grid .grid-group-cell:focus-visible {
469
+ outline: 2px solid var(--gridkit-accent);
470
+ outline-offset: -2px;
471
+ }
472
+
473
+ .gridkit-data-grid .grid-group-cell-content {
474
+ display: flex;
475
+ align-items: center;
476
+ gap: 0.5rem;
477
+ padding: 0.5rem;
478
+ font-weight: 600;
479
+ }
480
+
481
+ /* A right-pointing triangle that rotates open on expand. */
482
+ .gridkit-data-grid .grid-group-row .group-toggle {
483
+ display: inline-block;
484
+ flex-shrink: 0;
485
+ width: 0;
486
+ height: 0;
487
+ border-style: solid;
488
+ border-width: 0.25rem 0 0.25rem 0.4rem;
489
+ border-color: transparent transparent transparent var(--gridkit-fg-muted);
490
+ transition: transform 0.1s ease;
491
+ }
492
+
493
+ .gridkit-data-grid .grid-group-row .group-toggle.is-expanded {
494
+ transform: rotate(90deg);
495
+ }
496
+
497
+ .gridkit-data-grid .grid-group-row .group-count {
498
+ font-weight: 400;
499
+ color: var(--gridkit-fg-muted);
500
+ }
501
+
358
502
  /*
359
503
  * Selection, after the hover rules so that a selected row hovered stays
360
504
  * selected — the two would otherwise be the same colour, since hover already
@@ -408,7 +552,8 @@
408
552
 
409
553
  /* Horizontal borders */
410
554
  .gridkit-data-grid.borders-horizontal .grid-header .header-cell,
411
- .gridkit-data-grid.borders-horizontal .grid-cell {
555
+ .gridkit-data-grid.borders-horizontal .grid-cell,
556
+ .gridkit-data-grid.borders-horizontal .grid-group-cell {
412
557
  border-bottom: 1px solid var(--gridkit-line);
413
558
  }
414
559
 
@@ -416,8 +561,13 @@
416
561
  * The last row's bottom edge has no row below it to collapse with, so
417
562
  * unlike every internal boundary it is a genuinely extra pixel — the same
418
563
  * reason `borders-vertical` drops its `:last-child` border-right below.
564
+ * Matched against both row kinds: the last rendered row can just as well
565
+ * be a collapsed group header as a data row.
419
566
  */
420
- .gridkit-data-grid.borders-horizontal .grid-row:last-child .grid-cell {
567
+ .gridkit-data-grid.borders-horizontal .grid-row:last-child .grid-cell,
568
+ .gridkit-data-grid.borders-horizontal
569
+ .grid-group-row:last-child
570
+ .grid-group-cell {
421
571
  border-bottom: none;
422
572
  }
423
573
 
@@ -434,7 +584,8 @@
434
584
 
435
585
  /* Borders on all sides */
436
586
  .gridkit-data-grid.borders-all .grid-header .header-cell,
437
- .gridkit-data-grid.borders-all .grid-cell {
587
+ .gridkit-data-grid.borders-all .grid-cell,
588
+ .gridkit-data-grid.borders-all .grid-group-cell {
438
589
  border-bottom: 1px solid var(--gridkit-line);
439
590
  border-right: 1px solid var(--gridkit-line);
440
591
  }
@@ -442,19 +593,162 @@
442
593
  /*
443
594
  * The outer left/right edges have no neighbouring cell to collapse with, so
444
595
  * unlike every internal boundary they are a genuinely extra pixel — without
445
- * this the table would render 2px wider than the sum of its columns.
596
+ * this the table would render 2px wider than the sum of its columns. A
597
+ * group cell is both its row's first and last child at once (it is the
598
+ * only cell), so it takes both exceptions.
446
599
  */
447
600
  .gridkit-data-grid.borders-all .grid-header .header-cell:first-child,
448
- .gridkit-data-grid.borders-all .grid-cell:first-child {
601
+ .gridkit-data-grid.borders-all .grid-cell:first-child,
602
+ .gridkit-data-grid.borders-all .grid-group-cell {
449
603
  border-left: none;
450
604
  }
451
605
 
452
606
  .gridkit-data-grid.borders-all .grid-header .header-cell:last-child,
453
- .gridkit-data-grid.borders-all .grid-cell:last-child {
607
+ .gridkit-data-grid.borders-all .grid-cell:last-child,
608
+ .gridkit-data-grid.borders-all .grid-group-cell {
454
609
  border-right: none;
455
610
  }
456
611
 
457
- .gridkit-data-grid.borders-all .grid-row:last-child .grid-cell {
612
+ .gridkit-data-grid.borders-all .grid-row:last-child .grid-cell,
613
+ .gridkit-data-grid.borders-all .grid-group-row:last-child .grid-group-cell {
458
614
  border-bottom: none;
459
615
  }
616
+
617
+ /*
618
+ * The group-by bar. A sibling of the table, not a row inside it — see
619
+ * `GroupByBar.tsx`'s own note on why — so it's unscoped by `.gridkit-data-grid`
620
+ * the way `.gridkit-sr-only` is.
621
+ */
622
+ .gridkit-group-by-bar {
623
+ display: flex;
624
+ flex-wrap: wrap;
625
+ align-items: center;
626
+ gap: 0.5rem;
627
+ padding: 0.5rem;
628
+ background-color: var(--gridkit-surface);
629
+ border-bottom: 1px solid var(--gridkit-line);
630
+ }
631
+
632
+ /*
633
+ * Drawn while a chip or an eligible header is being dragged — a dashed
634
+ * outline marking the bar itself as a valid drop zone, load-bearing when
635
+ * it's otherwise empty, with no chip of its own to show a drop indicator
636
+ * on. Where exactly the drop would land is the chips' own
637
+ * `is-drop-before`/`is-drop-after` marks; this outline doesn't also wash
638
+ * the bar's background once hovered — the marks are enough on their own.
639
+ */
640
+ .gridkit-group-by-bar.is-drag-target {
641
+ outline: 2px dashed var(--gridkit-accent);
642
+ outline-offset: -2px;
643
+ }
644
+
645
+ /*
646
+ * A header already in the group-by stack, dragged back toward it — never a
647
+ * valid drop, so no accent outline invites it: a muted dashed line in the
648
+ * same neutral tone as the grid's own borders, plus a `not-allowed` cursor
649
+ * for the pointer icon itself.
650
+ */
651
+ .gridkit-group-by-bar.is-drag-blocked {
652
+ cursor: not-allowed;
653
+ outline: 2px dashed var(--gridkit-line);
654
+ outline-offset: -2px;
655
+ }
656
+
657
+ .group-by-bar-placeholder {
658
+ font-size: 0.8125rem;
659
+ color: var(--gridkit-fg-muted);
660
+ }
661
+
662
+ .group-by-chip {
663
+ position: relative;
664
+ display: inline-flex;
665
+ align-items: center;
666
+ gap: 0.375rem;
667
+ padding: 0.25rem 0.5rem;
668
+ font-size: 0.8125rem;
669
+ color: var(--gridkit-fg);
670
+ background-color: var(--gridkit-selected);
671
+ border-radius: 9999px;
672
+ cursor: grab;
673
+ touch-action: none;
674
+ user-select: none;
675
+ }
676
+
677
+ .group-by-chip:focus-visible {
678
+ outline: 2px solid var(--gridkit-accent);
679
+ outline-offset: 1px;
680
+ }
681
+
682
+ .group-by-chip.is-dragging {
683
+ cursor: grabbing;
684
+ opacity: 0.5;
685
+ }
686
+
687
+ /*
688
+ * Where the chip would land. `.header-cell.is-drop-before`/`.is-drop-after`
689
+ * draw this as an inset line, but an inset line on a pill this round would
690
+ * be clipped by the chip's own `border-radius` into a curved sliver rather
691
+ * than a clean mark — so this is a `::before`/`::after` mark of its own
692
+ * instead, sitting in the gap beside the chip. Absolutely positioned and
693
+ * so out of flow, it never shifts the chip or its neighbors the way a
694
+ * change to border or padding would.
695
+ */
696
+ .group-by-chip.is-drop-before::before,
697
+ .group-by-chip.is-drop-after::after {
698
+ content: "";
699
+ position: absolute;
700
+ top: 0;
701
+ bottom: 0;
702
+ width: 2px;
703
+ border-radius: 1px;
704
+ background-color: var(--gridkit-accent);
705
+ }
706
+
707
+ .group-by-chip.is-drop-before::before {
708
+ left: calc(-0.25rem - 1px);
709
+ }
710
+
711
+ .group-by-chip.is-drop-after::after {
712
+ right: calc(-0.25rem - 1px);
713
+ }
714
+
715
+ /*
716
+ * The chip trailing the pointer mid-drag. Unlike the header's own
717
+ * `.gridkit-data-grid.drag-ghost` this can't share that compound selector
718
+ * — a chip ghost isn't part of the grid's own table — so it restates the
719
+ * positioning in full rather than only the parts that differ.
720
+ */
721
+ .group-by-chip.drag-ghost {
722
+ position: fixed;
723
+ top: 0;
724
+ left: 0;
725
+ z-index: 50;
726
+ border: 1px dashed var(--gridkit-accent);
727
+ opacity: 0.75;
728
+ pointer-events: none;
729
+ will-change: transform;
730
+ }
731
+
732
+ .group-by-chip-remove {
733
+ display: inline-flex;
734
+ align-items: center;
735
+ justify-content: center;
736
+ width: 1rem;
737
+ height: 1rem;
738
+ padding: 0;
739
+ line-height: 1;
740
+ color: inherit;
741
+ cursor: pointer;
742
+ background: none;
743
+ border: none;
744
+ }
745
+
746
+ .group-by-chip-remove:hover {
747
+ color: var(--gridkit-accent);
748
+ }
749
+
750
+ .group-by-chip-remove:focus-visible {
751
+ outline: 2px solid var(--gridkit-accent);
752
+ outline-offset: 1px;
753
+ }
460
754
  }