Skip to content

Commit

Permalink
Merge pull request #965 from nature-of-code/dev/mobile-purchase-button
Browse files Browse the repository at this point in the history
Add purchase button to the index page on mobile
  • Loading branch information
shiffman authored May 27, 2024
2 parents 3d63a4d + fc269e3 commit 6f1709a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/components/PurchaseButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const links = [
},
];

const PurchaseButton = () => {
const PurchaseButton = ({ aligned = 'right', className }) => {
const [isOpen, setIsOpen] = useState(false);
const dropdownRef = useRef(null);

Expand Down Expand Up @@ -45,7 +45,7 @@ const PurchaseButton = () => {
}, []);

return (
<div className="relative" ref={dropdownRef}>
<div className={`not-prose relative ${className}`} ref={dropdownRef}>
<button
aria-haspopup="true"
aria-expanded={isOpen}
Expand All @@ -59,7 +59,9 @@ const PurchaseButton = () => {
</button>

{isOpen && (
<ul className="absolute right-0 z-50 mt-1 w-40 divide-y rounded-xl border border-noc-200 bg-white">
<ul
className={`absolute ${aligned === 'right' ? 'right-0' : 'left-0'} z-50 mt-1 w-40 divide-y rounded-xl border border-noc-200 bg-white`}
>
{links.map((link) => (
<li key={link.href} className="border-noc-200">
<a
Expand Down
22 changes: 20 additions & 2 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { StaticImage } from 'gatsby-plugin-image';

import SideNavLayout from '../layouts/SideNavLayout';
import PurchaseButton from '../components/PurchaseButton';

export default function IndexPage() {
return (
Expand All @@ -11,8 +12,25 @@ export default function IndexPage() {
width={1200}
alt="nature of code book cover"
/>
<div className='my-8'>
Hi there! Welcome to The Nature of Code! Ever wondered how the unpredictable evolutionary and emergent properties of nature can be captured in a digital canvas, all through the magic of code? Running right in your browser! That’s exactly what this book is all about! You can read the whole thing right here, thank you to Creative Commons! If this project sparks joy and want to support it, you can <a href="https://github.com/sponsors/CodingTrain">sponsor on GitHub</a> or grab a copy of an artfully bound version of processed cellulose fibers, imprinted with symbolic glyphs via pigment-based transfer particles, available at <a href="https://nostarch.com/nature-code">No Starch Press</a> and <a href="https://www.amazon.com/Nature-Code-Daniel-Shiffman/dp/1718503709">other places where people buy books</a>. Don't forget to touch grass!

<PurchaseButton className="my-6 lg:hidden" aligned="left" />

<div className="my-6">
Hi there! Welcome to The Nature of Code! Ever wondered how the
unpredictable evolutionary and emergent properties of nature can be
captured in a digital canvas, all through the magic of code? Running
right in your browser! That’s exactly what this book is all about! You
can read the whole thing right here, thank you to Creative Commons! If
this project sparks joy and want to support it, you can{' '}
<a href="https://github.com/sponsors/CodingTrain">sponsor on GitHub</a>{' '}
or grab a copy of an artfully bound version of processed cellulose
fibers, imprinted with symbolic glyphs via pigment-based transfer
particles, available at{' '}
<a href="https://nostarch.com/nature-code">No Starch Press</a> and{' '}
<a href="https://www.amazon.com/Nature-Code-Daniel-Shiffman/dp/1718503709">
other places where people buy books
</a>
. Don't forget to touch grass!
</div>
</SideNavLayout>
);
Expand Down

0 comments on commit 6f1709a

Please sign in to comment.