Skip to content

feat(react): add Input component with light theme and states #52

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

Merged
merged 8 commits into from
Jul 3, 2025
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
2 changes: 2 additions & 0 deletions js/react/lib/components/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./input";
export * from "./input.types";
33 changes: 33 additions & 0 deletions js/react/lib/components/input/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import clsx from "clsx";
import { InputFieldProps } from "./input.types";

export function Input({
errorMessage,
hasError = !!errorMessage,
icon,
disabled,
className,
...props
}: InputFieldProps) {
return (
<div className="rustlanges-input__container">
<div
className={clsx(
"rustlanges-input",
hasError && "rustlanges-input--error",
className
)}
>
{icon && <span className="rustlanges-input__icon">{icon}</span>}
<input
disabled={disabled}
className="rustlanges-input__inner"
{...props}
/>
</div>
{hasError && errorMessage && (
<span className="rustlanges-input__error">{errorMessage}</span>
)}
</div>
);
}
7 changes: 7 additions & 0 deletions js/react/lib/components/input/input.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { InputHTMLAttributes, ReactNode } from "react";

export interface InputFieldProps extends InputHTMLAttributes<HTMLInputElement> {
hasError?: boolean;
errorMessage?: string;
icon?: ReactNode;
}
1 change: 1 addition & 0 deletions js/react/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from "./components/contact-form";
export * from "./components/chip";
export * from "./components/tag";
export * from "./components/flap";
export * from "./components/input";
export * from "./components/level";
export * from "./components/avatar";
export * from "./components/collaborators";
Expand Down
27 changes: 27 additions & 0 deletions js/react/showcase/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
Github,
Tag,
Telegram,
Input,
Location,
Flap,
Chip,
Level,
Expand Down Expand Up @@ -524,6 +526,31 @@ export function App() {
</div>
</div>
</ShowComponent>
<ShowComponent
title="Input"
propsDef={{
placeholder: {
type: "string",
default: "Input",
},
disabled: {
type: "boolean",
default: false,
},
hasError: {
type: "boolean",
default: false,
},
errorMessage: {
type: "string",
default: "Error",
},
}}
component={Input}
/>
<ShowComponent title="Input With Icon">
<Input icon={<Location />} placeholder="Input" />
</ShowComponent>
<ShowComponent title="Input Search">
<div className="flex min-h-60 w-full flex-wrap justify-evenly gap-40 p-5">
<InputSearch
Expand Down
1 change: 1 addition & 0 deletions styles/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@import "./components/collaborators.css";
@import "./components/dropdown.css";
@import "./components/flap.css";
@import "./components/input.css";
@import "./components/level.css";
@import "./components/radio.css";
@import "./components/tag.css";
Expand Down
4 changes: 1 addition & 3 deletions styles/components/input-search.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
@layer components {


.rustlanges-input-search-container {
@apply relative flex h-fit w-full;

svg {
@apply text-gray-600 dark:text-gray-400;
}
Expand Down
43 changes: 43 additions & 0 deletions styles/components/input.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@layer components {
.rustlanges-input {
@apply flex items-center gap-2 rounded-xl px-[10px] py-3 transition-colors;
@apply bg-light border-1 border-black text-black hover:bg-neutral-100;
@apply dark:bg-neutral-950 dark:text-white dark:hover:bg-neutral-900;

&:has(> :active),
&:has(> :focus) {
@apply border-primary-500;
}

@variant has-disabled {
@apply cursor-not-allowed border-neutral-400 bg-neutral-100 text-neutral-600;
@apply dark:bg-neutral-900 dark:text-neutral-400;
}
}

.rustlanges-input--error {
@apply border-error-600;
}

.rustlanges-input__container {
@apply flex flex-col gap-1;
}

.rustlanges-input__error {
@apply text-error-800 dark:text-error-300 mt-1 text-sm;
}

.rustlanges-input__inner {
@apply w-full bg-transparent outline-none;
@apply placeholder:text-neutral-600 dark:placeholder:text-neutral-400;
@apply disabled:pointer-events-none disabled:placeholder:text-neutral-400 dark:disabled:placeholder:text-neutral-600;
}

.rustlanges-input__icon {
@apply text-neutral-600;

&:has(+ :disabled) {
@apply text-neutral-400;
}
}
}