generated from yandex-praktikum/client-server-template-with-vite
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Timur233/SOK-22_user_profile_page
[SOK-22] User profile page
- Loading branch information
Showing
25 changed files
with
3,997 additions
and
2,472 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,58 @@ | ||
@import '../../../scss/vars.scss'; | ||
|
||
.avatar { | ||
width: 160px; | ||
max-width: 100%; | ||
height: 158px; | ||
max-height: 100%; | ||
position: relative; | ||
|
||
&__image, &__image-placeholder { | ||
border-radius: 50%; | ||
border: 5px solid $c_avatar-border-color; | ||
width: inherit; | ||
height: inherit; | ||
} | ||
|
||
&__overlay { | ||
opacity: 0; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
background-color: $c_overlay-background; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
transition: opacity 0.3s ease; | ||
border-radius: 50%; | ||
|
||
&:hover { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
&:hover { | ||
.overlay { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
&__change-button { | ||
border: none; | ||
color: white; | ||
font-size: 14px; | ||
font-weight: bold; | ||
text-transform: uppercase; | ||
cursor: pointer; | ||
padding: 8px 16px; | ||
border-radius: 20px; | ||
background-color: $c_overlay-background; | ||
transition: background-color 0.3s ease; | ||
|
||
&:hover { | ||
background-color: $c_overlay-background-hover; | ||
} | ||
} | ||
} |
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,70 @@ | ||
import './Avatar.scss' | ||
import React, { useState, useRef, useEffect } from 'react' | ||
import { Image } from '@/components/ui/Image/Image' | ||
import AvatarPlaceholder from '@/assets/images/avatar-placeholder.png' | ||
|
||
export const AVATAR_SRC = import.meta.env.VITE_SRC_URL | ||
|
||
export const Avatar = (props: { | ||
src: string | ||
containerClassName?: string | ||
imageClassName?: string | ||
onChange: (file: File) => void | ||
}) => { | ||
const { src, containerClassName, imageClassName, onChange } = props | ||
const [previewUrl, setPreviewUrl] = useState<string | null>(null) | ||
const fileInputRef = useRef<HTMLInputElement>(null) | ||
|
||
useEffect(() => { | ||
return () => { | ||
if (previewUrl) { | ||
URL.revokeObjectURL(previewUrl) | ||
} | ||
} | ||
}, [previewUrl]) | ||
|
||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const file = event.target.files?.[0] | ||
if (file) { | ||
const fileUrl = URL.createObjectURL(file) | ||
setPreviewUrl(fileUrl) | ||
onChange(file) | ||
} | ||
} | ||
|
||
const handleButtonClick = () => { | ||
fileInputRef.current?.click() | ||
} | ||
|
||
const displaySrc = previewUrl || src | ||
|
||
return ( | ||
<div className={`avatar ${containerClassName}`}> | ||
{displaySrc ? ( | ||
<Image | ||
src={displaySrc} | ||
className={`avatar__image ${imageClassName}`} | ||
alt="Avatar" | ||
/> | ||
) : ( | ||
<Image | ||
src={AvatarPlaceholder} | ||
className={'avatar__image-placeholder'} | ||
alt="Avatar" | ||
/> | ||
)} | ||
<div className="avatar__overlay"> | ||
<button className={'avatar__change-button'} onClick={handleButtonClick}> | ||
{'Изменить аватар'} | ||
</button> | ||
</div> | ||
<input | ||
ref={fileInputRef} | ||
type="file" | ||
accept="image/png, image/jpeg, image/jpg, image/gif" | ||
onChange={handleFileChange} | ||
style={{ display: 'none' }} | ||
/> | ||
</div> | ||
) | ||
} |
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
Empty file.
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,17 @@ | ||
import './Form.scss' | ||
import React from 'react' | ||
|
||
interface FormProps { | ||
className?: string | ||
children?: React.ReactNode | ||
onSubmit?: () => void | ||
} | ||
|
||
export const Form = (props: FormProps) => { | ||
const { onSubmit, className, children } = props | ||
return ( | ||
<form onSubmit={onSubmit} className={`form-fields ${className}`}> | ||
{children} | ||
</form> | ||
) | ||
} |
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,10 @@ | ||
interface ImageProps { | ||
src: string | ||
className?: string | ||
alt?: string | ||
} | ||
|
||
export const Image = (props: ImageProps) => { | ||
const { src, className, alt } = props | ||
return <img {...props} /> | ||
} |
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,17 @@ | ||
@import '../../../scss/vars'; | ||
|
||
.input-default { | ||
padding: 12px 15px; | ||
border-radius: 12px; | ||
border: 2px solid $c_input-default-border; | ||
text-align: center; | ||
background-color: $c_default-background; | ||
color: $c_font-default; | ||
font-size: 18px; | ||
|
||
&:focus-visible, | ||
&:hover { | ||
outline: none; | ||
border-color: $c_input-default-border-hover; | ||
} | ||
} |
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,32 @@ | ||
import './Input.scss' | ||
import React, { ChangeEventHandler, CSSProperties } from 'react' | ||
|
||
interface InputProps { | ||
placeholder?: string | ||
name?: string | ||
className?: string | ||
disabled?: boolean | ||
value?: string | ||
type?: string | ||
label?: string | ||
onChange?: ChangeEventHandler | undefined | ||
style?: CSSProperties | undefined | ||
} | ||
|
||
export const Input = (props: InputProps) => { | ||
const { value, name, className, label, disabled, onChange, style } = props | ||
return ( | ||
<div className={'input-wrapper'}> | ||
{label && <label htmlFor={name}>{label}</label>} | ||
<input | ||
{...props} | ||
name={name} | ||
value={value} | ||
className={`input-default ${className}`} | ||
disabled={disabled} | ||
onChange={onChange} | ||
style={style} | ||
/> | ||
</div> | ||
) | ||
} |
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.