diff --git a/packages/volto-slate-glossary/news/11.feature b/packages/volto-slate-glossary/news/11.feature new file mode 100644 index 0000000..f7b92bd --- /dev/null +++ b/packages/volto-slate-glossary/news/11.feature @@ -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 diff --git a/packages/volto-slate-glossary/src/components/GlossaryView.jsx b/packages/volto-slate-glossary/src/components/GlossaryView.jsx index b3df2d4..68f4601 100644 --- a/packages/volto-slate-glossary/src/components/GlossaryView.jsx +++ b/packages/volto-slate-glossary/src/components/GlossaryView.jsx @@ -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); @@ -17,18 +17,36 @@ const GlossaryView = ({ content }) => { ); return ( - -
-
-

{content.title}

- {content.description && ( -

{content.description}

- )} -
-
+
+
+

{content.title}

+ {content.description && ( +

{content.description}

+ )} + +
+ {alphabet.split('').map((letter) => ( + { + document + .getElementById(letter) + ?.scrollIntoView({ behavior: 'smooth' }); + }} + > + {letter} + + ))} +
+ +
{Object.keys(glossaryentries || {})?.map((letter) => (
-

{letter}

+ +

{letter}

+
{glossaryentries[letter].map((item) => (

@@ -50,8 +68,8 @@ const GlossaryView = ({ content }) => {

))}
-
-
+ + ); };