Skip to content

Commit 5e01ce5

Browse files
Merge pull request #79 from TobitSoftware/feature/gallery
Feature/gallery
2 parents 12d15ba + 5c31ba6 commit 5e01ce5

File tree

12 files changed

+319
-0
lines changed

12 files changed

+319
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The following components are part of this package:
2525
| [react-chayns-contextmenu](/src/react-chayns-contextmenu/) | ContextMenu Component | [Readme](/src/react-chayns-contextmenu/README.md) |
2626
| [react-chayns-detail-view](/src/react-chayns-detail-view/) | DetailView Component | [Readme](/src/react-chayns-detail-view/README.md) |
2727
| [react-chayns-emoji_input](/src/react-chayns-emoji_input/) | EmojiInput Component | [Readme](/src/react-chayns-emoji_input/README.md) |
28+
| [react-chayns-gallery](/src/react-chayns-gallery/) | Gallery Component | [Readme](/src/react-chayns-gallery/README.md) |
2829
| [react-chayns-gridcalendar](/src/react-chayns-gridcalendar/) | GridCalendar Component | [Readme](/src/react-chayns-gridcalendar/README.md) |
2930
| [react-chayns-input](/src/react-chayns-input/) | Input Component | [Readme](/src/react-chayns-input/README.md) |
3031
| [react-chayns-modeswitch](/src/react-chayns-modeswitch/) | ModeSwitch Component (React + ES6) | [Readme](/src/react-chayns-modeswitch/README.md) |

examples/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</head>
1313
<body>
1414
<div class="tapp">
15+
1516
<div id="react-chayns-accordion"></div>
1617
<div id="react-chayns-amountcontrol"></div>
1718
<div id="react-chayns-animations"></div>
@@ -21,6 +22,7 @@
2122
<div id="react-chayns-contextmenu"></div>
2223
<div id="react-chayns-detail_view"></div>
2324
<div id="react-chayns-emoji_input"></div>
25+
<div id="react-chayns-gallery"></div>
2426
<div id="react-chayns-gridcalendar"></div>
2527
<div id="react-chayns-input"></div>
2628
<div id="react-chayns-modeswitch"></div>

