Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Card)!: removing spacing prop in favor of Tailwind classes #821

Merged
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
9 changes: 2 additions & 7 deletions packages/ui-card/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 @@ -40,12 +38,9 @@
"dependencies": {
"@tailwindcss/typography": "0.5.15",
"@versini/ui-hooks": "workspace:../ui-hooks",
"@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-card/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const Card = ({
className,
bodyClassName,
"aria-labelledby": ariaLabelledby,
spacing,
mode = "system",
compact = false,
noBorder = false,
Expand All @@ -55,7 +54,6 @@ export const Card = ({
headerClassName,
bodyClassName,
footerClassName,
spacing,
mode,
compact,
noBorder,
Expand Down
10 changes: 10 additions & 0 deletions packages/ui-card/src/components/Card/__tests__/Card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ describe("Card (exceptions)", () => {
});
});

describe("Card spacing", () => {
it("should render a button with a right margin spacing", async () => {
const { container } = render(<Card className="mr-2">{cardContent}</Card>);
const card = container.children[0];
// not only it should be there, but it should be the last entry
expect(card?.className).toContain("mr-2");
expect(card?.className.slice(-4)).toBe("mr-2");
});
});

describe("Card modifiers", () => {
it("should render a dark or light (system) card", async () => {
const { container } = render(<Card>{cardContent}</Card>);
Expand Down
9 changes: 3 additions & 6 deletions packages/ui-card/src/components/Card/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";

import { CARD_CLASSNAME } from "../../common/constants";
Expand All @@ -12,23 +10,21 @@ type getCardClassesProps = {
headerClassName?: string;
mode?: "dark" | "light" | "system" | "alt-system" | "darker";
noBorder?: boolean;
} & SpacingTypes.Props;
};

export const getCardClasses = ({
className,
headerClassName,
bodyClassName,
footerClassName,
spacing,

mode,
compact,
noBorder,
}: getCardClassesProps) => {
const wrapper = clsx(
CARD_CLASSNAME,
className,
"rounded-md",
getSpacing(spacing),
{
"border-none": noBorder,
"border-2": !noBorder,
Expand All @@ -44,6 +40,7 @@ export const getCardClasses = ({
"border-border-accent bg-surface-dark text-copy-light dark:border-border-dark dark:bg-surface-lighter dark:text-copy-dark":
mode === "alt-system",
},
className,
);
const header = headerClassName
? headerClassName
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-card/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-card");
7 changes: 6 additions & 1 deletion packages/ui-styles/src/plugins/tailwindcss/tailwindPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ const customPlugins = [
* anymore. They are using the new TailwindCSS classes, and therefore
* don't need to be added to the safelist.
*/
const componentsWithNoSpacingProp = ["ui-button", "ui-truncate", "ui-bubble"];
const componentsWithNoSpacingProp = [
"ui-button",
"ui-truncate",
"ui-bubble",
"ui-card",
];

/**
* The plugin "merge" function is used to merge the custom configuration with
Expand Down
3 changes: 1 addition & 2 deletions packages/ui-types/src/card.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import type { SpacingTypes } from "./spacing";

declare namespace CardTypes {
export type Props = {
Expand Down Expand Up @@ -49,7 +48,7 @@ declare namespace CardTypes {
* @default false
*/
noBorder?: boolean;
} & SpacingTypes.Props;
};

export type HeaderProps = {
className: string;
Expand Down
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.

Loading