generated from codersforcauses/django-nextjs-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Issue 44 add textarea component #48
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c07fbe
Add textarea component and a simple test file.
EdenWuyt 625906e
Change label and placeholder styles.
EdenWuyt 58257ff
Add documentation at the top of textarea.tsx.
EdenWuyt b16abb1
Fix naming consistency issues. Add optional required and multiple cla…
EdenWuyt fd23ac7
Perform requested change in terms of styling and customization. Updat…
EdenWuyt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| "use client"; | ||
| import React, { useState } from "react"; | ||
|
|
||
| import { Button } from "@/components/ui/button"; | ||
| import Textarea from "@/components/ui/textarea"; | ||
|
|
||
| export default function TextareaTestPage() { | ||
| const [message, setMessage] = useState(""); | ||
|
|
||
| const handleSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
| alert(`Submitted text: ${message}`); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="min-h-screen p-8"> | ||
| <div className="mx-auto my-5 flex w-full max-w-lg flex-col items-center justify-center"> | ||
| <form onSubmit={handleSubmit} className="w-full rounded-md border p-4"> | ||
| <Textarea // basic textarea | ||
| name="message" | ||
| value={message} | ||
| onChange={setMessage} | ||
| /> | ||
| {/* <Textarea // with customization | ||
| id="message" | ||
| name="message" | ||
| label="Additional message" | ||
| placeholder="This is an textarea with customization" | ||
| rows={6} | ||
| value={message} | ||
| onChange={setMessage} | ||
| required={true} | ||
| className="bg-green-100 placeholder:text-red-600 w-[90%] bg-green-100" | ||
| /> */} | ||
| <Button type="submit" className="mx-auto mt-4"> | ||
| Submit | ||
| </Button> | ||
| </form> | ||
| <p className="mt-4">Current value message: {message}</p> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Usage: | ||
| // <Textarea id="componentIdentifier" // optional (defaults to name if not provided) | ||
| // name="fieldName" | ||
| // label="fieldLabel" // optional (defaults to name with first letter capitalized if not provided) | ||
| // placeholder="placeholderText" // optional (defaults to name with first letter capitalized if not provided) | ||
| // rows={4} // optional (defaults to 4 if not provided) | ||
| // value={fieldValue} // useState variable | ||
| // onChange={fieldSetterFunction} // useState setter function | ||
| // required={true} // optional (if required, shows asterisk) | ||
| // className="customTextareaClass" // optional, additional classNames for textarea | ||
| // /> | ||
|
|
||
| // Style (apart from border color: --border, other styles match InputField): | ||
| // label: body-sm-bold, default text color | ||
| // textarea: border color: --border, background color: --background, shadow: 0 4px 0 #D1D5DB | ||
| // placeholder: text color: --bloom-gray | ||
|
|
||
| "use client"; | ||
| import React from "react"; | ||
|
|
||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| interface TextareaProps { | ||
| id?: string; | ||
| name: string; | ||
| label?: string; | ||
| placeholder?: string; | ||
| rows?: number; | ||
| value: string; | ||
| onChange: (value: string) => void; | ||
| required?: boolean; | ||
| className?: string; | ||
| } | ||
|
|
||
| // Use to capitalize the first letter of name as label placeholder if not passed | ||
| const capitalizeFirstLetter = (str: string) => { | ||
| return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase(); | ||
| }; | ||
|
|
||
| const Textarea: React.FC<TextareaProps> = ({ | ||
| id, | ||
| name, | ||
| label, | ||
| placeholder, | ||
| rows, | ||
| value, | ||
| onChange, | ||
| required, | ||
| className, | ||
| }) => { | ||
| return ( | ||
| <> | ||
| <label htmlFor={name} className={"body-sm-bold mb-1 block"}> | ||
| {label ? label : capitalizeFirstLetter(name)} | ||
| {required && <span className={"text-[var(--bloom-red)]"}> *</span>} | ||
| </label> | ||
| <textarea | ||
| id={id ? id : name} | ||
| name={name} | ||
| placeholder={placeholder ? placeholder : capitalizeFirstLetter(name)} | ||
| rows={rows ? rows : 4} | ||
| className={cn( | ||
| "w-full rounded-md border border-[hsl(var(--border))] bg-background shadow-[0_4px_0_0_#D1D5DB] outline-none", | ||
| "body px-3 py-2 placeholder:text-bloom-gray", | ||
| className, | ||
| )} | ||
| value={value} | ||
| onChange={(e) => onChange(e.target.value)} | ||
| /> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default Textarea; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency / extra styling add these extra fields:
required?:- The text area might be a required field in a formclassname?:- The text area might need extra classes in some use cases