@carbon/ibm-products
Version:
Carbon for IBM Products
87 lines (79 loc) • 2.92 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
;
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
require('../Coachmark/Coachmark.js');
var context = require('../Coachmark/utils/context.js');
var index = require('../../_virtual/index.js');
var React = require('react');
var cx = require('classnames');
var devtools = require('../../global/js/utils/devtools.js');
var settings = require('../../settings.js');
var _div, _circle;
// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${settings.pkg.prefix}--coachmark-beacon`;
const componentName = 'CoachmarkBeacon';
const defaults = {
kind: 'default'
};
/**
* Use beacon for the target prop of a Coachmark component.
*/
exports.CoachmarkBeacon = /*#__PURE__*/React.forwardRef((_ref, ref) => {
let {
label,
className,
kind = defaults.kind,
...rest
} = _ref;
const coachmark = context.useCoachmark();
if (!coachmark) {
return _div || (_div = /*#__PURE__*/React.createElement("div", null, "CoachmarkBeacon is to be use exclusively within the target prop of Coachmark"));
}
return /*#__PURE__*/React.createElement("span", _rollupPluginBabelHelpers.extends({}, rest, {
className: cx(blockClass, `${blockClass}-${kind}`, className),
ref: ref
}, devtools.getDevtoolsProps(componentName), {
role: "tooltip"
}), /*#__PURE__*/React.createElement("button", _rollupPluginBabelHelpers.extends({
tabIndex: 0,
type: "button"
}, coachmark.buttonProps, {
className: `${blockClass}__target`
}), /*#__PURE__*/React.createElement("svg", {
className: `${blockClass}__center`,
"aria-label": label
}, /*#__PURE__*/React.createElement("title", null, label), _circle || (_circle = /*#__PURE__*/React.createElement("circle", {
r: 1,
cx: 38,
cy: 38
})))));
});
// Return a placeholder if not released and not enabled by feature flag
exports.CoachmarkBeacon = settings.pkg.checkComponentEnabled(exports.CoachmarkBeacon, componentName);
// The display name of the component, used by React. Note that displayName
// is used in preference to relying on function.name.
exports.CoachmarkBeacon.displayName = componentName;
// The types and DocGen commentary for the component props,
// in alphabetical order (for consistency).
// See https://www.npmjs.com/package/prop-types#usage.
exports.CoachmarkBeacon.propTypes = {
/**
* Optional class name for this component.
*/
className: index.default.string,
/**
* What style of beacon.
* BEACON_KIND is an exported enum from the Coachmark and can be used for this value.
* @see {@link BEACON_KIND}
*/
kind: index.default.oneOf(['default']),
/**
* The aria label.
*/
label: index.default.string.isRequired
};