-
Notifications
You must be signed in to change notification settings - Fork 186
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 #1992 from VKCOM/feat/gallery-autosize
Feat/gallery autosize
- Loading branch information
Showing
5 changed files
with
120 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,93 @@ | ||
```jsx | ||
class Example extends React.Component { | ||
const [slideIndex, setSlideIndex] = useState(0); | ||
const [isDraggable, setIsDraggable] = useState(true); | ||
const [showArrows, setShowArrows] = useState(true); | ||
|
||
constructor (props) { | ||
<View activePanel="gallery"> | ||
<Panel nav="gallery"> | ||
<PanelHeader>Gallery</PanelHeader> | ||
<Group header={<Header mode="secondary">Sticks right</Header>}> | ||
<Gallery | ||
slideWidth="90%" | ||
bullets="dark" | ||
> | ||
<div style={{ backgroundColor: 'var(--destructive)' }} /> | ||
<img src="https://picsum.photos/1024/640" style={{ display: 'block'}} /> | ||
<div style={{ backgroundColor: 'var(--accent)' }} /> | ||
</Gallery> | ||
</Group> | ||
<Group header={<Header mode="secondary">Sticks left</Header>}> | ||
<Gallery | ||
slideWidth="90%" | ||
align="right" | ||
> | ||
<div style={{ height: 150, backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ backgroundColor: 'var(--accent)' }} /> | ||
</Gallery> | ||
</Group> | ||
<Group header={<Header mode="secondary">Centered</Header>}> | ||
<Gallery | ||
slideWidth="90%" | ||
align="center" | ||
> | ||
<div style={{ backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ backgroundColor: 'var(--accent)' }} /> | ||
</Gallery> | ||
</Group> | ||
<Group header={<Header mode="secondary">Custom width</Header>}> | ||
<Gallery | ||
slideWidth="custom" | ||
style={{ height: 150 }} | ||
> | ||
<div style={{ width: 200, backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ width: 120, backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ width: 70, backgroundColor: 'var(--accent)' }} /> | ||
<div style={{ width: 220, backgroundColor: 'var(--icon_secondary)' }} /> | ||
</Gallery> | ||
</Group> | ||
<Group header={<Header mode="secondary">Arrows</Header>}> | ||
<Gallery | ||
slideWidth="90%" | ||
style={{ height: 150 }} | ||
bullets="dark" | ||
showArrows | ||
> | ||
<div style={{ backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ backgroundColor: 'var(--accent)' }} /> | ||
</Gallery> | ||
</Group> | ||
<Group header={<Header mode="secondary">Controled</Header>}> | ||
<Gallery | ||
slideWidth="90%" | ||
align="center" | ||
style={{ height: 150 }} | ||
slideIndex={slideIndex} | ||
onChange={setSlideIndex} | ||
isDraggable={isDraggable} | ||
showArrows={showArrows} | ||
> | ||
<div style={{ backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ backgroundColor: 'var(--accent)' }} /> | ||
</Gallery> | ||
|
||
super(props); | ||
|
||
this.state = { | ||
slideIndex: 0, | ||
isDraggable: true, | ||
showArrows: true, | ||
} | ||
} | ||
|
||
render () { | ||
const { isDraggable, showArrows, slideIndex } = this.state | ||
return ( | ||
<View activePanel="gallery"> | ||
<Panel id="gallery"> | ||
<PanelHeader>Gallery</PanelHeader> | ||
<Group header={<Header mode="secondary">Sticks right</Header>}> | ||
<Gallery | ||
slideWidth="90%" | ||
style={{ height: 150 }} | ||
bullets="dark" | ||
> | ||
<div style={{ backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ backgroundColor: 'var(--accent)' }} /> | ||
</Gallery> | ||
</Group> | ||
<Group header={<Header mode="secondary">Sticks left</Header>}> | ||
<Gallery | ||
slideWidth="90%" | ||
align="right" | ||
style={{ height: 150 }} | ||
> | ||
<div style={{ backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ backgroundColor: 'var(--accent)' }} /> | ||
</Gallery> | ||
</Group> | ||
<Group header={<Header mode="secondary">Centered</Header>}> | ||
<Gallery | ||
slideWidth="90%" | ||
align="center" | ||
style={{ height: 150 }} | ||
> | ||
<div style={{ backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ backgroundColor: 'var(--accent)' }} /> | ||
</Gallery> | ||
</Group> | ||
<Group header={<Header mode="secondary">Custom width</Header>}> | ||
<Gallery | ||
slideWidth="custom" | ||
style={{ height: 150 }} | ||
> | ||
<div style={{ width: 200, backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ width: 120, backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ width: 70, backgroundColor: 'var(--accent)' }} /> | ||
<div style={{ width: 220, backgroundColor: 'var(--icon_secondary)' }} /> | ||
</Gallery> | ||
</Group> | ||
<Group header={<Header mode="secondary">Arrows</Header>}> | ||
<Gallery | ||
slideWidth="90%" | ||
style={{ height: 150 }} | ||
bullets="dark" | ||
showArrows | ||
> | ||
<div style={{ backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ backgroundColor: 'var(--accent)' }} /> | ||
</Gallery> | ||
</Group> | ||
<Group header={<Header mode="secondary">Controled</Header>}> | ||
<Gallery | ||
slideWidth="90%" | ||
align="center" | ||
style={{ height: 150 }} | ||
slideIndex={slideIndex} | ||
onChange={slideIndex => this.setState({slideIndex})} | ||
isDraggable={isDraggable} | ||
showArrows={showArrows} | ||
> | ||
<div style={{ backgroundColor: 'var(--destructive)' }} /> | ||
<div style={{ backgroundColor: 'var(--button_commerce_background)' }} /> | ||
<div style={{ backgroundColor: 'var(--accent)' }} /> | ||
</Gallery> | ||
|
||
<FormItem> | ||
<Checkbox checked={isDraggable} onChange={e => this.setState({ isDraggable: e.target.checked })}> | ||
isDraggable | ||
</Checkbox> | ||
<Checkbox checked={showArrows} onChange={e => this.setState({ showArrows: e.target.checked })}> | ||
showArrows | ||
</Checkbox> | ||
</FormItem> | ||
<FormItem> | ||
<Button size='l' stretched onClick={() => this.setState({ slideIndex: (slideIndex + 1) % 3 })}> | ||
Next slide | ||
</Button> | ||
</FormItem> | ||
</Group> | ||
</Panel> | ||
</View> | ||
) | ||
} | ||
} | ||
|
||
<Example /> | ||
<FormItem> | ||
<Checkbox checked={isDraggable} onChange={e => setIsDraggable(e.target.checked)}> | ||
isDraggable | ||
</Checkbox> | ||
<Checkbox checked={showArrows} onChange={e => setShowArrows(e.target.checked)}> | ||
showArrows | ||
</Checkbox> | ||
</FormItem> | ||
<FormItem> | ||
<Button size='l' stretched onClick={() => setSlideIndex((slideIndex + 1) % 3)}> | ||
Next slide | ||
</Button> | ||
</FormItem> | ||
</Group> | ||
</Panel> | ||
</View> | ||
``` |
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,9 @@ | ||
import React from 'react'; | ||
|
||
export function useUnmountCleanup(cleanup: VoidFunction) { | ||
const cleanupRef = React.useRef(cleanup); | ||
React.useEffect(() => { | ||
cleanupRef.current = cleanup; | ||
}); | ||
React.useEffect(() => () => cleanupRef.current(), []); | ||
} |