examples/index.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import './react-chayns-checkbox/index';
77
import './react-chayns-contextmenu/index';
88
import './react-chayns-detail_view/index';
99
import './react-chayns-emoji_input/index';
10+
import './react-chayns-gallery/index';
1011
import './react-chayns-gridcalendar/index';
1112
import './react-chayns-input/index';
1213
import './react-chayns-modeswitch/index';
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
3+
import '../../src/react-chayns-gallery/index.scss';
4+
import ExampleContainer from '../ExampleContainer';
5+
import Gallery from '../../src/react-chayns-gallery/component/Gallery';
6+
7+
8+
export default class Example extends React.Component {
9+
constructor() {
10+
super();
11+
}
12+
13+
14+
render() {
15+
const urls = ['https://tsimg.space/v1/images/6ffbd340-a77b-e811-80d6-0025905a8161.jpg',
16+
'https://tsimg.space/v1/images/c9a8d7ad-ee72-e811-80d6-0025905a8161.jpg',
17+
'https://tsimg.space/v1/images/416b53f0-ee72-e811-80d6-0025905a8161.jpg',
18+
'https://tsimg.space/v1/images/416b53f0-ee72-e811-80d6-0025905a8161.jpg'];
19+
return(
20+
<ExampleContainer headline="Gallery">
21+
<div style={{ marginTop: '30px' }}>
22+
<Gallery urls={[urls[0]]} />
23+
</div>
24+
25+
<div style={{ marginTop: '30px' }}>
26+
<Gallery urls={[urls[0], urls[1]]} />
27+
</div>
28+
29+
<div style={{ marginTop: '30px' }}>
30+
<Gallery urls={[urls[0], urls[1], urls[3]]} />
31+
</div>
32+
33+
<div style={{ marginTop: '30px' }}>
34+
<Gallery urls={urls} />
35+
</div>
36+
37+
<div style={{ marginTop: '30px' }}>
38+
<Gallery urls={urls} onlyIcon />
39+
</div>
40+
41+
<div style={{ marginTop: '30px' }}>
42+
<Gallery
43+
urls={urls}
44+
onlyIcon
45+
onClick={console.log}
46+
/>
47+
</div>
48+
</ExampleContainer>
49+
);
50+
}
51+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import ReactDom from 'react-dom';
3+
4+
import Example from './Example';
5+
6+
window.chayns.ready.then(() => {
7+
ReactDom.render(
8+
<Example />,
9+
document.querySelector('#react-chayns-gallery')
10+
);
11+
});

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import DetailViewHeader from './react-chayns-detail_view/component/DetailViewHea
2222
import DetailViewFooter from './react-chayns-detail_view/component/DetailViewFooter';
2323

2424
import EmojiInput from './react-chayns-emoji_input/component/EmojiInput';
25+
import Gallery from './react-chayns-gallery/component/Gallery';
2526
import GridCalendar from './react-chayns-gridcalendar/component/GridCalendar';
2627
import Input from './react-chayns-input/component/Input';
2728

@@ -85,6 +86,7 @@ export {
8586
DetailViewHeader,
8687
DetailViewFooter,
8788
EmojiInput,
89+
Gallery,
8890
GridCalendar,
8991
Input,
9092
ModeSwitch,

src/react-chayns-gallery/README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Gallery
2+
3+
The Gallery is part of the *chayns-components* package. It can be installed via npm:
4+
5+
npm install -S chayns-components@latest
6+
7+
8+
## Usage of the Gallery
9+
The input has to be imported:
10+
11+
```jsx
12+
import { Gallery } from 'chayns-components';
13+
import 'chayns-components/lib/react-chayns-gallery/index.css';
14+
```
15+
16+
17+
You can use the input like this:
18+
```jsx
19+
<Gallery
20+
urls={['https://tsimg.space/v1/images/6ffbd340-a77b-e811-80d6-0025905a8161.jpg',
21+
'https://tsimg.space/v1/images/c9a8d7ad-ee72-e811-80d6-0025905a8161.jpg',
22+
'https://tsimg.space/v1/images/416b53f0-ee72-e811-80d6-0025905a8161.jpg',
23+
'https://tsimg.space/v1/images/416b53f0-ee72-e811-80d6-0025905a8161.jpg']}
24+
onlyIcon
25+
/>
26+
```
27+
28+
29+
## Props
30+
The following properties can be set on the Gallery-Component
31+
32+
| **Property** | **Description** | **Type** | **Default Value** | **Required** |
33+
| ------------ | ---------------------------------------------------- | -------- | ----------------- | ------------ |
34+
| urls | The Images which should be displayed | array | | true |
35+
| onlyIcon | Show only an icon, if there is more then three images| bool | false | |
36+
| onClick | Called when clicked on a image | func | chayns.openImage | |
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import MoreImages from './MoreImages';
4+
import ImageContainer from './ImageContainer';
5+
6+
export default class Gallery extends React.Component {
7+
static propTypes = {
8+
urls: PropTypes.array.isRequired,
9+
onlyIcon: PropTypes.bool,
10+
onClick: PropTypes.func
11+
12+
};
13+
static defaultProps = {
14+
onlyIcon: false,
15+
onClick: chayns.openImage
16+
};
17+
18+
constructor() {
19+
super();
20+
this.openFirstImage = this.openGallery.bind(this, 0);
21+
this.openSecondImage = this.openGallery.bind(this, 1);
22+
this.openThirdImage = this.openGallery.bind(this, 2);
23+
}
24+
25+
openGallery(start) {
26+
this.props.onClick(this.props.urls, start);
27+
}
28+
29+
render() {
30+
const { urls, onlyIcon } = this.props;
31+
const count = urls.length;
32+
33+
return (
34+
<div className="chayns-gallery" >
35+
<div className="gallery-grid">
36+
<ImageContainer
37+
className="gallery_item"
38+
url={urls[0]}
39+
onClick={this.openFirstImage}
40+
/>
41+
{(count > 1) && (
42+
<ImageContainer
43+
className="gallery_item"
44+
url={urls[1]}
45+
onClick={this.openSecondImage}
46+
/>
47+
)}
48+
{(count > 2) && (
49+
<ImageContainer
50+
className="gallery_item"
51+
url={urls[2]}
52+
onClick={this.openThirdImage}
53+
>
54+
{(count > 3) && (
55+
<MoreImages
56+
count={count - 3}
57+
onlyIcon={onlyIcon}
58+
/>
59+
)}
60+
</ImageContainer>
61+
)}
62+
</div>
63+
</div>
64+
);
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-disable jsx-a11y/click-events-have-key-events */
2+
import React from 'react';
3+
import PropTypes from 'prop-types';
4+
5+
6+
const ImageContainer = ({
7+
className,
8+
url,
9+
onClick,
10+
children,
11+
}) => {
12+
return(
13+
<div className={className}>
14+
<div
15+
className="gallery_item_inner"
16+
style={{ backgroundImage: `url(${url})` }}
17+
onClick={onClick}
18+
>
19+
{children}
20+
</div>
21+
</div>
22+
);
23+
};
24+
25+
ImageContainer.propTypes = {
26+
className: PropTypes.string.isRequired,
27+
url: PropTypes.string.isRequired,
28+
onClick: PropTypes.func.isRequired,
29+
children: PropTypes.element
30+
};
31+
32+
ImageContainer.defaultProps = {
33+
children: undefined
34+
};
35+
36+
export default ImageContainer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
5+
const MoreImages = ({ count, onlyIcon }) => {
6+
const text = `${count} weitere Bilder`;
7+
return(
8+
<div className="more-images">
9+
<div className="more-images__container">
10+
<div className="more-image__text__wrapper">
11+
<i className="more-image__icon fa fa-plus"/>
12+
{(!onlyIcon) && (
13+
<div className="more-image__text">
14+
{text}
15+
</div>
16+
)}
17+
</div>
18+
</div>
19+
</div>
20+
);
21+
};
22+
23+
MoreImages.propTypes = {
24+
count: PropTypes.number.isRequired,
25+
onlyIcon: PropTypes.bool
26+
};
27+
28+
MoreImages.defaultProps = {
29+
onlyIcon: false
30+
};
31+
32+
export default MoreImages;

src/react-chayns-gallery/index.scss

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
.chayns-gallery {
2+
position: relative;
3+
width: 100%;
4+
padding-top: 428px;
5+
6+
.chayns--mobile & {
7+
padding-top: 256px;
8+
}
9+
10+
.gallery-grid{
11+
display: flex;
12+
flex-flow: column;
13+
position: absolute;
14+
flex-wrap: wrap;
15+
top: 0;
16+
right: 0;
17+
bottom: 0;
18+
left: 0;
19+
.gallery_item {
20+
height: 50%;
21+
.gallery_item_inner {
22+
height: 100%;
23+
background-size: cover;
24+
background-position: center center;
25+
background-repeat: no-repeat;
26+
}
27+
28+
}
29+
.gallery_item:nth-child(1) {
30+
height: 100%;
31+
padding-right: 1%;
32+
&:nth-last-child(1){
33+
padding: 0;
34+
}
35+
}
36+
.gallery_item:nth-child(2) {
37+
padding: 0 0 1% 1%;
38+
&:nth-last-child(1){
39+
height: 100%;
40+
padding: 0 0 0 1%;
41+
}
42+
}
43+
.gallery_item:nth-child(3) {
44+
padding: 1% 0 0 1%;
45+
}
46+
}
47+
.more-images {
48+
position: relative;
49+
width: 100%;
50+
height: 100%;
51+
overflow: hidden;
52+
.more-images__container {
53+
width: 100%;
54+
height: 100%;
55+
position: absolute;
56+
background-color: rgba(0, 0, 0, 0.4);
57+
display: flex;
58+
justify-content: center;
59+
align-items: center;
60+
.more-image__text__wrapper {
61+
text-align: center;
62+
.more-image__text {
63+
color: rgba(255, 255, 255, 0.8);;
64+
text-align: center;
65+
font-size: 14px;
66+
margin-top: 5px;
67+
}
68+
.more-image__icon:before {
69+
color: rgba(255, 255, 255, 0.8);;
70+
display: flex;
71+
justify-content: center;
72+
align-items: center;
73+
content: '\f067';
74+
font-size: 30px;
75+
}
76+
}
77+
}
78+
}
79+
}

src/utils/babel/resolveAbsoluteImport.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = function resolveAbsoluteImport(importName) {
1919
DetailViewFooter: 'react-chayns-detail_view/component/DetailViewFooter.js',
2020
DetailViewGroup: 'react-chayns-detail_view/component/DetailViewGroup.js',
2121
EmojiInput: 'react-chayns-emoji_input/component/EmojiInput.js',
22+
Gallery: 'react-chayns-gallery/component/Gallery.js',
2223
GridCalendar: 'react-chayns-gridcalendar/component/GridCalendar.js',
2324
Input: 'react-chayns-input/component/Input.js',
2425
ModeSwitch: 'react-chayns-modeswitch/component/ModeSwitch.js',

0 commit comments

Comments
 (0)