Skip to content

Commit 41d16a6

Browse files
committed
UI improvements
1 parent 8381865 commit 41d16a6

File tree

4 files changed

+87
-15
lines changed

4 files changed

+87
-15
lines changed

packages/nextjs/app/create/Create.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import { useEffect, useState } from "react";
44
import { ImageUploader } from "./_components/ImageUploader";
55
import { MintingButtons } from "./_components/MintingButtons";
6-
import { TextInput } from "./_components/TextInput";
76
import generateTokenURI from "./_components/generateTokenURI";
8-
import { InputBase } from "~~/components/scaffold-eth";
7+
import { InputBase } from "~~/components/punk-society/InputBase";
8+
import { TextInput } from "~~/components/punk-society/TextInput";
99

1010
// import type { NextPage } from "next";
1111

@@ -58,7 +58,7 @@ const Create = ({ onClose }: { onClose: any }) => {
5858
</div>
5959
<div className="flex flex-col gap-3 text-left flex-shrink-0 w-full">
6060
<InputBase placeholder="Article name" value={name} onChange={setName} />
61-
<TextInput description={description} setDescription={setDescription} />
61+
<TextInput placeholder="Describe your article" content={description} setContent={setDescription} />
6262
<div className="flex flex-row gap-3">
6363
<div className="w-1/2">
6464
<InputBase placeholder="Price in ETH" value={price} onChange={setPrice} />

packages/nextjs/app/profile/_components/ProfileInfo.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import ProfilePictureUpload from "./ProfilePictureUpload";
33
import { FundButton, getOnrampBuyUrl } from "@coinbase/onchainkit/fund";
44
import { useAccount } from "wagmi";
55
import { PencilIcon } from "@heroicons/react/24/outline";
6+
import { InputBase } from "~~/components/punk-society/InputBase";
67
import { LoadingBars } from "~~/components/punk-society/LoadingBars";
7-
import { Address, InputBase, RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
8+
import { TextInput } from "~~/components/punk-society/TextInput";
9+
import { Address, RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
810
import { useScaffoldReadContract, useScaffoldWriteContract } from "~~/hooks/scaffold-eth";
911
import { notification } from "~~/utils/scaffold-eth";
1012

@@ -105,7 +107,7 @@ const ProfileInfo: React.FC<ProfileInfoProps> = ({ address }) => {
105107
{/* User Info Section */}
106108
<div className="flex flex-col justify-center items-center">
107109
{isEditing ? (
108-
<InputBase placeholder="Your Name" value={username} onChange={setUsername} />
110+
""
109111
) : (
110112
<>
111113
<h2 className="text-2xl font-bold">{username || "Guest user"}</h2>
@@ -142,9 +144,11 @@ const ProfileInfo: React.FC<ProfileInfoProps> = ({ address }) => {
142144
<div></div>
143145
{/* User Bio */}
144146
{isEditing ? (
145-
<div className="flex-grow text-center md:mx-auto mt-4 md:mt-0">
147+
<div className="flex flex-col justify-center items-center flex-grow text-center gap-3 md:mx-auto mt-4 md:mt-0">
146148
<>
147-
<InputBase placeholder="Your Bio" value={bio} onChange={setBio} />
149+
<InputBase placeholder="Your Name" value={username} onChange={setUsername} />
150+
<TextInput placeholder="Your Bio" content={bio} setContent={setBio} />
151+
{/* <InputBase placeholder="Your Bio" value={bio} onChange={setBio} /> */}
148152
<InputBase placeholder="Your Email" value={email} onChange={setEmail} />
149153
</>
150154
</div>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { ChangeEvent, FocusEvent, ReactNode, useCallback, useEffect, useRef } from "react";
2+
import { CommonInputProps } from "~~/components/scaffold-eth";
3+
4+
type InputBaseProps<T> = CommonInputProps<T> & {
5+
error?: boolean;
6+
prefix?: ReactNode;
7+
suffix?: ReactNode;
8+
reFocus?: boolean;
9+
};
10+
11+
export const InputBase = <T extends { toString: () => string } | undefined = string>({
12+
name,
13+
value,
14+
onChange,
15+
placeholder,
16+
error,
17+
disabled,
18+
prefix,
19+
suffix,
20+
reFocus,
21+
}: InputBaseProps<T>) => {
22+
const inputReft = useRef<HTMLInputElement>(null);
23+
24+
let modifier = "";
25+
if (error) {
26+
modifier = "border-error";
27+
} else if (disabled) {
28+
modifier = "border-disabled bg-base-300";
29+
}
30+
31+
const handleChange = useCallback(
32+
(e: ChangeEvent<HTMLInputElement>) => {
33+
onChange(e.target.value as unknown as T);
34+
},
35+
[onChange],
36+
);
37+
38+
// Runs only when reFocus prop is passed, useful for setting the cursor
39+
// at the end of the input. Example AddressInput
40+
const onFocus = (e: FocusEvent<HTMLInputElement, Element>) => {
41+
if (reFocus !== undefined) {
42+
e.currentTarget.setSelectionRange(e.currentTarget.value.length, e.currentTarget.value.length);
43+
}
44+
};
45+
useEffect(() => {
46+
if (reFocus !== undefined && reFocus === true) inputReft.current?.focus();
47+
}, [reFocus]);
48+
49+
return (
50+
<div className={`flex border-2 border-base-300 bg-base-200 rounded-full text-accent ${modifier}`}>
51+
{prefix}
52+
<input
53+
className="input input-ghost focus-within:border-transparent focus:outline-green-500 focus:bg-transparent focus:text-gray-400 h-[2.2rem] min-h-[2.2rem] px-4 border w-full font-medium placeholder:text-accent/50 text-green-500"
54+
placeholder={placeholder}
55+
name={name}
56+
value={value?.toString()}
57+
onChange={handleChange}
58+
disabled={disabled}
59+
autoComplete="off"
60+
ref={inputReft}
61+
onFocus={onFocus}
62+
/>
63+
{suffix}
64+
</div>
65+
);
66+
};

packages/nextjs/app/create/_components/TextInput.tsx renamed to packages/nextjs/components/punk-society/TextInput.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { ChangeEvent, FocusEvent, ReactNode, useCallback, useEffect, useRef } from "react";
22

33
interface TextInputProps {
4-
description: string;
5-
setDescription: (desc: string) => void;
4+
content: string;
5+
setContent: (desc: string) => void;
6+
placeholder?: string;
67
error?: boolean;
78
prefix?: ReactNode;
89
suffix?: ReactNode;
910
reFocus?: boolean;
1011
}
1112

1213
export const TextInput: React.FC<TextInputProps> = ({
13-
description,
14-
setDescription,
14+
content,
15+
setContent,
16+
placeholder,
1517
error,
1618
prefix,
1719
suffix,
@@ -26,9 +28,9 @@ export const TextInput: React.FC<TextInputProps> = ({
2628

2729
const handleChange = useCallback(
2830
(e: ChangeEvent<HTMLTextAreaElement>) => {
29-
setDescription(e.target.value);
31+
setContent(e.target.value);
3032
},
31-
[setDescription],
33+
[setContent],
3234
);
3335

3436
const onFocus = (e: FocusEvent<HTMLTextAreaElement, Element>) => {
@@ -47,9 +49,9 @@ export const TextInput: React.FC<TextInputProps> = ({
4749
{prefix}
4850
<textarea
4951
className="textarea text-lg textarea-ghost border-base-300 focus:border-green-600 border-2 rounded-lg focus:outline-none focus:bg-transparent focus:text-gray-400 h-auto min-h-[3rem] px-4 w-full font-medium placeholder:text-accent/50 text-green-500 resize-none"
50-
placeholder="Describe your article"
52+
placeholder={placeholder}
5153
name="description"
52-
value={description}
54+
value={content}
5355
onChange={handleChange}
5456
autoComplete="off"
5557
ref={textAreaRef}

0 commit comments

Comments
 (0)