diff --git a/resources/boost/skills/saucebase-module-development/SKILL.md b/resources/boost/skills/saucebase-module-development/SKILL.md index cec6f85..c028953 100644 --- a/resources/boost/skills/saucebase-module-development/SKILL.md +++ b/resources/boost/skills/saucebase-module-development/SKILL.md @@ -94,7 +94,8 @@ Navigation::add('Roadmap', fn () => route('roadmap.index'), function (Section $s Pass the URL as a closure: it resolves when navigation renders, not when the file loads. `Navigation::addWhen($condition, ...)` shows an item only while `$condition` returns true. Besides `group`, `slug`, `icon`, and `order`, items may set `action`, `type`, `external`, `newPage`, `class`, and `badge`. The `icon` and `action` names must be -registered by the frontend; see `saucebase-frontend-development`. +registered by the frontend; see `saucebase-frontend-development`. An item is active on its exact URL; for a +section with pages under it, `active` decides instead (a bool or closure: `fn () => request()->routeIs('chat.*')`). ## Breadcrumbs diff --git a/src/Navigation/Navigation.php b/src/Navigation/Navigation.php index ab5d455..b38231f 100644 --- a/src/Navigation/Navigation.php +++ b/src/Navigation/Navigation.php @@ -223,7 +223,10 @@ protected function transformItem(array $item): array $menuItem = [ 'title' => $item['title'], - 'active' => $this->isItemActiveForUrl($resolvedUrl), + // An `active` attribute (bool or closure) decides for a section with pages under it. + 'active' => array_key_exists('active', $attributes) + ? (bool) value($attributes['active']) + : $this->isItemActiveForUrl($resolvedUrl), 'slug' => $attributes['slug'] ?? Str::slug($item['title'], '-'), ]; diff --git a/stubs/app/README.md b/stubs/app/README.md index 75a436e..178fdc6 100644 --- a/stubs/app/README.md +++ b/stubs/app/README.md @@ -6,7 +6,7 @@ Built with [Saucebase](https://github.com/saucebase-dev/saucebase), on Laravel a | Installed with | Open the app | | --- | --- | -| Herd | Already served at `https://.test`. Run `npm run dev` for live reload. | +| Herd or Lerd | Herd serves `https://.test`. Lerd serves `http://.test`; `lerd secure ` adds HTTPS. Run `npm run dev` for live reload. | | Native | `composer dev` (app, queue, logs and Vite), then open the URL it prints. | | Docker | `docker compose up -d`, then open `APP_URL` from `.env`. Logs: `docker compose logs -f`. Stop: `docker compose down`. | diff --git a/stubs/stack/react/config/package-lock.json b/stubs/stack/react/config/package-lock.json index 3883b97..1459a6a 100644 --- a/stubs/stack/react/config/package-lock.json +++ b/stubs/stack/react/config/package-lock.json @@ -65,6 +65,7 @@ "prettier": "^3.9.10", "prettier-plugin-organize-imports": "^4.3.0", "prettier-plugin-tailwindcss": "^0.8.1", + "react-docgen": "^8.0.4", "shadcn": "^4.22.1", "storybook": "^11.0.0-rc.0", "storybook-addon-pseudo-states": "^11.0.0-rc.0", @@ -5893,6 +5894,51 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/babel__core": { + "version": "7.20.5", + "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", + "integrity": "sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.20.7", + "@babel/types": "^7.20.7", + "@types/babel__generator": "*", + "@types/babel__template": "*", + "@types/babel__traverse": "*" + } + }, + "node_modules/@types/babel__generator": { + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.27.0.tgz", + "integrity": "sha512-ufFd2Xi92OAVPYsy+P4n7/U7e68fex0+Ee8gSG9KX7eo084CWiQ4sdxktvdl0bOPupXtVJPY19zk6EwWqUQ8lg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.0.0" + } + }, + "node_modules/@types/babel__template": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.4.tgz", + "integrity": "sha512-h/NUaSyG5EyxBIp8YRxo4RMe2/qQgvyowRwVMzhYhBCONbW8PUsg4lkFMrhgZhUe5z3L3MiLDuvyJ/CaPa2A8A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.1.0", + "@babel/types": "^7.0.0" + } + }, + "node_modules/@types/babel__traverse": { + "version": "7.28.0", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.28.0.tgz", + "integrity": "sha512-8PvcXf70gTDZBgt9ptxJ8elBeBjcLOAcOtoO/mPJjtji1+CdGbHgm77om1GrsPxsiE+uXIpNSK64UYaIwQXd4Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.28.2" + } + }, "node_modules/@types/chai": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", @@ -5911,6 +5957,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/doctrine": { + "version": "0.0.9", + "resolved": "https://registry.npmjs.org/@types/doctrine/-/doctrine-0.0.9.tgz", + "integrity": "sha512-eOIHzCUSH7SMfonMG1LsC2f8vxBFtho6NGBznK41R84YzPuvSBzrhEps33IsQiOW9+VL6NQ9DbjQJznk/S4uRA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/esrecurse": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", @@ -5969,6 +6022,13 @@ "@types/react": "^19.3.0" } }, + "node_modules/@types/resolve": { + "version": "1.20.6", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.6.tgz", + "integrity": "sha512-A4STmOXPhMUtHH+S6ymgE2GiBSMqf4oTvcQZMcHzokuTLVYzXTB8ttjcgxOVaAp2lGwEdzZ0J+cRbbeevQj1UQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/validate-npm-package-name": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/@types/validate-npm-package-name/-/validate-npm-package-name-4.0.2.tgz", @@ -7847,6 +7907,19 @@ "node": ">=0.3.1" } }, + "node_modules/doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "esutils": "^2.0.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/dot-case": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz", @@ -12005,6 +12078,28 @@ "node": ">=0.10.0" } }, + "node_modules/react-docgen": { + "version": "8.0.4", + "resolved": "https://registry.npmjs.org/react-docgen/-/react-docgen-8.0.4.tgz", + "integrity": "sha512-gIYjtVTU4NCWZnb/LXVSWfClZXnjzX3+xxi69Tkfu4YsmYuqiOk8giLkKt/WwxWqh+U66CTh8Kqbha1uPv8/qQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/core": "^7.28.0", + "@babel/traverse": "^7.28.0", + "@babel/types": "^7.28.2", + "@types/babel__core": "^7.20.5", + "@types/babel__traverse": "^7.20.7", + "@types/doctrine": "^0.0.9", + "@types/resolve": "^1.20.2", + "doctrine": "^3.0.0", + "resolve": "^1.22.1", + "strip-indent": "^4.0.0" + }, + "engines": { + "node": "^20.9.0 || >=22" + } + }, "node_modules/react-dom": { "version": "19.3.1", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.1.tgz", @@ -13124,6 +13219,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/strip-indent": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-4.1.1.tgz", + "integrity": "sha512-SlyRoSkdh1dYP0PzclLE7r0M9sgbFKKMFXpFRUMNuKhQSbC6VQIGzq3E0qsfvGJaUFJPGv6Ws1NZ/haTAjfbMA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", diff --git a/stubs/stack/react/config/package.json b/stubs/stack/react/config/package.json index a53c25e..6bc3c4e 100644 --- a/stubs/stack/react/config/package.json +++ b/stubs/stack/react/config/package.json @@ -69,6 +69,7 @@ "prettier": "^3.9.10", "prettier-plugin-organize-imports": "^4.3.0", "prettier-plugin-tailwindcss": "^0.8.1", + "react-docgen": "^8.0.4", "shadcn": "^4.22.1", "storybook": "^11.0.0-rc.0", "storybook-addon-pseudo-states": "^11.0.0-rc.0", diff --git a/stubs/stack/react/js/components/SidebarResizer.stories.tsx b/stubs/stack/react/js/components/SidebarResizer.stories.tsx new file mode 100644 index 0000000..ec1654f --- /dev/null +++ b/stubs/stack/react/js/components/SidebarResizer.stories.tsx @@ -0,0 +1,82 @@ +import preview from '@/.storybook/preview'; +import { useState, type CSSProperties } from 'react'; +import { expect, waitFor } from 'storybook/test'; +import { SidebarResizer } from './SidebarResizer'; + +/** + * A sidebar's draggable edge: drag it, or use the arrow keys, between 224 and 448px; a + * double click resets it. AppLayout renders it for the app sidebar (`resizable`), where it + * is fixed to the window. `contained` puts it on a panel inside the page instead: it sits + * on the panel's edge and measures from the panel's left. + */ +const meta = preview.meta({ + title: 'App/SidebarResizer', + component: SidebarResizer, + parameters: { layout: 'fullscreen' }, +}); +export default meta; + +function Panel() { + const [width, setWidth] = useState(null); + const [resizing, setResizing] = useState(false); + + return ( +
+
+ +
+ ); +} + +/** On a panel 200px in from the window's edge: the drag sets the panel's own width. */ +export const Contained = meta.story({ + render: () => , + play: async ({ canvas, userEvent }) => { + const handle = canvas.getByRole('separator', { + name: 'Resize sidebar', + }); + const panel = canvas.getByTestId('panel'); + const start = panel.getBoundingClientRect(); + const box = handle.getBoundingClientRect(); + + // Positioned in the panel: a fixed handle is placed by the window, measured from its left. + await expect(getComputedStyle(handle).position).toBe('absolute'); + // On the panel's edge, not 256px from the window's. + await expect( + Math.abs(box.left + box.width / 2 - start.right), + ).toBeLessThanOrEqual(2); + + const y = box.top + box.height / 2; + await userEvent.pointer([ + { + keys: '[MouseLeft>]', + target: handle, + coords: { clientX: start.right, clientY: y }, + }, + { + target: handle, + coords: { clientX: start.right + 80, clientY: y }, + }, + { keys: '[/MouseLeft]', target: handle }, + ]); + await waitFor(() => + expect(panel.getBoundingClientRect().width).toBe(336), + ); + }, +}); diff --git a/stubs/stack/react/js/components/SidebarResizer.tsx b/stubs/stack/react/js/components/SidebarResizer.tsx new file mode 100644 index 0000000..14bfee8 --- /dev/null +++ b/stubs/stack/react/js/components/SidebarResizer.tsx @@ -0,0 +1,90 @@ +import { useT } from '@saucebase/react/i18n'; +import { + clampSidebarWidth as clamp, + SIDEBAR_DEFAULT_WIDTH, + SIDEBAR_MAX_WIDTH as MAX, + SIDEBAR_MIN_WIDTH as MIN, +} from '@/hooks/useSidebarState'; +import { useRef } from 'react'; + +const STEP = 16; + +interface SidebarResizerProps { + width: number | null; + /** On a panel inside the page (positioned, `relative`) rather than fixed to the window. */ + contained?: boolean; + onWidthChange: (width: number | null) => void; + resizing: boolean; + onResizingChange: (resizing: boolean) => void; +} + +/** + * The sidebar's edge: drag it, or use the arrow keys, to resize the sidebar; a double + * click resets it. Rendered right after the sidebar inside SidebarProvider, so it sits on + * `--sidebar-width` and hides with the collapsed sidebar (the sidebar is its `peer`). + * Left-side sidebars only: the width is the pointer's distance from the sidebar's left edge + * (the window's, or the positioned panel the handle sits in). + */ +export function SidebarResizer({ + width, + onWidthChange, + resizing, + onResizingChange, + contained = false, +}: SidebarResizerProps) { + const t = useT(); + const handle = useRef(null); + + // The sidebar's left edge: the window's for the app sidebar (the handle is fixed, so it + // has no offsetParent), a panel's own when the handle sits in it (positioned, `relative`). + const origin = () => + handle.current?.offsetParent?.getBoundingClientRect().left ?? 0; + + const nudge = (by: number) => { + // The handle straddles the edge: its middle is the current width. + const rect = handle.current!.getBoundingClientRect(); + onWidthChange(clamp(rect.left + rect.width / 2 - origin() + by)); + }; + + // A focusable separator with a value is the WAI-ARIA window splitter: interactive by spec. + /* eslint-disable jsx-a11y/no-noninteractive-tabindex, jsx-a11y/no-noninteractive-element-interactions */ + return ( +