Skip to content

Commit

Permalink
When viewing a Glossary, show an alphabet at the top.
Browse files Browse the repository at this point in the history
Clicking a letter scrolls the entries for that letter into view.
  • Loading branch information
mauritsvanrees authored and ksuess committed Oct 25, 2024
1 parent 553b5db commit 0bd29de
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
3 changes: 3 additions & 0 deletions packages/volto-slate-glossary/news/11.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
When viewing a Glossary, show an alphabet at the top.
Clicking a letter scrolls the entries for that letter into view.
@mauritsvanrees
44 changes: 31 additions & 13 deletions packages/volto-slate-glossary/src/components/GlossaryView.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { Link } from 'react-router-dom';
import { Container } from 'semantic-ui-react';
import { useSelector, useDispatch } from 'react-redux';
import { getGlossaryTerms } from '../actions';

const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const GlossaryView = ({ content }) => {
const dispatch = useDispatch();
const pathname = useSelector((state) => state.router.location.pathname);
Expand All @@ -17,18 +17,36 @@ const GlossaryView = ({ content }) => {
);

return (
<Container className="view-wrapper">
<article id="content">
<header>
<h1 className="documentFirstHeading">{content.title}</h1>
{content.description && (
<p className="documentDescription">{content.description}</p>
)}
</header>
<section id="content-core" className="glossary">
<div id="page-document" className="q-container">
<div className="blocks-group-wrapper transparent">
<h1 className="documentFirstHeading">{content.title}</h1>
{content.description && (
<p className="documentDescription">{content.description}</p>
)}

<div className="glossaryAlphabet">
{alphabet.split('').map((letter) => (
<Link
key={letter}
to={'#' + letter}
className="alphabetLetter"
onClick={() => {
document
.getElementById(letter)
?.scrollIntoView({ behavior: 'smooth' });
}}
>
<span>{letter}</span>
</Link>
))}
</div>

<section className="glossary">
{Object.keys(glossaryentries || {})?.map((letter) => (
<div key={letter}>
<h2 className="letter">{letter}</h2>
<a id={letter} anchor={letter} href={false}>
<h2 className="letter">{letter}</h2>
</a>
{glossaryentries[letter].map((item) => (
<article className="term" key={item['@id']}>
<h3>
Expand All @@ -50,8 +68,8 @@ const GlossaryView = ({ content }) => {
</div>
))}
</section>
</article>
</Container>
</div>
</div>
);
};

Expand Down

0 comments on commit 0bd29de

Please sign in to comment.