@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
|
@@ -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,
|