@codecraftkit
Documentation
The Profile Image is used to Handle the Avatar, like chooses and avatar or upload one
it can be imported from the core.
import { ProfileImage } from "@codecraftkit/core";
or alone.
import ProfileImage from "@codecraftkit/profile-image";
const avatarsImages = [{category: 'Avatars',items: [{url: '/images/img1.jpg',fileName: 'img1'}, {url: '/images/img2.jpg',fileName: 'img2'}, {url: '/images/img3.jpg',fileName: 'img3'}, {url: '/images/img4.jpg',fileName: 'img4'}, {url: '/images/img5.jpg',fileName: 'img5'}, {url: '/images/img6.jpg',fileName: 'img6'}, {url: '/images/img7.jpg',fileName: 'img7'}]}]
We use a state to save the image submitted, and the show it in the avatar
function MyApp() {const [profileImage, setProfileImage] = useState("");return <ProfileImageimage={profileImage}getImage={setProfileImage}avatarsData={avatarsImages}closeModalOnSubmit/>}
We use the props chooseAvatarAction
and uploadImageAction
to send submit functions to their respective tab
note: in the first parameter it receive the image or file uploaded, and as second parameter it receive an object with useful tools
function MyApp() {const [profileImage, setProfileImage] = useState("");const chooseAvatarAction = async (img, {setLoading, onCloseModal, callback, item}) => {onCloseModal()alert("Image Set Succesffuly " + img)}const uploadImageAction = async (files, {onCloseModal, callback, item, setLoading}) => {onCloseModal()alert("File uploaded Succesffuly " + files)}return <ProfileImageimage={profileImage}getImage={setProfileImage}avatarsData={avatarsImages}chooseAvatarAction={chooseAvatarAction}uploadImageAction={uploadImageAction}noShadowisRounded/>}
We use the props type
toggle between tabs or just a single component by its name, they could be upload
and chooseAvatar
function MyApp() {const [profileImage, setProfileImage] = useState("");const uploadImageAction = async (files, {onCloseModal, callback, item, setLoading}) => {onCloseModal()alert("File uploaded Succesffuly " + files)}return <ProfileImagetype="upload"image={profileImage}getImage={setProfileImage}uploadImageAction={uploadImageAction}noShadowisRounded/>}
How to add more custom tabs
function MyApp() {const [profileImage, setProfileImage] = useState("");const chooseAvatarAction = async (img, {setLoading, onCloseModal, callback, item}) => {onCloseModal()alert("Image Set Succesffuly " + img)}const uploadImageAction = async (files, {onCloseModal, callback, item, setLoading}) => {onCloseModal()alert("File uploaded Succesffuly " + files)}const customTabs = [{name:'customTab',label: 'Custom Tab',isEnabled: true, // by default is enabledcontent: <Animationautoplayloopname="chicken-70"height={200}width={200}/>},]return <ProfileImageimage={profileImage}getImage={setProfileImage}avatarsData={avatarsImages}chooseAvatarAction={chooseAvatarAction}uploadImageAction={uploadImageAction}addTabs={customTabs}noShadowisRounded/>}
We can pass children
, to change the way the base is rendered
The children
are rendered using the render props method that allows to pass props from the parent to its children through a function
This render props pass five arguments AvatarImage
, item
, onOpen
, isOpen
, onClose
function MyApp() {const [profileImage, setProfileImage] = useState("");const user = {name:"Juan", username:"ElJuan"}const isLoading = falsereturn <ProfileImageitem={user}image={profileImage}getImage={setProfileImage}avatarsData={avatarsImages}isLoading={isLoading}closeModalOnSubmitisRounded>{({ AvatarImage, item }) =><Grid justifyContent='center'><Grid templateColumns="auto 1fr" gap={4} alignItems="center" justifyContent="center"><AvatarImage /><Grid templateRows="repeat(2, 30px)"><Skeleton w="150px" h="18px" isLoaded={!isLoading}><TextfontSize={['sm', 'xl']}w="300px"textAlign="left"fontWeight="600"mb="0">{item.name}</Text></Skeleton><Skeleton w="120px" h="16px" isLoaded={!isLoading}><Text fontSize={['sm', 'md']} w="300px" textAlign="left">@{item.username}</Text></Skeleton></Grid></Grid></Grid>}</ProfileImage>}
The AvatarImage
is the component that renders the image with an onOpen function to open the modal, but it is completely optional you can achieved the same using the onOpen
and item
arguments and make your own custom profile images
isDisabled
Boolean
no
false
Disable modal
type
upload
chooseAvatar
default
no
default
Choose which components are displayed or if they are displayed in tabs
addTabs
array>objects
no
Add more tabs
imageTitle
String
no
Profile picture
Title of the Profile Image
item
object
no
The object which contains the information about the profile
children
function({AvatarImage, item, onOpen, isOpen, onClose})=>React<node>
no
Customize how the profile image is display, it uses render props method and received some parameters
nameField
String
no
name
Specify the field where the profile name comes
urlField
String
no
img
Specify the field where the profile image comes
image
String
no
The profile Image, this one would take priority over the item image
isRounded
Boolean
no
false
Round the profile image and its crop
noShadow
Boolean
no
false
Remove the image shadow
noBorder
Boolean
no
false
Remove Profile Border
aspect
Object
no
Crop options
modalTitle
String
no
New
Modal Title.
modalSize
px
xs
sm
md
lg
xl
no
800px
Specifies whether the modal is closed when the ESC key is pressed.
modalBoxSize
px
no
specify modal boxSize
closeModalOnSubmit
Boolean
no
false
Close Modal when the users clicks submit
getImage
Function
no
Called when a new image is set, is called before the image is uploaded
uploadImageAction
Function
no
Called when a new image is set, the image is doesn't upload
chooseAvatarAction
Function
no
Called when a new image is chosen
callback
Function
no
Function called when the image has been uploaded
avatarImageGroupKey
String
no
The key from where the images are being called, internally calls useQuery to get the images
avatarsData
array>objects
no
List of images to bee shown in the choose avatar tab
loading
Boolean
no
Optional loading to Choose Avatar tab
getUserPermissionToUploadImage
Boolean
no
false
Send props to Chakra Modal
checkForAgencyToChooseAvatar
Boolean
no
false
Check if the user have an agency before choose an image
isUploadImageEnabled
Boolean
no
true
Hide the upload Tab
isChooseAvatarEnabled
Boolean
no
true
Hide choose image tab