Repository navigation
Expand file tree
/
Copy pathshellPageActionsSlot.ts
More file actions
67 lines (58 loc) · 2.92 KB
/
Copy pathshellPageActionsSlot.ts
File metadata and controls
67 lines (58 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
/**
* The shell's top-right button group as the page headers see it
* (objectstack#36111): a slot, not an import of the group.
*
* The headers that place the group (the console `PageHeader`, the list's view
* bar, the record page's navigation row) are imported by pages that run
* outside the console shell too: a page bundled on its own, a test that
* mounts one bare. The group itself reads the app's metadata, the Studio
* gate, the AI surface and the help menu's docs, so importing it from a
* header would drag all of that into every one of those pages. The shell
* hands the group in through this context instead (`ShellPageActionsScope`,
* in `ShellPageActions.tsx`); a header reads it here, which imports nothing
* but React and the phone breakpoint.
*
* `null` (outside a scope, the scope turned off, or a phone): the header
* draws nothing for the group.
*/
import * as React from 'react';
import { usePhoneViewport } from '../hooks/usePhoneViewport.js';
export interface ShellPageActionsSlotProps {
/**
* The comments entry, first in the group: handed by the record page
* (objectstack#36112) and the list page (objectstack#39085, through
* `PageHeader`'s `comments`) only.
*/
comments?: React.ReactNode;
/**
* objectstack#37858 — the header measured that its own content no longer
* fits beside the Ask AI button's words: the button draws its icon
* alone. The words yield first, before the page's own actions fold.
*/
assistantIconOnly?: boolean;
}
/** Draws the group with the header's comments entry. */
export type ShellPageActionsRender = (props: ShellPageActionsSlotProps) => React.ReactNode;
/** The group the shell turned on for the pages under it; `null` when off. */
export const ShellPageActionsSlotContext = React.createContext<ShellPageActionsRender | null>(null);
/** The group to draw here: the shell's, unless it is off or this is a phone. */
export function useShellPageActionsSlot(): ShellPageActionsRender | null {
const renderGroup = React.useContext(ShellPageActionsSlotContext);
const phone = usePhoneViewport();
return renderGroup && !phone ? renderGroup : null;
}
/** Draws the sidebar's expand button for a header's left edge. */
export type ShellSidebarExpandRender = () => React.ReactNode;
/** The expand button the shell hands its headers; `null` outside the shell. */
export const ShellSidebarExpandSlotContext = React.createContext<ShellSidebarExpandRender | null>(null);
/**
* The expand button to draw at a header's left edge (objectstack#36112): the
* shell's, unless this is a phone, whose top bar keeps its own controls. It
* draws itself only while the sidebar is collapsed.
*/
export function useShellSidebarExpandSlot(): ShellSidebarExpandRender | null {
const render = React.useContext(ShellSidebarExpandSlotContext);
const phone = usePhoneViewport();
return render && !phone ? render : null;
}