@etsoo/toolpad 1.0.30 → 1.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,6 +42,10 @@ type PageContainerBarProps = {
42
42
  * The props used for each slot inside.
43
43
  */
44
44
  slotProps?: PageContainerSlotProps;
45
+ /**
46
+ * The component that renders the actions toolbar.
47
+ */
48
+ titleBar?: false | ((title: string) => React.ReactNode);
45
49
  };
46
50
  export type PageContainerProps = React.PropsWithChildren<StackProps & PageContainerBarProps>;
47
51
  /**
@@ -88,7 +88,7 @@ function PageDataContextProvider(props) {
88
88
  return (0, jsx_runtime_1.jsx)(exports.PageDataContext.Provider, { value: { state, dispatch }, ...rest });
89
89
  }
90
90
  function PageContainerBar(props) {
91
- const { slots, slotProps } = props;
91
+ const { slots, slotProps, titleBar } = props;
92
92
  const { state } = React.useContext(exports.PageDataContext);
93
93
  const activePage = (0, useActivePage_1.useActivePage)();
94
94
  React.useEffect(() => {
@@ -110,8 +110,10 @@ function PageContainerBar(props) {
110
110
  const breadcrumbs = state.breadcrumbs ?? activePage?.breadcrumbs ?? [];
111
111
  const title = state.title ?? activePage?.title ?? "";
112
112
  const pageHeader = state.pageHeader ?? activePage?.pageHeader ?? null;
113
+ // No page header
113
114
  if (pageHeader === false)
114
115
  return undefined;
116
+ // Custom page header
115
117
  if (pageHeader != null)
116
118
  return pageHeader;
117
119
  if (state.page) {
@@ -119,7 +121,7 @@ function PageContainerBar(props) {
119
121
  }
120
122
  return ((0, jsx_runtime_1.jsxs)(Stack_1.default, { children: [breadcrumbs && ((0, jsx_runtime_1.jsx)(Breadcrumbs_1.default, { "aria-label": "breadcrumb", children: breadcrumbs.map((item, index) => {
121
123
  return index < breadcrumbs.length - 1 ? ((0, jsx_runtime_1.jsx)(Link_1.default, { component: Link_2.Link, underline: "hover", color: "inherit", href: item.path, children: (0, navigation_1.getItemTitle)(item) }, item.path)) : ((0, jsx_runtime_1.jsx)(Typography_1.default, { color: "text.primary", children: (0, navigation_1.getItemTitle)(item) }, item.path));
122
- }) })), (0, jsx_runtime_1.jsxs)(PageContentHeader, { children: [title ? (0, jsx_runtime_1.jsx)(Typography_1.default, { variant: "h4", children: title }) : null, (0, jsx_runtime_1.jsx)(ToolbarComponent, { ...toolbarSlotProps })] })] }));
124
+ }) })), (0, jsx_runtime_1.jsxs)(PageContentHeader, { children: [typeof titleBar === "function" ? (titleBar(title)) : titleBar === false ? undefined : ((0, jsx_runtime_1.jsx)(Typography_1.default, { variant: "h4", children: title })), (0, jsx_runtime_1.jsx)(ToolbarComponent, { ...toolbarSlotProps })] })] }));
123
125
  }
124
126
  /**
125
127
  * A container component to provide a title and breadcrumbs for your pages.
@@ -133,6 +135,6 @@ function PageContainerBar(props) {
133
135
  * - [PageContainer API](https://mui.com/toolpad/core/api/page-container)
134
136
  */
135
137
  function PageContainer(props) {
136
- const { children, slots, slotProps, ...rest } = props;
137
- return ((0, jsx_runtime_1.jsxs)(Stack_1.default, { sx: { mx: 3, my: 2 }, spacing: 2, ...rest, children: [(0, jsx_runtime_1.jsx)(PageContainerBar, { slots: slots, slotProps: slotProps }), children] }));
138
+ const { children, slots, slotProps, titleBar, ...rest } = props;
139
+ return ((0, jsx_runtime_1.jsxs)(Stack_1.default, { sx: { mx: 3, my: 2 }, spacing: 2, ...rest, children: [(0, jsx_runtime_1.jsx)(PageContainerBar, { slots: slots, slotProps: slotProps, titleBar: titleBar }), children] }));
138
140
  }
@@ -42,6 +42,10 @@ type PageContainerBarProps = {
42
42
  * The props used for each slot inside.
43
43
  */
44
44
  slotProps?: PageContainerSlotProps;
45
+ /**
46
+ * The component that renders the actions toolbar.
47
+ */
48
+ titleBar?: false | ((title: string) => React.ReactNode);
45
49
  };
46
50
  export type PageContainerProps = React.PropsWithChildren<StackProps & PageContainerBarProps>;
