@payglocal_ui/flux-ui 0.3.0 → 0.3.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.
@@ -177,7 +177,25 @@ export type DataTableExpandable<T> = {
177
177
  export type Column<T> = {
178
178
  key: string;
179
179
  header: ReactNode;
180
- /** Table column width, e.g. `48px`, `18%`, `minmax(12rem,1fr)` (fixed layout) */
180
+ /**
181
+ * Table column width: `48px`, `18%`, or `minmax(12rem, 1fr)` for a floor
182
+ * that can still grow into whatever the other columns leave over.
183
+ *
184
+ * `minmax(min, max)` is translated rather than passed straight through: this
185
+ * is a real `<table>`/`<colgroup>`, and `minmax()` is a CSS Grid function
186
+ * that is not a legal `width` value outside a grid — the browser drops the
187
+ * whole declaration and the column gets no floor at all. `min` becomes the
188
+ * `<col>`'s `min-width`, and `max` becomes its `width` unless `max` is `1fr`
189
+ * (or any other flex unit), in which case no `width` is set and the column
190
+ * takes its share of whatever `table-layout: fixed` has left over, the same
191
+ * way a grid track's `1fr` would.
192
+ *
193
+ * `overflow-x-auto` on the table's own scroll container is what makes the
194
+ * floor mean something: once every column's minimum no longer fits, the
195
+ * table grows past its container and scrolls instead of every column
196
+ * shrinking under its `min-width` and the header text — deliberately not
197
+ * truncated, see the `<th>` render below — overlapping the column beside it.
198
+ */
181
199
  width?: string;
182
200
  minWidth?: number;
183
201
  maxWidth?: number;
@@ -425,6 +443,51 @@ function SortIndicator({ order }: { order: SortOrder | null }) {
425
443
  );
426
444
  }
427
445
 
446
+ /**
447
+ * `minmax(A, B)` → its two halves, tolerant of whichever whitespace someone
448
+ * wrote it with. `null` for anything else, including a plain length like
449
+ * `"180px"` — that already IS a valid `width` and passes through untouched.
450
+ */
451
+ function parseMinMaxWidth(width: string | undefined): { min: string; max: string } | null {
452
+ if (!width) return null;
453
+ const match = /^minmax\(\s*([^,]+?)\s*,\s*([^)]+?)\s*\)$/.exec(width.trim());
454
+ return match ? { min: match[1], max: match[2] } : null;
455
+ }
456
+
457
+ /** `1fr`, `2fr`, … — a Grid flex unit, meaningless as a table `width`. */
458
+ function isFlexUnit(value: string): boolean {
459
+ return /^[\d.]*fr$/.test(value.trim());
460
+ }
461
+
462
+ /**
463
+ * A column's `width` as the three real CSS properties a `<col>` understands.
464
+ *
465
+ * Anything that is not a `minmax(...)` string passes through exactly as it did
466
+ * before this existed, so a plain `"48px"` or `"18%"` column is untouched.
467
+ */
468
+ function colWidthStyle(col: Pick<Column<unknown>, "width" | "minWidth" | "maxWidth">): {
469
+ width: string | number | undefined;
470
+ minWidth: string | number | undefined;
471
+ maxWidth: string | number | undefined;
472
+ } {
473
+ const parsed = parseMinMaxWidth(col.width);
474
+ if (!parsed) {
475
+ return {
476
+ width: col.width ?? (col.minWidth != null ? `${col.minWidth}px` : undefined),
477
+ minWidth: col.minWidth,
478
+ maxWidth: col.maxWidth,
479
+ };
480
+ }
481
+ return {
482
+ width: isFlexUnit(parsed.max) ? undefined : parsed.max,
483
+ // An explicit numeric `minWidth`/`maxWidth` alongside a `minmax()` string
484
+ // is not a combination any caller uses today; the string wins because it
485
+ // is the more specific of the two.
486
+ minWidth: parsed.min,
487
+ maxWidth: isFlexUnit(parsed.max) ? col.maxWidth : undefined,
488
+ };
489
+ }
490
+
428
491
  export function DataTable<T>({
429
492
  columns,
430
493
  data,
@@ -706,14 +769,7 @@ export function DataTable<T>({
706
769
  <colgroup>
707
770
  {hasExpand ? <col style={{ width: 40 }} /> : null}
708
771
  {columns.map((col) => (
709
- <col
710
- key={col.key}
711
- style={{
712
- width: col.width ?? (col.minWidth != null ? `${col.minWidth}px` : undefined),
713
- minWidth: col.minWidth,
714
- maxWidth: col.maxWidth,
715
- }}
716
- />
772
+ <col key={col.key} style={colWidthStyle(col)} />
717
773
  ))}
718
774
  {/* Zero-width column: the action floats out of it as an overlay,
719
775
  so the last data column stays flush and nothing trails it. */}