Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/.oxlintrc.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"rules": {
// React 19's JSX Transform handles React imports automatically
"react/react-in-jsx-scope": "off",
"no-nested-ternary": "error",
},
"ignorePatterns": ["dist", "node_modules"],
}
18 changes: 11 additions & 7 deletions packages/core/src/components/csv-importer/CsvImporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ function MappingStep({
>
{/* Status icon */}
<td className="astw:px-3 astw:py-2 astw:align-middle astw:text-center">
{isMapped ? (
<CheckCircle2Icon className="astw:size-5 astw:text-primary" />
) : col.required ? (
{isMapped && <CheckCircle2Icon className="astw:size-5 astw:text-primary" />}
{!isMapped && col.required && (
<CircleAlertIcon className="astw:size-5 astw:text-destructive" />
) : (
)}
{!isMapped && !col.required && (
<CircleDashedIcon className="astw:size-5 astw:text-muted-foreground/40" />
)}
</td>
Expand Down Expand Up @@ -741,9 +741,7 @@ export function CsvImporter<T extends CsvSchema>({
"astw:flex astw:size-7 astw:items-center astw:justify-center astw:rounded-full astw:text-xs astw:font-medium",
step === s
? "astw:bg-primary astw:text-primary-foreground"
: stepIndex(step) > idx
? "astw:bg-primary/20 astw:text-primary"
: "astw:bg-muted astw:text-muted-foreground",
: stepClassForIndex(step, idx),
)}
>
{idx + 1}
Expand Down Expand Up @@ -900,3 +898,9 @@ function stepIndex(step: CsvImporterStep): number {
const steps: CsvImporterStep[] = ["upload", "mapping", "review", "complete"];
return steps.indexOf(step);
}

function stepClassForIndex(step: CsvImporterStep, idx: number): string {
return stepIndex(step) > idx
? "astw:bg-primary/20 astw:text-primary"
: "astw:bg-muted astw:text-muted-foreground";
}
17 changes: 11 additions & 6 deletions packages/core/src/components/csv-importer/process-rows.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import type { CsvCellIssue, CsvColumnMapping, CsvCorrection, CsvSchema, ParsedRow } from "./types";

function resolveRawValue(
correction: CsvCorrection | undefined,
colIdx: number | undefined,
row: string[],
): string {
if (correction !== undefined) return String(correction.newValue);
if (colIdx !== undefined) return row[colIdx];
return "";
}

/** Single-pass: validate all cells and build parsed rows for onValidate. */
export function processRows(
rawRows: string[][],
Expand All @@ -24,12 +34,7 @@ export function processRows(
const correction = corrections.find(
(c) => c.row === rowIdx && c.columnKey === mapping.columnKey,
);
const rawValue: string =
correction !== undefined
? String(correction.newValue)
: colIdx !== undefined
? row[colIdx]
: "";
const rawValue = resolveRawValue(correction, colIdx, row);

const column = schema.columns.find((c) => c.key === mapping.columnKey);
if (column?.schema) {
Expand Down
32 changes: 19 additions & 13 deletions packages/core/src/components/data-table/cell-renderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ import type {
NumberCellOptions,
} from "./types";

function resolveDateFormatOptions(format: string): Intl.DateTimeFormatOptions {
if (format === "long") return { month: "long", day: "numeric", year: "numeric" };
if (format === "datetime") {
return {
month: "short",
day: "numeric",
year: "numeric",
hour: "numeric",
minute: "2-digit",
};
}
return { month: "short", day: "numeric", year: "numeric" };
}

const PLACEHOLDER = (
<span className="astw:text-muted-foreground" aria-hidden="true">
Expand Down Expand Up @@ -79,7 +93,10 @@ function renderMoney<TRow extends Record<string, unknown>>(
// `maxDecimals` raises the cap above the currency default while keeping the
// minimum at the currency default (e.g. 2 for USD). Lets a JPY column stay
// at 0 decimals while a USD price-detail column shows up to 4.
const formatOptions: Intl.NumberFormatOptions = { style: "currency", currency };
const formatOptions: Intl.NumberFormatOptions = {
style: "currency",
currency,
};
if (options?.maxDecimals != null) {
formatOptions.maximumFractionDigits = options.maxDecimals;
}
Expand All @@ -101,18 +118,7 @@ function renderDate(value: unknown, options: DateCellOptions | undefined): React
const date = toDate(value);
if (!date) return PLACEHOLDER;
const format = options?.dateFormat ?? "short";
const formatOptions: Intl.DateTimeFormatOptions =
format === "long"
? { month: "long", day: "numeric", year: "numeric" }
: format === "datetime"
? {
month: "short",
day: "numeric",
year: "numeric",
hour: "numeric",
minute: "2-digit",
}
: { month: "short", day: "numeric", year: "numeric" };
const formatOptions = resolveDateFormatOptions(format);
return new Intl.DateTimeFormat(options?.locale, formatOptions).format(date);
}

Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/components/data-table/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ function resolveAlign<TRow extends Record<string, unknown>>(col: Column<TRow>):
return "left";
}

function nextSortDirection(current: string | undefined): "Asc" | "Desc" | undefined {
if (current === "Asc") return "Desc";
if (current === "Desc") return undefined;
return "Asc";
}

// =============================================================================
// DataTableLoaderRows (internal)
// =============================================================================
Expand Down Expand Up @@ -260,13 +266,7 @@ function DataTableHeaders({ className }: { className?: string }) {

const handleClick = () => {
if (!isSortable || !onSort || !col.sort) return;
const nextDirection =
currentSort?.direction === "Asc"
? "Desc"
: currentSort?.direction === "Desc"
? undefined
: "Asc";
onSort(col.sort.field, nextDirection);
onSort(col.sort.field, nextSortDirection(currentSort?.direction));
};

const align = resolveAlign(col);
Expand Down
16 changes: 6 additions & 10 deletions packages/core/src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,12 @@ export function Layout({ columns, className, style, gap, title, actions, childre
}
}

const gapClass =
gap === undefined
? "astw:gap-4"
: gap === 4
? "astw:gap-4"
: gap === 6
? "astw:gap-6"
: gap === 8
? "astw:gap-8"
: "astw:gap-4";
const GAP_CLASSES: Record<number, string> = {
4: "astw:gap-4",
6: "astw:gap-6",
8: "astw:gap-8",
};
const gapClass = gap === undefined ? "astw:gap-4" : (GAP_CLASSES[gap] ?? "astw:gap-4");

const hasLegacyHeader = !hasHeaderChild && (title || (actions != null && actions.length > 0));

Expand Down
16 changes: 12 additions & 4 deletions packages/core/src/components/sidebar/default-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ import { useT } from "@/i18n-labels";
import { useNavItems, type NavItem } from "@/routing/navigation";
import { cn } from "@/lib/utils";

function resolveCollapsibleMode(
collapsible: boolean | undefined,
isIconMode: boolean,
): "none" | "icon" | "offcanvas" {
if (!collapsible) return "none";
if (isIconMode) return "icon";
return "offcanvas";
}

// Always rendered regardless of searchSources — the palette searches routes
// and contextual actions too, so there is always something to search.
const SearchEntry = () => {
Expand Down Expand Up @@ -102,11 +111,10 @@ export const DefaultSidebar = (props: DefaultSidebarProps) => {
);
const DefaultFooter = null;

const collapsibleMode = resolveCollapsibleMode(collapsible, isIconMode);

return (
<Sidebar
variant="inset"
collapsible={!collapsible ? "none" : isIconMode ? "icon" : "offcanvas"}
>
<Sidebar variant="inset" collapsible={collapsibleMode}>
{!isIconMode && (
<div className="astw:flex astw:justify-between astw:items-center">
{props.header ?? DefaultHeader}
Expand Down
26 changes: 16 additions & 10 deletions packages/core/src/components/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ import { cn } from "@/lib/utils";

type TabsVariant = "default" | "line" | "capsule";

const LIST_VARIANT_CLASSES: Record<TabsVariant, string> = {
line: "astw:h-9 astw:gap-2",
capsule: "astw:h-10 astw:gap-0.5 astw:rounded-md astw:bg-muted astw:p-1",
default: "astw:text-muted-foreground astw:h-9 astw:gap-1",
};

const TAB_VARIANT_CLASSES: Record<TabsVariant, string> = {
line: "astw:px-3 astw:py-1.5 astw:-mb-px astw:border-b-2 astw:border-transparent astw:data-active:border-primary astw:data-active:text-foreground",
capsule:
"astw:rounded-md astw:px-3 astw:py-1.5 astw:data-active:bg-background astw:data-active:text-foreground astw:data-active:shadow-sm",
default:
"astw:rounded-md astw:px-3 astw:py-1 astw:data-active:bg-muted astw:data-active:text-foreground",
};

const TabsVariantContext = React.createContext<TabsVariant>("default");

// Only the props relevant to the Tabs abstraction are picked from BaseTabs.Root.
Expand Down Expand Up @@ -55,11 +69,7 @@ function List({ className, children, ...props }: React.ComponentProps<typeof Bas
data-slot="tabs-list"
className={cn(
"astw:relative astw:inline-flex astw:items-center astw:justify-center",
variant === "line"
? "astw:h-9 astw:gap-2"
: variant === "capsule"
? "astw:h-10 astw:gap-0.5 astw:rounded-md astw:bg-muted astw:p-1"
: "astw:text-muted-foreground astw:h-9 astw:gap-1",
LIST_VARIANT_CLASSES[variant],
className,
)}
{...props}
Expand All @@ -81,11 +91,7 @@ function Tab({ className, children, ...props }: React.ComponentProps<typeof Base
"astw:text-muted-foreground",
"astw:focus-visible:outline-ring/70 astw:focus-visible:ring-ring/50 astw:focus-visible:outline-1 astw:focus-visible:ring-[3px]",
"astw:data-disabled:pointer-events-none astw:data-disabled:opacity-50",
variant === "line"
? "astw:px-3 astw:py-1.5 astw:-mb-px astw:border-b-2 astw:border-transparent astw:data-active:border-primary astw:data-active:text-foreground"
: variant === "capsule"
? "astw:rounded-md astw:px-3 astw:py-1.5 astw:data-active:bg-background astw:data-active:text-foreground astw:data-active:shadow-sm"
: "astw:rounded-md astw:px-3 astw:py-1 astw:data-active:bg-muted astw:data-active:text-foreground",
TAB_VARIANT_CLASSES[variant],
className,
)}
{...props}
Expand Down
Loading