@atlaskit/spotlight 0.6.3 → 0.7.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 +16 -0
- package/dist/cjs/controllers/context.js +40 -0
- package/dist/cjs/ui/popover-content/index.js +43 -14
- package/dist/cjs/ui/primary-action/index.js +7 -1
- package/dist/cjs/ui/secondary-action/index.js +7 -1
- package/dist/es2019/controllers/context.js +28 -0
- package/dist/es2019/ui/popover-content/index.js +39 -9
- package/dist/es2019/ui/primary-action/index.js +9 -2
- package/dist/es2019/ui/secondary-action/index.js +9 -2
- package/dist/esm/controllers/context.js +40 -0
- package/dist/esm/ui/popover-content/index.js +43 -14
- package/dist/esm/ui/primary-action/index.js +8 -2
- package/dist/esm/ui/secondary-action/index.js +8 -2
- package/dist/types/controllers/context.d.ts +9 -1
- package/dist/types/types.d.ts +3 -0
- package/dist/types/ui/popover-content/index.d.ts +15 -3
- package/dist/types-ts4.5/controllers/context.d.ts +9 -1
- package/dist/types-ts4.5/types.d.ts +3 -0
- package/dist/types-ts4.5/ui/popover-content/index.d.ts +15 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/spotlight
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`6e38d616cae8e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6e38d616cae8e) -
|
|
8
|
+
Allow back, next, done actions to be passed into PopoverContent. These actions will be used if no
|
|
9
|
+
onClick handler is passed to SpotlightSecondaryAction, SpotlightPrimaryAction. If onClick handlers
|
|
10
|
+
are provided to the specific components, then they will take preference over what is passed to
|
|
11
|
+
PopoverContent.
|
|
12
|
+
|
|
13
|
+
## 0.6.4
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 0.6.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -61,6 +61,26 @@ var SpotlightContext = exports.SpotlightContext = /*#__PURE__*/(0, _react.create
|
|
|
61
61
|
setDismiss: function setDismiss() {
|
|
62
62
|
return undefined;
|
|
63
63
|
}
|
|
64
|
+
},
|
|
65
|
+
primaryAction: {
|
|
66
|
+
action: {
|
|
67
|
+
current: function current() {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
setAction: function setAction() {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
secondaryAction: {
|
|
76
|
+
action: {
|
|
77
|
+
current: function current() {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
setAction: function setAction() {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
64
84
|
}
|
|
65
85
|
});
|
|
66
86
|
|
|
@@ -106,6 +126,18 @@ var SpotlightContextProvider = exports.SpotlightContextProvider = function Spotl
|
|
|
106
126
|
var setDismiss = function setDismiss(dismissFn) {
|
|
107
127
|
dismissRef.current = dismissFn;
|
|
108
128
|
};
|
|
129
|
+
var secondaryActionRef = (0, _react.useRef)(function () {
|
|
130
|
+
return undefined;
|
|
131
|
+
});
|
|
132
|
+
var setSecondaryAction = function setSecondaryAction(actionFn) {
|
|
133
|
+
secondaryActionRef.current = actionFn;
|
|
134
|
+
};
|
|
135
|
+
var primaryActionRef = (0, _react.useRef)(function () {
|
|
136
|
+
return undefined;
|
|
137
|
+
});
|
|
138
|
+
var setPrimaryAction = function setPrimaryAction(actionFn) {
|
|
139
|
+
primaryActionRef.current = actionFn;
|
|
140
|
+
};
|
|
109
141
|
return /*#__PURE__*/React.createElement(SpotlightContext.Provider, {
|
|
110
142
|
value: {
|
|
111
143
|
card: {
|
|
@@ -125,6 +157,14 @@ var SpotlightContextProvider = exports.SpotlightContextProvider = function Spotl
|
|
|
125
157
|
setUpdate: setUpdate,
|
|
126
158
|
dismiss: dismissRef,
|
|
127
159
|
setDismiss: setDismiss
|
|
160
|
+
},
|
|
161
|
+
primaryAction: {
|
|
162
|
+
action: primaryActionRef,
|
|
163
|
+
setAction: setPrimaryAction
|
|
164
|
+
},
|
|
165
|
+
secondaryAction: {
|
|
166
|
+
action: secondaryActionRef,
|
|
167
|
+
setAction: setSecondaryAction
|
|
128
168
|
}
|
|
129
169
|
}
|
|
130
170
|
}, children);
|
|
@@ -55,15 +55,24 @@ var popperPlacementMap = {
|
|
|
55
55
|
*
|
|
56
56
|
* A `PopoverContent` is the element that is shown as a popover.
|
|
57
57
|
*/
|
|
58
|
-
var PopoverContent = exports.PopoverContent = function PopoverContent(
|
|
59
|
-
var children =
|
|
60
|
-
placement =
|
|
61
|
-
|
|
62
|
-
isVisible =
|
|
63
|
-
|
|
64
|
-
shouldDismissOnClickOutside =
|
|
65
|
-
dismiss =
|
|
66
|
-
|
|
58
|
+
var PopoverContent = exports.PopoverContent = function PopoverContent(props) {
|
|
59
|
+
var children = props.children,
|
|
60
|
+
placement = props.placement,
|
|
61
|
+
_props$isVisible = props.isVisible,
|
|
62
|
+
isVisible = _props$isVisible === void 0 ? true : _props$isVisible,
|
|
63
|
+
_props$shouldDismissO = props.shouldDismissOnClickOutside,
|
|
64
|
+
shouldDismissOnClickOutside = _props$shouldDismissO === void 0 ? true : _props$shouldDismissO,
|
|
65
|
+
dismiss = props.dismiss,
|
|
66
|
+
back = props.back,
|
|
67
|
+
testId = props.testId;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A user should only be able to pass a `done` or a `next`. Not both.
|
|
71
|
+
* The type is set up as a discriminant union. So, we need a typeguard
|
|
72
|
+
* here to destructure it properly.
|
|
73
|
+
*/
|
|
74
|
+
var done = 'done' in props ? props.done : undefined;
|
|
75
|
+
var next = 'next' in props ? props.next : undefined;
|
|
67
76
|
var updateRef = (0, _react.useRef)(function () {
|
|
68
77
|
return new Promise(function () {
|
|
69
78
|
return undefined;
|
|
@@ -73,14 +82,34 @@ var PopoverContent = exports.PopoverContent = function PopoverContent(_ref) {
|
|
|
73
82
|
var _useContext = (0, _react.useContext)(_context.SpotlightContext),
|
|
74
83
|
heading = _useContext.heading,
|
|
75
84
|
popoverContent = _useContext.popoverContent,
|
|
76
|
-
card = _useContext.card
|
|
85
|
+
card = _useContext.card,
|
|
86
|
+
primaryAction = _useContext.primaryAction,
|
|
87
|
+
secondaryAction = _useContext.secondaryAction;
|
|
77
88
|
var focusWithin = (0, _useFocusWithin.useFocusWithin)(popoverContent.ref);
|
|
78
89
|
(0, _react.useEffect)(function () {
|
|
79
90
|
popoverContent.setRef(ref);
|
|
80
91
|
}, [ref, popoverContent]);
|
|
92
|
+
(0, _react.useEffect)(function () {
|
|
93
|
+
if (!done && !next) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (done) {
|
|
97
|
+
primaryAction.setAction(done);
|
|
98
|
+
return;
|
|
99
|
+
} else if (next) {
|
|
100
|
+
primaryAction.setAction(next);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}, [done, next, primaryAction]);
|
|
81
104
|
(0, _react.useEffect)(function () {
|
|
82
105
|
popoverContent.setDismiss(dismiss);
|
|
83
106
|
}, [dismiss, popoverContent]);
|
|
107
|
+
(0, _react.useEffect)(function () {
|
|
108
|
+
if (!back) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
secondaryAction.setAction(back);
|
|
112
|
+
}, [back, secondaryAction]);
|
|
84
113
|
(0, _react.useEffect)(function () {
|
|
85
114
|
card.setPlacement(placement);
|
|
86
115
|
}, [placement, card]);
|
|
@@ -106,10 +135,10 @@ var PopoverContent = exports.PopoverContent = function PopoverContent(_ref) {
|
|
|
106
135
|
return /*#__PURE__*/React.createElement(_popper.Popper, {
|
|
107
136
|
offset: offset,
|
|
108
137
|
placement: popperPlacementMap[placement]
|
|
109
|
-
}, function (
|
|
110
|
-
var localRef =
|
|
111
|
-
style =
|
|
112
|
-
update =
|
|
138
|
+
}, function (_ref) {
|
|
139
|
+
var localRef = _ref.ref,
|
|
140
|
+
style = _ref.style,
|
|
141
|
+
update = _ref.update;
|
|
113
142
|
if (!isVisible) {
|
|
114
143
|
return;
|
|
115
144
|
}
|
|
@@ -11,6 +11,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
var React = _react;
|
|
12
12
|
var _runtime = require("@compiled/react/runtime");
|
|
13
13
|
var _compiled = require("@atlaskit/primitives/compiled");
|
|
14
|
+
var _context = require("../../controllers/context");
|
|
14
15
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
15
16
|
var styles = {
|
|
16
17
|
root: "_2rko12b0 _1dqonqa1 _189ee4h9 _1h6dz9xs _syaz15cr _bfhkcdhy _irr31bsc _1di61b6k"
|
|
@@ -27,12 +28,17 @@ var SpotlightPrimaryAction = exports.SpotlightPrimaryAction = /*#__PURE__*/(0, _
|
|
|
27
28
|
onClick = _ref.onClick,
|
|
28
29
|
children = _ref.children,
|
|
29
30
|
testId = _ref.testId;
|
|
31
|
+
var _useContext = (0, _react.useContext)(_context.SpotlightContext),
|
|
32
|
+
primaryAction = _useContext.primaryAction;
|
|
33
|
+
var done = function done(event) {
|
|
34
|
+
primaryAction.action.current(event);
|
|
35
|
+
};
|
|
30
36
|
return /*#__PURE__*/React.createElement(_compiled.Pressable, {
|
|
31
37
|
"aria-label": ariaLabel,
|
|
32
38
|
ref: ref,
|
|
33
39
|
testId: testId,
|
|
34
40
|
xcss: styles.root,
|
|
35
|
-
onClick: onClick
|
|
41
|
+
onClick: onClick || done
|
|
36
42
|
}, /*#__PURE__*/React.createElement(_compiled.Text, {
|
|
37
43
|
as: "span"
|
|
38
44
|
}, children));
|
|
@@ -11,6 +11,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
var React = _react;
|
|
12
12
|
var _runtime = require("@compiled/react/runtime");
|
|
13
13
|
var _compiled = require("@atlaskit/primitives/compiled");
|
|
14
|
+
var _context = require("../../controllers/context");
|
|
14
15
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
15
16
|
var styles = {
|
|
16
17
|
root: "_2rko12b0 _syaz15cr _bfhkcdhy _irr31bsc _1di61b6k"
|
|
@@ -27,12 +28,17 @@ var SpotlightSecondaryAction = exports.SpotlightSecondaryAction = /*#__PURE__*/(
|
|
|
27
28
|
onClick = _ref.onClick,
|
|
28
29
|
children = _ref.children,
|
|
29
30
|
testId = _ref.testId;
|
|
31
|
+
var _useContext = (0, _react.useContext)(_context.SpotlightContext),
|
|
32
|
+
secondaryAction = _useContext.secondaryAction;
|
|
33
|
+
var back = function back(event) {
|
|
34
|
+
secondaryAction.action.current(event);
|
|
35
|
+
};
|
|
30
36
|
return /*#__PURE__*/React.createElement(_compiled.Pressable, {
|
|
31
37
|
"aria-label": ariaLabel,
|
|
32
38
|
ref: ref,
|
|
33
39
|
testId: testId,
|
|
34
40
|
xcss: styles.root,
|
|
35
|
-
onClick: onClick
|
|
41
|
+
onClick: onClick || back
|
|
36
42
|
}, /*#__PURE__*/React.createElement(_compiled.Text, {
|
|
37
43
|
as: "span"
|
|
38
44
|
}, children));
|
|
@@ -26,6 +26,18 @@ export const SpotlightContext = /*#__PURE__*/createContext({
|
|
|
26
26
|
current: () => undefined
|
|
27
27
|
},
|
|
28
28
|
setDismiss: () => undefined
|
|
29
|
+
},
|
|
30
|
+
primaryAction: {
|
|
31
|
+
action: {
|
|
32
|
+
current: () => undefined
|
|
33
|
+
},
|
|
34
|
+
setAction: () => undefined
|
|
35
|
+
},
|
|
36
|
+
secondaryAction: {
|
|
37
|
+
action: {
|
|
38
|
+
current: () => undefined
|
|
39
|
+
},
|
|
40
|
+
setAction: () => undefined
|
|
29
41
|
}
|
|
30
42
|
});
|
|
31
43
|
|
|
@@ -43,6 +55,14 @@ export const SpotlightContextProvider = ({
|
|
|
43
55
|
const setDismiss = dismissFn => {
|
|
44
56
|
dismissRef.current = dismissFn;
|
|
45
57
|
};
|
|
58
|
+
const secondaryActionRef = useRef(() => undefined);
|
|
59
|
+
const setSecondaryAction = actionFn => {
|
|
60
|
+
secondaryActionRef.current = actionFn;
|
|
61
|
+
};
|
|
62
|
+
const primaryActionRef = useRef(() => undefined);
|
|
63
|
+
const setPrimaryAction = actionFn => {
|
|
64
|
+
primaryActionRef.current = actionFn;
|
|
65
|
+
};
|
|
46
66
|
return /*#__PURE__*/React.createElement(SpotlightContext.Provider, {
|
|
47
67
|
value: {
|
|
48
68
|
card: {
|
|
@@ -62,6 +82,14 @@ export const SpotlightContextProvider = ({
|
|
|
62
82
|
setUpdate,
|
|
63
83
|
dismiss: dismissRef,
|
|
64
84
|
setDismiss
|
|
85
|
+
},
|
|
86
|
+
primaryAction: {
|
|
87
|
+
action: primaryActionRef,
|
|
88
|
+
setAction: setPrimaryAction
|
|
89
|
+
},
|
|
90
|
+
secondaryAction: {
|
|
91
|
+
action: secondaryActionRef,
|
|
92
|
+
setAction: setSecondaryAction
|
|
65
93
|
}
|
|
66
94
|
}
|
|
67
95
|
}, children);
|
|
@@ -46,28 +46,58 @@ const popperPlacementMap = {
|
|
|
46
46
|
*
|
|
47
47
|
* A `PopoverContent` is the element that is shown as a popover.
|
|
48
48
|
*/
|
|
49
|
-
export const PopoverContent =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
export const PopoverContent = props => {
|
|
50
|
+
const {
|
|
51
|
+
children,
|
|
52
|
+
placement,
|
|
53
|
+
isVisible = true,
|
|
54
|
+
shouldDismissOnClickOutside = true,
|
|
55
|
+
dismiss,
|
|
56
|
+
back,
|
|
57
|
+
testId
|
|
58
|
+
} = props;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A user should only be able to pass a `done` or a `next`. Not both.
|
|
62
|
+
* The type is set up as a discriminant union. So, we need a typeguard
|
|
63
|
+
* here to destructure it properly.
|
|
64
|
+
*/
|
|
65
|
+
const done = 'done' in props ? props.done : undefined;
|
|
66
|
+
const next = 'next' in props ? props.next : undefined;
|
|
57
67
|
const updateRef = useRef(() => new Promise(() => undefined));
|
|
58
68
|
const ref = useRef();
|
|
59
69
|
const {
|
|
60
70
|
heading,
|
|
61
71
|
popoverContent,
|
|
62
|
-
card
|
|
72
|
+
card,
|
|
73
|
+
primaryAction,
|
|
74
|
+
secondaryAction
|
|
63
75
|
} = useContext(SpotlightContext);
|
|
64
76
|
const focusWithin = useFocusWithin(popoverContent.ref);
|
|
65
77
|
useEffect(() => {
|
|
66
78
|
popoverContent.setRef(ref);
|
|
67
79
|
}, [ref, popoverContent]);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!done && !next) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (done) {
|
|
85
|
+
primaryAction.setAction(done);
|
|
86
|
+
return;
|
|
87
|
+
} else if (next) {
|
|
88
|
+
primaryAction.setAction(next);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}, [done, next, primaryAction]);
|
|
68
92
|
useEffect(() => {
|
|
69
93
|
popoverContent.setDismiss(dismiss);
|
|
70
94
|
}, [dismiss, popoverContent]);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!back) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
secondaryAction.setAction(back);
|
|
100
|
+
}, [back, secondaryAction]);
|
|
71
101
|
useEffect(() => {
|
|
72
102
|
card.setPlacement(placement);
|
|
73
103
|
}, [placement, card]);
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import "./index.compiled.css";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
5
|
-
import { forwardRef } from 'react';
|
|
5
|
+
import { forwardRef, useContext } from 'react';
|
|
6
6
|
import { Pressable, Text } from '@atlaskit/primitives/compiled';
|
|
7
|
+
import { SpotlightContext } from '../../controllers/context';
|
|
7
8
|
const styles = {
|
|
8
9
|
root: "_2rko12b0 _1dqonqa1 _189ee4h9 _1h6dz9xs _syaz15cr _bfhkcdhy _irr31bsc _1di61b6k"
|
|
9
10
|
};
|
|
@@ -20,12 +21,18 @@ export const SpotlightPrimaryAction = /*#__PURE__*/forwardRef(({
|
|
|
20
21
|
children,
|
|
21
22
|
testId
|
|
22
23
|
}, ref) => {
|
|
24
|
+
const {
|
|
25
|
+
primaryAction
|
|
26
|
+
} = useContext(SpotlightContext);
|
|
27
|
+
const done = event => {
|
|
28
|
+
primaryAction.action.current(event);
|
|
29
|
+
};
|
|
23
30
|
return /*#__PURE__*/React.createElement(Pressable, {
|
|
24
31
|
"aria-label": ariaLabel,
|
|
25
32
|
ref: ref,
|
|
26
33
|
testId: testId,
|
|
27
34
|
xcss: styles.root,
|
|
28
|
-
onClick: onClick
|
|
35
|
+
onClick: onClick || done
|
|
29
36
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
30
37
|
as: "span"
|
|
31
38
|
}, children));
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import "./index.compiled.css";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
5
|
-
import { forwardRef } from 'react';
|
|
5
|
+
import { forwardRef, useContext } from 'react';
|
|
6
6
|
import { Pressable, Text } from '@atlaskit/primitives/compiled';
|
|
7
|
+
import { SpotlightContext } from '../../controllers/context';
|
|
7
8
|
const styles = {
|
|
8
9
|
root: "_2rko12b0 _syaz15cr _bfhkcdhy _irr31bsc _1di61b6k"
|
|
9
10
|
};
|
|
@@ -20,12 +21,18 @@ export const SpotlightSecondaryAction = /*#__PURE__*/forwardRef(({
|
|
|
20
21
|
children,
|
|
21
22
|
testId
|
|
22
23
|
}, ref) => {
|
|
24
|
+
const {
|
|
25
|
+
secondaryAction
|
|
26
|
+
} = useContext(SpotlightContext);
|
|
27
|
+
const back = event => {
|
|
28
|
+
secondaryAction.action.current(event);
|
|
29
|
+
};
|
|
23
30
|
return /*#__PURE__*/React.createElement(Pressable, {
|
|
24
31
|
"aria-label": ariaLabel,
|
|
25
32
|
ref: ref,
|
|
26
33
|
testId: testId,
|
|
27
34
|
xcss: styles.root,
|
|
28
|
-
onClick: onClick
|
|
35
|
+
onClick: onClick || back
|
|
29
36
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
30
37
|
as: "span"
|
|
31
38
|
}, children));
|
|
@@ -53,6 +53,26 @@ export var SpotlightContext = /*#__PURE__*/createContext({
|
|
|
53
53
|
setDismiss: function setDismiss() {
|
|
54
54
|
return undefined;
|
|
55
55
|
}
|
|
56
|
+
},
|
|
57
|
+
primaryAction: {
|
|
58
|
+
action: {
|
|
59
|
+
current: function current() {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
setAction: function setAction() {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
secondaryAction: {
|
|
68
|
+
action: {
|
|
69
|
+
current: function current() {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
setAction: function setAction() {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
56
76
|
}
|
|
57
77
|
});
|
|
58
78
|
|
|
@@ -98,6 +118,18 @@ export var SpotlightContextProvider = function SpotlightContextProvider(_ref) {
|
|
|
98
118
|
var setDismiss = function setDismiss(dismissFn) {
|
|
99
119
|
dismissRef.current = dismissFn;
|
|
100
120
|
};
|
|
121
|
+
var secondaryActionRef = useRef(function () {
|
|
122
|
+
return undefined;
|
|
123
|
+
});
|
|
124
|
+
var setSecondaryAction = function setSecondaryAction(actionFn) {
|
|
125
|
+
secondaryActionRef.current = actionFn;
|
|
126
|
+
};
|
|
127
|
+
var primaryActionRef = useRef(function () {
|
|
128
|
+
return undefined;
|
|
129
|
+
});
|
|
130
|
+
var setPrimaryAction = function setPrimaryAction(actionFn) {
|
|
131
|
+
primaryActionRef.current = actionFn;
|
|
132
|
+
};
|
|
101
133
|
return /*#__PURE__*/React.createElement(SpotlightContext.Provider, {
|
|
102
134
|
value: {
|
|
103
135
|
card: {
|
|
@@ -117,6 +149,14 @@ export var SpotlightContextProvider = function SpotlightContextProvider(_ref) {
|
|
|
117
149
|
setUpdate: setUpdate,
|
|
118
150
|
dismiss: dismissRef,
|
|
119
151
|
setDismiss: setDismiss
|
|
152
|
+
},
|
|
153
|
+
primaryAction: {
|
|
154
|
+
action: primaryActionRef,
|
|
155
|
+
setAction: setPrimaryAction
|
|
156
|
+
},
|
|
157
|
+
secondaryAction: {
|
|
158
|
+
action: secondaryActionRef,
|
|
159
|
+
setAction: setSecondaryAction
|
|
120
160
|
}
|
|
121
161
|
}
|
|
122
162
|
}, children);
|
|
@@ -46,15 +46,24 @@ var popperPlacementMap = {
|
|
|
46
46
|
*
|
|
47
47
|
* A `PopoverContent` is the element that is shown as a popover.
|
|
48
48
|
*/
|
|
49
|
-
export var PopoverContent = function PopoverContent(
|
|
50
|
-
var children =
|
|
51
|
-
placement =
|
|
52
|
-
|
|
53
|
-
isVisible =
|
|
54
|
-
|
|
55
|
-
shouldDismissOnClickOutside =
|
|
56
|
-
dismiss =
|
|
57
|
-
|
|
49
|
+
export var PopoverContent = function PopoverContent(props) {
|
|
50
|
+
var children = props.children,
|
|
51
|
+
placement = props.placement,
|
|
52
|
+
_props$isVisible = props.isVisible,
|
|
53
|
+
isVisible = _props$isVisible === void 0 ? true : _props$isVisible,
|
|
54
|
+
_props$shouldDismissO = props.shouldDismissOnClickOutside,
|
|
55
|
+
shouldDismissOnClickOutside = _props$shouldDismissO === void 0 ? true : _props$shouldDismissO,
|
|
56
|
+
dismiss = props.dismiss,
|
|
57
|
+
back = props.back,
|
|
58
|
+
testId = props.testId;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A user should only be able to pass a `done` or a `next`. Not both.
|
|
62
|
+
* The type is set up as a discriminant union. So, we need a typeguard
|
|
63
|
+
* here to destructure it properly.
|
|
64
|
+
*/
|
|
65
|
+
var done = 'done' in props ? props.done : undefined;
|
|
66
|
+
var next = 'next' in props ? props.next : undefined;
|
|
58
67
|
var updateRef = useRef(function () {
|
|
59
68
|
return new Promise(function () {
|
|
60
69
|
return undefined;
|
|
@@ -64,14 +73,34 @@ export var PopoverContent = function PopoverContent(_ref) {
|
|
|
64
73
|
var _useContext = useContext(SpotlightContext),
|
|
65
74
|
heading = _useContext.heading,
|
|
66
75
|
popoverContent = _useContext.popoverContent,
|
|
67
|
-
card = _useContext.card
|
|
76
|
+
card = _useContext.card,
|
|
77
|
+
primaryAction = _useContext.primaryAction,
|
|
78
|
+
secondaryAction = _useContext.secondaryAction;
|
|
68
79
|
var focusWithin = useFocusWithin(popoverContent.ref);
|
|
69
80
|
useEffect(function () {
|
|
70
81
|
popoverContent.setRef(ref);
|
|
71
82
|
}, [ref, popoverContent]);
|
|
83
|
+
useEffect(function () {
|
|
84
|
+
if (!done && !next) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (done) {
|
|
88
|
+
primaryAction.setAction(done);
|
|
89
|
+
return;
|
|
90
|
+
} else if (next) {
|
|
91
|
+
primaryAction.setAction(next);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}, [done, next, primaryAction]);
|
|
72
95
|
useEffect(function () {
|
|
73
96
|
popoverContent.setDismiss(dismiss);
|
|
74
97
|
}, [dismiss, popoverContent]);
|
|
98
|
+
useEffect(function () {
|
|
99
|
+
if (!back) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
secondaryAction.setAction(back);
|
|
103
|
+
}, [back, secondaryAction]);
|
|
75
104
|
useEffect(function () {
|
|
76
105
|
card.setPlacement(placement);
|
|
77
106
|
}, [placement, card]);
|
|
@@ -97,10 +126,10 @@ export var PopoverContent = function PopoverContent(_ref) {
|
|
|
97
126
|
return /*#__PURE__*/React.createElement(Popper, {
|
|
98
127
|
offset: offset,
|
|
99
128
|
placement: popperPlacementMap[placement]
|
|
100
|
-
}, function (
|
|
101
|
-
var localRef =
|
|
102
|
-
style =
|
|
103
|
-
update =
|
|
129
|
+
}, function (_ref) {
|
|
130
|
+
var localRef = _ref.ref,
|
|
131
|
+
style = _ref.style,
|
|
132
|
+
update = _ref.update;
|
|
104
133
|
if (!isVisible) {
|
|
105
134
|
return;
|
|
106
135
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import "./index.compiled.css";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
5
|
-
import { forwardRef } from 'react';
|
|
5
|
+
import { forwardRef, useContext } from 'react';
|
|
6
6
|
import { Pressable, Text } from '@atlaskit/primitives/compiled';
|
|
7
|
+
import { SpotlightContext } from '../../controllers/context';
|
|
7
8
|
var styles = {
|
|
8
9
|
root: "_2rko12b0 _1dqonqa1 _189ee4h9 _1h6dz9xs _syaz15cr _bfhkcdhy _irr31bsc _1di61b6k"
|
|
9
10
|
};
|
|
@@ -19,12 +20,17 @@ export var SpotlightPrimaryAction = /*#__PURE__*/forwardRef(function (_ref, ref)
|
|
|
19
20
|
onClick = _ref.onClick,
|
|
20
21
|
children = _ref.children,
|
|
21
22
|
testId = _ref.testId;
|
|
23
|
+
var _useContext = useContext(SpotlightContext),
|
|
24
|
+
primaryAction = _useContext.primaryAction;
|
|
25
|
+
var done = function done(event) {
|
|
26
|
+
primaryAction.action.current(event);
|
|
27
|
+
};
|
|
22
28
|
return /*#__PURE__*/React.createElement(Pressable, {
|
|
23
29
|
"aria-label": ariaLabel,
|
|
24
30
|
ref: ref,
|
|
25
31
|
testId: testId,
|
|
26
32
|
xcss: styles.root,
|
|
27
|
-
onClick: onClick
|
|
33
|
+
onClick: onClick || done
|
|
28
34
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
29
35
|
as: "span"
|
|
30
36
|
}, children));
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import "./index.compiled.css";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
5
|
-
import { forwardRef } from 'react';
|
|
5
|
+
import { forwardRef, useContext } from 'react';
|
|
6
6
|
import { Pressable, Text } from '@atlaskit/primitives/compiled';
|
|
7
|
+
import { SpotlightContext } from '../../controllers/context';
|
|
7
8
|
var styles = {
|
|
8
9
|
root: "_2rko12b0 _syaz15cr _bfhkcdhy _irr31bsc _1di61b6k"
|
|
9
10
|
};
|
|
@@ -19,12 +20,17 @@ export var SpotlightSecondaryAction = /*#__PURE__*/forwardRef(function (_ref, re
|
|
|
19
20
|
onClick = _ref.onClick,
|
|
20
21
|
children = _ref.children,
|
|
21
22
|
testId = _ref.testId;
|
|
23
|
+
var _useContext = useContext(SpotlightContext),
|
|
24
|
+
secondaryAction = _useContext.secondaryAction;
|
|
25
|
+
var back = function back(event) {
|
|
26
|
+
secondaryAction.action.current(event);
|
|
27
|
+
};
|
|
22
28
|
return /*#__PURE__*/React.createElement(Pressable, {
|
|
23
29
|
"aria-label": ariaLabel,
|
|
24
30
|
ref: ref,
|
|
25
31
|
testId: testId,
|
|
26
32
|
xcss: styles.root,
|
|
27
|
-
onClick: onClick
|
|
33
|
+
onClick: onClick || back
|
|
28
34
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
29
35
|
as: "span"
|
|
30
36
|
}, children));
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @jsx jsx
|
|
4
4
|
*/
|
|
5
5
|
import { type Dispatch, type MutableRefObject, type ReactNode, type SetStateAction } from 'react';
|
|
6
|
-
import type { DismissEvent, Placement } from '../types';
|
|
6
|
+
import type { BackEvent, DismissEvent, DoneEvent, Placement } from '../types';
|
|
7
7
|
export interface SpotlightContextType {
|
|
8
8
|
card: {
|
|
9
9
|
ref: MutableRefObject<HTMLDivElement | null> | null;
|
|
@@ -23,6 +23,14 @@ export interface SpotlightContextType {
|
|
|
23
23
|
dismiss: MutableRefObject<(_event: DismissEvent) => void>;
|
|
24
24
|
setDismiss: (dismissFn: (_event: DismissEvent) => void) => void;
|
|
25
25
|
};
|
|
26
|
+
primaryAction: {
|
|
27
|
+
action: MutableRefObject<(_event: DoneEvent) => void>;
|
|
28
|
+
setAction: (doneFn: (_event: DoneEvent) => void) => void;
|
|
29
|
+
};
|
|
30
|
+
secondaryAction: {
|
|
31
|
+
action: MutableRefObject<(_event: BackEvent) => void>;
|
|
32
|
+
setAction: (backFn: (_event: BackEvent) => void) => void;
|
|
33
|
+
};
|
|
26
34
|
}
|
|
27
35
|
export declare const SpotlightContext: import("react").Context<SpotlightContextType>;
|
|
28
36
|
export declare const SpotlightContextProvider: ({ children }: {
|
package/dist/types/types.d.ts
CHANGED
|
@@ -8,3 +8,6 @@ export type Placement = 'top-start' | 'top-center' | 'top-end' | 'bottom-start'
|
|
|
8
8
|
* These events align to the `React.MouseEvent<HTMLButtonElement, MouseEvent>`, `MouseEvent`, and `KeyboardEvent` events respectively.
|
|
9
9
|
*/
|
|
10
10
|
export type DismissEvent = React.MouseEvent<HTMLButtonElement, MouseEvent> | MouseEvent | KeyboardEvent;
|
|
11
|
+
export type BackEvent = React.MouseEvent<HTMLButtonElement, MouseEvent>;
|
|
12
|
+
export type NextEvent = React.MouseEvent<HTMLButtonElement, MouseEvent>;
|
|
13
|
+
export type DoneEvent = React.MouseEvent<HTMLButtonElement, MouseEvent>;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* @jsx jsx
|
|
4
4
|
*/
|
|
5
5
|
import { type ReactNode } from 'react';
|
|
6
|
-
import type { DismissEvent, Placement } from '../../types';
|
|
7
|
-
|
|
6
|
+
import type { BackEvent, DismissEvent, DoneEvent, NextEvent, Placement } from '../../types';
|
|
7
|
+
interface BasePopoverContentProps {
|
|
8
8
|
/**
|
|
9
9
|
* A `testId` prop is provided for specified elements, which is a unique
|
|
10
10
|
* string that appears as a data attribute `data-testid` in the rendered code,
|
|
@@ -15,11 +15,23 @@ export interface PopoverContentProps {
|
|
|
15
15
|
isVisible?: boolean;
|
|
16
16
|
shouldDismissOnClickOutside?: boolean;
|
|
17
17
|
dismiss: (event: DismissEvent) => void;
|
|
18
|
+
back?: (event: BackEvent) => void;
|
|
18
19
|
children: ReactNode;
|
|
19
20
|
}
|
|
21
|
+
export type PopoverContentProps = BasePopoverContentProps & ({
|
|
22
|
+
next: (event: NextEvent) => void;
|
|
23
|
+
done?: never;
|
|
24
|
+
} | {
|
|
25
|
+
done: (event: DoneEvent) => void;
|
|
26
|
+
next?: never;
|
|
27
|
+
} | {
|
|
28
|
+
next?: never;
|
|
29
|
+
done?: never;
|
|
30
|
+
});
|
|
20
31
|
/**
|
|
21
32
|
* __PopoverContent__
|
|
22
33
|
*
|
|
23
34
|
* A `PopoverContent` is the element that is shown as a popover.
|
|
24
35
|
*/
|
|
25
|
-
export declare const PopoverContent: (
|
|
36
|
+
export declare const PopoverContent: (props: PopoverContentProps) => JSX.Element;
|
|
37
|
+
export {};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @jsx jsx
|
|
4
4
|
*/
|
|
5
5
|
import { type Dispatch, type MutableRefObject, type ReactNode, type SetStateAction } from 'react';
|
|
6
|
-
import type { DismissEvent, Placement } from '../types';
|
|
6
|
+
import type { BackEvent, DismissEvent, DoneEvent, Placement } from '../types';
|
|
7
7
|
export interface SpotlightContextType {
|
|
8
8
|
card: {
|
|
9
9
|
ref: MutableRefObject<HTMLDivElement | null> | null;
|
|
@@ -23,6 +23,14 @@ export interface SpotlightContextType {
|
|
|
23
23
|
dismiss: MutableRefObject<(_event: DismissEvent) => void>;
|
|
24
24
|
setDismiss: (dismissFn: (_event: DismissEvent) => void) => void;
|
|
25
25
|
};
|
|
26
|
+
primaryAction: {
|
|
27
|
+
action: MutableRefObject<(_event: DoneEvent) => void>;
|
|
28
|
+
setAction: (doneFn: (_event: DoneEvent) => void) => void;
|
|
29
|
+
};
|
|
30
|
+
secondaryAction: {
|
|
31
|
+
action: MutableRefObject<(_event: BackEvent) => void>;
|
|
32
|
+
setAction: (backFn: (_event: BackEvent) => void) => void;
|
|
33
|
+
};
|
|
26
34
|
}
|
|
27
35
|
export declare const SpotlightContext: import("react").Context<SpotlightContextType>;
|
|
28
36
|
export declare const SpotlightContextProvider: ({ children }: {
|
|
@@ -8,3 +8,6 @@ export type Placement = 'top-start' | 'top-center' | 'top-end' | 'bottom-start'
|
|
|
8
8
|
* These events align to the `React.MouseEvent<HTMLButtonElement, MouseEvent>`, `MouseEvent`, and `KeyboardEvent` events respectively.
|
|
9
9
|
*/
|
|
10
10
|
export type DismissEvent = React.MouseEvent<HTMLButtonElement, MouseEvent> | MouseEvent | KeyboardEvent;
|
|
11
|
+
export type BackEvent = React.MouseEvent<HTMLButtonElement, MouseEvent>;
|
|
12
|
+
export type NextEvent = React.MouseEvent<HTMLButtonElement, MouseEvent>;
|
|
13
|
+
export type DoneEvent = React.MouseEvent<HTMLButtonElement, MouseEvent>;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* @jsx jsx
|
|
4
4
|
*/
|
|
5
5
|
import { type ReactNode } from 'react';
|
|
6
|
-
import type { DismissEvent, Placement } from '../../types';
|
|
7
|
-
|
|
6
|
+
import type { BackEvent, DismissEvent, DoneEvent, NextEvent, Placement } from '../../types';
|
|
7
|
+
interface BasePopoverContentProps {
|
|
8
8
|
/**
|
|
9
9
|
* A `testId` prop is provided for specified elements, which is a unique
|
|
10
10
|
* string that appears as a data attribute `data-testid` in the rendered code,
|
|
@@ -15,11 +15,23 @@ export interface PopoverContentProps {
|
|
|
15
15
|
isVisible?: boolean;
|
|
16
16
|
shouldDismissOnClickOutside?: boolean;
|
|
17
17
|
dismiss: (event: DismissEvent) => void;
|
|
18
|
+
back?: (event: BackEvent) => void;
|
|
18
19
|
children: ReactNode;
|
|
19
20
|
}
|
|
21
|
+
export type PopoverContentProps = BasePopoverContentProps & ({
|
|
22
|
+
next: (event: NextEvent) => void;
|
|
23
|
+
done?: never;
|
|
24
|
+
} | {
|
|
25
|
+
done: (event: DoneEvent) => void;
|
|
26
|
+
next?: never;
|
|
27
|
+
} | {
|
|
28
|
+
next?: never;
|
|
29
|
+
done?: never;
|
|
30
|
+
});
|
|
20
31
|
/**
|
|
21
32
|
* __PopoverContent__
|
|
22
33
|
*
|
|
23
34
|
* A `PopoverContent` is the element that is shown as a popover.
|
|
24
35
|
*/
|
|
25
|
-
export declare const PopoverContent: (
|
|
36
|
+
export declare const PopoverContent: (props: PopoverContentProps) => JSX.Element;
|
|
37
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/spotlight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A spotlight introduces users to various points of interest across Atlassian through focused messages or multi-step tours.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@atlaskit/icon": "^28.5.0",
|
|
35
35
|
"@atlaskit/image": "^3.0.0",
|
|
36
36
|
"@atlaskit/popper": "^7.1.0",
|
|
37
|
-
"@atlaskit/primitives": "^
|
|
37
|
+
"@atlaskit/primitives": "^16.0.0",
|
|
38
38
|
"@atlaskit/tokens": "^7.0.0",
|
|
39
39
|
"@atlaskit/visually-hidden": "^3.0.0",
|
|
40
40
|
"@babel/runtime": "^7.0.0",
|