Make the custom menu examples a bit clearer (#3106)

Use the Readme and bg color of elements to make it clearer which menu is
being customised.

- [x] `documentation` — Changes to the documentation only[^2]

### Release Notes

- Add a brief release note for your PR here.
This commit is contained in:
Taha 2024-03-12 09:13:42 +00:00 committed by GitHub
parent dba6d4c414
commit 8d02df8712
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 136 additions and 97 deletions

View file

@ -1,10 +1,29 @@
import { DefaultActionsMenu, TLComponents, Tldraw } from 'tldraw'
import {
DefaultActionsMenu,
DefaultActionsMenuContent,
TLComponents,
Tldraw,
TldrawUiMenuItem,
} from 'tldraw'
import 'tldraw/tldraw.css'
function CustomActionsMenu() {
return (
<div style={{ transform: 'rotate(90deg)' }}>
<DefaultActionsMenu />
<div style={{ backgroundColor: 'thistle' }}>
<DefaultActionsMenu>
<div style={{ backgroundColor: 'thistle' }}>
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</div>
<DefaultActionsMenuContent />
</DefaultActionsMenu>
</div>
)
}

View file

@ -8,4 +8,4 @@ You can customize tldraw's actions menu.
---
The actions menu can be customized by providing a `ActionsMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden.
The actions menu is a dropdown menu that can be found in the top-left of the tldraw component, or just above the toolbar on smaller screens. It contains actions related to editing shapes such as grouping, rotating or changing shape order. The actions menu can be customized by providing a `ActionsMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden.

View file

@ -13,15 +13,17 @@ function CustomContextMenu(props: TLUiContextMenuProps) {
return (
<DefaultContextMenu {...props}>
<TldrawUiMenuGroup id="example">
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
<div style={{ backgroundColor: 'thistle' }}>
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</div>
</TldrawUiMenuGroup>
<DefaultContextMenuContent />
</DefaultContextMenu>

View file

@ -8,4 +8,4 @@ You can customize tldraw's context menu.
---
The context menu can be customized by providing a `ContextMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden instead.
Create some shapes, select them and right click the selection to see the custom context menu. It can be customized by providing a `ContextMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden instead.

View file

@ -10,20 +10,24 @@ import 'tldraw/tldraw.css'
function CustomDebugMenu() {
return (
<DefaultDebugMenu>
<DefaultDebugMenuContent />
<TldrawUiMenuGroup id="example">
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</TldrawUiMenuGroup>
</DefaultDebugMenu>
<div style={{ backgroundColor: 'thistle' }}>
<DefaultDebugMenu>
<DefaultDebugMenuContent />
<div style={{ backgroundColor: 'thistle' }}>
<TldrawUiMenuGroup id="example">
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</TldrawUiMenuGroup>
</div>
</DefaultDebugMenu>
</div>
)
}

View file

@ -8,4 +8,4 @@ You can customize tldraw's debug menu.
---
The help menu can be customized by providing a `DebugMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden.
The debug menu contains helpful menu items for debugging the tldraw component. To show the debug menu, turn on debug mode in the preferences. It can be customized by providing a `DebugMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden.

View file

@ -11,17 +11,19 @@ import 'tldraw/tldraw.css'
function CustomHelpMenu() {
return (
<DefaultHelpMenu>
<TldrawUiMenuGroup id="example">
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</TldrawUiMenuGroup>
<div style={{ backgroundColor: 'thistle' }}>
<TldrawUiMenuGroup id="example">
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</TldrawUiMenuGroup>
</div>
<DefaultHelpMenuContent />
</DefaultHelpMenu>
)

View file

@ -8,4 +8,4 @@ You can customize tldraw's help menu.
---
The help menu can be customized by providing a `HelpMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden.
The help menu contains options for opening the keyboard shortcuts dialog and changing the language. It can be opened by clicking on the help icon in the bottom right of the screen at larger breakpoints. The help menu can be customized by providing a `HelpMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden.

View file

@ -11,16 +11,18 @@ import 'tldraw/tldraw.css'
function CustomKeyboardShortcutsDialog(props: TLUiKeyboardShortcutsDialogProps) {
return (
<DefaultKeyboardShortcutsDialog {...props}>
<TldrawUiMenuItem
id="like-my-posts"
label="Like my posts"
icon="external-link"
readonlyOk
kbd=":)"
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
<div style={{ backgroundColor: 'thistle' }}>
<TldrawUiMenuItem
id="like-my-posts"
label="Like my posts"
icon="external-link"
readonlyOk
kbd=":)"
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</div>
<DefaultKeyboardShortcutsDialogContent />
</DefaultKeyboardShortcutsDialog>
)

View file

@ -8,4 +8,4 @@ You can customize tldraw's keyboard shortcuts dialog.
---
The keyboard shortcuts dialog can be customized by providing a `KeyboardShortcutsDialog` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden instead.
The keyboard shortcuts dialog can be opened via the help menu in the bottom right corner of the tldraw component. It can be customized by providing a `KeyboardShortcutsDialog` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden instead.

View file

@ -11,17 +11,19 @@ import 'tldraw/tldraw.css'
function CustomMainMenu() {
return (
<DefaultMainMenu>
<TldrawUiMenuGroup id="example">
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</TldrawUiMenuGroup>
<div style={{ backgroundColor: 'thistle' }}>
<TldrawUiMenuGroup id="example">
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</TldrawUiMenuGroup>
</div>
<DefaultMainMenuContent />
</DefaultMainMenu>
)

View file

@ -8,4 +8,4 @@ You can customize tldraw's main menu.
---
The actions menu can be customized by providing a `MainMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden.
The main menu contains important submenus: Edit, Shape, Preferences etc. To open the main menu, click the hamburger icon in the top left corner of the tldraw component. It can be customized by providing a `MainMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden.

View file

@ -2,7 +2,7 @@ import { TLComponents, Tldraw } from 'tldraw'
import 'tldraw/tldraw.css'
function CustomNavigationPanel() {
return <div className="tlui-navigation-panel">here you are</div>
return <div style={{ backgroundColor: 'thistle', padding: '14px' }}>here you are</div>
}
const components: TLComponents = {

View file

@ -8,4 +8,4 @@ You can customize tldraw's navigation panel or remove it entirely.
---
The navigation panel can be customized by providing a `NavigationPanel` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden instead.
The navigation panel is in the bottom left of the tldraw component at larger breakpoints. It contains zoom controls and a mini map. It can be customized by providing a `NavigationPanel` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden instead.

View file

@ -3,7 +3,7 @@ import 'tldraw/tldraw.css'
function CustomPageMenu() {
return (
<div style={{ transform: 'rotate(3.14rad)' }}>
<div style={{ transform: 'rotate(3.14rad)', backgroundColor: 'thistle' }}>
<DefaultPageMenu />
</div>
)

View file

@ -8,4 +8,4 @@ You can customize tldraw's page menu, or remove it entirely.
---
The page menu can be customized by providing a `PageMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden.
The page menu contains options for creating and editing pages. To open the page menu, click the page name in the top left of the tldraw component. It can be customized by providing a `PageMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden.

View file

@ -11,7 +11,9 @@ function CustomQuickActions() {
return (
<DefaultQuickActions>
<DefaultQuickActionsContent />
<TldrawUiMenuItem id="code" icon="code" onSelect={() => window.alert('code')} />
<div style={{ backgroundColor: 'thistle' }}>
<TldrawUiMenuItem id="code" icon="code" onSelect={() => window.alert('code')} />
</div>
</DefaultQuickActions>
)
}

View file

@ -21,22 +21,26 @@ function CustomStylePanel(props: TLUiStylePanelProps) {
return (
<DefaultStylePanel {...props}>
<TldrawUiButton
type="menu"
onClick={() => {
editor.setStyleForSelectedShapes(DefaultColorStyle, 'red', { squashing: true })
}}
>
<TldrawUiButtonLabel>Red</TldrawUiButtonLabel>
</TldrawUiButton>
<TldrawUiButton
type="menu"
onClick={() => {
editor.setStyleForSelectedShapes(DefaultColorStyle, 'green', { squashing: true })
}}
>
<TldrawUiButtonLabel>Green</TldrawUiButtonLabel>
</TldrawUiButton>
<div style={{ backgroundColor: 'thistle' }}>
<TldrawUiButton
type="menu"
onClick={() => {
editor.setStyleForSelectedShapes(DefaultColorStyle, 'red', { squashing: true })
}}
>
<TldrawUiButtonLabel>Red</TldrawUiButtonLabel>
</TldrawUiButton>
</div>
<div style={{ backgroundColor: 'thistle' }}>
<TldrawUiButton
type="menu"
onClick={() => {
editor.setStyleForSelectedShapes(DefaultColorStyle, 'green', { squashing: true })
}}
>
<TldrawUiButtonLabel>Green</TldrawUiButtonLabel>
</TldrawUiButton>
</div>
<DefaultStylePanelContent styles={styles} />
</DefaultStylePanel>
)

View file

@ -11,17 +11,19 @@ import 'tldraw/tldraw.css'
function CustomZoomMenu() {
return (
<DefaultZoomMenu>
<TldrawUiMenuGroup id="example">
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</TldrawUiMenuGroup>
<div style={{ backgroundColor: 'thistle' }}>
<TldrawUiMenuGroup id="example">
<TldrawUiMenuItem
id="like"
label="Like my posts"
icon="external-link"
readonlyOk
onSelect={() => {
window.open('https://x.com/tldraw', '_blank')
}}
/>
</TldrawUiMenuGroup>
</div>
<DefaultZoomMenuContent />
</DefaultZoomMenu>
)

View file

@ -8,4 +8,4 @@ You can customize tldraw's zoom menu.
---
The zoom menu can be customized by providing a `ZoomMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden instead.
The zoom menu is in the bottom left of the tldraw component, the button to open it is labeled with a percentage indicating the editor's current zoom level. It can be customized by providing a `ZoomMenu` component to the `Tldraw` component's `components` prop. If you provide `null`, then that component will be hidden instead.