@cloudflare/component-page 5.0.2 → 5.1.0
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.
- package/CHANGELOG.md +17 -0
- package/dist/Heading.d.ts +14 -0
- package/dist/Page.d.ts +5 -5
- package/dist/index.d.ts +2 -1
- package/es/Heading.js +81 -0
- package/es/Page.js +62 -53
- package/es/index.js +2 -1
- package/lib/Heading.js +101 -0
- package/lib/Page.js +79 -75
- package/lib/index.js +14 -0
- package/package.json +2 -2
- package/src/Heading.tsx +107 -0
- package/src/Page.tsx +93 -82
- package/src/index.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.1.0](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/component-page@5.0.2...@cloudflare/component-page@5.1.0) (2021-11-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **component-page:** A11Y-86 Bug fix ([9ab1079](http://stash.cfops.it:7999/fe/stratus/commits/9ab1079))
|
|
12
|
+
* **component-page:** A11Y-86 remove unused type ([8929fec](http://stash.cfops.it:7999/fe/stratus/commits/8929fec))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **component-page:** A11Y-86 Section and Heading tags ([5b91d18](http://stash.cfops.it:7999/fe/stratus/commits/5b91d18))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
6
23
|
## [5.0.2](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/component-page@5.0.1...@cloudflare/component-page@5.0.2) (2021-11-23)
|
|
7
24
|
|
|
8
25
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { H1 } from '@cloudflare/elements';
|
|
3
|
+
declare type SectionProps = {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
level?: number;
|
|
6
|
+
offset?: number;
|
|
7
|
+
};
|
|
8
|
+
declare type HeadingProps = React.ComponentProps<typeof H1> & {
|
|
9
|
+
level?: number;
|
|
10
|
+
offset?: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function Section(props: SectionProps): JSX.Element;
|
|
13
|
+
export declare function Heading({ level, offset, ...props }: HeadingProps): JSX.Element;
|
|
14
|
+
export {};
|
package/dist/Page.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
declare type PageWidth = 'narrow' | 'wide' | 'unbounded';
|
|
3
3
|
declare const _default: React.ComponentType<{
|
|
4
|
-
type?: PageWidth | undefined;
|
|
5
|
-
className?: string | undefined;
|
|
6
|
-
testId?: string | undefined;
|
|
7
4
|
title?: React.ReactNode;
|
|
8
5
|
subtitle?: React.ReactNode;
|
|
9
6
|
description?: React.ReactNode;
|
|
10
7
|
control?: React.ReactNode;
|
|
8
|
+
children?: React.ReactNode;
|
|
11
9
|
centerHeader?: boolean | undefined;
|
|
10
|
+
beta?: boolean | undefined;
|
|
11
|
+
type?: PageWidth | undefined;
|
|
12
|
+
className?: string | undefined;
|
|
13
|
+
testId?: string | undefined;
|
|
12
14
|
sidebar?: React.ReactNode;
|
|
13
15
|
sidebarPosition?: "left" | "inside" | "outside" | undefined;
|
|
14
|
-
beta?: boolean | undefined;
|
|
15
|
-
children?: any;
|
|
16
16
|
autofocus?: boolean | undefined;
|
|
17
17
|
p?: import("csstype").PaddingProperty<string | number> | [import("csstype").PaddingProperty<string | number> | undefined, import("csstype").PaddingProperty<string | number> | undefined] | [import("csstype").PaddingProperty<string | number> | undefined, import("csstype").PaddingProperty<string | number> | undefined, import("csstype").PaddingProperty<string | number> | undefined] | undefined;
|
|
18
18
|
color?: string | [string | undefined, string | undefined] | [string | undefined, string | undefined, string | undefined] | undefined;
|
package/dist/index.d.ts
CHANGED
package/es/Heading.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
2
|
+
|
|
3
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { H1, H2, H3, H4, H5 } from '@cloudflare/elements';
|
|
7
|
+
import { createStyledComponent } from '@cloudflare/style-container';
|
|
8
|
+
const HeadingInfo = /*#__PURE__*/React.createContext({
|
|
9
|
+
level: 0,
|
|
10
|
+
offset: 0
|
|
11
|
+
});
|
|
12
|
+
const headerThemes = [({
|
|
13
|
+
theme
|
|
14
|
+
}) => ({
|
|
15
|
+
fontSize: theme.fontSizes[6],
|
|
16
|
+
lineHeight: 1.25,
|
|
17
|
+
color: theme.colors.gray[1],
|
|
18
|
+
fontWeight: 600
|
|
19
|
+
}), ({
|
|
20
|
+
theme
|
|
21
|
+
}) => ({
|
|
22
|
+
fontSize: theme.fontSizes[5],
|
|
23
|
+
lineHeight: 1.25,
|
|
24
|
+
color: theme.colors.gray[3],
|
|
25
|
+
fontWeight: 400
|
|
26
|
+
}), ({
|
|
27
|
+
theme
|
|
28
|
+
}) => ({
|
|
29
|
+
fontSize: theme.fontSizes[4],
|
|
30
|
+
fontWeight: 600
|
|
31
|
+
}), ({
|
|
32
|
+
theme
|
|
33
|
+
}) => ({
|
|
34
|
+
fontSize: theme.fontSizes[3],
|
|
35
|
+
lineHeight: 1.25,
|
|
36
|
+
fontWeight: 600
|
|
37
|
+
})];
|
|
38
|
+
const headings = [H1, H2, H3, H4, H5];
|
|
39
|
+
const maxHeadingLevel = headings.length - 1;
|
|
40
|
+
const maxOffset = 2;
|
|
41
|
+
const standardHeadings = headings.map((h, index) => {
|
|
42
|
+
const themeIndex = Math.min(index, headerThemes.length);
|
|
43
|
+
return createStyledComponent(headerThemes[themeIndex], h);
|
|
44
|
+
}); // Renders H1 with H2 style, H2 with H3 style etc.
|
|
45
|
+
|
|
46
|
+
const offsetOneHeadings = headings.map((h, index) => {
|
|
47
|
+
const themeIndex = Math.min(index + 1, headerThemes.length);
|
|
48
|
+
return createStyledComponent(headerThemes[themeIndex], h);
|
|
49
|
+
}); // Renders H1 with H3 style, H2 with H4 style etc.
|
|
50
|
+
|
|
51
|
+
const offsetTwoHeadings = headings.map((h, index) => {
|
|
52
|
+
const themeIndex = Math.min(index + 2, headerThemes.length);
|
|
53
|
+
return createStyledComponent(headerThemes[themeIndex], h);
|
|
54
|
+
});
|
|
55
|
+
export function Section(props) {
|
|
56
|
+
return /*#__PURE__*/React.createElement(HeadingInfo.Consumer, null, info => {
|
|
57
|
+
var _props$level, _props$offset;
|
|
58
|
+
|
|
59
|
+
return /*#__PURE__*/React.createElement(HeadingInfo.Provider, {
|
|
60
|
+
value: {
|
|
61
|
+
level: (_props$level = props.level) !== null && _props$level !== void 0 ? _props$level : info.level + 1,
|
|
62
|
+
offset: info.offset + ((_props$offset = props.offset) !== null && _props$offset !== void 0 ? _props$offset : 0)
|
|
63
|
+
}
|
|
64
|
+
}, props.children);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export function Heading(_ref) {
|
|
68
|
+
let level = _ref.level,
|
|
69
|
+
_ref$offset = _ref.offset,
|
|
70
|
+
offset = _ref$offset === void 0 ? 0 : _ref$offset,
|
|
71
|
+
props = _objectWithoutProperties(_ref, ["level", "offset"]);
|
|
72
|
+
|
|
73
|
+
return /*#__PURE__*/React.createElement(HeadingInfo.Consumer, null, info => {
|
|
74
|
+
const headingOffset = Math.min(maxOffset, info.offset + offset);
|
|
75
|
+
const headings = headingOffset === 1 ? offsetOneHeadings : headingOffset === 2 ? offsetTwoHeadings : standardHeadings;
|
|
76
|
+
const headingLevel = Math.min(level !== undefined ? level - 1 : info.level, maxHeadingLevel);
|
|
77
|
+
const Heading = headings[Math.max(0, headingLevel)]; // @ts-ignore
|
|
78
|
+
|
|
79
|
+
return /*#__PURE__*/React.createElement(Heading, props);
|
|
80
|
+
});
|
|
81
|
+
}
|
package/es/Page.js
CHANGED
|
@@ -4,32 +4,12 @@ import { createStyledComponent, createComponent } from '@cloudflare/style-contai
|
|
|
4
4
|
import { Main, Header, Div } from '@cloudflare/elements';
|
|
5
5
|
import { Label } from '@cloudflare/component-label';
|
|
6
6
|
import { Trans } from '@cloudflare/intl-react';
|
|
7
|
+
import { Heading, Section } from './Heading';
|
|
7
8
|
const maxWidthByType = {
|
|
8
9
|
narrow: '64em',
|
|
9
10
|
wide: '79em',
|
|
10
11
|
unbounded: '100%'
|
|
11
12
|
};
|
|
12
|
-
const PageTitle = createComponent(({
|
|
13
|
-
theme
|
|
14
|
-
}) => ({
|
|
15
|
-
fontSize: theme.fontSizes[6],
|
|
16
|
-
marginTop: theme.space[0],
|
|
17
|
-
marginBottom: theme.space[0],
|
|
18
|
-
lineHeight: 1.25,
|
|
19
|
-
color: theme.colors.gray[1],
|
|
20
|
-
fontWeight: 600
|
|
21
|
-
}), 'h1');
|
|
22
|
-
PageTitle.displayName = 'Title';
|
|
23
|
-
const PageSubtitle = createComponent(({
|
|
24
|
-
theme
|
|
25
|
-
}) => ({
|
|
26
|
-
fontSize: theme.fontSizes[5],
|
|
27
|
-
marginBottom: theme.space[0],
|
|
28
|
-
lineHeight: 1.25,
|
|
29
|
-
color: theme.colors.gray[3],
|
|
30
|
-
fontWeight: 400
|
|
31
|
-
}), 'h2');
|
|
32
|
-
PageTitle.displayName = 'PageSubtitle';
|
|
33
13
|
const PageDescription = createComponent(({
|
|
34
14
|
theme
|
|
35
15
|
}) => ({
|
|
@@ -40,16 +20,56 @@ const PageDescription = createComponent(({
|
|
|
40
20
|
fontWeight: 400
|
|
41
21
|
}), 'p');
|
|
42
22
|
PageDescription.displayName = 'PageDescription';
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}),
|
|
52
|
-
|
|
23
|
+
|
|
24
|
+
const ControlWrapper = ({
|
|
25
|
+
control,
|
|
26
|
+
children
|
|
27
|
+
}) => {
|
|
28
|
+
return control ? /*#__PURE__*/React.createElement(Div, {
|
|
29
|
+
display: ['block', 'flex'],
|
|
30
|
+
justifyContent: "space-between"
|
|
31
|
+
}, children, control) : /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const maxPageTitles = 2;
|
|
35
|
+
|
|
36
|
+
const PageHeader = ({
|
|
37
|
+
title,
|
|
38
|
+
subtitle,
|
|
39
|
+
description,
|
|
40
|
+
centerHeader,
|
|
41
|
+
control,
|
|
42
|
+
children,
|
|
43
|
+
beta
|
|
44
|
+
}) => {
|
|
45
|
+
const headerVisible = !!(title || subtitle || description);
|
|
46
|
+
const titlesCount = Math.min([title, subtitle, description].filter(Boolean).length, 2);
|
|
47
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ControlWrapper, {
|
|
48
|
+
control: control
|
|
49
|
+
}, /*#__PURE__*/React.createElement(Header, {
|
|
50
|
+
mb: headerVisible ? 3 : 0,
|
|
51
|
+
textAlign: centerHeader ? 'center' : undefined
|
|
52
|
+
}, title && /*#__PURE__*/React.createElement(Heading, null, title, beta && /*#__PURE__*/React.createElement(Label, {
|
|
53
|
+
hue: "orange",
|
|
54
|
+
ml: 2,
|
|
55
|
+
verticalAlign: "middle"
|
|
56
|
+
}, /*#__PURE__*/React.createElement(Trans, {
|
|
57
|
+
_: "Beta",
|
|
58
|
+
id: "common.beta"
|
|
59
|
+
}))), subtitle && /*#__PURE__*/React.createElement(Heading, {
|
|
60
|
+
level: title ? 2 : 1,
|
|
61
|
+
offset: title ? 0 : 1
|
|
62
|
+
}, subtitle), description && (subtitle ? /*#__PURE__*/React.createElement(PageDescription, null, description) : /*#__PURE__*/React.createElement(Heading, {
|
|
63
|
+
level: 2,
|
|
64
|
+
fontSize: 4,
|
|
65
|
+
color: "gray.3"
|
|
66
|
+
}, description)))), /*#__PURE__*/React.createElement(Section, {
|
|
67
|
+
level: titlesCount,
|
|
68
|
+
offset: maxPageTitles - titlesCount
|
|
69
|
+
}, children));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
PageHeader.displayName = 'PageHeader'; // firstPage is used when dealing with focus. When navigating the dash, focus
|
|
53
73
|
// jumps to the page content, but not when the dash is initially loaded.
|
|
54
74
|
|
|
55
75
|
let firstPage = ''; // firstLoad is used to ensure focus is handled correctly if the user navigates
|
|
@@ -99,31 +119,12 @@ const Page = ({
|
|
|
99
119
|
}
|
|
100
120
|
}
|
|
101
121
|
}, [path]);
|
|
102
|
-
const headerVisible = !!(title || subtitle || description);
|
|
103
|
-
let header = /*#__PURE__*/React.createElement(Header, {
|
|
104
|
-
mb: headerVisible ? 3 : 0,
|
|
105
|
-
textAlign: centerHeader ? 'center' : undefined
|
|
106
|
-
}, title && /*#__PURE__*/React.createElement(PageTitle, null, title, beta && /*#__PURE__*/React.createElement(Label, {
|
|
107
|
-
hue: "orange",
|
|
108
|
-
ml: 2,
|
|
109
|
-
verticalAlign: "middle"
|
|
110
|
-
}, /*#__PURE__*/React.createElement(Trans, {
|
|
111
|
-
_: "Beta",
|
|
112
|
-
id: "common.beta"
|
|
113
|
-
}))), subtitle && /*#__PURE__*/React.createElement(PageSubtitle, null, subtitle), description && (subtitle ? /*#__PURE__*/React.createElement(PageDescription, null, description) : /*#__PURE__*/React.createElement(PageSubtitleDescription, null, description)));
|
|
114
|
-
|
|
115
|
-
if (control) {
|
|
116
|
-
header = /*#__PURE__*/React.createElement(Div, {
|
|
117
|
-
display: ['block', 'flex'],
|
|
118
|
-
justifyContent: "space-between"
|
|
119
|
-
}, header, control);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
122
|
const sidebarInside = sidebarPosition === 'inside';
|
|
123
123
|
return /*#__PURE__*/React.createElement(Main, {
|
|
124
124
|
"data-testid": testId,
|
|
125
125
|
className: className,
|
|
126
|
-
display: sidebar && sidebarInside ? undefined : 'flex'
|
|
126
|
+
display: sidebar && sidebarInside ? undefined : 'flex',
|
|
127
|
+
py: 4
|
|
127
128
|
}, /*#__PURE__*/React.createElement(Div, {
|
|
128
129
|
ml: "auto",
|
|
129
130
|
mr: sidebar && !sidebarInside ? 0 : 'auto',
|
|
@@ -138,7 +139,15 @@ const Page = ({
|
|
|
138
139
|
id: "skipTarget",
|
|
139
140
|
ref: skipTargetRef,
|
|
140
141
|
tabIndex: -1
|
|
141
|
-
}),
|
|
142
|
+
}), /*#__PURE__*/React.createElement(PageHeader, {
|
|
143
|
+
title: title,
|
|
144
|
+
subtitle: subtitle,
|
|
145
|
+
description: description,
|
|
146
|
+
centerHeader: centerHeader,
|
|
147
|
+
control: control,
|
|
148
|
+
children: children,
|
|
149
|
+
beta: beta
|
|
150
|
+
})), sidebar && sidebarInside && /*#__PURE__*/React.createElement(Div, {
|
|
142
151
|
width: [1, 1, 1 / 3],
|
|
143
152
|
pl: [0, 0, 3],
|
|
144
153
|
pt: [4, 4, 0]
|
package/es/index.js
CHANGED
package/lib/Heading.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Section = Section;
|
|
7
|
+
exports.Heading = Heading;
|
|
8
|
+
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
|
|
11
|
+
var _elements = require("@cloudflare/elements");
|
|
12
|
+
|
|
13
|
+
var _styleContainer = require("@cloudflare/style-container");
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
|
|
17
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
18
|
+
|
|
19
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
20
|
+
|
|
21
|
+
var HeadingInfo = /*#__PURE__*/_react.default.createContext({
|
|
22
|
+
level: 0,
|
|
23
|
+
offset: 0
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
var headerThemes = [function (_ref) {
|
|
27
|
+
var theme = _ref.theme;
|
|
28
|
+
return {
|
|
29
|
+
fontSize: theme.fontSizes[6],
|
|
30
|
+
lineHeight: 1.25,
|
|
31
|
+
color: theme.colors.gray[1],
|
|
32
|
+
fontWeight: 600
|
|
33
|
+
};
|
|
34
|
+
}, function (_ref2) {
|
|
35
|
+
var theme = _ref2.theme;
|
|
36
|
+
return {
|
|
37
|
+
fontSize: theme.fontSizes[5],
|
|
38
|
+
lineHeight: 1.25,
|
|
39
|
+
color: theme.colors.gray[3],
|
|
40
|
+
fontWeight: 400
|
|
41
|
+
};
|
|
42
|
+
}, function (_ref3) {
|
|
43
|
+
var theme = _ref3.theme;
|
|
44
|
+
return {
|
|
45
|
+
fontSize: theme.fontSizes[4],
|
|
46
|
+
fontWeight: 600
|
|
47
|
+
};
|
|
48
|
+
}, function (_ref4) {
|
|
49
|
+
var theme = _ref4.theme;
|
|
50
|
+
return {
|
|
51
|
+
fontSize: theme.fontSizes[3],
|
|
52
|
+
lineHeight: 1.25,
|
|
53
|
+
fontWeight: 600
|
|
54
|
+
};
|
|
55
|
+
}];
|
|
56
|
+
var headings = [_elements.H1, _elements.H2, _elements.H3, _elements.H4, _elements.H5];
|
|
57
|
+
var maxHeadingLevel = headings.length - 1;
|
|
58
|
+
var maxOffset = 2;
|
|
59
|
+
var standardHeadings = headings.map(function (h, index) {
|
|
60
|
+
var themeIndex = Math.min(index, headerThemes.length);
|
|
61
|
+
return (0, _styleContainer.createStyledComponent)(headerThemes[themeIndex], h);
|
|
62
|
+
}); // Renders H1 with H2 style, H2 with H3 style etc.
|
|
63
|
+
|
|
64
|
+
var offsetOneHeadings = headings.map(function (h, index) {
|
|
65
|
+
var themeIndex = Math.min(index + 1, headerThemes.length);
|
|
66
|
+
return (0, _styleContainer.createStyledComponent)(headerThemes[themeIndex], h);
|
|
67
|
+
}); // Renders H1 with H3 style, H2 with H4 style etc.
|
|
68
|
+
|
|
69
|
+
var offsetTwoHeadings = headings.map(function (h, index) {
|
|
70
|
+
var themeIndex = Math.min(index + 2, headerThemes.length);
|
|
71
|
+
return (0, _styleContainer.createStyledComponent)(headerThemes[themeIndex], h);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
function Section(props) {
|
|
75
|
+
return /*#__PURE__*/_react.default.createElement(HeadingInfo.Consumer, null, function (info) {
|
|
76
|
+
var _props$level, _props$offset;
|
|
77
|
+
|
|
78
|
+
return /*#__PURE__*/_react.default.createElement(HeadingInfo.Provider, {
|
|
79
|
+
value: {
|
|
80
|
+
level: (_props$level = props.level) !== null && _props$level !== void 0 ? _props$level : info.level + 1,
|
|
81
|
+
offset: info.offset + ((_props$offset = props.offset) !== null && _props$offset !== void 0 ? _props$offset : 0)
|
|
82
|
+
}
|
|
83
|
+
}, props.children);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function Heading(_ref5) {
|
|
88
|
+
var level = _ref5.level,
|
|
89
|
+
_ref5$offset = _ref5.offset,
|
|
90
|
+
offset = _ref5$offset === void 0 ? 0 : _ref5$offset,
|
|
91
|
+
props = _objectWithoutProperties(_ref5, ["level", "offset"]);
|
|
92
|
+
|
|
93
|
+
return /*#__PURE__*/_react.default.createElement(HeadingInfo.Consumer, null, function (info) {
|
|
94
|
+
var headingOffset = Math.min(maxOffset, info.offset + offset);
|
|
95
|
+
var headings = headingOffset === 1 ? offsetOneHeadings : headingOffset === 2 ? offsetTwoHeadings : standardHeadings;
|
|
96
|
+
var headingLevel = Math.min(level !== undefined ? level - 1 : info.level, maxHeadingLevel);
|
|
97
|
+
var Heading = headings[Math.max(0, headingLevel)]; // @ts-ignore
|
|
98
|
+
|
|
99
|
+
return /*#__PURE__*/_react.default.createElement(Heading, props);
|
|
100
|
+
});
|
|
101
|
+
}
|
package/lib/Page.js
CHANGED
|
@@ -19,6 +19,8 @@ var _componentLabel = require("@cloudflare/component-label");
|
|
|
19
19
|
|
|
20
20
|
var _intlReact = require("@cloudflare/intl-react");
|
|
21
21
|
|
|
22
|
+
var _Heading = require("./Heading");
|
|
23
|
+
|
|
22
24
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
23
25
|
|
|
24
26
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -28,31 +30,8 @@ var maxWidthByType = {
|
|
|
28
30
|
wide: '79em',
|
|
29
31
|
unbounded: '100%'
|
|
30
32
|
};
|
|
31
|
-
var
|
|
33
|
+
var PageDescription = (0, _styleContainer.createComponent)(function (_ref) {
|
|
32
34
|
var theme = _ref.theme;
|
|
33
|
-
return {
|
|
34
|
-
fontSize: theme.fontSizes[6],
|
|
35
|
-
marginTop: theme.space[0],
|
|
36
|
-
marginBottom: theme.space[0],
|
|
37
|
-
lineHeight: 1.25,
|
|
38
|
-
color: theme.colors.gray[1],
|
|
39
|
-
fontWeight: 600
|
|
40
|
-
};
|
|
41
|
-
}, 'h1');
|
|
42
|
-
PageTitle.displayName = 'Title';
|
|
43
|
-
var PageSubtitle = (0, _styleContainer.createComponent)(function (_ref2) {
|
|
44
|
-
var theme = _ref2.theme;
|
|
45
|
-
return {
|
|
46
|
-
fontSize: theme.fontSizes[5],
|
|
47
|
-
marginBottom: theme.space[0],
|
|
48
|
-
lineHeight: 1.25,
|
|
49
|
-
color: theme.colors.gray[3],
|
|
50
|
-
fontWeight: 400
|
|
51
|
-
};
|
|
52
|
-
}, 'h2');
|
|
53
|
-
PageTitle.displayName = 'PageSubtitle';
|
|
54
|
-
var PageDescription = (0, _styleContainer.createComponent)(function (_ref3) {
|
|
55
|
-
var theme = _ref3.theme;
|
|
56
35
|
return {
|
|
57
36
|
fontSize: theme.fontSizes[4],
|
|
58
37
|
marginBottom: theme.space[0],
|
|
@@ -62,17 +41,54 @@ var PageDescription = (0, _styleContainer.createComponent)(function (_ref3) {
|
|
|
62
41
|
};
|
|
63
42
|
}, 'p');
|
|
64
43
|
PageDescription.displayName = 'PageDescription';
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
44
|
+
|
|
45
|
+
var ControlWrapper = function ControlWrapper(_ref2) {
|
|
46
|
+
var control = _ref2.control,
|
|
47
|
+
children = _ref2.children;
|
|
48
|
+
return control ? /*#__PURE__*/_react.default.createElement(_elements.Div, {
|
|
49
|
+
display: ['block', 'flex'],
|
|
50
|
+
justifyContent: "space-between"
|
|
51
|
+
}, children, control) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var maxPageTitles = 2;
|
|
55
|
+
|
|
56
|
+
var PageHeader = function PageHeader(_ref3) {
|
|
57
|
+
var title = _ref3.title,
|
|
58
|
+
subtitle = _ref3.subtitle,
|
|
59
|
+
description = _ref3.description,
|
|
60
|
+
centerHeader = _ref3.centerHeader,
|
|
61
|
+
control = _ref3.control,
|
|
62
|
+
children = _ref3.children,
|
|
63
|
+
beta = _ref3.beta;
|
|
64
|
+
var headerVisible = !!(title || subtitle || description);
|
|
65
|
+
var titlesCount = Math.min([title, subtitle, description].filter(Boolean).length, 2);
|
|
66
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(ControlWrapper, {
|
|
67
|
+
control: control
|
|
68
|
+
}, /*#__PURE__*/_react.default.createElement(_elements.Header, {
|
|
69
|
+
mb: headerVisible ? 3 : 0,
|
|
70
|
+
textAlign: centerHeader ? 'center' : undefined
|
|
71
|
+
}, title && /*#__PURE__*/_react.default.createElement(_Heading.Heading, null, title, beta && /*#__PURE__*/_react.default.createElement(_componentLabel.Label, {
|
|
72
|
+
hue: "orange",
|
|
73
|
+
ml: 2,
|
|
74
|
+
verticalAlign: "middle"
|
|
75
|
+
}, /*#__PURE__*/_react.default.createElement(_intlReact.Trans, {
|
|
76
|
+
_: "Beta",
|
|
77
|
+
id: "common.beta"
|
|
78
|
+
}))), subtitle && /*#__PURE__*/_react.default.createElement(_Heading.Heading, {
|
|
79
|
+
level: title ? 2 : 1,
|
|
80
|
+
offset: title ? 0 : 1
|
|
81
|
+
}, subtitle), description && (subtitle ? /*#__PURE__*/_react.default.createElement(PageDescription, null, description) : /*#__PURE__*/_react.default.createElement(_Heading.Heading, {
|
|
82
|
+
level: 2,
|
|
83
|
+
fontSize: 4,
|
|
84
|
+
color: "gray.3"
|
|
85
|
+
}, description)))), /*#__PURE__*/_react.default.createElement(_Heading.Section, {
|
|
86
|
+
level: titlesCount,
|
|
87
|
+
offset: maxPageTitles - titlesCount
|
|
88
|
+
}, children));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
PageHeader.displayName = 'PageHeader'; // firstPage is used when dealing with focus. When navigating the dash, focus
|
|
76
92
|
// jumps to the page content, but not when the dash is initially loaded.
|
|
77
93
|
|
|
78
94
|
var firstPage = ''; // firstLoad is used to ensure focus is handled correctly if the user navigates
|
|
@@ -93,25 +109,25 @@ var focus = function focus(el) {
|
|
|
93
109
|
}
|
|
94
110
|
};
|
|
95
111
|
|
|
96
|
-
var Page = function Page(
|
|
112
|
+
var Page = function Page(_ref4) {
|
|
97
113
|
var _history$location;
|
|
98
114
|
|
|
99
|
-
var title =
|
|
100
|
-
subtitle =
|
|
101
|
-
description =
|
|
102
|
-
centerHeader =
|
|
103
|
-
beta =
|
|
104
|
-
testId =
|
|
105
|
-
className =
|
|
106
|
-
sidebar =
|
|
107
|
-
|
|
108
|
-
type =
|
|
109
|
-
|
|
110
|
-
sidebarPosition =
|
|
111
|
-
|
|
112
|
-
autofocus =
|
|
113
|
-
control =
|
|
114
|
-
children =
|
|
115
|
+
var title = _ref4.title,
|
|
116
|
+
subtitle = _ref4.subtitle,
|
|
117
|
+
description = _ref4.description,
|
|
118
|
+
centerHeader = _ref4.centerHeader,
|
|
119
|
+
beta = _ref4.beta,
|
|
120
|
+
testId = _ref4.testId,
|
|
121
|
+
className = _ref4.className,
|
|
122
|
+
sidebar = _ref4.sidebar,
|
|
123
|
+
_ref4$type = _ref4.type,
|
|
124
|
+
type = _ref4$type === void 0 ? 'wide' : _ref4$type,
|
|
125
|
+
_ref4$sidebarPosition = _ref4.sidebarPosition,
|
|
126
|
+
sidebarPosition = _ref4$sidebarPosition === void 0 ? 'inside' : _ref4$sidebarPosition,
|
|
127
|
+
_ref4$autofocus = _ref4.autofocus,
|
|
128
|
+
autofocus = _ref4$autofocus === void 0 ? true : _ref4$autofocus,
|
|
129
|
+
control = _ref4.control,
|
|
130
|
+
children = _ref4.children;
|
|
115
131
|
var history = (0, _reactRouterDom.useHistory)();
|
|
116
132
|
var skipTargetRef = (0, _react.useRef)(null);
|
|
117
133
|
var path = history === null || history === void 0 ? void 0 : (_history$location = history.location) === null || _history$location === void 0 ? void 0 : _history$location.pathname;
|
|
@@ -127,32 +143,12 @@ var Page = function Page(_ref5) {
|
|
|
127
143
|
}
|
|
128
144
|
}
|
|
129
145
|
}, [path]);
|
|
130
|
-
var headerVisible = !!(title || subtitle || description);
|
|
131
|
-
|
|
132
|
-
var header = /*#__PURE__*/_react.default.createElement(_elements.Header, {
|
|
133
|
-
mb: headerVisible ? 3 : 0,
|
|
134
|
-
textAlign: centerHeader ? 'center' : undefined
|
|
135
|
-
}, title && /*#__PURE__*/_react.default.createElement(PageTitle, null, title, beta && /*#__PURE__*/_react.default.createElement(_componentLabel.Label, {
|
|
136
|
-
hue: "orange",
|
|
137
|
-
ml: 2,
|
|
138
|
-
verticalAlign: "middle"
|
|
139
|
-
}, /*#__PURE__*/_react.default.createElement(_intlReact.Trans, {
|
|
140
|
-
_: "Beta",
|
|
141
|
-
id: "common.beta"
|
|
142
|
-
}))), subtitle && /*#__PURE__*/_react.default.createElement(PageSubtitle, null, subtitle), description && (subtitle ? /*#__PURE__*/_react.default.createElement(PageDescription, null, description) : /*#__PURE__*/_react.default.createElement(PageSubtitleDescription, null, description)));
|
|
143
|
-
|
|
144
|
-
if (control) {
|
|
145
|
-
header = /*#__PURE__*/_react.default.createElement(_elements.Div, {
|
|
146
|
-
display: ['block', 'flex'],
|
|
147
|
-
justifyContent: "space-between"
|
|
148
|
-
}, header, control);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
146
|
var sidebarInside = sidebarPosition === 'inside';
|
|
152
147
|
return /*#__PURE__*/_react.default.createElement(_elements.Main, {
|
|
153
148
|
"data-testid": testId,
|
|
154
149
|
className: className,
|
|
155
|
-
display: sidebar && sidebarInside ? undefined : 'flex'
|
|
150
|
+
display: sidebar && sidebarInside ? undefined : 'flex',
|
|
151
|
+
py: 4
|
|
156
152
|
}, /*#__PURE__*/_react.default.createElement(_elements.Div, {
|
|
157
153
|
ml: "auto",
|
|
158
154
|
mr: sidebar && !sidebarInside ? 0 : 'auto',
|
|
@@ -167,7 +163,15 @@ var Page = function Page(_ref5) {
|
|
|
167
163
|
id: "skipTarget",
|
|
168
164
|
ref: skipTargetRef,
|
|
169
165
|
tabIndex: -1
|
|
170
|
-
}),
|
|
166
|
+
}), /*#__PURE__*/_react.default.createElement(PageHeader, {
|
|
167
|
+
title: title,
|
|
168
|
+
subtitle: subtitle,
|
|
169
|
+
description: description,
|
|
170
|
+
centerHeader: centerHeader,
|
|
171
|
+
control: control,
|
|
172
|
+
children: children,
|
|
173
|
+
beta: beta
|
|
174
|
+
})), sidebar && sidebarInside && /*#__PURE__*/_react.default.createElement(_elements.Div, {
|
|
171
175
|
width: [1, 1, 1 / 3],
|
|
172
176
|
pl: [0, 0, 3],
|
|
173
177
|
pt: [4, 4, 0]
|
package/lib/index.js
CHANGED
|
@@ -9,7 +9,21 @@ Object.defineProperty(exports, "Page", {
|
|
|
9
9
|
return _Page.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "Heading", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _Heading.Heading;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "Section", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _Heading.Section;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
12
24
|
|
|
13
25
|
var _Page = _interopRequireDefault(require("./Page"));
|
|
14
26
|
|
|
27
|
+
var _Heading = require("./Heading");
|
|
28
|
+
|
|
15
29
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/component-page",
|
|
3
3
|
"description": "Cloudflare Page Component",
|
|
4
|
-
"version": "5.0
|
|
4
|
+
"version": "5.1.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
7
7
|
"author": "James Kyle <jkyle@cloudflare.com>",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"test-coverage": "stratus test --coverage",
|
|
32
32
|
"test-watch": "stratus test --watch"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "e1f1fecb460540213dd9f08e78e91e8d71dcbe27"
|
|
35
35
|
}
|
package/src/Heading.tsx
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { H1, H2, H3, H4, H5 } from '@cloudflare/elements';
|
|
3
|
+
import { createStyledComponent, ThemeProp } from '@cloudflare/style-container';
|
|
4
|
+
|
|
5
|
+
type SectionProps = {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
level?: number;
|
|
8
|
+
offset?: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type HeadingProps = React.ComponentProps<typeof H1> & {
|
|
12
|
+
level?: number;
|
|
13
|
+
offset?: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const HeadingInfo = React.createContext({
|
|
17
|
+
level: 0,
|
|
18
|
+
offset: 0
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const headerThemes = [
|
|
22
|
+
({ theme }: { theme: ThemeProp['theme'] }) => ({
|
|
23
|
+
fontSize: theme.fontSizes[6],
|
|
24
|
+
lineHeight: 1.25,
|
|
25
|
+
color: theme.colors.gray[1],
|
|
26
|
+
fontWeight: 600
|
|
27
|
+
}),
|
|
28
|
+
({ theme }: { theme: ThemeProp['theme'] }) => ({
|
|
29
|
+
fontSize: theme.fontSizes[5],
|
|
30
|
+
lineHeight: 1.25,
|
|
31
|
+
color: theme.colors.gray[3],
|
|
32
|
+
fontWeight: 400
|
|
33
|
+
}),
|
|
34
|
+
({ theme }: { theme: ThemeProp['theme'] }) => ({
|
|
35
|
+
fontSize: theme.fontSizes[4],
|
|
36
|
+
fontWeight: 600
|
|
37
|
+
}),
|
|
38
|
+
({ theme }: { theme: ThemeProp['theme'] }) => ({
|
|
39
|
+
fontSize: theme.fontSizes[3],
|
|
40
|
+
lineHeight: 1.25,
|
|
41
|
+
fontWeight: 600
|
|
42
|
+
})
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
const headings = [H1, H2, H3, H4, H5];
|
|
46
|
+
|
|
47
|
+
const maxHeadingLevel = headings.length - 1;
|
|
48
|
+
|
|
49
|
+
const maxOffset = 2;
|
|
50
|
+
|
|
51
|
+
const standardHeadings = headings.map((h, index) => {
|
|
52
|
+
const themeIndex = Math.min(index, headerThemes.length);
|
|
53
|
+
return createStyledComponent(headerThemes[themeIndex], h);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Renders H1 with H2 style, H2 with H3 style etc.
|
|
57
|
+
const offsetOneHeadings = headings.map((h, index) => {
|
|
58
|
+
const themeIndex = Math.min(index + 1, headerThemes.length);
|
|
59
|
+
return createStyledComponent(headerThemes[themeIndex], h);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Renders H1 with H3 style, H2 with H4 style etc.
|
|
63
|
+
const offsetTwoHeadings = headings.map((h, index) => {
|
|
64
|
+
const themeIndex = Math.min(index + 2, headerThemes.length);
|
|
65
|
+
return createStyledComponent(headerThemes[themeIndex], h);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export function Section(props: SectionProps) {
|
|
69
|
+
return (
|
|
70
|
+
<HeadingInfo.Consumer>
|
|
71
|
+
{info => (
|
|
72
|
+
<HeadingInfo.Provider
|
|
73
|
+
value={{
|
|
74
|
+
level: props.level ?? info.level + 1,
|
|
75
|
+
offset: info.offset + (props.offset ?? 0)
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
{props.children}
|
|
79
|
+
</HeadingInfo.Provider>
|
|
80
|
+
)}
|
|
81
|
+
</HeadingInfo.Consumer>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function Heading({ level, offset = 0, ...props }: HeadingProps) {
|
|
86
|
+
return (
|
|
87
|
+
<HeadingInfo.Consumer>
|
|
88
|
+
{info => {
|
|
89
|
+
const headingOffset = Math.min(maxOffset, info.offset + offset);
|
|
90
|
+
const headings =
|
|
91
|
+
headingOffset === 1
|
|
92
|
+
? offsetOneHeadings
|
|
93
|
+
: headingOffset === 2
|
|
94
|
+
? offsetTwoHeadings
|
|
95
|
+
: standardHeadings;
|
|
96
|
+
|
|
97
|
+
const headingLevel = Math.min(
|
|
98
|
+
level !== undefined ? level - 1 : info.level,
|
|
99
|
+
maxHeadingLevel
|
|
100
|
+
);
|
|
101
|
+
const Heading = headings[Math.max(0, headingLevel)];
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
return <Heading {...props} />;
|
|
104
|
+
}}
|
|
105
|
+
</HeadingInfo.Consumer>
|
|
106
|
+
);
|
|
107
|
+
}
|
package/src/Page.tsx
CHANGED
|
@@ -7,22 +7,26 @@ import {
|
|
|
7
7
|
import { Main, Header, Div } from '@cloudflare/elements';
|
|
8
8
|
import { Label } from '@cloudflare/component-label';
|
|
9
9
|
import { Trans } from '@cloudflare/intl-react';
|
|
10
|
+
import { Heading, Section } from './Heading';
|
|
10
11
|
|
|
11
12
|
type PageWidth = 'narrow' | 'wide' | 'unbounded';
|
|
12
13
|
|
|
13
|
-
type
|
|
14
|
-
type?: PageWidth;
|
|
15
|
-
className?: string;
|
|
16
|
-
testId?: string;
|
|
14
|
+
type PageHeaderProps = {
|
|
17
15
|
title?: React.ReactNode;
|
|
18
16
|
subtitle?: React.ReactNode;
|
|
19
17
|
description?: React.ReactNode;
|
|
20
18
|
control?: React.ReactNode;
|
|
19
|
+
children?: React.ReactNode;
|
|
21
20
|
centerHeader?: boolean;
|
|
21
|
+
beta?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type Props = PageHeaderProps & {
|
|
25
|
+
type?: PageWidth;
|
|
26
|
+
className?: string;
|
|
27
|
+
testId?: string;
|
|
22
28
|
sidebar?: React.ReactNode;
|
|
23
29
|
sidebarPosition?: 'outside' | 'inside' | 'left';
|
|
24
|
-
beta?: boolean;
|
|
25
|
-
children?: any;
|
|
26
30
|
autofocus?: boolean;
|
|
27
31
|
};
|
|
28
32
|
|
|
@@ -32,33 +36,6 @@ const maxWidthByType = {
|
|
|
32
36
|
unbounded: '100%'
|
|
33
37
|
};
|
|
34
38
|
|
|
35
|
-
const PageTitle = createComponent(
|
|
36
|
-
({ theme }) => ({
|
|
37
|
-
fontSize: theme.fontSizes[6],
|
|
38
|
-
marginTop: theme.space[0],
|
|
39
|
-
marginBottom: theme.space[0],
|
|
40
|
-
lineHeight: 1.25,
|
|
41
|
-
color: theme.colors.gray[1],
|
|
42
|
-
fontWeight: 600
|
|
43
|
-
}),
|
|
44
|
-
'h1'
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
PageTitle.displayName = 'Title';
|
|
48
|
-
|
|
49
|
-
const PageSubtitle = createComponent(
|
|
50
|
-
({ theme }) => ({
|
|
51
|
-
fontSize: theme.fontSizes[5],
|
|
52
|
-
marginBottom: theme.space[0],
|
|
53
|
-
lineHeight: 1.25,
|
|
54
|
-
color: theme.colors.gray[3],
|
|
55
|
-
fontWeight: 400
|
|
56
|
-
}),
|
|
57
|
-
'h2'
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
PageTitle.displayName = 'PageSubtitle';
|
|
61
|
-
|
|
62
39
|
const PageDescription = createComponent(
|
|
63
40
|
({ theme }) => ({
|
|
64
41
|
fontSize: theme.fontSizes[4],
|
|
@@ -72,18 +49,79 @@ const PageDescription = createComponent(
|
|
|
72
49
|
|
|
73
50
|
PageDescription.displayName = 'PageDescription';
|
|
74
51
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
52
|
+
type ControlWrapperProps = {
|
|
53
|
+
control?: React.ReactNode;
|
|
54
|
+
children: React.ReactNode;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const ControlWrapper = ({ control, children }: ControlWrapperProps) => {
|
|
58
|
+
return control ? (
|
|
59
|
+
<Div display={['block', 'flex']} justifyContent="space-between">
|
|
60
|
+
{children}
|
|
61
|
+
{control}
|
|
62
|
+
</Div>
|
|
63
|
+
) : (
|
|
64
|
+
<>{children}</>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const maxPageTitles = 2;
|
|
69
|
+
|
|
70
|
+
const PageHeader = ({
|
|
71
|
+
title,
|
|
72
|
+
subtitle,
|
|
73
|
+
description,
|
|
74
|
+
centerHeader,
|
|
75
|
+
control,
|
|
76
|
+
children,
|
|
77
|
+
beta
|
|
78
|
+
}: PageHeaderProps) => {
|
|
79
|
+
const headerVisible = !!(title || subtitle || description);
|
|
80
|
+
const titlesCount = Math.min(
|
|
81
|
+
[title, subtitle, description].filter(Boolean).length,
|
|
82
|
+
2
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<>
|
|
87
|
+
<ControlWrapper control={control}>
|
|
88
|
+
<Header
|
|
89
|
+
mb={headerVisible ? 3 : 0}
|
|
90
|
+
textAlign={centerHeader ? 'center' : undefined}
|
|
91
|
+
>
|
|
92
|
+
{title && (
|
|
93
|
+
<Heading>
|
|
94
|
+
{title}
|
|
95
|
+
{beta && (
|
|
96
|
+
<Label hue="orange" ml={2} verticalAlign="middle">
|
|
97
|
+
<Trans _="Beta" id="common.beta" />
|
|
98
|
+
</Label>
|
|
99
|
+
)}
|
|
100
|
+
</Heading>
|
|
101
|
+
)}
|
|
102
|
+
{subtitle && (
|
|
103
|
+
<Heading level={title ? 2 : 1} offset={title ? 0 : 1}>
|
|
104
|
+
{subtitle}
|
|
105
|
+
</Heading>
|
|
106
|
+
)}
|
|
107
|
+
{description &&
|
|
108
|
+
(subtitle ? (
|
|
109
|
+
<PageDescription>{description}</PageDescription>
|
|
110
|
+
) : (
|
|
111
|
+
<Heading level={2} fontSize={4} color="gray.3">
|
|
112
|
+
{description}
|
|
113
|
+
</Heading>
|
|
114
|
+
))}
|
|
115
|
+
</Header>
|
|
116
|
+
</ControlWrapper>
|
|
117
|
+
<Section level={titlesCount} offset={maxPageTitles - titlesCount}>
|
|
118
|
+
{children}
|
|
119
|
+
</Section>
|
|
120
|
+
</>
|
|
121
|
+
);
|
|
122
|
+
};
|
|
85
123
|
|
|
86
|
-
|
|
124
|
+
PageHeader.displayName = 'PageHeader';
|
|
87
125
|
|
|
88
126
|
// firstPage is used when dealing with focus. When navigating the dash, focus
|
|
89
127
|
// jumps to the page content, but not when the dash is initially loaded.
|
|
@@ -138,42 +176,6 @@ const Page = ({
|
|
|
138
176
|
}
|
|
139
177
|
}, [path]);
|
|
140
178
|
|
|
141
|
-
const headerVisible = !!(title || subtitle || description);
|
|
142
|
-
|
|
143
|
-
let header = (
|
|
144
|
-
<Header
|
|
145
|
-
mb={headerVisible ? 3 : 0}
|
|
146
|
-
textAlign={centerHeader ? 'center' : undefined}
|
|
147
|
-
>
|
|
148
|
-
{title && (
|
|
149
|
-
<PageTitle>
|
|
150
|
-
{title}
|
|
151
|
-
{beta && (
|
|
152
|
-
<Label hue="orange" ml={2} verticalAlign="middle">
|
|
153
|
-
<Trans _="Beta" id="common.beta" />
|
|
154
|
-
</Label>
|
|
155
|
-
)}
|
|
156
|
-
</PageTitle>
|
|
157
|
-
)}
|
|
158
|
-
{subtitle && <PageSubtitle>{subtitle}</PageSubtitle>}
|
|
159
|
-
{description &&
|
|
160
|
-
(subtitle ? (
|
|
161
|
-
<PageDescription>{description}</PageDescription>
|
|
162
|
-
) : (
|
|
163
|
-
<PageSubtitleDescription>{description}</PageSubtitleDescription>
|
|
164
|
-
))}
|
|
165
|
-
</Header>
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
if (control) {
|
|
169
|
-
header = (
|
|
170
|
-
<Div display={['block', 'flex']} justifyContent="space-between">
|
|
171
|
-
{header}
|
|
172
|
-
{control}
|
|
173
|
-
</Div>
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
179
|
const sidebarInside = sidebarPosition === 'inside';
|
|
178
180
|
|
|
179
181
|
return (
|
|
@@ -181,6 +183,7 @@ const Page = ({
|
|
|
181
183
|
data-testid={testId}
|
|
182
184
|
className={className}
|
|
183
185
|
display={sidebar && sidebarInside ? undefined : 'flex'}
|
|
186
|
+
py={4}
|
|
184
187
|
>
|
|
185
188
|
<Div
|
|
186
189
|
ml="auto"
|
|
@@ -195,8 +198,16 @@ const Page = ({
|
|
|
195
198
|
mt={0}
|
|
196
199
|
>
|
|
197
200
|
<a id="skipTarget" ref={skipTargetRef} tabIndex={-1} />
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
|
|
202
|
+
<PageHeader
|
|
203
|
+
title={title}
|
|
204
|
+
subtitle={subtitle}
|
|
205
|
+
description={description}
|
|
206
|
+
centerHeader={centerHeader}
|
|
207
|
+
control={control}
|
|
208
|
+
children={children}
|
|
209
|
+
beta={beta}
|
|
210
|
+
/>
|
|
200
211
|
</Div>
|
|
201
212
|
{sidebar && sidebarInside && (
|
|
202
213
|
<Div width={[1, 1, 1 / 3]} pl={[0, 0, 3]} pt={[4, 4, 0]}>
|
package/src/index.ts
CHANGED