Skip to content

Commit

Permalink
wip: basic image with arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
roadlittledawn committed Jun 21, 2021
1 parent 7780b79 commit 1b0951c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/@newrelic/gatsby-theme-newrelic/icons/feather.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export default {
/>
</>
),
'chevron-right': (
<>
<polyline points="9 18 15 12 9 6" />
</>
),
clock: (
<>
<circle cx="12" cy="12" r="10" />
Expand Down
76 changes: 76 additions & 0 deletions src/components/ImageSlider/ImageSlider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import PropTypes from 'prop-types';
import React, { useState } from 'react';
import { css } from '@emotion/react';
import { Icon } from '@newrelic/gatsby-theme-newrelic';

const ImageSlider = ({ images, height }) => {
const [selectedImageIndex, setSelectedImageIndex] = useState(0);

const handleClickNext = () => {
const nextImageIndex = selectedImageIndex + 1;
setSelectedImageIndex(nextImageIndex % images.length);
};

return (
<div
css={css`
position: relative;
margin-bottom: 2rem;
`}
>
<button
onClick={handleClickNext}
css={css`
position: absolute;
top: 38%;
right: 0;
background: none;
color: var(--color-white);
border: none;
cursor: pointer;
`}
>
<Icon name="chevron-right" size="4rem" />
</button>
{CreateImageBlock(images[selectedImageIndex], height)}
</div>
);
};

ImageSlider.propTypes = {
images: PropTypes.array,
height: PropTypes.number,
};

const CreateImageBlock = (image, height) => {
return (
<a
href={image}
target="_blank"
rel="noreferrer"
css={css`
height: ${height}px;
width: 100%;
margin-right: 1rem;
`}
>
<img
src={image}
alt="placeholder-text"
css={css`
height: ${height}px;
width: 100%;
box-sizing: border-box;
box-shadow: inset 0px 0px 0px 4px var(--divider-color);
border-radius: 4px;
padding: 0.25rem;
`}
/>
</a>
);
};

const noImagePlaceholder =
'https://socialistmodernism.com/wp-content/uploads/2017/07/placeholder-image.png';

export default ImageSlider;
6 changes: 2 additions & 4 deletions src/templates/ObservabilityPackDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import ImageGallery from '../components/ImageGallery';
import Intro from '../components/Intro';
import InstallButton from '../components/InstallButton';
import ImageSlider from '../components/ImageSlider/ImageSlider';

const ObservabilityPackDetails = ({ data, location }) => {
const pack = data.observabilityPacks;
Expand Down Expand Up @@ -134,7 +135,7 @@ const ObservabilityPackDetails = ({ data, location }) => {
{pack.dashboards?.map((dashboard) => (
<>
<h3>{dashboard.name}</h3>
<ImageGallery images={dashboard.screenshots} />
<ImageSlider height={400} images={dashboard.screenshots} />
{dashboard.description && (
<>
<h4>Description</h4>
Expand Down Expand Up @@ -267,11 +268,8 @@ export const pageQuery = graphql`
query($id: String!) {
observabilityPacks(id: { eq: $id }) {
name
websiteUrl
logoUrl
level
id
iconUrl
description
dashboards {
description
Expand Down

0 comments on commit 1b0951c

Please sign in to comment.