@atlaskit/spotlight
Version:
A spotlight introduces users to points of interest, from focused messages to multi-step tours.
208 lines (204 loc) • 6.08 kB
JavaScript
/* context.tsx generated by @compiled/babel-plugin v3.0.2 */
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { createContext, useId, useRef, useState } from 'react';
// eslint-disable-next-line @repo/internal/react/consistent-types-definitions
// eslint-disable-next-line @repo/internal/react/require-jsdoc
export var SpotlightContext = /*#__PURE__*/createContext({
card: {
ref: null,
setRef: function setRef() {
return undefined;
},
placement: 'bottom-end',
setPlacement: function setPlacement() {
return undefined;
},
motion: undefined,
setMotion: function setMotion() {
return undefined;
}
},
heading: {
id: '',
setId: function setId() {
return undefined;
}
},
popoverContent: {
ref: undefined,
setRef: function setRef() {
return undefined;
},
positionArea: undefined,
setPositionArea: function setPositionArea() {
return undefined;
},
update: function update() {
return new Promise(function () {
return null;
});
},
setUpdate: function setUpdate() {
return new Promise(function () {
return null;
});
},
dismiss: {
current: function current() {
return undefined;
}
},
setDismiss: function setDismiss() {
return undefined;
}
},
target: {
ref: {
current: null
},
setRef: function setRef() {
return undefined;
}
},
primaryAction: {
action: {
current: function current() {
return undefined;
}
},
setAction: function setAction() {
return undefined;
}
},
secondaryAction: {
action: {
current: function current() {
return undefined;
}
},
setAction: function setAction() {
return undefined;
}
}
});
/**
* Props accepted by `SpotlightContextProvider`.
*/
// eslint-disable-next-line @repo/internal/react/consistent-types-definitions
// eslint-disable-next-line @repo/internal/react/require-jsdoc
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export var SpotlightContextProvider = function SpotlightContextProvider(_ref) {
var children = _ref.children,
targetRef = _ref.targetRef;
var id = useId();
var defaultTargetRef = useRef(null);
var _useState = useState(),
_useState2 = _slicedToArray(_useState, 2),
motion = _useState2[0],
setMotion = _useState2[1];
var _useState3 = useState('bottom-end'),
_useState4 = _slicedToArray(_useState3, 2),
placement = _useState4[0],
setPlacement = _useState4[1];
var _useState5 = useState("".concat(id, "-heading")),
_useState6 = _slicedToArray(_useState5, 2),
headingId = _useState6[0],
setHeadingId = _useState6[1];
var _useState7 = useState(function () {
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function (_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", undefined);
case 1:
case "end":
return _context.stop();
}
}, _callee);
}));
}),
_useState8 = _slicedToArray(_useState7, 2),
update = _useState8[0],
setUpdate = _useState8[1];
var _useState9 = useState(),
_useState0 = _slicedToArray(_useState9, 2),
popoverRef = _useState0[0],
setPopoverRef = _useState0[1];
var _useState1 = useState(),
_useState10 = _slicedToArray(_useState1, 2),
positionArea = _useState10[0],
setPositionArea = _useState10[1];
var _useState11 = useState(null),
_useState12 = _slicedToArray(_useState11, 2),
cardRef = _useState12[0],
setCardRef = _useState12[1];
var _useState13 = useState(defaultTargetRef),
_useState14 = _slicedToArray(_useState13, 2),
internalTargetRef = _useState14[0],
setInternalTargetRef = _useState14[1];
// `targetRef` (the prop) takes precedence when provided. Its identity is
// allowed to change over time; downstream consumers that depend on
// `target.ref` identity (e.g. `useAnchoredPopover`'s effect deps) will
// re-run accordingly.
var effectiveTargetRef = targetRef !== null && targetRef !== void 0 ? targetRef : internalTargetRef;
var dismissRef = useRef(function () {
return undefined;
});
var setDismiss = function setDismiss(dismissFn) {
dismissRef.current = dismissFn;
};
var secondaryActionRef = useRef(function () {
return undefined;
});
var setSecondaryAction = function setSecondaryAction(actionFn) {
secondaryActionRef.current = actionFn;
};
var primaryActionRef = useRef(function () {
return undefined;
});
var setPrimaryAction = function setPrimaryAction(actionFn) {
primaryActionRef.current = actionFn;
};
return /*#__PURE__*/React.createElement(SpotlightContext.Provider, {
value: {
card: {
ref: cardRef,
setRef: setCardRef,
placement: placement,
setPlacement: setPlacement,
motion: motion,
setMotion: setMotion
},
heading: {
id: headingId,
setId: setHeadingId
},
popoverContent: {
ref: popoverRef,
setRef: setPopoverRef,
positionArea: positionArea,
setPositionArea: setPositionArea,
update: update,
setUpdate: setUpdate,
dismiss: dismissRef,
setDismiss: setDismiss
},
target: {
ref: effectiveTargetRef,
setRef: setInternalTargetRef
},
primaryAction: {
action: primaryActionRef,
setAction: setPrimaryAction
},
secondaryAction: {
action: secondaryActionRef,
setAction: setSecondaryAction
}
}
}, children);
};