-
Notifications
You must be signed in to change notification settings - Fork 1
63 aurora slots tags #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
63 aurora slots tags #112
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| --- | ||
| myst: | ||
| html_meta: | ||
| "description": "How to hide or replace the tags (subjects) shown below content in Plone Aurora" | ||
| "property=og:description": "How to hide or replace the tags (subjects) shown below content in Plone Aurora" | ||
| "property=og:title": "Customize the content tags" | ||
| "keywords": "Plone Aurora, tags, subjects, slot, belowContent" | ||
| --- | ||
|
|
||
| # Customize the content tags | ||
|
|
||
| Plone Aurora renders a content item's tags (its `subjects`) below the content as links to the search. | ||
| The tags come from a slot component registered for the `belowContent` slot. | ||
| This guide shows you how to hide or replace them. | ||
|
|
||
| ## Hide the tags | ||
|
|
||
| Set `showTags` to `false` in your add-on configuration to hide the tags on every page. | ||
|
|
||
| ```ts | ||
| import type { ConfigType } from '@plone/registry'; | ||
|
|
||
| export default function install(config: ConfigType) { | ||
| config.settings.showTags = false; | ||
| return config; | ||
| } | ||
| ``` | ||
|
|
||
| The slot renders the tags whenever an item has `subjects`, unless `showTags` is `false`. | ||
|
|
||
| ## Replace the tags component | ||
|
|
||
| Register your own component for the `belowContent` slot under the same name to override the default. | ||
|
|
||
| ```ts | ||
| import type { ConfigType } from '@plone/registry'; | ||
| import MyTags from './MyTags'; | ||
|
|
||
| export default function install(config: ConfigType) { | ||
| config.registerSlotComponent({ | ||
| name: 'Tags', | ||
| slot: 'belowContent', | ||
| component: MyTags, | ||
| }); | ||
| return config; | ||
| } | ||
| ``` | ||
|
|
||
| Your component receives the slot props, including `content`, from which you can read `content.subjects`. | ||
| To learn how slots work in general, refer to {doc}`register-slots`. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added a Tags (Subjects) slot that renders a content item's tags below the content as links to the search. @nils-pzr |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| @layer custom { | ||
| .tags { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| margin-top: 16px; | ||
| gap: 8px; | ||
| } | ||
|
|
||
| .tag { | ||
| padding: 4px 12px; | ||
| border-radius: 9999px; | ||
| background: var(--quanta-azure); | ||
| color: var(--quanta-puya); | ||
|
Comment on lines
+12
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not meet minimum contrast requirements. Not sure if that's a concern for the layout package, but if swapped with a |
||
| font-size: 0.875rem; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| .tag:hover { | ||
| opacity: 0.8; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { MemoryRouter } from 'react-router'; | ||
| import Tags from './Tags'; | ||
|
|
||
| const renderTags = (subjects: string[]) => | ||
| render( | ||
| <MemoryRouter> | ||
| <Tags | ||
| content={{ subjects } as never} | ||
| location={{ pathname: '/' } as never} | ||
| /> | ||
| </MemoryRouter>, | ||
| ); | ||
|
|
||
| describe('Tags slot', () => { | ||
| it('renders nothing when there are no tags', () => { | ||
| const { container } = renderTags([]); | ||
| expect(container).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| it('renders a search link for each tag', () => { | ||
| renderTags(['News', 'Plone & Co']); | ||
| expect(screen.getByRole('link', { name: 'News' })).toHaveAttribute( | ||
| 'href', | ||
| '/search?Subject=News', | ||
| ); | ||
| expect(screen.getByRole('link', { name: 'Plone & Co' })).toHaveAttribute( | ||
| 'href', | ||
| '/search?Subject=Plone%20%26%20Co', | ||
| ); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||
| import { Link } from 'react-router'; | ||||||
| import { useTranslation } from 'react-i18next'; | ||||||
| import config from '@plone/registry'; | ||||||
| import type { SlotComponentProps } from '../SlotRenderer'; | ||||||
| import SectionWrapper from '../../components/SectionWrapper/SectionWrapper'; | ||||||
| import styles from './Tags.module.css'; | ||||||
|
|
||||||
| const Tags = (props: SlotComponentProps) => { | ||||||
| const { t } = useTranslation(); | ||||||
| const tags = (props.content?.subjects ?? []) as string[]; | ||||||
|
|
||||||
| if (config.settings.showTags === false || tags.length === 0) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified. Not a big deal, but this is enough for my IDE to spit out a warning.
Suggested change
|
||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| return ( | ||||||
| <SectionWrapper as="nav" width="layout" aria-label={t('layout.tags.label')}> | ||||||
| <div className={styles.tags}> | ||||||
| {tags.map((tag) => ( | ||||||
| <Link | ||||||
| key={tag} | ||||||
| to={`/search?Subject=${encodeURIComponent(tag)}`} | ||||||
| className={styles.tag} | ||||||
| > | ||||||
| {tag} | ||||||
| </Link> | ||||||
| ))} | ||||||
| </div> | ||||||
|
Comment on lines
+18
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be a candidate for a |
||||||
| </SectionWrapper> | ||||||
| ); | ||||||
| }; | ||||||
|
|
||||||
| export default Tags; | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ok. However, since the
Tagsare registered slot components, the same can be achieved by just unregistering theTagsslot component. That would also render this documentation unnecessary, "debloating" the docs. What do you think @pnicolli ?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense if we point this to the slots docs in some way so people can find those easily while reading this.
@sneridagh ?