@blaze-cms/admin 0.146.0-node18-tooltips.56 → 0.146.0-node18-core-styles-tooltips.61
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 +92 -45
- package/blaze.config.js +2 -0
- package/lib/components/ConfirmAction/ConfirmAction.js +92 -0
- package/lib/components/ConfirmAction/ConfirmAction.js.map +1 -0
- package/lib/components/ConfirmAction/index.js +11 -0
- package/lib/components/ConfirmAction/index.js.map +1 -0
- package/lib/components/DeleteAction/DeleteAction.js +11 -15
- package/lib/components/DeleteAction/DeleteAction.js.map +1 -1
- package/lib/components/PageHeader/HeaderIconButton.js +38 -0
- package/lib/components/PageHeader/HeaderIconButton.js.map +1 -0
- package/lib/components/PageHeader/PageHeader.js +84 -13
- package/lib/components/PageHeader/PageHeader.js.map +1 -1
- package/lib/components/PageHeader/TitleEditor.js +107 -0
- package/lib/components/PageHeader/TitleEditor.js.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -1
- package/lib-es/components/ConfirmAction/ConfirmAction.js +68 -0
- package/lib-es/components/ConfirmAction/ConfirmAction.js.map +1 -0
- package/lib-es/components/ConfirmAction/index.js +3 -0
- package/lib-es/components/ConfirmAction/index.js.map +1 -0
- package/lib-es/components/DeleteAction/DeleteAction.js +13 -19
- package/lib-es/components/DeleteAction/DeleteAction.js.map +1 -1
- package/lib-es/components/PageHeader/HeaderIconButton.js +32 -0
- package/lib-es/components/PageHeader/HeaderIconButton.js.map +1 -0
- package/lib-es/components/PageHeader/PageHeader.js +80 -24
- package/lib-es/components/PageHeader/PageHeader.js.map +1 -1
- package/lib-es/components/PageHeader/TitleEditor.js +79 -0
- package/lib-es/components/PageHeader/TitleEditor.js.map +1 -0
- package/lib-es/index.js +2 -1
- package/lib-es/index.js.map +1 -1
- package/package.json +16 -15
- package/src/components/ConfirmAction/ConfirmAction.js +72 -0
- package/src/components/ConfirmAction/index.js +3 -0
- package/src/components/DeleteAction/DeleteAction.js +16 -23
- package/src/components/PageHeader/HeaderIconButton.js +27 -0
- package/src/components/PageHeader/PageHeader.js +90 -19
- package/src/components/PageHeader/TitleEditor.js +87 -0
- package/src/index.js +2 -0
|
@@ -1,44 +1,99 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import MetaTitle from '../MetaTitle/MetaTitle';
|
|
4
|
+
import HeaderIconButton from './HeaderIconButton';
|
|
5
|
+
import TitleEditor from './TitleEditor';
|
|
4
6
|
const PageHeader = ({
|
|
5
7
|
title,
|
|
6
8
|
subtitle,
|
|
7
9
|
children,
|
|
8
10
|
pageName,
|
|
9
|
-
onViewUrl
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
onViewUrl,
|
|
12
|
+
viewUrlDisabledReason,
|
|
13
|
+
onTitleChange,
|
|
14
|
+
titleActions
|
|
15
|
+
}) => {
|
|
16
|
+
const [isEditingTitle, setIsEditingTitle] = useState(false);
|
|
17
|
+
const isTitleEditable = typeof onTitleChange === 'function';
|
|
18
|
+
// A reason renders the button disabled instead of dropping it.
|
|
19
|
+
const showViewButton = !!onViewUrl || !!viewUrlDisabledReason;
|
|
20
|
+
const hasTitleActions = isTitleEditable || !!titleActions || showViewButton;
|
|
21
|
+
const startEditing = () => setIsEditingTitle(true);
|
|
22
|
+
const stopEditing = () => setIsEditingTitle(false);
|
|
23
|
+
const saveTitle = nextTitle => {
|
|
24
|
+
stopEditing();
|
|
25
|
+
onTitleChange(nextTitle);
|
|
26
|
+
};
|
|
27
|
+
const renderTitle = () => {
|
|
28
|
+
if (isEditingTitle) {
|
|
29
|
+
return /*#__PURE__*/React.createElement(TitleEditor, {
|
|
30
|
+
title: title,
|
|
31
|
+
onSave: saveTitle,
|
|
32
|
+
onCancel: stopEditing
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, isTitleEditable ? /*#__PURE__*/React.createElement("div", {
|
|
36
|
+
className: "page-header__heading page-header__heading--editable",
|
|
37
|
+
onClick: startEditing,
|
|
38
|
+
title: "Edit title",
|
|
39
|
+
role: "button",
|
|
40
|
+
tabIndex: 0,
|
|
41
|
+
onKeyDown: ({
|
|
42
|
+
key
|
|
43
|
+
}) => key === 'Enter' && startEditing()
|
|
44
|
+
}, title) : /*#__PURE__*/React.createElement("div", {
|
|
45
|
+
className: "page-header__heading"
|
|
46
|
+
}, title), hasTitleActions && /*#__PURE__*/React.createElement("div", {
|
|
47
|
+
className: "page-header__title-actions"
|
|
48
|
+
}, isTitleEditable && /*#__PURE__*/React.createElement(HeaderIconButton, {
|
|
49
|
+
icon: "edit",
|
|
50
|
+
label: "Edit title",
|
|
51
|
+
onClick: startEditing,
|
|
52
|
+
"data-testid": "page-header-title-edit"
|
|
53
|
+
}), titleActions, showViewButton && /*#__PURE__*/React.createElement(HeaderIconButton, {
|
|
54
|
+
icon: "open_in_new",
|
|
55
|
+
label: viewUrlDisabledReason || 'View',
|
|
56
|
+
className: viewUrlDisabledReason ? 'page-header__icon-button--disabled' : '',
|
|
57
|
+
"aria-disabled": viewUrlDisabledReason ? 'true' : undefined,
|
|
58
|
+
onClick: viewUrlDisabledReason ? undefined : onViewUrl,
|
|
59
|
+
"data-testid": "page-header-view"
|
|
60
|
+
})));
|
|
61
|
+
};
|
|
62
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MetaTitle, {
|
|
63
|
+
title: title,
|
|
64
|
+
pageName: pageName
|
|
65
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
66
|
+
className: "page-header--wrapper"
|
|
67
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
68
|
+
className: "page-header page-header--sticky"
|
|
69
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
70
|
+
className: "page-header__title"
|
|
71
|
+
}, renderTitle()), /*#__PURE__*/React.createElement("div", {
|
|
72
|
+
className: "page-header__button"
|
|
73
|
+
}, children)), /*#__PURE__*/React.createElement("div", {
|
|
74
|
+
className: "page-header page-header--base"
|
|
75
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
76
|
+
className: "page-header__subheading"
|
|
77
|
+
}, subtitle))));
|
|
78
|
+
};
|
|
30
79
|
PageHeader.propTypes = {
|
|
31
80
|
title: PropTypes.string.isRequired,
|
|
32
81
|
subtitle: PropTypes.string,
|
|
33
82
|
children: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
|
|
34
83
|
pageName: PropTypes.string,
|
|
35
|
-
onViewUrl: PropTypes.func
|
|
84
|
+
onViewUrl: PropTypes.func,
|
|
85
|
+
viewUrlDisabledReason: PropTypes.string,
|
|
86
|
+
onTitleChange: PropTypes.func,
|
|
87
|
+
titleActions: PropTypes.node
|
|
36
88
|
};
|
|
37
89
|
PageHeader.defaultProps = {
|
|
38
90
|
subtitle: '',
|
|
39
91
|
children: '',
|
|
40
92
|
pageName: '',
|
|
41
|
-
onViewUrl: null
|
|
93
|
+
onViewUrl: null,
|
|
94
|
+
viewUrlDisabledReason: null,
|
|
95
|
+
onTitleChange: null,
|
|
96
|
+
titleActions: null
|
|
42
97
|
};
|
|
43
98
|
const PageHeaderActions = ({
|
|
44
99
|
children
|
|
@@ -47,5 +102,6 @@ PageHeaderActions.propTypes = {
|
|
|
47
102
|
children: PropTypes.oneOfType([PropTypes.array, PropTypes.object]).isRequired
|
|
48
103
|
};
|
|
49
104
|
PageHeader.Actions = PageHeaderActions;
|
|
105
|
+
PageHeader.IconButton = HeaderIconButton;
|
|
50
106
|
export default PageHeader;
|
|
51
107
|
//# sourceMappingURL=PageHeader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageHeader.js","names":["React","PropTypes","MetaTitle","PageHeader","title","subtitle","children","pageName","onViewUrl","createElement","Fragment","className","onClick","role","propTypes","string","isRequired","oneOfType","array","object","func","defaultProps","PageHeaderActions","Children","map","child","cloneElement","Actions"],"sources":["../../../src/components/PageHeader/PageHeader.js"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport MetaTitle from '../MetaTitle/MetaTitle';\n\nconst PageHeader = ({
|
|
1
|
+
{"version":3,"file":"PageHeader.js","names":["React","useState","PropTypes","MetaTitle","HeaderIconButton","TitleEditor","PageHeader","title","subtitle","children","pageName","onViewUrl","viewUrlDisabledReason","onTitleChange","titleActions","isEditingTitle","setIsEditingTitle","isTitleEditable","showViewButton","hasTitleActions","startEditing","stopEditing","saveTitle","nextTitle","renderTitle","createElement","onSave","onCancel","Fragment","className","onClick","role","tabIndex","onKeyDown","key","icon","label","undefined","propTypes","string","isRequired","oneOfType","array","object","func","node","defaultProps","PageHeaderActions","Children","map","child","cloneElement","Actions","IconButton"],"sources":["../../../src/components/PageHeader/PageHeader.js"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport MetaTitle from '../MetaTitle/MetaTitle';\nimport HeaderIconButton from './HeaderIconButton';\nimport TitleEditor from './TitleEditor';\n\nconst PageHeader = ({\n title,\n subtitle,\n children,\n pageName,\n onViewUrl,\n viewUrlDisabledReason,\n onTitleChange,\n titleActions\n}) => {\n const [isEditingTitle, setIsEditingTitle] = useState(false);\n const isTitleEditable = typeof onTitleChange === 'function';\n // A reason renders the button disabled instead of dropping it.\n const showViewButton = !!onViewUrl || !!viewUrlDisabledReason;\n const hasTitleActions = isTitleEditable || !!titleActions || showViewButton;\n\n const startEditing = () => setIsEditingTitle(true);\n const stopEditing = () => setIsEditingTitle(false);\n const saveTitle = nextTitle => {\n stopEditing();\n onTitleChange(nextTitle);\n };\n\n const renderTitle = () => {\n if (isEditingTitle) {\n return <TitleEditor title={title} onSave={saveTitle} onCancel={stopEditing} />;\n }\n\n return (\n <>\n {isTitleEditable ? (\n <div\n className=\"page-header__heading page-header__heading--editable\"\n onClick={startEditing}\n title=\"Edit title\"\n role=\"button\"\n tabIndex={0}\n onKeyDown={({ key }) => key === 'Enter' && startEditing()}>\n {title}\n </div>\n ) : (\n <div className=\"page-header__heading\">{title}</div>\n )}\n {hasTitleActions && (\n <div className=\"page-header__title-actions\">\n {isTitleEditable && (\n <HeaderIconButton\n icon=\"edit\"\n label=\"Edit title\"\n onClick={startEditing}\n data-testid=\"page-header-title-edit\"\n />\n )}\n {titleActions}\n {showViewButton && (\n <HeaderIconButton\n icon=\"open_in_new\"\n label={viewUrlDisabledReason || 'View'}\n className={viewUrlDisabledReason ? 'page-header__icon-button--disabled' : ''}\n aria-disabled={viewUrlDisabledReason ? 'true' : undefined}\n onClick={viewUrlDisabledReason ? undefined : onViewUrl}\n data-testid=\"page-header-view\"\n />\n )}\n </div>\n )}\n </>\n );\n };\n\n return (\n <>\n <MetaTitle title={title} pageName={pageName} />\n <div className=\"page-header--wrapper\">\n <div className=\"page-header page-header--sticky\">\n <div className=\"page-header__title\">{renderTitle()}</div>\n <div className=\"page-header__button\">{children}</div>\n </div>\n <div className=\"page-header page-header--base\">\n <div className=\"page-header__subheading\">{subtitle}</div>\n </div>\n </div>\n </>\n );\n};\n\nPageHeader.propTypes = {\n title: PropTypes.string.isRequired,\n subtitle: PropTypes.string,\n children: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),\n pageName: PropTypes.string,\n onViewUrl: PropTypes.func,\n viewUrlDisabledReason: PropTypes.string,\n onTitleChange: PropTypes.func,\n titleActions: PropTypes.node\n};\n\nPageHeader.defaultProps = {\n subtitle: '',\n children: '',\n pageName: '',\n onViewUrl: null,\n viewUrlDisabledReason: null,\n onTitleChange: null,\n titleActions: null\n};\n\nconst PageHeaderActions = ({ children }) => (\n <>{React.Children.map(children, child => child && React.cloneElement(child))}</>\n);\n\nPageHeaderActions.propTypes = {\n children: PropTypes.oneOfType([PropTypes.array, PropTypes.object]).isRequired\n};\n\nPageHeader.Actions = PageHeaderActions;\nPageHeader.IconButton = HeaderIconButton;\n\nexport default PageHeader;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,SAAS,MAAM,wBAAwB;AAC9C,OAAOC,gBAAgB,MAAM,oBAAoB;AACjD,OAAOC,WAAW,MAAM,eAAe;AAEvC,MAAMC,UAAU,GAAGA,CAAC;EAClBC,KAAK;EACLC,QAAQ;EACRC,QAAQ;EACRC,QAAQ;EACRC,SAAS;EACTC,qBAAqB;EACrBC,aAAa;EACbC;AACF,CAAC,KAAK;EACJ,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGf,QAAQ,CAAC,KAAK,CAAC;EAC3D,MAAMgB,eAAe,GAAG,OAAOJ,aAAa,KAAK,UAAU;EAC3D;EACA,MAAMK,cAAc,GAAG,CAAC,CAACP,SAAS,IAAI,CAAC,CAACC,qBAAqB;EAC7D,MAAMO,eAAe,GAAGF,eAAe,IAAI,CAAC,CAACH,YAAY,IAAII,cAAc;EAE3E,MAAME,YAAY,GAAGA,CAAA,KAAMJ,iBAAiB,CAAC,IAAI,CAAC;EAClD,MAAMK,WAAW,GAAGA,CAAA,KAAML,iBAAiB,CAAC,KAAK,CAAC;EAClD,MAAMM,SAAS,GAAGC,SAAS,IAAI;IAC7BF,WAAW,CAAC,CAAC;IACbR,aAAa,CAACU,SAAS,CAAC;EAC1B,CAAC;EAED,MAAMC,WAAW,GAAGA,CAAA,KAAM;IACxB,IAAIT,cAAc,EAAE;MAClB,oBAAOf,KAAA,CAAAyB,aAAA,CAACpB,WAAW;QAACE,KAAK,EAAEA,KAAM;QAACmB,MAAM,EAAEJ,SAAU;QAACK,QAAQ,EAAEN;MAA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AG5B,KAAK,CAACgD,QAAQ,CAACC,GAAG,CAACxC,QAAQ,EAAEyC,KAAK,IAAIA,KAAK,IAAIlD,KAAK,CAACmD,YAAY,CAACD,KAAK,CAAC,CAAI,CAChF;AAEDH,iBAAiB,CAACT,SAAS,GAAG;EAC5B7B,QAAQ,EAAEP,SAAS,CAACuC,SAAS,CAAC,CAACvC,SAAS,CAACwC,KAAK,EAAExC,SAAS,CAACyC,MAAM,CAAC,CAAC,CAACH;AACrE,CAAC;AAEDlC,UAAU,CAAC8C,OAAO,GAAGL,iBAAiB;AACtCzC,UAAU,CAAC+C,UAAU,GAAGjD,gBAAgB;AAExC,eAAeE,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import HeaderIconButton from './HeaderIconButton';
|
|
4
|
+
const TitleEditor = ({
|
|
5
|
+
title,
|
|
6
|
+
onSave,
|
|
7
|
+
onCancel
|
|
8
|
+
}) => {
|
|
9
|
+
const [value, setValue] = useState(title);
|
|
10
|
+
const inputRef = useRef(null);
|
|
11
|
+
// Blur and the tick/cross clicks can both fire for one edit; only the first wins.
|
|
12
|
+
const isDone = useRef(false);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (inputRef.current) {
|
|
15
|
+
inputRef.current.focus();
|
|
16
|
+
inputRef.current.select();
|
|
17
|
+
}
|
|
18
|
+
}, []);
|
|
19
|
+
const finish = callback => {
|
|
20
|
+
if (isDone.current) return;
|
|
21
|
+
isDone.current = true;
|
|
22
|
+
callback();
|
|
23
|
+
};
|
|
24
|
+
const save = () => finish(() => {
|
|
25
|
+
const nextTitle = value.trim();
|
|
26
|
+
if (!nextTitle || nextTitle === title) {
|
|
27
|
+
onCancel();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
onSave(nextTitle);
|
|
31
|
+
});
|
|
32
|
+
const cancel = () => finish(onCancel);
|
|
33
|
+
const onKeyDown = event => {
|
|
34
|
+
if (event.key === 'Enter') {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
save();
|
|
37
|
+
} else if (event.key === 'Escape') {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
cancel();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const keepInputFocus = event => event.preventDefault();
|
|
43
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
44
|
+
className: "page-header__title-editor"
|
|
45
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
46
|
+
ref: inputRef,
|
|
47
|
+
type: "text",
|
|
48
|
+
className: "page-header__title-input",
|
|
49
|
+
value: value,
|
|
50
|
+
onChange: ({
|
|
51
|
+
target
|
|
52
|
+
}) => setValue(target.value),
|
|
53
|
+
onKeyDown: onKeyDown,
|
|
54
|
+
onBlur: save,
|
|
55
|
+
"aria-label": "Title",
|
|
56
|
+
"data-testid": "page-header-title-input"
|
|
57
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
58
|
+
className: "page-header__title-editor-actions"
|
|
59
|
+
}, /*#__PURE__*/React.createElement(HeaderIconButton, {
|
|
60
|
+
icon: "check",
|
|
61
|
+
label: "Save title",
|
|
62
|
+
onMouseDown: keepInputFocus,
|
|
63
|
+
onClick: save,
|
|
64
|
+
"data-testid": "page-header-title-save"
|
|
65
|
+
}), /*#__PURE__*/React.createElement(HeaderIconButton, {
|
|
66
|
+
icon: "close",
|
|
67
|
+
label: "Cancel",
|
|
68
|
+
onMouseDown: keepInputFocus,
|
|
69
|
+
onClick: cancel,
|
|
70
|
+
"data-testid": "page-header-title-cancel"
|
|
71
|
+
})));
|
|
72
|
+
};
|
|
73
|
+
TitleEditor.propTypes = {
|
|
74
|
+
title: PropTypes.string.isRequired,
|
|
75
|
+
onSave: PropTypes.func.isRequired,
|
|
76
|
+
onCancel: PropTypes.func.isRequired
|
|
77
|
+
};
|
|
78
|
+
export default TitleEditor;
|
|
79
|
+
//# sourceMappingURL=TitleEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TitleEditor.js","names":["React","useEffect","useRef","useState","PropTypes","HeaderIconButton","TitleEditor","title","onSave","onCancel","value","setValue","inputRef","isDone","current","focus","select","finish","callback","save","nextTitle","trim","cancel","onKeyDown","event","key","preventDefault","keepInputFocus","createElement","className","ref","type","onChange","target","onBlur","icon","label","onMouseDown","onClick","propTypes","string","isRequired","func"],"sources":["../../../src/components/PageHeader/TitleEditor.js"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport PropTypes from 'prop-types';\nimport HeaderIconButton from './HeaderIconButton';\n\nconst TitleEditor = ({ title, onSave, onCancel }) => {\n const [value, setValue] = useState(title);\n const inputRef = useRef(null);\n // Blur and the tick/cross clicks can both fire for one edit; only the first wins.\n const isDone = useRef(false);\n\n useEffect(() => {\n if (inputRef.current) {\n inputRef.current.focus();\n inputRef.current.select();\n }\n }, []);\n\n const finish = callback => {\n if (isDone.current) return;\n isDone.current = true;\n callback();\n };\n\n const save = () =>\n finish(() => {\n const nextTitle = value.trim();\n if (!nextTitle || nextTitle === title) {\n onCancel();\n return;\n }\n onSave(nextTitle);\n });\n\n const cancel = () => finish(onCancel);\n\n const onKeyDown = event => {\n if (event.key === 'Enter') {\n event.preventDefault();\n save();\n } else if (event.key === 'Escape') {\n event.preventDefault();\n cancel();\n }\n };\n\n const keepInputFocus = event => event.preventDefault();\n\n return (\n <div className=\"page-header__title-editor\">\n <input\n ref={inputRef}\n type=\"text\"\n className=\"page-header__title-input\"\n value={value}\n onChange={({ target }) => setValue(target.value)}\n onKeyDown={onKeyDown}\n onBlur={save}\n aria-label=\"Title\"\n data-testid=\"page-header-title-input\"\n />\n <div className=\"page-header__title-editor-actions\">\n <HeaderIconButton\n icon=\"check\"\n label=\"Save title\"\n onMouseDown={keepInputFocus}\n onClick={save}\n data-testid=\"page-header-title-save\"\n />\n <HeaderIconButton\n icon=\"close\"\n label=\"Cancel\"\n onMouseDown={keepInputFocus}\n onClick={cancel}\n data-testid=\"page-header-title-cancel\"\n />\n </div>\n </div>\n );\n};\n\nTitleEditor.propTypes = {\n title: PropTypes.string.isRequired,\n onSave: PropTypes.func.isRequired,\n onCancel: PropTypes.func.isRequired\n};\n\nexport default TitleEditor;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAC1D,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,gBAAgB,MAAM,oBAAoB;AAEjD,MAAMC,WAAW,GAAGA,CAAC;EAAEC,KAAK;EAAEC,MAAM;EAAEC;AAAS,CAAC,KAAK;EACnD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGR,QAAQ,CAACI,KAAK,CAAC;EACzC,MAAMK,QAAQ,GAAGV,MAAM,CAAC,IAAI,CAAC;EAC7B;EACA,MAAMW,MAAM,GAAGX,MAAM,CAAC,KAAK,CAAC;EAE5BD,SAAS,CAAC,MAAM;IACd,IAAIW,QAAQ,CAACE,OAAO,EAAE;MACpBF,QAAQ,CAACE,OAAO,CAACC,KAAK,CAAC,CAAC;MACxBH,QAAQ,CAACE,OAAO,CAACE,MAAM,CAAC,CAAC;IAC3B;EACF,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMC,MAAM,GAAGC,QAAQ,IAAI;IACzB,IAAIL,MAAM,CAACC,OAAO,EAAE;IACpBD,MAAM,CAACC,OAAO,GAAG,IAAI;IACrBI,QAAQ,CAAC,CAAC;EACZ,CAAC;EAED,MAAMC,IAAI,GAAGA,CAAA,KACXF,MAAM,CAAC,MAAM;IACX,MAAMG,SAAS,GAAGV,KAAK,CAACW,IAAI,CAAC,CAAC;IAC9B,IAAI,CAACD,SAAS,IAAIA,SAAS,KAAKb,KAAK,EAAE;MACrCE,QAAQ,CAAC,CAAC;MACV;IACF;IACAD,MAAM,CAACY,SAAS,CAAC;EACnB,CAAC,CAAC;EAEJ,MAAME,MAAM,GAAGA,C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,WAAW,CAACiC,SAAS,GAAG;EACtBhC,KAAK,EAAEH,SAAS,CAACoC,MAAM,CAACC,UAAU;EAClCjC,MAAM,EAAEJ,SAAS,CAACsC,IAAI,CAACD,UAAU;EACjChC,QAAQ,EAAEL,SAAS,CAACsC,IAAI,CAACD;AAC3B,CAAC;AAED,eAAenC,WAAW","ignoreList":[]}
|
package/lib-es/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import PageHeader from './components/PageHeader';
|
|
2
2
|
import DeleteAction from './components/DeleteAction';
|
|
3
|
+
import ConfirmAction from './components/ConfirmAction';
|
|
3
4
|
import CardPrompt from './components/CardPrompt';
|
|
4
5
|
import CopyDataFromAction from './components/CopyDataFromAction';
|
|
5
6
|
import MetaTitle from './components/MetaTitle';
|
|
@@ -7,5 +8,5 @@ import LeaveAction from './components/LeaveAction';
|
|
|
7
8
|
import RevertToTemplate from './components/RevertToTemplate';
|
|
8
9
|
import Loading from './components/Loading';
|
|
9
10
|
import { getBlazeAdmin } from './utils/get-blaze-admin';
|
|
10
|
-
export { getBlazeAdmin, PageHeader, DeleteAction, CardPrompt, CopyDataFromAction, MetaTitle, LeaveAction, RevertToTemplate, Loading };
|
|
11
|
+
export { getBlazeAdmin, PageHeader, DeleteAction, ConfirmAction, CardPrompt, CopyDataFromAction, MetaTitle, LeaveAction, RevertToTemplate, Loading };
|
|
11
12
|
//# sourceMappingURL=index.js.map
|
package/lib-es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["PageHeader","DeleteAction","CardPrompt","CopyDataFromAction","MetaTitle","LeaveAction","RevertToTemplate","Loading","getBlazeAdmin"],"sources":["../src/index.js"],"sourcesContent":["import PageHeader from './components/PageHeader';\nimport DeleteAction from './components/DeleteAction';\nimport CardPrompt from './components/CardPrompt';\nimport CopyDataFromAction from './components/CopyDataFromAction';\nimport MetaTitle from './components/MetaTitle';\nimport LeaveAction from './components/LeaveAction';\nimport RevertToTemplate from './components/RevertToTemplate';\nimport Loading from './components/Loading';\nimport { getBlazeAdmin } from './utils/get-blaze-admin';\n\nexport {\n getBlazeAdmin,\n PageHeader,\n DeleteAction,\n CardPrompt,\n CopyDataFromAction,\n MetaTitle,\n LeaveAction,\n RevertToTemplate,\n Loading\n};\n"],"mappings":"AAAA,OAAOA,UAAU,MAAM,yBAAyB;AAChD,OAAOC,YAAY,MAAM,2BAA2B;AACpD,OAAOC,UAAU,MAAM,yBAAyB;AAChD,OAAOC,kBAAkB,MAAM,iCAAiC;AAChE,OAAOC,SAAS,MAAM,wBAAwB;AAC9C,OAAOC,WAAW,MAAM,0BAA0B;AAClD,OAAOC,gBAAgB,MAAM,+BAA+B;AAC5D,OAAOC,OAAO,MAAM,sBAAsB;AAC1C,SAASC,aAAa,QAAQ,yBAAyB;AAEvD,SACEA,aAAa,
|
|
1
|
+
{"version":3,"file":"index.js","names":["PageHeader","DeleteAction","ConfirmAction","CardPrompt","CopyDataFromAction","MetaTitle","LeaveAction","RevertToTemplate","Loading","getBlazeAdmin"],"sources":["../src/index.js"],"sourcesContent":["import PageHeader from './components/PageHeader';\nimport DeleteAction from './components/DeleteAction';\nimport ConfirmAction from './components/ConfirmAction';\nimport CardPrompt from './components/CardPrompt';\nimport CopyDataFromAction from './components/CopyDataFromAction';\nimport MetaTitle from './components/MetaTitle';\nimport LeaveAction from './components/LeaveAction';\nimport RevertToTemplate from './components/RevertToTemplate';\nimport Loading from './components/Loading';\nimport { getBlazeAdmin } from './utils/get-blaze-admin';\n\nexport {\n getBlazeAdmin,\n PageHeader,\n DeleteAction,\n ConfirmAction,\n CardPrompt,\n CopyDataFromAction,\n MetaTitle,\n LeaveAction,\n RevertToTemplate,\n Loading\n};\n"],"mappings":"AAAA,OAAOA,UAAU,MAAM,yBAAyB;AAChD,OAAOC,YAAY,MAAM,2BAA2B;AACpD,OAAOC,aAAa,MAAM,4BAA4B;AACtD,OAAOC,UAAU,MAAM,yBAAyB;AAChD,OAAOC,kBAAkB,MAAM,iCAAiC;AAChE,OAAOC,SAAS,MAAM,wBAAwB;AAC9C,OAAOC,WAAW,MAAM,0BAA0B;AAClD,OAAOC,gBAAgB,MAAM,+BAA+B;AAC5D,OAAOC,OAAO,MAAM,sBAAsB;AAC1C,SAASC,aAAa,QAAQ,yBAAyB;AAEvD,SACEA,aAAa,EACbT,UAAU,EACVC,YAAY,EACZC,aAAa,EACbC,UAAU,EACVC,kBAAkB,EAClBC,SAAS,EACTC,WAAW,EACXC,gBAAgB,EAChBC,OAAO","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaze-cms/admin",
|
|
3
|
-
"version": "0.146.0-node18-tooltips.
|
|
3
|
+
"version": "0.146.0-node18-core-styles-tooltips.61",
|
|
4
4
|
"description": "Blaze example project",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib-es/index.js",
|
|
@@ -28,19 +28,20 @@
|
|
|
28
28
|
"license": "GPL-3.0",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@apollo/client": "3.13.8",
|
|
31
|
-
"@blaze-cms/admin-ui-utils": "0.146.0-node18-tooltips.
|
|
32
|
-
"@blaze-cms/core-errors-ui": "0.146.0-node18-tooltips.
|
|
33
|
-
"@blaze-cms/core-ui": "0.146.0-node18-tooltips.
|
|
34
|
-
"@blaze-cms/plugin-admin-core-ui": "0.146.0-node18-tooltips.
|
|
35
|
-
"@blaze-cms/plugin-auth-local-ui": "0.146.0-node18-tooltips.
|
|
36
|
-
"@blaze-cms/plugin-auth-ui": "0.146.0-node18-tooltips.
|
|
37
|
-
"@blaze-cms/plugin-data-ui": "0.146.0-node18-tooltips.
|
|
38
|
-
"@blaze-cms/plugin-google-maps-ui": "0.146.0-node18-tooltips.
|
|
39
|
-
"@blaze-cms/plugin-gtm-ui": "0.146.0-node18-tooltips.
|
|
40
|
-
"@blaze-cms/plugin-media-ui": "0.146.0-node18-tooltips.
|
|
41
|
-
"@blaze-cms/plugin-page-builder-ui": "0.146.0-node18-tooltips.
|
|
42
|
-
"@blaze-cms/
|
|
43
|
-
"@blaze-cms/
|
|
31
|
+
"@blaze-cms/admin-ui-utils": "0.146.0-node18-core-styles-tooltips.61",
|
|
32
|
+
"@blaze-cms/core-errors-ui": "0.146.0-node18-core-styles-tooltips.46",
|
|
33
|
+
"@blaze-cms/core-ui": "0.146.0-node18-core-styles-tooltips.61",
|
|
34
|
+
"@blaze-cms/plugin-admin-core-ui": "0.146.0-node18-core-styles-tooltips.61",
|
|
35
|
+
"@blaze-cms/plugin-auth-local-ui": "0.146.0-node18-core-styles-tooltips.61",
|
|
36
|
+
"@blaze-cms/plugin-auth-ui": "0.146.0-node18-core-styles-tooltips.61",
|
|
37
|
+
"@blaze-cms/plugin-data-ui": "0.146.0-node18-core-styles-tooltips.61",
|
|
38
|
+
"@blaze-cms/plugin-google-maps-ui": "0.146.0-node18-core-styles-tooltips.61",
|
|
39
|
+
"@blaze-cms/plugin-gtm-ui": "0.146.0-node18-core-styles-tooltips.61",
|
|
40
|
+
"@blaze-cms/plugin-media-ui": "0.146.0-node18-core-styles-tooltips.61",
|
|
41
|
+
"@blaze-cms/plugin-page-builder-ui": "0.146.0-node18-core-styles-tooltips.61",
|
|
42
|
+
"@blaze-cms/plugin-workflow-ui": "0.146.0-node18-core-styles-tooltips.61",
|
|
43
|
+
"@blaze-cms/react-form-builder": "0.146.0-node18-core-styles-tooltips.61",
|
|
44
|
+
"@blaze-cms/setup-ui": "0.146.0-node18-core-styles-tooltips.46",
|
|
44
45
|
"@blaze-react/alert": "^0.7.0",
|
|
45
46
|
"@blaze-react/modal": "^0.7.0",
|
|
46
47
|
"@blaze-react/toaster": "^0.7.0",
|
|
@@ -62,5 +63,5 @@
|
|
|
62
63
|
"lib/*",
|
|
63
64
|
"lib-es/*"
|
|
64
65
|
],
|
|
65
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "cf8d14164ed65eddb8e1d1b00e22825ee684e116"
|
|
66
67
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React, { useId, useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Modal from '@blaze-react/modal';
|
|
4
|
+
|
|
5
|
+
const normalise = value => value.replace(/[\s,]/g, '');
|
|
6
|
+
|
|
7
|
+
// with confirmPhrase, confirming only runs once the phrase has been typed, for large or irreversible actions
|
|
8
|
+
const ConfirmAction = ({ onClose, onConfirm, confirmLabel, confirmPhrase, children }) => {
|
|
9
|
+
const phraseId = useId();
|
|
10
|
+
const [typed, setTyped] = useState('');
|
|
11
|
+
const [showHint, setShowHint] = useState(false);
|
|
12
|
+
const confirmed = !confirmPhrase || normalise(typed) === normalise(confirmPhrase);
|
|
13
|
+
|
|
14
|
+
const alertActions = [
|
|
15
|
+
{
|
|
16
|
+
callback: event => {
|
|
17
|
+
event.stopPropagation();
|
|
18
|
+
if (!confirmed) {
|
|
19
|
+
setShowHint(true);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
onConfirm();
|
|
23
|
+
},
|
|
24
|
+
modifiers: confirmed ? ['small'] : ['small', 'disabled'],
|
|
25
|
+
textButton: confirmLabel
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Modal actions={alertActions} onClose={onClose} isAlert>
|
|
31
|
+
{children}
|
|
32
|
+
{confirmPhrase && (
|
|
33
|
+
<div className="confirm-action__confirm">
|
|
34
|
+
<label htmlFor={phraseId}>
|
|
35
|
+
Type <strong>{confirmPhrase}</strong> to confirm
|
|
36
|
+
</label>
|
|
37
|
+
<input
|
|
38
|
+
id={phraseId}
|
|
39
|
+
type="text"
|
|
40
|
+
inputMode="numeric"
|
|
41
|
+
autoComplete="off"
|
|
42
|
+
value={typed}
|
|
43
|
+
onChange={({ target: { value } }) => {
|
|
44
|
+
setTyped(value);
|
|
45
|
+
setShowHint(false);
|
|
46
|
+
}}
|
|
47
|
+
/>
|
|
48
|
+
{showHint && (
|
|
49
|
+
<p role="alert">
|
|
50
|
+
Type {confirmPhrase} to {confirmLabel.toLowerCase()} them all
|
|
51
|
+
</p>
|
|
52
|
+
)}
|
|
53
|
+
</div>
|
|
54
|
+
)}
|
|
55
|
+
</Modal>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
ConfirmAction.propTypes = {
|
|
60
|
+
onClose: PropTypes.func.isRequired,
|
|
61
|
+
onConfirm: PropTypes.func.isRequired,
|
|
62
|
+
confirmLabel: PropTypes.string.isRequired,
|
|
63
|
+
confirmPhrase: PropTypes.string,
|
|
64
|
+
children: PropTypes.node
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
ConfirmAction.defaultProps = {
|
|
68
|
+
confirmPhrase: null,
|
|
69
|
+
children: null
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default ConfirmAction;
|
|
@@ -1,36 +1,29 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import
|
|
3
|
+
import ConfirmAction from '../ConfirmAction';
|
|
4
4
|
|
|
5
|
-
const DeleteAction = ({ onClose, deleteAction, itemName }) =>
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<Modal actions={alertActions} onClose={onClose} isAlert>
|
|
19
|
-
<p>
|
|
20
|
-
You are about to delete: <strong>{itemName}</strong>
|
|
21
|
-
</p>
|
|
22
|
-
</Modal>
|
|
23
|
-
);
|
|
24
|
-
};
|
|
5
|
+
const DeleteAction = ({ onClose, deleteAction, itemName, confirmPhrase }) => (
|
|
6
|
+
<ConfirmAction
|
|
7
|
+
onClose={onClose}
|
|
8
|
+
onConfirm={deleteAction}
|
|
9
|
+
confirmLabel="Delete"
|
|
10
|
+
confirmPhrase={confirmPhrase}>
|
|
11
|
+
<p>
|
|
12
|
+
You are about to delete: <strong>{itemName}</strong>
|
|
13
|
+
</p>
|
|
14
|
+
</ConfirmAction>
|
|
15
|
+
);
|
|
25
16
|
|
|
26
17
|
DeleteAction.propTypes = {
|
|
27
18
|
onClose: PropTypes.func.isRequired,
|
|
28
19
|
deleteAction: PropTypes.func.isRequired,
|
|
29
|
-
itemName: PropTypes.string
|
|
20
|
+
itemName: PropTypes.string,
|
|
21
|
+
confirmPhrase: PropTypes.string
|
|
30
22
|
};
|
|
31
23
|
|
|
32
24
|
DeleteAction.defaultProps = {
|
|
33
|
-
itemName: ''
|
|
25
|
+
itemName: '',
|
|
26
|
+
confirmPhrase: null
|
|
34
27
|
};
|
|
35
28
|
|
|
36
29
|
export default DeleteAction;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
const HeaderIconButton = ({ icon, label, className, ...rest }) => (
|
|
5
|
+
<button
|
|
6
|
+
type="button"
|
|
7
|
+
className={`page-header__icon-button${className ? ` ${className}` : ''}`}
|
|
8
|
+
title={label}
|
|
9
|
+
aria-label={label}
|
|
10
|
+
{...rest}>
|
|
11
|
+
<span className="material-icons" aria-hidden="true">
|
|
12
|
+
{icon}
|
|
13
|
+
</span>
|
|
14
|
+
</button>
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
HeaderIconButton.propTypes = {
|
|
18
|
+
icon: PropTypes.string.isRequired,
|
|
19
|
+
label: PropTypes.string.isRequired,
|
|
20
|
+
className: PropTypes.string
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
HeaderIconButton.defaultProps = {
|
|
24
|
+
className: ''
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default HeaderIconButton;
|
|
@@ -1,44 +1,114 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import MetaTitle from '../MetaTitle/MetaTitle';
|
|
4
|
+
import HeaderIconButton from './HeaderIconButton';
|
|
5
|
+
import TitleEditor from './TitleEditor';
|
|
4
6
|
|
|
5
|
-
const PageHeader = ({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const PageHeader = ({
|
|
8
|
+
title,
|
|
9
|
+
subtitle,
|
|
10
|
+
children,
|
|
11
|
+
pageName,
|
|
12
|
+
onViewUrl,
|
|
13
|
+
viewUrlDisabledReason,
|
|
14
|
+
onTitleChange,
|
|
15
|
+
titleActions
|
|
16
|
+
}) => {
|
|
17
|
+
const [isEditingTitle, setIsEditingTitle] = useState(false);
|
|
18
|
+
const isTitleEditable = typeof onTitleChange === 'function';
|
|
19
|
+
// A reason renders the button disabled instead of dropping it.
|
|
20
|
+
const showViewButton = !!onViewUrl || !!viewUrlDisabledReason;
|
|
21
|
+
const hasTitleActions = isTitleEditable || !!titleActions || showViewButton;
|
|
22
|
+
|
|
23
|
+
const startEditing = () => setIsEditingTitle(true);
|
|
24
|
+
const stopEditing = () => setIsEditingTitle(false);
|
|
25
|
+
const saveTitle = nextTitle => {
|
|
26
|
+
stopEditing();
|
|
27
|
+
onTitleChange(nextTitle);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const renderTitle = () => {
|
|
31
|
+
if (isEditingTitle) {
|
|
32
|
+
return <TitleEditor title={title} onSave={saveTitle} onCancel={stopEditing} />;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
{isTitleEditable ? (
|
|
11
38
|
<div
|
|
12
|
-
className="page-header__heading page-header__heading--
|
|
13
|
-
onClick={
|
|
14
|
-
|
|
39
|
+
className="page-header__heading page-header__heading--editable"
|
|
40
|
+
onClick={startEditing}
|
|
41
|
+
title="Edit title"
|
|
42
|
+
role="button"
|
|
43
|
+
tabIndex={0}
|
|
44
|
+
onKeyDown={({ key }) => key === 'Enter' && startEditing()}>
|
|
15
45
|
{title}
|
|
16
46
|
</div>
|
|
17
47
|
) : (
|
|
18
48
|
<div className="page-header__heading">{title}</div>
|
|
19
49
|
)}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
50
|
+
{hasTitleActions && (
|
|
51
|
+
<div className="page-header__title-actions">
|
|
52
|
+
{isTitleEditable && (
|
|
53
|
+
<HeaderIconButton
|
|
54
|
+
icon="edit"
|
|
55
|
+
label="Edit title"
|
|
56
|
+
onClick={startEditing}
|
|
57
|
+
data-testid="page-header-title-edit"
|
|
58
|
+
/>
|
|
59
|
+
)}
|
|
60
|
+
{titleActions}
|
|
61
|
+
{showViewButton && (
|
|
62
|
+
<HeaderIconButton
|
|
63
|
+
icon="open_in_new"
|
|
64
|
+
label={viewUrlDisabledReason || 'View'}
|
|
65
|
+
className={viewUrlDisabledReason ? 'page-header__icon-button--disabled' : ''}
|
|
66
|
+
aria-disabled={viewUrlDisabledReason ? 'true' : undefined}
|
|
67
|
+
onClick={viewUrlDisabledReason ? undefined : onViewUrl}
|
|
68
|
+
data-testid="page-header-view"
|
|
69
|
+
/>
|
|
70
|
+
)}
|
|
71
|
+
</div>
|
|
72
|
+
)}
|
|
73
|
+
</>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
<MetaTitle title={title} pageName={pageName} />
|
|
80
|
+
<div className="page-header--wrapper">
|
|
81
|
+
<div className="page-header page-header--sticky">
|
|
82
|
+
<div className="page-header__title">{renderTitle()}</div>
|
|
83
|
+
<div className="page-header__button">{children}</div>
|
|
84
|
+
</div>
|
|
85
|
+
<div className="page-header page-header--base">
|
|
86
|
+
<div className="page-header__subheading">{subtitle}</div>
|
|
87
|
+
</div>
|
|
24
88
|
</div>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
89
|
+
</>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
28
92
|
|
|
29
93
|
PageHeader.propTypes = {
|
|
30
94
|
title: PropTypes.string.isRequired,
|
|
31
95
|
subtitle: PropTypes.string,
|
|
32
96
|
children: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
|
|
33
97
|
pageName: PropTypes.string,
|
|
34
|
-
onViewUrl: PropTypes.func
|
|
98
|
+
onViewUrl: PropTypes.func,
|
|
99
|
+
viewUrlDisabledReason: PropTypes.string,
|
|
100
|
+
onTitleChange: PropTypes.func,
|
|
101
|
+
titleActions: PropTypes.node
|
|
35
102
|
};
|
|
36
103
|
|
|
37
104
|
PageHeader.defaultProps = {
|
|
38
105
|
subtitle: '',
|
|
39
106
|
children: '',
|
|
40
107
|
pageName: '',
|
|
41
|
-
onViewUrl: null
|
|
108
|
+
onViewUrl: null,
|
|
109
|
+
viewUrlDisabledReason: null,
|
|
110
|
+
onTitleChange: null,
|
|
111
|
+
titleActions: null
|
|
42
112
|
};
|
|
43
113
|
|
|
44
114
|
const PageHeaderActions = ({ children }) => (
|
|
@@ -50,5 +120,6 @@ PageHeaderActions.propTypes = {
|
|
|
50
120
|
};
|
|
51
121
|
|
|
52
122
|
PageHeader.Actions = PageHeaderActions;
|
|
123
|
+
PageHeader.IconButton = HeaderIconButton;
|
|
53
124
|
|
|
54
125
|
export default PageHeader;
|