diff --git a/packages/policy/src/index.js b/packages/policy/src/index.js index 51562a3..c3ac63d 100644 --- a/packages/policy/src/index.js +++ b/packages/policy/src/index.js @@ -4,6 +4,7 @@ const applyConfig = (config) => { // glossary tooltips config.settings.glossary.caseSensitive = false; config.settings.glossary.matchOnlyFirstOccurence = false; + config.settings.glossary.showAlphabetNavigation = true; // Tooltips everywhere config.settings.appExtras = [ diff --git a/packages/volto-slate-glossary/news/11.feature b/packages/volto-slate-glossary/news/11.feature index f7b92bd..1b733bc 100644 --- a/packages/volto-slate-glossary/news/11.feature +++ b/packages/volto-slate-glossary/news/11.feature @@ -1,3 +1 @@ -When viewing a Glossary, show an alphabet at the top. -Clicking a letter scrolls the entries for that letter into view. -@mauritsvanrees +Show an alphabet navigation on glossary. Clicking a letter scrolls the entries for this 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 68f4601..8f854ae 100644 --- a/packages/volto-slate-glossary/src/components/GlossaryView.jsx +++ b/packages/volto-slate-glossary/src/components/GlossaryView.jsx @@ -1,9 +1,15 @@ import React from 'react'; import { Link } from 'react-router-dom'; +import { Container } from 'semantic-ui-react'; import { useSelector, useDispatch } from 'react-redux'; +import cx from 'classnames'; import { getGlossaryTerms } from '../actions'; +import config from '@plone/volto/registry'; const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; +const showAlphabetNavigation = + config.settings?.glossary?.showAlphabetNavigation || true; + const GlossaryView = ({ content }) => { const dispatch = useDispatch(); const pathname = useSelector((state) => state.router.location.pathname); @@ -12,41 +18,49 @@ const GlossaryView = ({ content }) => { dispatch(getGlossaryTerms()); }, [dispatch, pathname]); - let glossaryentries = useSelector( + const glossaryentries = useSelector( (state) => state.glossaryterms.result.items, ); + const lettersWithTerm = Object.keys(glossaryentries || {}); return ( -
-
-

{content.title}

- {content.description && ( -

{content.description}

- )} + +
+
+

{content.title}

+ {content.description && ( +

{content.description}

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

{letter}

-
+

+ {letter} +

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

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

))}
-
-
+ + ); }; diff --git a/packages/volto-slate-glossary/src/components/glossarytooltips.less b/packages/volto-slate-glossary/src/components/glossarytooltips.less index 62b713d..c47a483 100644 --- a/packages/volto-slate-glossary/src/components/glossarytooltips.less +++ b/packages/volto-slate-glossary/src/components/glossarytooltips.less @@ -21,6 +21,15 @@ background: #963c38; color: white; } +.glossary-view .glossaryAlphabet { + padding: 1em 0; + .alphabetLetter { + padding-right: 0.3em; + &.unmatched { + filter: opacity(0.5); + } + } +} .term h3 { span { font-size: 80%; diff --git a/packages/volto-slate-glossary/src/index.js b/packages/volto-slate-glossary/src/index.js index 6568c9d..3cc4670 100644 --- a/packages/volto-slate-glossary/src/index.js +++ b/packages/volto-slate-glossary/src/index.js @@ -8,6 +8,7 @@ const applyConfig = (config) => { config.settings.glossary = { caseSensitive: false, matchOnlyFirstOccurence: false, + showAlphabetNavigation: true, }; config.settings.slate.leafs = {