-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
236 additions
and
97 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
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
41 changes: 41 additions & 0 deletions
41
src/ui/image-gallery/image-gallery-item/image-gallery-item.tsx
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,41 @@ | ||
import * as React from 'react'; | ||
import styled from '@emotion/styled'; | ||
|
||
const ImageStyled = styled.img` | ||
width: 100%; | ||
cursor: zoom-in; | ||
`; | ||
|
||
export interface ModalProps { | ||
isOpened: boolean; | ||
srcSmall: string; | ||
srcLarge: string; | ||
alt: string; | ||
className?: string; | ||
} | ||
|
||
interface ModalImageProps { | ||
src: string; | ||
alt: string; | ||
id: number; | ||
className?: string; | ||
srcLarge?: string; | ||
onClick?: (key: number) => any; | ||
} | ||
|
||
export class ImageGalleryItem extends React.Component<ModalImageProps> { | ||
constructor(props: ModalImageProps) { | ||
super(props); | ||
} | ||
|
||
handleClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => { | ||
if (!this.props.onClick) { | ||
return; | ||
} | ||
this.props.onClick(this.props.id); | ||
}; | ||
|
||
render(): React.ReactNode { | ||
return <ImageStyled onClick={this.handleClick} className={this.props.className} src={this.props.src} alt={this.props.alt} />; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/ui/image-gallery/image-gallery-overlay/image-gallery-overlay.component.tsx
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,96 @@ | ||
import * as React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import {FC, memo} from 'react'; | ||
import {TriangleIcon} from '../../../assets/index'; | ||
import {Icon} from '../../ui-kit/icon/icon.component'; | ||
|
||
//#region styled | ||
const OverlayStyled = styled.div` | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background: rgba(0, 0, 0, 0.7); | ||
z-index: 999; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
flex-wrap: nowrap; | ||
user-select: none; | ||
`; | ||
const NextStyled = styled.div` | ||
right: 20px; | ||
color: rgba(255, 255, 255, 0.7); | ||
position: absolute; | ||
width: 40px; | ||
height: 100%; | ||
cursor: pointer; | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-end; | ||
&:hover { | ||
color: var(--yellow); | ||
} | ||
`; | ||
const PrevStyled = styled.div` | ||
left: 20px; | ||
transform: rotate(180deg); | ||
color: rgba(255, 255, 255, 0.7); | ||
position: absolute; | ||
width: 40px; | ||
height: 100%; | ||
cursor: pointer; | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-end; | ||
&:hover { | ||
color: var(--yellow); | ||
} | ||
`; | ||
const ImageStyled = styled.img` | ||
width: auto; | ||
max-width: 50%; | ||
max-height: 60%; | ||
height: auto; | ||
display: block; | ||
cursor: pointer; | ||
user-select: none; | ||
&:hover + ${NextStyled} { | ||
color: var(--yellow); | ||
} | ||
`; | ||
//#endregion | ||
|
||
interface ImageGalleryOverlayProps { | ||
isLast: boolean; | ||
isFirst: boolean; | ||
src: string; | ||
onNextClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => any; | ||
onPrevClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => any; | ||
onOverlayClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => any; | ||
className?: string; | ||
} | ||
|
||
export const ImageGalleryOverlay: FC<ImageGalleryOverlayProps> = memo( | ||
({src, isLast, isFirst, onNextClick, onPrevClick, onOverlayClick, className}) => { | ||
return ( | ||
<OverlayStyled className={className} onClick={onOverlayClick}> | ||
{!isFirst && ( | ||
<PrevStyled onClick={onPrevClick}> | ||
<Icon svg={TriangleIcon} /> | ||
</PrevStyled> | ||
)} | ||
<ImageStyled onClick={onNextClick} src={src}></ImageStyled> | ||
{!isLast && ( | ||
<NextStyled onClick={onNextClick}> | ||
<Icon svg={TriangleIcon} /> | ||
</NextStyled> | ||
)} | ||
</OverlayStyled> | ||
); | ||
}, | ||
); |
87 changes: 87 additions & 0 deletions
87
src/ui/image-gallery/image-gallery/image-gallery.component.tsx
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,87 @@ | ||
import * as React from 'react'; | ||
import {ImageGalleryItem} from '../image-gallery-item/image-gallery-item'; | ||
import {ImageGalleryOverlay} from '../image-gallery-overlay/image-gallery-overlay.component'; | ||
|
||
interface ImageGalleryProps { | ||
images: Image[]; | ||
className?: string; | ||
} | ||
|
||
interface ImageGalleryState { | ||
isOpened: boolean; | ||
activeIndex: number; | ||
} | ||
|
||
interface Image { | ||
alt: string; | ||
src: string; | ||
srcLarge?: string; | ||
} | ||
|
||
export class ImageGallery extends React.Component<ImageGalleryProps> { | ||
state: ImageGalleryState; | ||
|
||
constructor(props: ImageGalleryProps) { | ||
super(props); | ||
|
||
this.state = { | ||
isOpened: false, | ||
activeIndex: 0, | ||
}; | ||
} | ||
|
||
onImageClick = (id: number): void => { | ||
this.setState({ | ||
isOpened: true, | ||
activeIndex: id, | ||
}); | ||
}; | ||
|
||
onOverlayClick = (): void => { | ||
this.setState({ | ||
isOpened: false, | ||
}); | ||
}; | ||
|
||
onNextClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent>): void => { | ||
event.stopPropagation(); | ||
|
||
const nextIndex = Math.min(this.state.activeIndex + 1, this.props.images.length - 1); | ||
this.setState({activeIndex: nextIndex}); | ||
}; | ||
|
||
onPrevClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent>): void => { | ||
event.stopPropagation(); | ||
|
||
const prevIndex = Math.max(this.state.activeIndex - 1, 0); | ||
this.setState({activeIndex: prevIndex}); | ||
}; | ||
|
||
render(): React.ReactNode { | ||
// Create Overlay | ||
let overlay: JSX.Element | null = null; | ||
if (this.state.isOpened) { | ||
const img = this.props.images[this.state.activeIndex]; | ||
overlay = ( | ||
<ImageGalleryOverlay | ||
src={img.srcLarge || img.src} | ||
onNextClick={this.onNextClick} | ||
onPrevClick={this.onPrevClick} | ||
onOverlayClick={this.onOverlayClick} | ||
isFirst={this.state.activeIndex === 0} | ||
isLast={this.state.activeIndex + 1 === this.props.images.length} | ||
/> | ||
); | ||
} | ||
|
||
// Images list | ||
const images = this.props.images.map((img, i) => <ImageGalleryItem onClick={this.onImageClick} {...img} key={i} id={i} />); | ||
|
||
return ( | ||
<div className={this.props.className}> | ||
{images} | ||
{overlay} | ||
</div> | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.