Skip to content

Commit

Permalink
fix(Table)!: removing spacing prop in favor of Tailwind classes (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini authored Dec 29, 2024
1 parent ffe1486 commit 88ccc05
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const componentsWithNoSpacingProp = [
"ui-pill",
"ui-spinner",
"ui-svgicon",
"ui-table",
"ui-truncate",
];

Expand Down
9 changes: 2 additions & 7 deletions packages/ui-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"files": ["dist"],
"scripts": {
"build:check": "tsc",
"build:js": "vite build",
Expand All @@ -41,12 +39,9 @@
"@tailwindcss/typography": "0.5.15",
"@versini/ui-button": "workspace:../ui-button",
"@versini/ui-icons": "workspace:../ui-icons",
"@versini/ui-spacing": "workspace:../ui-spacing",
"@versini/ui-types": "workspace:../ui-types",
"clsx": "2.1.1",
"tailwindcss": "3.4.17"
},
"sideEffects": [
"**/*.css"
]
"sideEffects": ["**/*.css"]
}
2 changes: 0 additions & 2 deletions packages/ui-table/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const Table = ({
maxHeight,
stickyHeader,
stickyFooter,
spacing,
...otherProps
}: TableProps) => {
const tableClass = getTableClasses({
Expand All @@ -44,7 +43,6 @@ export const Table = ({
wrapperClassName,
stickyHeader,
stickyFooter,
spacing,
});
return (
<TableContext.Provider
Expand Down
4 changes: 1 addition & 3 deletions packages/ui-table/src/components/Table/TableTypes.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { SpacingTypes } from "@versini/ui-types";
import React from "react";

import { TableCellSortDirections } from "./utilities";
Expand Down Expand Up @@ -44,8 +43,7 @@ export type TableProps = {
* CSS class to apply to the table wrapper.
*/
wrapperClassName?: string;
} & SpacingTypes.Props &
React.HTMLAttributes<HTMLTableElement>;
} & React.HTMLAttributes<HTMLTableElement>;

export type TableRowProps = React.HTMLAttributes<HTMLTableRowElement>;
export type TableBodyProps = React.HTMLAttributes<HTMLTableSectionElement>;
Expand Down
130 changes: 71 additions & 59 deletions packages/ui-table/src/components/Table/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { getSpacing } from "@versini/ui-spacing";
import type { SpacingTypes } from "@versini/ui-types";
import clsx from "clsx";

export const CELL_WRAPPER_HEAD = "thead";
Expand All @@ -17,18 +15,16 @@ export const getTableClasses = ({
wrapperClassName,
stickyHeader,
stickyFooter,
spacing,
}: {
mode: string;
className?: string;
stickyFooter?: boolean;
stickyHeader?: boolean;
wrapperClassName?: string;
} & SpacingTypes.Props) => {
}) => {
return {
wrapper: clsx(
"not-prose relative w-full rounded-lg shadow-md",
getSpacing(spacing),
{
"overflow-x-auto": !stickyHeader && !stickyFooter,
"overflow-y-scroll": stickyHeader || stickyFooter,
Expand Down Expand Up @@ -65,17 +61,20 @@ export const getTableHeadClasses = ({
className?: string;
stickyHeader?: boolean;
}) => {
return clsx(className, {
"sticky top-0 z-10": stickyHeader,
"shadow-[rgb(190_190_190_/20%)_0_0.5rem_1rem]":
stickyHeader && mode === "dark",
"shadow-[rgb(190_190_190_/20%)_0_0.5rem_1rem] dark:shadow-[rgb(65_65_65_/30%)_0_0.5rem_1rem]":
stickyHeader && mode === "system",
"shadow-[rgb(65_65_65_/30%)_0_0.5rem_1rem]":
stickyHeader && mode === "light",
"shadow-[rgb(65_65_65_/30%)_0_0.5rem_1rem] dark:shadow-[rgb(190_190_190_/20%)_0_0.5rem_1rem]":
stickyHeader && mode === "alt-system",
});
return clsx(
{
"sticky top-0 z-10": stickyHeader,
"shadow-[rgb(190_190_190_/20%)_0_0.5rem_1rem]":
stickyHeader && mode === "dark",
"shadow-[rgb(190_190_190_/20%)_0_0.5rem_1rem] dark:shadow-[rgb(65_65_65_/30%)_0_0.5rem_1rem]":
stickyHeader && mode === "system",
"shadow-[rgb(65_65_65_/30%)_0_0.5rem_1rem]":
stickyHeader && mode === "light",
"shadow-[rgb(65_65_65_/30%)_0_0.5rem_1rem] dark:shadow-[rgb(190_190_190_/20%)_0_0.5rem_1rem]":
stickyHeader && mode === "alt-system",
},
className,
);
};

export const getTableFooterClasses = ({
Expand All @@ -87,17 +86,20 @@ export const getTableFooterClasses = ({
className?: string;
stickyFooter?: boolean;
}) => {
return clsx(className, {
"sticky bottom-0 z-10": stickyFooter,
"shadow-[rgb(190_190_190_/20%)_0_-0.5rem_1rem]":
stickyFooter && mode === "dark",
"shadow-[rgb(190_190_190_/20%)_0_-0.5rem_1rem] dark:shadow-[rgb(65_65_65_/30%)_0_-0.5rem_1rem]":
stickyFooter && mode === "system",
"shadow-[rgb(65_65_65_/30%)_0_-0.5rem_1rem]":
stickyFooter && mode === "light",
"shadow-[rgb(65_65_65_/30%)_-0_0.5rem_1rem] dark:shadow-[rgb(190_190_190_/20%)_0_-0.5rem_1rem]":
stickyFooter && mode === "alt-system",
});
return clsx(
{
"sticky bottom-0 z-10": stickyFooter,
"shadow-[rgb(190_190_190_/20%)_0_-0.5rem_1rem]":
stickyFooter && mode === "dark",
"shadow-[rgb(190_190_190_/20%)_0_-0.5rem_1rem] dark:shadow-[rgb(65_65_65_/30%)_0_-0.5rem_1rem]":
stickyFooter && mode === "system",
"shadow-[rgb(65_65_65_/30%)_0_-0.5rem_1rem]":
stickyFooter && mode === "light",
"shadow-[rgb(65_65_65_/30%)_-0_0.5rem_1rem] dark:shadow-[rgb(190_190_190_/20%)_0_-0.5rem_1rem]":
stickyFooter && mode === "alt-system",
},
className,
);
};

export const getTableRowClasses = ({
Expand All @@ -113,30 +115,37 @@ export const getTableRowClasses = ({
cellWrapper === CELL_WRAPPER_HEAD ||
cellWrapper === CELL_WRAPPER_FOOTER
) {
return clsx({
"bg-table-head-dark": mode === "dark",
"bg-table-head-light": mode === "light",
"bg-table-head-dark dark:bg-table-head-light": mode === "system",
"bg-table-head-light dark:bg-table-head-dark": mode === "alt-system",
});
return clsx(
{
"bg-table-head-dark": mode === "dark",
"bg-table-head-light": mode === "light",
"bg-table-head-dark dark:bg-table-head-light": mode === "system",
"bg-table-head-light dark:bg-table-head-dark": mode === "alt-system",
},
className,
);
}
return clsx("border-b last:border-0", className, {
"border-table-dark": mode === "dark",
"odd:bg-table-dark-odd even:bg-table-dark-even":
cellWrapper === CELL_WRAPPER_BODY && mode === "dark",
return clsx(
"border-b last:border-0",
{
"border-table-dark": mode === "dark",
"odd:bg-table-dark-odd even:bg-table-dark-even":
cellWrapper === CELL_WRAPPER_BODY && mode === "dark",

"border-table-light": mode === "light",
"odd:bg-table-light-odd even:bg-table-light-even":
cellWrapper === CELL_WRAPPER_BODY && mode === "light",
"border-table-light": mode === "light",
"odd:bg-table-light-odd even:bg-table-light-even":
cellWrapper === CELL_WRAPPER_BODY && mode === "light",

"border-table-dark dark:border-table-light": mode === "system",
"odd:bg-table-dark-odd even:bg-table-dark-even dark:odd:bg-table-light-odd dark:even:bg-table-light-even":
cellWrapper === CELL_WRAPPER_BODY && mode === "system",
"border-table-dark dark:border-table-light": mode === "system",
"odd:bg-table-dark-odd even:bg-table-dark-even dark:odd:bg-table-light-odd dark:even:bg-table-light-even":
cellWrapper === CELL_WRAPPER_BODY && mode === "system",

"border-table-light dark:border-table-dark": mode === "alt-system",
"odd:bg-table-light-odd even:bg-table-light-even dark:odd:bg-table-dark-odd dark:even:bg-table-dark-even":
cellWrapper === CELL_WRAPPER_BODY && mode === "alt-system",
});
"border-table-light dark:border-table-dark": mode === "alt-system",
"odd:bg-table-light-odd even:bg-table-light-even dark:odd:bg-table-dark-odd dark:even:bg-table-dark-even":
cellWrapper === CELL_WRAPPER_BODY && mode === "alt-system",
},
className,
);
};

export const getTableCellClasses = ({
Expand All @@ -150,18 +159,21 @@ export const getTableCellClasses = ({
className?: string;
compact?: boolean;
}) => {
return clsx(className, {
"text-copy-light": mode === "dark",
"text-copy-dark": mode === "light",
"text-copy-light dark:text-copy-dark": mode === "system",
"text-copy-dark dark:text-copy-light": mode === "alt-system",
"px-4 py-3":
!compact &&
(cellWrapper === CELL_WRAPPER_HEAD ||
cellWrapper === CELL_WRAPPER_FOOTER),
"p-4": !compact && cellWrapper === CELL_WRAPPER_BODY,
"px-2 py-1.5": compact,
});
return clsx(
{
"text-copy-light": mode === "dark",
"text-copy-dark": mode === "light",
"text-copy-light dark:text-copy-dark": mode === "system",
"text-copy-dark dark:text-copy-light": mode === "alt-system",
"px-4 py-3":
!compact &&
(cellWrapper === CELL_WRAPPER_HEAD ||
cellWrapper === CELL_WRAPPER_FOOTER),
"p-4": !compact && cellWrapper === CELL_WRAPPER_BODY,
"px-2 py-1.5": compact,
},
className,
);
};

export const getTableCellSortButtonClasses = ({
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-table/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { commonTailwindConfigForComponent } from "../../configuration/tailwind.common";
export default commonTailwindConfigForComponent();
export default commonTailwindConfigForComponent("ui-table");
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 88ccc05

Please sign in to comment.