47
51
  /**
@@ -47,7 +47,7 @@ export function PageDataContextProvider(props) {
47
47
  return _jsx(PageDataContext.Provider, { value: { state, dispatch }, ...rest });
48
48
  }
49
49
  function PageContainerBar(props) {
50
- const { slots, slotProps } = props;
50
+ const { slots, slotProps, titleBar } = props;
51
51
  const { state } = React.useContext(PageDataContext);
52
52
  const activePage = useActivePage();
53
53
  React.useEffect(() => {
@@ -69,8 +69,10 @@ function PageContainerBar(props) {
69
69
  const breadcrumbs = state.breadcrumbs ?? activePage?.breadcrumbs ?? [];
70
70
  const title = state.title ?? activePage?.title ?? "";
71
71
  const pageHeader = state.pageHeader ?? activePage?.pageHeader ?? null;
72
+ // No page header
72
73
  if (pageHeader === false)
73
74
  return undefined;
75
+ // Custom page header
74
76
  if (pageHeader != null)
75
77
  return pageHeader;
76
78
  if (state.page) {
@@ -78,7 +80,7 @@ function PageContainerBar(props) {
78
80
  }
79
81
  return (_jsxs(Stack, { children: [breadcrumbs && (_jsx(Breadcrumbs, { "aria-label": "breadcrumb", children: breadcrumbs.map((item, index) => {
80
82
  return index < breadcrumbs.length - 1 ? (_jsx(Link, { component: ToolpadLink, underline: "hover", color: "inherit", href: item.path, children: getItemTitle(item) }, item.path)) : (_jsx(Typography, { color: "text.primary", children: getItemTitle(item) }, item.path));
81
- }) })), _jsxs(PageContentHeader, { children: [title ? _jsx(Typography, { variant: "h4", children: title }) : null, _jsx(ToolbarComponent, { ...toolbarSlotProps })] })] }));
83
+ }) })), _jsxs(PageContentHeader, { children: [typeof titleBar === "function" ? (titleBar(title)) : titleBar === false ? undefined : (_jsx(Typography, { variant: "h4", children: title })), _jsx(ToolbarComponent, { ...toolbarSlotProps })] })] }));
82
84
  }
83
85
  /**
84
86
  * A container component to provide a title and breadcrumbs for your pages.
@@ -92,7 +94,7 @@ function PageContainerBar(props) {
92
94
  * - [PageContainer API](https://mui.com/toolpad/core/api/page-container)
93
95
  */
94
96
  function PageContainer(props) {
95
- const { children, slots, slotProps, ...rest } = props;
96
- return (_jsxs(Stack, { sx: { mx: 3, my: 2 }, spacing: 2, ...rest, children: [_jsx(PageContainerBar, { slots: slots, slotProps: slotProps }), children] }));
97
+ const { children, slots, slotProps, titleBar, ...rest } = props;
98
+ return (_jsxs(Stack, { sx: { mx: 3, my: 2 }, spacing: 2, ...rest, children: [_jsx(PageContainerBar, { slots: slots, slotProps: slotProps, titleBar: titleBar }), children] }));
97
99
  }
98
100
  export { PageContainer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/toolpad",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "author": "ETSOO",
5
5
  "description": "Dashboard framework extention based on Toolpad Core",
6
6
  "main": "build/cjs/index.js",
@@ -99,14 +99,20 @@ type PageContainerBarProps = {
99
99
  * The components used for each slot inside.
100
100
  */
101
101
  slots?: PageContainerSlots;
102
+
102
103
  /**
103
104
  * The props used for each slot inside.
104
105
  */
105
106
  slotProps?: PageContainerSlotProps;
107
+
108
+ /**
109
+ * The component that renders the actions toolbar.
110
+ */
111
+ titleBar?: false | ((title: string) => React.ReactNode);
106
112
  };
107
113
 
108
114
  function PageContainerBar(props: PageContainerBarProps) {
109
- const { slots, slotProps } = props;
115
+ const { slots, slotProps, titleBar } = props;
110
116
 
111
117
  const { state } = React.useContext(PageDataContext);
112
118
 
@@ -134,7 +140,10 @@ function PageContainerBar(props: PageContainerBarProps) {
134
140
  const title = state.title ?? activePage?.title ?? "";
135
141
  const pageHeader = state.pageHeader ?? activePage?.pageHeader ?? null;
136
142
 
143
+ // No page header
137
144
  if (pageHeader === false) return undefined;
145
+
146
+ // Custom page header
138
147
  if (pageHeader != null) return pageHeader;
139
148
 
140
149
  if (state.page) {
@@ -165,7 +174,11 @@ function PageContainerBar(props: PageContainerBarProps) {
165
174
  </Breadcrumbs>
166
175
  )}
167
176
  <PageContentHeader>
168
- {title ? <Typography variant="h4">{title}</Typography> : null}
177
+ {typeof titleBar === "function" ? (
178
+ titleBar(title)
179
+ ) : titleBar === false ? undefined : (
180
+ <Typography variant="h4">{title}</Typography>
181
+ )}
169
182
  <ToolbarComponent {...toolbarSlotProps} />
170
183
  </PageContentHeader>
171
184
  </Stack>
@@ -188,11 +201,15 @@ export type PageContainerProps = React.PropsWithChildren<
188
201
  * - [PageContainer API](https://mui.com/toolpad/core/api/page-container)
189
202
  */
190
203
  function PageContainer(props: PageContainerProps) {
191
- const { children, slots, slotProps, ...rest } = props;
204
+ const { children, slots, slotProps, titleBar, ...rest } = props;
192
205
 
193
206
  return (
194
207
  <Stack sx={{ mx: 3, my: 2 }} spacing={2} {...rest}>
195
- <PageContainerBar slots={slots} slotProps={slotProps} />
208
+ <PageContainerBar
209
+ slots={slots}
210
+ slotProps={slotProps}
211
+ titleBar={titleBar}
212
+ />
196
213
  {children}
197
214
  </Stack>
198
215
  );