-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: optimize sui、tron、cfx example
- Loading branch information
1 parent
d349624
commit 9843a1f
Showing
27 changed files
with
979 additions
and
317 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,69 @@ | ||
import React, { memo, useContext, useEffect } from 'react'; | ||
import { useAtom } from 'jotai'; | ||
import { Label } from '../ui/label'; | ||
import { ApiFormContext } from './ApiForm'; | ||
import { AutoHeightTextarea } from '../ui/textarea'; | ||
|
||
|
||
interface AutoTextAreaProps { | ||
id: string; | ||
placeholder?: string; | ||
label?: string; | ||
required?: boolean; | ||
} | ||
|
||
const TextArea = memo(({ | ||
id, | ||
placeholder, | ||
label, | ||
required | ||
}: AutoTextAreaProps) => { | ||
const context = useContext(ApiFormContext); | ||
if (!context) throw new Error('ApiField must be used within ApiForm'); | ||
|
||
const { store } = context; | ||
const [field, setField] = useAtom(store.fieldsAtom(id)); | ||
|
||
useEffect(() => { | ||
field.name = label; | ||
field.required = required; | ||
}, []); | ||
|
||
return <> | ||
<AutoHeightTextarea | ||
id={id} | ||
value={field.value} | ||
onChange={(e) => setField({ ...field, value: e.target.value })} | ||
placeholder={placeholder} | ||
disabled={field.disabled} | ||
/> | ||
{field.error && ( | ||
<div className="text-sm text-red-500">{field.error}</div> | ||
)} | ||
</> | ||
}); | ||
|
||
export interface ApiAutoTextAreaProps extends AutoTextAreaProps { | ||
id: string; | ||
} | ||
|
||
export const ApiAutoTextArea = memo(({ | ||
id, | ||
label, | ||
placeholder, | ||
required | ||
}: ApiAutoTextAreaProps) => { | ||
return ( | ||
<div> | ||
{label && ( | ||
<Label htmlFor={id}> | ||
{label} | ||
{required && <span className="text-red-500">*</span>} | ||
</Label> | ||
)} | ||
<TextArea id={id} placeholder={placeholder} label={label} required={required} /> | ||
</div> | ||
); | ||
}); | ||
|
||
ApiAutoTextArea.displayName = 'ApiAutoTextArea'; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.