{packet.name}
{packet.when}
{packet.heirloom &&{pill(packet.heirloom)}
}{packet.detail}
{packet.past && Past sow-by}import React, {useEffect, useRef, useState} from 'react';
// How long the packets take to fold back into the pile, in ms. Matches the
// seed-group-close animation in _seeds.scss.
const CLOSE_MS = 260;
const pill = (heirloom) => heirloom && (
{heirloom.charAt(0).toUpperCase() + heirloom.slice(1)}
);
// The owner's avatar, small, beside a pile on a page of other people's seeds.
const Owner = ({owner}) => owner && (
);
// Several packets of one variety. Closed, they are a pile with a count on top;
// opened, the pile spreads out where it stood, one packet each, to pick from.
// Rails renders the top packet first (see seeds/_stack), so there is something
// to see before this loads and without JavaScript.
export default function SeedStack({crop, count, image_url: imageUrl, heirloom, rule, packets, owner}) {
const [state, setState] = useState('closed');
const toggle = useRef(null);
const closeTimer = useRef(null);
useEffect(() => () => clearTimeout(closeTimer.current), []);
const open = () => setState('open');
const close = () => {
setState('closing');
closeTimer.current = setTimeout(() => {
setState('closed');
toggle.current?.focus();
}, CLOSE_MS);
};
if (state === 'closed') {
return (
{packet.when}
{packet.heirloom &&{pill(packet.heirloom)}
}{packet.detail}
{packet.past && Past sow-by}