Skip to content

Commit

Permalink
fix(ToggleGroup)!: removing spacing prop in favor of Tailwind classes (
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini authored Dec 29, 2024
1 parent d9a76f8 commit 4fb7406
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 22 deletions.
3 changes: 2 additions & 1 deletion packages/ui-styles/src/plugins/tailwindcss/tailwindPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ const componentsWithNoSpacingProp = [
"ui-table",
"ui-textarea",
"ui-textinput",
"ui-truncate",
"ui-toggle",
"ui-togglegroup",
"ui-truncate",
];

/**
Expand Down
9 changes: 2 additions & 7 deletions packages/ui-togglegroup/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": {
"@radix-ui/react-toggle-group": "1.1.1",
"@tailwindcss/typography": "0.5.15",
"@versini/ui-spacing": "workspace:../ui-spacing",
"@versini/ui-types": "workspace:../ui-types",
"clsx": "2.1.1",
"tailwindcss": "3.4.17"
},
"sideEffects": [
"**/*.css"
]
"sideEffects": ["**/*.css"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export const ToggleGroup = ({
focusMode = "system",
size = "medium",
defaultValue,
spacing,
className,

...otherProps
}: ToggleGroupProps) => {
const toggleGroupClasses = getToggleGroupClasses({ mode, spacing });
const toggleGroupClasses = getToggleGroupClasses({ mode, className });
const contextValue = { size, focusMode, mode };
return (
<ToggleGroupContext.Provider value={contextValue}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type * as ToggleGroupRadix from "@radix-ui/react-toggle-group";
import type { SpacingTypes } from "@versini/ui-types";

export type Size = "small" | "medium" | "large";
export type Mode = "dark" | "light" | "system" | "alt-system";
Expand All @@ -18,7 +17,10 @@ export type ToggleGroupProps = {
* The size of the component.
*/
size?: Size;
} & Omit<ToggleGroupRadix.ToggleGroupSingleProps, "type", "defaultValue"> &
SpacingTypes.Props;
/**
* The classes to apply to the component.
*/
className?: string;
} & Omit<ToggleGroupRadix.ToggleGroupSingleProps, "type", "defaultValue">;

export type ToggleGroupItemProps = ToggleGroupRadix.ToggleGroupItemProps;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ describe("ToggleGroup (exceptions)", () => {
});
});

describe("ToggleGroup spacing", () => {
it("should render a toggle group with a right margin spacing", async () => {
render(
<ToggleGroup className="mr-2">
<ToggleGroupItem value="toto" />
</ToggleGroup>,
);
const group = screen.getByRole("group");
// not only it should be there, but it should be the last entry
expect(group.className).toContain("mr-2");
expect(group.className.slice(-4)).toBe("mr-2");
});
});

describe("ToggleGroup modifiers", () => {
it("should render a default ToggleGroup (light)", async () => {
render(
Expand Down
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 {
Expand Down Expand Up @@ -86,11 +84,10 @@ export const getToggleGroupItemClasses = ({

export const getToggleGroupClasses = ({
mode,
spacing,
}: { mode: Mode } & SpacingTypes.Props) => {
className,
}: { mode: Mode; className: string }) => {
return clsx(
TOGGLEGROUP_CLASSNAME,
getSpacing(spacing),
"inline-flex p-1",
"rounded-sm",
{
Expand All @@ -101,5 +98,6 @@ export const getToggleGroupClasses = ({
"bg-surface-darker text-copy-lighter dark:bg-surface-light dark:text-copy-dark":
mode === "alt-system",
},
className,
);
};
2 changes: 1 addition & 1 deletion packages/ui-togglegroup/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-togglegroup");
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 4fb7406

Please sign in to comment.