Skip to content

Commit

Permalink
Merge pull request #29 from eneskaya12/enes
Browse files Browse the repository at this point in the history
add react-awesome-lightbox
  • Loading branch information
altaysimsek authored May 2, 2023
2 parents 2be37cb + 74de02f commit adbac48
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 237 deletions.
17 changes: 16 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"nextra": "^2.0.0-beta.5",
"nextra-theme-blog": "^2.0.0-beta.5",
"react": "^17.0.2",
"react-awesome-lightbox": "^1.8.1",
"react-dom": "^17.0.2",
"rss": "^1.2.2"
},
Expand Down
10 changes: 9 additions & 1 deletion pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import 'nextra-theme-blog/style.css'
import Head from 'next/head'
import { MDXProvider } from '@mdx-js/react'
import CenteredImageLightbox from './components/CenteredImageLightbox';

import '../styles/main.css'

const mdxComponents = {
CenteredImageLightbox,
}

export default function Nextra({ Component, pageProps }) {
return (
<>
Expand All @@ -21,7 +27,9 @@ export default function Nextra({ Component, pageProps }) {
crossOrigin="anonymous"
/>
</Head>
<Component {...pageProps} />
<MDXProvider components={mdxComponents}>
<Component {...pageProps} />
</MDXProvider>
</>
)
}
29 changes: 29 additions & 0 deletions pages/components/CenteredImageLightbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useState } from 'react';
import Lightbox from 'react-awesome-lightbox';
import 'react-awesome-lightbox/build/style.css';

const CenteredImageLightbox = ({ src, alt, width, ...rest }) => {
const [isOpen, setIsOpen] = useState(false);

const handleClick = () => {
setIsOpen(!isOpen);
};

return (
<>
<div style={{ textAlign: 'center' }} onClick={handleClick}>
<img src={src} alt={alt} width={width} {...rest} style={{ cursor: 'pointer' }} />
</div>
{isOpen && (
<Lightbox
image={src}
alt={alt}
title={alt}
onClose={() => setIsOpen(false)}
/>
)}
</>
);
};

export default CenteredImageLightbox;
Loading

0 comments on commit adbac48

Please sign in to comment.