@blaze-cms/admin 0.146.0-node18-tooltips.56 → 0.146.0-node18-tooltips.57
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/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 +14 -13
- 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,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;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import HeaderIconButton from './HeaderIconButton';
|
|
4
|
+
|
|
5
|
+
const TitleEditor = ({ title, onSave, onCancel }) => {
|
|
6
|
+
const [value, setValue] = useState(title);
|
|
7
|
+
const inputRef = useRef(null);
|
|
8
|
+
// Blur and the tick/cross clicks can both fire for one edit; only the first wins.
|
|
9
|
+
const isDone = useRef(false);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (inputRef.current) {
|
|
13
|
+
inputRef.current.focus();
|
|
14
|
+
inputRef.current.select();
|
|
15
|
+
}
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
const finish = callback => {
|
|
19
|
+
if (isDone.current) return;
|
|
20
|
+
isDone.current = true;
|
|
21
|
+
callback();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const save = () =>
|
|
25
|
+
finish(() => {
|
|
26
|
+
const nextTitle = value.trim();
|
|
27
|
+
if (!nextTitle || nextTitle === title) {
|
|
28
|
+
onCancel();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
onSave(nextTitle);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const cancel = () => finish(onCancel);
|
|
35
|
+
|
|
36
|
+
const onKeyDown = event => {
|
|
37
|
+
if (event.key === 'Enter') {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
save();
|
|
40
|
+
} else if (event.key === 'Escape') {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
cancel();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const keepInputFocus = event => event.preventDefault();
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div className="page-header__title-editor">
|
|
50
|
+
<input
|
|
51
|
+
ref={inputRef}
|
|
52
|
+
type="text"
|
|
53
|
+
className="page-header__title-input"
|
|
54
|
+
value={value}
|
|
55
|
+
onChange={({ target }) => setValue(target.value)}
|
|
56
|
+
onKeyDown={onKeyDown}
|
|
57
|
+
onBlur={save}
|
|
58
|
+
aria-label="Title"
|
|
59
|
+
data-testid="page-header-title-input"
|
|
60
|
+
/>
|
|
61
|
+
<div className="page-header__title-editor-actions">
|
|
62
|
+
<HeaderIconButton
|
|
63
|
+
icon="check"
|
|
64
|
+
label="Save title"
|
|
65
|
+
onMouseDown={keepInputFocus}
|
|
66
|
+
onClick={save}
|
|
67
|
+
data-testid="page-header-title-save"
|
|
68
|
+
/>
|
|
69
|
+
<HeaderIconButton
|
|
70
|
+
icon="close"
|
|
71
|
+
label="Cancel"
|
|
72
|
+
onMouseDown={keepInputFocus}
|
|
73
|
+
onClick={cancel}
|
|
74
|
+
data-testid="page-header-title-cancel"
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
TitleEditor.propTypes = {
|
|
82
|
+
title: PropTypes.string.isRequired,
|
|
83
|
+
onSave: PropTypes.func.isRequired,
|
|
84
|
+
onCancel: PropTypes.func.isRequired
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default TitleEditor;
|
package/src/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';
|
|
@@ -12,6 +13,7 @@ export {
|
|
|
12
13
|
getBlazeAdmin,
|
|
13
14
|
PageHeader,
|
|
14
15
|
DeleteAction,
|
|
16
|
+
ConfirmAction,
|
|
15
17
|
CardPrompt,
|
|
16
18
|
CopyDataFromAction,
|
|
17
19
|
MetaTitle,
|