@morze/ui 0.2.0 → 0.2.2

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/README.md CHANGED
@@ -200,10 +200,28 @@ sink them into the page.
200
200
 
201
201
  ## Customisation
202
202
 
203
+ **One colour re-tints the whole kit.** The neutral surfaces — panels, inputs,
204
+ table headers, the sunken wells — are not flat grey: each is a neutral mixed
205
+ with a few percent of `--mz-tint`, which points at the brand colour. Change
206
+ `--mz-primary-rgb` and the greys follow it, instead of keeping the violet cast
207
+ they were born with:
208
+
209
+ ```css
210
+ :root {
211
+ --mz-primary-rgb: 16, 175, 122; /* the panels and wells go green with it */
212
+ --mz-tint: #8b8b96; /* …or point the tint at a grey for none */
213
+ }
214
+ ```
215
+
216
+ Text is deliberately left out of this: its contrast is calibrated against the
217
+ background, and dragging a saturated brand through it costs more than it buys.
218
+ The tinted surfaces need `color-mix()` — Chrome 111+, Firefox 113+, Safari 16.2+,
219
+ the same baseline as the rest of the kit.
220
+
203
221
  Everything is driven by custom properties; override them after importing the
204
222
  styles. The main groups: surfaces (`--mz-bg`, `--mz-surface`, `--mz-elevated`),
205
- borders, text, tones, the convex recipe (`--mz-convex-*`, `--mz-face*`,
206
- `--mz-well*`), geometry (`--mz-radius*`), type (`--mz-font-*`, `--mz-label-*`),
223
+ borders, text, tones, the tint (`--mz-tint`, `--mz-shade`), the convex recipe
224
+ (`--mz-convex-*`, `--mz-face*`, `--mz-well*`), geometry (`--mz-radius*`), type (`--mz-font-*`, `--mz-label-*`),
207
225
  motion and states (`--mz-ease`, `--mz-duration`, `--mz-hover-scale`,
208
226
  `--mz-press-scale`, `--mz-hover-mix`, `--mz-press-mix`), focus (`--mz-ring-*`).
209
227
 
package/dist/index.cjs CHANGED
@@ -2420,20 +2420,27 @@ function useColumnLayout({
2420
2420
  () => controlled ? merge(baseline, controlled, baseline) : internal,
2421
2421
  [controlled, internal, baseline]
2422
2422
  );
2423
+ const onLayoutChangeRef = React39__namespace.useRef(onLayoutChange);
2424
+ React39__namespace.useEffect(() => {
2425
+ onLayoutChangeRef.current = onLayoutChange;
2426
+ });
2427
+ const internalRef = React39__namespace.useRef(internal);
2428
+ React39__namespace.useEffect(() => {
2429
+ internalRef.current = internal;
2430
+ }, [internal]);
2423
2431
  const update = React39__namespace.useCallback(
2424
2432
  (patch, options) => {
2425
- setInternal((current) => {
2426
- const base = controlled ? merge(baseline, controlled, baseline) : current;
2427
- const next = patch(base);
2428
- if (next === base) return current;
2429
- if (options?.persist !== false) {
2430
- writeStored2(persistKey, next);
2431
- onLayoutChange?.(next);
2432
- }
2433
- return next;
2434
- });
2433
+ const base = controlled ? merge(baseline, controlled, baseline) : internalRef.current;
2434
+ const next = patch(base);
2435
+ if (next === base) return;
2436
+ internalRef.current = next;
2437
+ setInternal(next);
2438
+ if (options?.persist !== false) {
2439
+ writeStored2(persistKey, next);
2440
+ onLayoutChangeRef.current?.(next);
2441
+ }
2435
2442
  },
2436
- [controlled, baseline, persistKey, onLayoutChange]
2443
+ [controlled, baseline, persistKey]
2437
2444
  );
2438
2445
  const byId = React39__namespace.useMemo(
2439
2446
  () => new Map(columns.map((c) => [c.id, c])),
@@ -2617,6 +2624,7 @@ function useRowSelection(options) {
2617
2624
  }
2618
2625
  var SELECT_WIDTH = 44;
2619
2626
  var EXPAND_WIDTH = 40;
2627
+ var FIT_CYCLE_MS = 250;
2620
2628
  function DataTable({
2621
2629
  columns,
2622
2630
  data,
@@ -2680,22 +2688,28 @@ function DataTable({
2680
2688
  }),
2681
2689
  pageKeys
2682
2690
  });
2683
- const lastFitWidth = React39__namespace.useRef(0);
2691
+ const recentFits = React39__namespace.useRef([]);
2692
+ const hiddenKey = layout.hidden.join("\0");
2693
+ const orderKey = layout.order.join("\0");
2684
2694
  React39__namespace.useEffect(() => {
2685
2695
  const scroller = scrollerRef.current;
2686
2696
  if (!scroller || !autoFit) return;
2687
2697
  const controls = (selectable ? SELECT_WIDTH : 0) + (renderExpanded ? EXPAND_WIDTH : 0);
2698
+ recentFits.current = [];
2688
2699
  const run = () => {
2689
2700
  const available = scroller.clientWidth - controls - 2;
2690
- if (Math.abs(available - lastFitWidth.current) < 1) return;
2691
- lastFitWidth.current = available;
2701
+ const now = Date.now();
2702
+ const recent = recentFits.current.filter((entry) => now - entry.at < FIT_CYCLE_MS);
2703
+ recentFits.current = recent;
2704
+ if (recent.some((entry) => Math.abs(available - entry.width) < 1)) return;
2705
+ recent.push({ width: available, at: now });
2692
2706
  fitTo(available);
2693
2707
  };
2694
2708
  run();
2695
2709
  const observer = new ResizeObserver(run);
2696
2710
  observer.observe(scroller);
2697
2711
  return () => observer.disconnect();
2698
- }, [autoFit, fitTo, selectable, renderExpanded, layout.hidden, layout.order]);
2712
+ }, [autoFit, fitTo, selectable, renderExpanded, hiddenKey, orderKey]);
2699
2713
  React39__namespace.useEffect(() => {
2700
2714
  const scroller = scrollerRef.current;
2701
2715
  if (!scroller) return;
@@ -2827,6 +2841,7 @@ function DataTable({
2827
2841
  columnLabel: label,
2828
2842
  def: column.filter,
2829
2843
  value: query.filters[column.id],
2844
+ labels: labelsProp,
2830
2845
  onApply: (value) => onQueryChange(setFilter(query, column.id, value))
2831
2846
  }
2832
2847
  ) : null