-
-
Notifications
You must be signed in to change notification settings - Fork 889
6653 contenttype menu #8032
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
Open
arybakov05
wants to merge
30
commits into
seven
Choose a base branch
from
6653-contenttype_menu
base: seven
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
6653 contenttype menu #8032
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
2da629e
use react-aria 3.47.0
arybakov05 ddf08e2
add content type icon mapping to config
arybakov05 bd73eed
specify contentIcon type
arybakov05 50e8e9b
use types apiExpander when logged in
arybakov05 22462dc
replace plugs with slots, use portal provider so toolbar overlays are…
arybakov05 2e57560
correct the GetTypesResponse type
arybakov05 83f9ad5
added NotRouteCondition helper
arybakov05 6519d69
added ContentFolderishCondition helper
arybakov05 10e63c2
added ToolbarMenu wrapper to handle shadow dom stuff
arybakov05 3281f91
added contenttypes menu, toolbar cleanup
arybakov05 3fe8c3a
change import path
arybakov05 626915c
add missing svg type declarations
arybakov05 e0d64d2
Merge branch 'refs/heads/seven' into 6653-contenttype_menu
arybakov05 645db43
added translations
arybakov05 6e8eee7
update docs
arybakov05 4b5feef
clean up a little
arybakov05 0f50287
make popovers in the toolbar wider
arybakov05 b2e351b
fix typescript errors for svgs
arybakov05 f8341a4
use @plone/components menu for toolbarmenu
arybakov05 2fc531a
added news
arybakov05 2e4132a
gitignore auto generated files
arybakov05 5da049f
fix route conditions
arybakov05 9240a9e
small docs improvements
arybakov05 c2ad148
added toolbar customization docs
arybakov05 3f2e9ab
use slots instead of plugs for toolbar components
arybakov05 b108cde
update outdated jsdoc
arybakov05 6b35555
clean up docs
arybakov05 18cb271
fix vale suggestions and warnings
arybakov05 12e4c89
added missing italian translations (ai generated)
arybakov05 4d51d80
remove eslint ignore statements
arybakov05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Use `types` API expander when token is available. | ||
| Added automatically generated files to `.gitignore` @arybakov05 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| myst: | ||
| html_meta: | ||
| "description": "How to access and modify the configuration regisrey" | ||
| "property=og:description": "How to access and modify the configuration registry" | ||
| "property=og:title": "Customize Seven using the configuration registry" | ||
| "keywords": "Seven, @plone/registry, registry, configuration" | ||
| --- | ||
|
|
||
| # Customize Seven using the configuration registry | ||
|
|
||
| The registry is the central place for configuring your Seven application. | ||
| Configuration is typically located either in the index.ts file at the add-ons root level or in config/settings.ts. | ||
| In this file, you can modify existing entries or add new ones as needed. | ||
|
|
||
| ```ts | ||
| import type { ConfigType } from '@plone/registry'; | ||
| import MyBlockInfo from 'my/addon/blocks/MyBlockInfo'; | ||
|
|
||
| export default function install(config: ConfigType) { | ||
| // Example: registering a new block | ||
| config.blocks.blocksConfig.myBlock = MyBlockInfo; | ||
|
|
||
| // Example: Adding a content type to the "most used" section | ||
| // of the content type menu in the toolbar | ||
| config.settings.mostUsedTypes = [ | ||
| // Keep existing entries and append the new one | ||
| // to avoid overwriting them (unless intentional) | ||
| ...config.settings.mostUsedTypes, | ||
| 'My Content Type', | ||
| ]; | ||
|
|
||
| // Rest of the configuration goes here | ||
|
|
||
| return config; | ||
| } | ||
| ``` | ||
|
|
||
| You can then use the configuration in your code using the `config` exported from `@plone/registry`. | ||
|
|
||
| ```ts | ||
| import config from '@plone/registry'; | ||
|
|
||
| const mostUsedTypes = config.settings.mostUsedTypes; | ||
| // Value: ["Document", "Folder", "File", "My Content Type"] | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ myst: | |
| ```{toctree} | ||
| :maxdepth: 2 | ||
|
|
||
| configuration-registry | ||
| component-registry | ||
| expanders | ||
| ``` | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| --- | ||
| myst: | ||
| html_meta: | ||
| "description": "How to customize the toolbar using slots" | ||
| "property=og:description": "How to customize the toolbar using slots" | ||
| "property=og:title": "Customize the toolbar" | ||
| "keywords": "Plone, Volto, Seven, Toolbar, Slots" | ||
| --- | ||
|
|
||
| # Customize the toolbar | ||
|
|
||
| The toolbar uses the slot system for extensibility. | ||
| It exposes two slots: | ||
|
|
||
| `toolbarTop` | ||
| : Rendered at the top of the toolbar. Typically used for action buttons (save, cancel, edit, add). | ||
|
|
||
| `toolbarBottom` | ||
| : Rendered at the bottom of the toolbar. Typically used for settings or navigation. | ||
|
|
||
| ## Register a toolbar button | ||
|
|
||
| Use `config.registerSlotComponent()` to add a component to either slot. | ||
| Predicates control when the component appears. | ||
|
|
||
| ```ts | ||
| import { RouteCondition, NotRouteCondition } from '@plone/helpers'; | ||
|
|
||
| // Show only in the edit view (cmsui) | ||
| config.registerSlotComponent({ | ||
| slot: 'toolbarTop', | ||
| name: 'myEditButton', | ||
| component: MyEditButton, | ||
| predicates: [RouteCondition('@@edit/*')], | ||
| }); | ||
|
|
||
| // Show everywhere except the edit view (publicui) | ||
| config.registerSlotComponent({ | ||
| slot: 'toolbarTop', | ||
| name: 'myViewButton', | ||
| component: MyViewButton, | ||
| predicates: [NotRouteCondition('@@edit/*')], | ||
| }); | ||
| ``` | ||
|
|
||
| The component receives `content` and `location` as props from the `SlotRenderer`. | ||
|
|
||
| ## Add a menu to the toolbar | ||
|
|
||
| Menus in the toolbar require the `ToolbarMenu` wrapper component from `@plone/layout`. | ||
| Use it in place of the standard `Menu` component. | ||
| The menu children follow the same API as [React Aria's Menu](https://react-aria.adobe.com/Menu). | ||
|
|
||
| ### Create the menu component | ||
|
|
||
| ```tsx | ||
| import { | ||
| ToolbarMenu, | ||
| ToolbarMenuItem, | ||
| } from '@plone/layout/components/Toolbar/ToolbarMenu'; | ||
| import { Header, MenuSection, Text } from 'react-aria-components'; | ||
| import type { Content } from '@plone/types'; | ||
| import MyIcon from './my-icon.svg?react'; | ||
|
|
||
| import menuStyles from './MyMenu.css?inline'; | ||
|
|
||
| interface MyMenuProps { | ||
| content: Content; | ||
| } | ||
|
|
||
| export const MyMenu = ({ content }: MyMenuProps) => { | ||
| return ( | ||
| <ToolbarMenu | ||
| className="menu-my-menu" | ||
| button={<MyIcon />} | ||
| styles={menuStyles} | ||
| > | ||
| <MenuSection> | ||
| <Header>My menu</Header> | ||
| <ToolbarMenuItem id="item-1" href="/some-action"> | ||
| <Text slot="label">Item 1</Text> | ||
| </ToolbarMenuItem> | ||
| </MenuSection> | ||
| </ToolbarMenu> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| `ToolbarMenu` accepts the following props: | ||
|
|
||
| `button` | ||
| : The trigger element rendered in the toolbar (typically an SVG icon). | ||
|
|
||
| `styles` | ||
| : A CSS string imported with `?inline`. | ||
| Injects the styles into the toolbar's shadow root so that your menu styles apply correctly. | ||
|
|
||
| `className` | ||
| : CSS classes applied to the menu container for styling. | ||
|
|
||
| ### Register the menu as a slot component | ||
|
|
||
| The process of registering a menu is the same as registering a button. | ||
|
|
||
| ```ts | ||
| import { RouteCondition } from '@plone/helpers'; | ||
|
|
||
| config.registerSlotComponent({ | ||
| slot: 'toolbarTop', | ||
| name: 'myMenu', | ||
| component: MyMenu, | ||
| predicates: [RouteCondition('@@edit/*')], | ||
| }); | ||
| ``` | ||
|
|
||
| ## Remove a toolbar button or menu | ||
|
|
||
| To remove a button or menu from the toolbar, unregister the corresponding slot in the `config`. | ||
|
|
||
| ```ts | ||
| config.unRegisterSlotComponent('toolbarTop', 'myButton', 0); | ||
| ``` | ||
|
|
||
| For a full example, see the `ContentTypesMenu` component in `@plone/publicui`. | ||
|
|
||
| See {doc}`register-slots` for the full slot API reference. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { Link } from 'react-aria-components'; | ||
| import { useCallback } from 'react'; | ||
|
|
||
| import Close from '@plone/components/icons/close.svg?react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| interface ToolbarCancelProps { | ||
| location: Location; | ||
| } | ||
|
|
||
| export const ToolbarCancel = ({ location }: ToolbarCancelProps) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| const getReturnLocation = useCallback(() => { | ||
| const path = location.pathname.startsWith('/') | ||
| ? location.pathname.slice(1) | ||
| : location.pathname; | ||
|
|
||
| const paths = path.split('/'); | ||
|
|
||
| const returnPath = paths | ||
| .filter((segment) => segment !== '@@edit') | ||
| .join('/'); | ||
|
|
||
| return `/${returnPath}`; | ||
| }, [location.pathname]); | ||
|
|
||
| return ( | ||
| <Link aria-label={t('cmsui.cancel')} href={getReturnLocation()}> | ||
| <Close /> | ||
| </Link> | ||
| ); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@sneridagh @pnicolli @davisagli I like the revisions on this page, as it improves grammar and readability. Would you please check it for technical accuracy?