Skip to content

feat(DataTable): add align prop to Column#248

Merged
erickteowarang merged 1 commit into
mainfrom
feat/data-table/column-align
May 13, 2026
Merged

feat(DataTable): add align prop to Column#248
erickteowarang merged 1 commit into
mainfrom
feat/data-table/column-align

Conversation

@erickteowarang
Copy link
Copy Markdown
Contributor

@erickteowarang erickteowarang commented May 13, 2026

Summary

  • Adds align: "left" | "right" to Column<TRow>. Numeric columns (Amount, Score, Total) need right alignment everywhere; today callers wrap content in <span className="text-right"> inside render. This pushes the concern down to the column-type level.
  • Auto-defaults align to "right" for type: "number" and type: "money" so typed numeric columns are right-aligned without any extra config. Other types default to "left". Explicit align always wins.
  • Header label, sort indicator, body cell, and loading-skeleton bar all flip right together — so the column doesn't visually shift between the skeleton and loaded states.
// Auto-aligned right
column({
  label: "Total",
  type: "money",
  accessor: (row) => row.total,
  typeOptions: { currency: "USD" },
});

// Opt out of the numeric auto-default
column({
  label: "Order #",
  type: "number",
  accessor: (row) => row.orderId,
  align: "left",
});

// Explicit alignment for a custom-render column
column({
  label: "Score",
  align: "right",
  render: (row) => <ScoreBadge value={row.score} />,
});

Stacked on PR #247

This branch is rebased on `feat/data-table/type-aware-cells` (#247) — the auto-default needs `Column.type` from that PR. Merge #247 first; the diff here will collapse to just the align changes.

Why this is part of a three-PR series

This is 2 / 3 in a series porting patterns from a downstream consumer's `ReconciliationList` into the platform `DataTable`. PR 1 (#247) adds `type` for built-in cell renderers; PR 3 (#249) adds `truncate`.

Notes for reviewers

  • New internal helper `resolveAlign(col)` in `data-table.tsx` centralizes the "explicit > numeric-type default > left" logic. Used at all four sites (header ``, sort-indicator span, body ``, and loading-skeleton bar).
  • Auto-default doesn't touch typed columns that the user explicitly opts out of with `align: "left"`, and doesn't change behavior for any column that doesn't have a numeric `type`.

Test plan

  • `pnpm --filter @tailor-platform/app-shell type-check` — clean
  • `pnpm --filter @tailor-platform/app-shell test` — 999 passed (was 991 on PR 1's base; +8 new cases: explicit-right alignment, skeleton ml-auto, default-left, number auto-right, money auto-right, non-numeric types stay left, explicit-left override)
  • `pnpm --filter @tailor-platform/app-shell lint` — clean
  • `pnpm fmt:check` — clean across 342 files (oxfmt 0.47.0, matches CI)
  • Reviewer smoke-test: drop a `type: "money"` column into the data-table demo, confirm header + body + skeleton are all right-aligned without an explicit `align` prop

🤖 Generated with Claude Code

@erickteowarang erickteowarang force-pushed the feat/data-table/column-align branch from 8454d3c to d392787 Compare May 13, 2026 04:55
@erickteowarang erickteowarang changed the base branch from main to feat/data-table/type-aware-cells May 13, 2026 04:55
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 13, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@tailor-platform/app-shell@248
npm i https://pkg.pr.new/@tailor-platform/app-shell-sdk-plugin@248
npm i https://pkg.pr.new/@tailor-platform/app-shell-vite-plugin@248

commit: 35284a7

if (col.align) return col.align;
if (col.type === "number" || col.type === "money") return "right";
return "left";
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels right!

Copy link
Copy Markdown
Contributor

@IzumiSy IzumiSy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs fixing conflict, but LGTM

Base automatically changed from feat/data-table/type-aware-cells to main May 13, 2026 06:43
@erickteowarang erickteowarang force-pushed the feat/data-table/column-align branch from d392787 to 5dac62f Compare May 13, 2026 07:16
Adds `align: "left" | "right"` to `Column<TRow>`. Numeric columns (Amount,
Score, Total) need right alignment universally; today callers wrap content
in `<span className="text-right">` inside `render`. With this prop, header
labels, body cells, and the loading-skeleton bar are right-aligned together
so the column doesn't visually shift between loading and loaded states.

When `align` is omitted, `type: "number"` and `type: "money"` default to
"right" so the common case Just Works without extra config. Other types
default to "left". Explicit `align` always wins.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@erickteowarang erickteowarang force-pushed the feat/data-table/column-align branch from 5dac62f to 35284a7 Compare May 13, 2026 07:27
@erickteowarang erickteowarang merged commit 8a09b26 into main May 13, 2026
5 checks passed
@erickteowarang erickteowarang deleted the feat/data-table/column-align branch May 13, 2026 07:31
erickteowarang pushed a commit that referenced this pull request May 14, 2026
Brings in #247 (type-aware cell renderers), #248 (column align), #251
(oxlint upgrade), #253 (accessor narrowing docs), and #254 (inferColumns
no longer carries an accessor). Conflicts:

- types.ts: dropped the duplicate `accessor` declaration from
  `ColumnBase` (it now lives per-branch in `ColumnTypeBranch` per #247)
  and kept both new fields — `align` (from #248) and `truncate` (from
  this branch). Updated `truncate`'s JSDoc to describe the Tooltip
  wiring rather than the `title` attribute.
- field-helpers.ts: kept main's spread-based `column()` so the
  discriminated union survives.
- data-table.tsx: combined `align` and `truncate` into the same cell
  classes; rebuilt `content` via `col.render ?? renderTypedCell(...)`
  (from #247).
- data-table.test.tsx / docs: kept both feature describe blocks and
  combined doc tables.

Per @IzumiSy's review (#249), the truncate tooltip now uses the
app-shell `<Tooltip>` component (with a `Tooltip.Provider` mounted at
`DataTable.Root`) instead of the browser `title` attribute. The cell
is wrapped in `Tooltip.Trigger` only when `accessor` returns a
stringifiable primitive — objects / arrays / no accessor still apply
the truncate CSS but skip the tooltip wiring.

Tests: 1010 passing (was 992 + 8 new truncate tests). Lint, fmt,
workspace typecheck all clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants