@enact/moonstone
Version:
Large-screen/TV support library for Enact, containing a variety of UI components.
160 lines (157 loc) • 7.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.IconButtonDecorator = exports.IconButtonBase = exports.IconButton = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _Button = require("../Button");
var _Icon = _interopRequireDefault(require("../Icon"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _TooltipDecorator = _interopRequireDefault(require("../TooltipDecorator"));
var _UiIconButton = require("../UiIconButton");
var _IconButtonModule = _interopRequireDefault(require("./IconButton.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "css"];
/**
* An {@link moonstone/Icon.Icon|Icon} that acts like a {@link moonstone/Button.Button|Button}.
* You may specify an image or a font-based icon by setting the `children` to either the path
* to the image or a string from an {@link moonstone/Icon.IconBase.iconList|iconList}.
*
* @example
* <IconButton size="small">plus</IconButton>
*
* @module moonstone/IconButton
* @exports IconButton
* @exports IconButtonBase
* @exports IconButtonDecorator
*/
/**
* A moonstone-styled icon button without any behavior.
*
* @class IconButtonBase
* @memberof moonstone/IconButton
* @extends moonstone/Button.ButtonBase
* @extends moonstone/UiIconButton.IconButtonBase
* @omit buttonComponent
* @omit iconComponent
* @ui
* @public
*/
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
var IconButtonBase = exports.IconButtonBase = (0, _kind["default"])({
name: 'IconButton',
propTypes: /** @lends moonstone/IconButton.IconButtonBase.prototype */{
/**
* The background-color opacity of this icon button.
*
* Valid values are:
* * `'translucent'`,
* * `'lightTranslucent'`, and
* * `'transparent'`.
*
* @type {String}
* @public
*/
backgroundOpacity: _propTypes["default"].oneOf(['translucent', 'lightTranslucent', 'transparent']),
/**
* The color of the underline beneath the icon.
*
* This property accepts one of the following color names, which correspond with the
* colored buttons on a standard remote control: `'red'`, `'green'`, `'yellow'`, `'blue'`
*
* @type {String}
* @public
*/
color: _propTypes["default"].oneOf(['red', 'green', 'yellow', 'blue']),
/**
* Customizes the component by mapping the supplied collection of CSS class names to the
* corresponding internal elements and states of this component.
*
* The following classes are supported:
*
* * `iconButton` - The root class name
* * `bg` - The background node of the icon button
* * `large` - Applied to a `size='large'` icon button
* * `selected` - Applied to a `selected` icon button
* * `small` - Applied to a `size='small'` icon button
*
* @type {Object}
* @public
*/
css: _propTypes["default"].object
},
defaultProps: {
size: 'small'
},
styles: {
css: _IconButtonModule["default"],
publicClassNames: ['iconButton', 'bg', 'large', 'selected', 'small']
},
computed: {
className: function className(_ref) {
var color = _ref.color,
styler = _ref.styler;
return styler.append(color);
}
},
render: function render(_ref2) {
var children = _ref2.children,
css = _ref2.css,
rest = _objectWithoutProperties(_ref2, _excluded);
return _UiIconButton.IconButtonBase.inline(_objectSpread(_objectSpread({
'data-webos-voice-intent': 'Select'
}, rest), {}, {
buttonComponent: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, {
css: css
}),
css: css,
icon: children,
iconComponent: _Icon["default"]
}));
}
});
/**
* Moonstone-specific button behaviors to apply to
* {@link moonstone/IconButton.IconButtonBase|IconButton}.
*
* @hoc
* @memberof moonstone/IconButton
* @mixes moonstone/TooltipDecorator.TooltipDecorator
* @mixes moonstone/UiIconButton.IconButtonDecorator
* @mixes spotlight/Spottable.Spottable
* @mixes moonstone/Skinnable.Skinnable
* @public
*/
var IconButtonDecorator = exports.IconButtonDecorator = (0, _compose["default"])(_Pure["default"], (0, _TooltipDecorator["default"])({
tooltipDestinationProp: 'decoration'
}), _UiIconButton.IconButtonDecorator, _Spottable["default"], _Skinnable["default"]);
/**
* `IconButton` does not have `Marquee` like `Button` has, as it should not contain text.
*
* Usage:
* ```
* <IconButton onClick={handleClick} size="small">
* plus
* </IconButton>
* ```
*
* @class IconButton
* @memberof moonstone/IconButton
* @extends moonstone/IconButton.IconButtonBase
* @mixes moonstone/IconButton.IconButtonDecorator
* @ui
* @public
*/
var IconButton = exports.IconButton = IconButtonDecorator(IconButtonBase);
var _default = exports["default"] = IconButton;