mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: sidebar tabs support (#6213)
* feat: Sidebar tabs support [wip] * tab trigger styling tweaks * add `:hover` & `:active` states * replace `@dwelle/tunnel-rat` with `tunnel-rat` * make stuff more explicit - remove `Sidebar.Header` fallback (host apps need to render manually), and stop tunneling it (render in place) - make `docked` state explicit - stop tunneling `Sidebar.TabTriggers` (render in place) * redesign sidebar / library as per latest spec * support no label on `Sidebar.Trigger` * add Sidebar `props.onStateChange` * style fixes * make `appState.isSidebarDocked` into a soft user preference * px -> rem & refactor * remove `props.renderSidebar` * update tests * remove * refactor * rename constants * tab triggers styling fixes * factor out library-related logic from generic sidebar trigger * change `props.onClose` to `onToggle` * rename `props.value` -> `props.tab` * add displayNames * allow HTMLAttributes on applicable compos * fix example App * more styling tweaks and fixes * fix not setting `dockable` * more style fixes * fix and align sidebar header button styling * make DefaultSidebar dockable on if host apps supplies `onDock` * stop `Sidebar.Trigger` hiding label on mobile this should be only the default sidebar trigger behavior, and for that we don't need to use `device` hook as we handle in CSS * fix `dockable` prop of defaultSidebar * remove extra `typescript` dep * remove `defaultTab` prop in favor of explicit `tab` value in `<Sidebar.Trigger/>` and `toggleSidebar()`, to reduce API surface area and solve inconsistency of `appState.openSidebar.tab` not reflecting actual UI value if `defaultTab` was supported (without additional syncing logic which feels like the wrong solution). * remove `onToggle` in favor of `onStateChange` reducing API surface area * fix restore * comment no longer applies * reuse `Button` component in sidebar buttons * fix tests * split Sidebar sub-components into files * remove `props.dockable` in favor of `props.onDock` only * split tests * fix sidebar showing dock button if no `props.docked` supplied & add more tests * reorder and group sidebar tests * clarify * rename classes & dedupe css * refactor tests * update changelog * update changelog --------- Co-authored-by: barnabasmolnar <barnabas@excalidraw.com>
This commit is contained in:
parent
b1311a407a
commit
e9cae918a7
61 changed files with 1972 additions and 1431 deletions
|
@ -11,6 +11,22 @@ The change should be grouped under one of the below section and must contain PR
|
|||
Please add the latest change on the top under the correct section.
|
||||
-->
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Features
|
||||
|
||||
- Sidebar component now supports tabs — for more detailed description of new behavior and breaking changes, see the linked PR. [#6213](https://github.com/excalidraw/excalidraw/pull/6213)
|
||||
- Exposed `DefaultSidebar` component to allow modifying the default sidebar, such as adding custom tabs to it. [#6213](https://github.com/excalidraw/excalidraw/pull/6213)
|
||||
|
||||
#### BREAKING CHANGES
|
||||
|
||||
- `props.renderSidebar` is removed in favor of rendering as `children`.
|
||||
- `appState.isSidebarDocked` replaced with `appState.defaultSidebarDockedPreference` with slightly different semantics, and relating only to the default sidebar. You need to handle `docked` state for your custom sidebars yourself.
|
||||
- Sidebar `props.dockable` is removed. To indicate dockability, supply `props.onDock()` alongside setting `props.docked`.
|
||||
- `Sidebar.Header` is no longer rendered by default. You need to render it yourself.
|
||||
- `props.onClose` replaced with `props.onStateChange`.
|
||||
- `restore()`/`restoreAppState()` now retains `appState.openSidebar` regardless of docked state.
|
||||
|
||||
## 0.15.2 (2023-04-20)
|
||||
|
||||
### Docs
|
||||
|
|
|
@ -494,15 +494,6 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) {
|
|||
);
|
||||
};
|
||||
|
||||
const renderSidebar = () => {
|
||||
return (
|
||||
<Sidebar>
|
||||
<Sidebar.Header>Custom header!</Sidebar.Header>
|
||||
Custom sidebar!
|
||||
</Sidebar>
|
||||
);
|
||||
};
|
||||
|
||||
const renderMenu = () => {
|
||||
return (
|
||||
<MainMenu>
|
||||
|
@ -668,23 +659,6 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) {
|
|||
</div>
|
||||
</div>
|
||||
<div className="excalidraw-wrapper">
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
left: "50%",
|
||||
bottom: "20px",
|
||||
display: "flex",
|
||||
zIndex: 9999999999999999,
|
||||
padding: "5px 10px",
|
||||
transform: "translateX(-50%)",
|
||||
background: "rgba(255, 255, 255, 0.8)",
|
||||
gap: "1rem",
|
||||
}}
|
||||
>
|
||||
<button onClick={() => excalidrawAPI?.toggleMenu("customSidebar")}>
|
||||
Toggle Custom Sidebar
|
||||
</button>
|
||||
</div>
|
||||
<Excalidraw
|
||||
ref={(api: ExcalidrawImperativeAPI) => setExcalidrawAPI(api)}
|
||||
initialData={initialStatePromiseRef.current.promise}
|
||||
|
@ -706,7 +680,6 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) {
|
|||
onLinkOpen={onLinkOpen}
|
||||
onPointerDown={onPointerDown}
|
||||
onScrollChange={rerenderCommentIcons}
|
||||
renderSidebar={renderSidebar}
|
||||
>
|
||||
{excalidrawAPI && (
|
||||
<Footer>
|
||||
|
@ -714,6 +687,30 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) {
|
|||
</Footer>
|
||||
)}
|
||||
<WelcomeScreen />
|
||||
<Sidebar name="custom">
|
||||
<Sidebar.Tabs>
|
||||
<Sidebar.Header />
|
||||
<Sidebar.Tab tab="one">Tab one!</Sidebar.Tab>
|
||||
<Sidebar.Tab tab="two">Tab two!</Sidebar.Tab>
|
||||
<Sidebar.TabTriggers>
|
||||
<Sidebar.TabTrigger tab="one">One</Sidebar.TabTrigger>
|
||||
<Sidebar.TabTrigger tab="two">Two</Sidebar.TabTrigger>
|
||||
</Sidebar.TabTriggers>
|
||||
</Sidebar.Tabs>
|
||||
</Sidebar>
|
||||
<Sidebar.Trigger
|
||||
name="custom"
|
||||
tab="one"
|
||||
style={{
|
||||
position: "absolute",
|
||||
left: "50%",
|
||||
transform: "translateX(-50%)",
|
||||
bottom: "20px",
|
||||
zIndex: 9999999999999999,
|
||||
}}
|
||||
>
|
||||
Toggle Custom Sidebar
|
||||
</Sidebar.Trigger>
|
||||
{renderMenu()}
|
||||
</Excalidraw>
|
||||
{Object.keys(commentIcons || []).length > 0 && renderCommentIcons()}
|
||||
|
|
|
@ -24,7 +24,6 @@ const ExcalidrawBase = (props: ExcalidrawProps) => {
|
|||
isCollaborating = false,
|
||||
onPointerUpdate,
|
||||
renderTopRightUI,
|
||||
renderSidebar,
|
||||
langCode = defaultLang.code,
|
||||
viewModeEnabled,
|
||||
zenModeEnabled,
|
||||
|
@ -47,6 +46,8 @@ const ExcalidrawBase = (props: ExcalidrawProps) => {
|
|||
|
||||
const canvasActions = props.UIOptions?.canvasActions;
|
||||
|
||||
// FIXME normalize/set defaults in parent component so that the memo resolver
|
||||
// compares the same values
|
||||
const UIOptions: AppProps["UIOptions"] = {
|
||||
...props.UIOptions,
|
||||
canvasActions: {
|
||||
|
@ -114,7 +115,6 @@ const ExcalidrawBase = (props: ExcalidrawProps) => {
|
|||
onLinkOpen={onLinkOpen}
|
||||
onPointerDown={onPointerDown}
|
||||
onScrollChange={onScrollChange}
|
||||
renderSidebar={renderSidebar}
|
||||
>
|
||||
{children}
|
||||
</App>
|
||||
|
@ -245,3 +245,5 @@ export { MainMenu };
|
|||
export { useDevice } from "../../components/App";
|
||||
export { WelcomeScreen };
|
||||
export { LiveCollaborationTrigger };
|
||||
|
||||
export { DefaultSidebar } from "../../components/DefaultSidebar";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue