Skip to content

Commit

Permalink
fix(TextInput)!: 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 ee99870 commit 6f28910
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/with-vite/src/components/CustomForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const CustomForm = () => {
<form>
<div className="flex gap-2">
<TextInput
spacing={{ t: 4 }}
className="mt-4"
name="question"
label="Type your question here"
helperText="Powered by the sun"
Expand Down
2 changes: 1 addition & 1 deletion examples/with-webpack/src/components/CustomForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const CustomForm = () => {
<form>
<div className="flex gap-2">
<TextInput
spacing={{ t: 4 }}
className="mt-4"
name="question"
label="Type your question here"
helperText="Powered by the sun"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const componentsWithNoSpacingProp = [
"ui-svgicon",
"ui-table",
"ui-textarea",
"ui-textinput",
"ui-truncate",
];

Expand Down
9 changes: 2 additions & 7 deletions packages/ui-textinput/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-hooks": "workspace:../ui-hooks",
"@versini/ui-liveregion": "workspace:../ui-liveregion",
"@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-textinput/src/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(

rightElement,
rightElementClassName,
spacing,
size = "md",

...extraProps
Expand Down Expand Up @@ -60,7 +59,6 @@ export const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
focusMode,
disabled,
noBorder,
spacing,
mode,
size,
rightElementClassName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export const TextInputMask = React.forwardRef<

rightElement,

spacing,

...otherProps
},
ref,
Expand Down Expand Up @@ -166,7 +164,6 @@ export const TextInputMask = React.forwardRef<
labelHidden={labelHidden}
type={masked ? "password" : "text"}
disabled={disabled}
spacing={spacing}
onBlur={handleFieldBlur}
onFocus={handleFieldFocus}
onChange={handleChange}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { SpacingTypes } from "@versini/ui-types";

export type Size = "xs" | "sm" | "md" | "lg" | "xl";
export type SetTimeoutResult = ReturnType<typeof setTimeout> | null;
export type CommonTextInputProps = {
Expand Down Expand Up @@ -55,8 +53,7 @@ export type CommonTextInputProps = {
* Controls input height and horizontal padding, 'md' by default
*/
size?: Size;
} & SpacingTypes.Props &
Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">;
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">;

export type TextInputProps = {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ describe("TextInput (exceptions)", () => {
});
});

describe("TextInput spacing", () => {
it("should render a text input with a right margin spacing", async () => {
render(
<TextInput
label="toto"
name="toto"
className="mr-2"
data-testid="txtnpt-1"
/>,
);
const input = await screen.findByTestId("txtnpt-1");
expect(input.className).not.toContain("mr-2");
if (input.parentElement) {
// not only it should be there, but it should be the last entry
expect(input.parentElement.className).toContain("mr-2");
expect(input.parentElement.className).toContain("relative");
expect(input.parentElement.className.slice(-4)).toBe("mr-2");
}
});
});

describe("TextInput sizes", () => {
it.each`
size | description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ describe("TextInputMask (exceptions)", () => {
});
});

describe("TextInputMask spacing", () => {
it("should render a text input with a right margin spacing", async () => {
render(
<TextInputMask
label="toto"
name="toto"
className="mr-2"
data-testid="txtnpt-1"
rightElement={
<MyButtonIcon>
<MyIconHide />
</MyButtonIcon>
}
/>,
);
const input = await screen.findByTestId("txtnpt-1");
expect(input.className).not.toContain("mr-2");
if (input.parentElement) {
// not only it should be there, but it should be the last entry
expect(input.parentElement.className).toContain("mr-2");
expect(input.parentElement.className).toContain("relative");
expect(input.parentElement.className.slice(-4)).toBe("mr-2");
}
});
});

describe("TextInputMask modifiers", () => {
it("should render a dark or light (system) text input", async () => {
render(
Expand Down
9 changes: 3 additions & 6 deletions packages/ui-textinput/src/components/TextInput/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 {
Expand All @@ -21,7 +19,7 @@ type getTextInputClassesProps = {
className?: string;
rightElementClassName?: string;
inputClassName?: string;
} & SpacingTypes.Props;
};

const getTextInputColorClasses = ({
mode,
Expand Down Expand Up @@ -151,7 +149,6 @@ export const getTextInputClasses = ({
disabled,
noBorder,
error,
spacing,
mode,
focusMode,
size,
Expand All @@ -163,7 +160,6 @@ export const getTextInputClasses = ({
"relative flex w-full flex-col justify-center",
TEXT_INPUT_WRAPPER_CLASSNAME,
className,
getSpacing(spacing),
);

let heightClass = "";
Expand All @@ -190,7 +186,7 @@ export const getTextInputClasses = ({
? clsx(inputClassName)
: clsx(
TEXT_INPUT_CLASSNAME,
inputClassName,

heightClass,
"rounded-md text-base px-4",
getTextInputColorClasses({ mode }),
Expand All @@ -199,6 +195,7 @@ export const getTextInputClasses = ({
{
"disabled:cursor-not-allowed disabled:opacity-50": disabled,
},
inputClassName,
);

const accessibleLabel = raw ? undefined : "sr-only";
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-textinput/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-textinput");
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 6f28910

Please sign in to comment.