UNPKG

@enact/ui

Version:

A collection of simplified unstyled cross-platform UI components for Enact

192 lines (189 loc) 8.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.HeadingDecorator = exports.HeadingBase = exports.Heading = void 0; var _kind = _interopRequireDefault(require("@enact/core/kind")); var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types")); var _propTypes2 = _interopRequireDefault(require("prop-types")); var _compose = _interopRequireDefault(require("ramda/src/compose")); var _ForwardRef = _interopRequireDefault(require("../ForwardRef")); var _HeadingModule = _interopRequireDefault(require("./Heading.module.css")); var _jsxRuntime = require("react/jsx-runtime"); var _excluded = ["Tag", "componentRef"]; function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } 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 _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : 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); } /** * A component for instantiating a section of content with a title. * * @example * <Heading spacing="none"> * A Content Section Heading * </Heading> * * @module ui/Heading * @exports Heading * @exports HeadingBase * @exports HeadingDecorator */ /** * A labeled Heading component. * * @class HeadingBase * @memberof ui/Heading * @ui * @public */ var HeadingBase = exports.HeadingBase = (0, _kind["default"])({ name: 'ui:Heading', propTypes: /** @lends ui/Heading.Heading.prototype */{ /** * The text for the label of the Heading. * * @type {Node} * @public */ children: _propTypes2["default"].node, /** * Called with a reference to the root component. * * When using {@link ui/Heading.Heading}, the `ref` prop is forwarded to this component * as `componentRef`. * * @type {Object|Function} * @public */ componentRef: _propTypes["default"].ref, /** * 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: * * * `heading` - The root component class * * `title` - Applied when `size` is set to "title" * * `subtitle` - Applied when `size` is set to "subtitle" * * `large` - Applied when `size` is set to "large" * * `medium` - Applied when `size` is set to "medium" * * `small` - Applied when `size` is set to "small" * * `tiny` - Applied when `size` is set to "tiny" * * `largeSpacing` - Applied when `spacing` is set to "large" * * `mediumSpacing` - Applied when `spacing` is set to "medium" * * `smallSpacing` - Applied when `spacing` is set to "small" * * `noneSpacing` - Applied when `spacing` is set to "none" * * @type {Object} * @public */ css: _propTypes2["default"].object, /** * Set the size of this component. * * * `'title'` and `'subtitle'` are generally considered to be used only once on a given screen. * * `'large'`, `'medium'`, `'small'`, and `'tiny'` are typically used as section headings * for content on a screen, starting with `'large'` for the first tier of information * followed by `'medium'` for the next, and so forth. * * If the `spacing` prop is not set (defaulting to "auto"), these values automatically set * the spacing to the correlated names. * * @type {('title'|'subtitle'|'large'|'medium'|'small'|'tiny')} * @public */ size: _propTypes2["default"].oneOf(['title', 'subtitle', 'large', 'medium', 'small', 'tiny']), /** * The size of the spacing around the Heading. * * These have no built-in measurements, as they are intended to be defined by the theme * consuming this UI element. The values correlate with customizable classes made available * by this component's `css` prop. * * Allowed values include: * * `'auto'` (default) - Lets this value be based on the `size` prop for automatic usage. * * `'large'` - Specifically assign the `'large'` spacing. * * `'medium'` - Specifically assign the `'medium'` spacing. * * `'small'` - Specifically assign the `'small'` spacing. * * `'none'` - No spacing at all. Neighboring elements will directly touch the Heading. * * @type {('auto'|'large'|'medium'|'small'|'none')} * @default 'auto' * @public */ spacing: _propTypes2["default"].oneOf(['auto', 'large', 'medium', 'small', 'none']) }, defaultProps: { size: 'medium', spacing: 'auto' }, styles: { css: _HeadingModule["default"], className: 'heading', publicClassNames: true }, computed: { // This logic is intended to have the following result: // Apply a class for the current 'size'. Use the 'size' to determine the spacing, unless a // "non-auto" spacing value was specified. className: function className(_ref) { var size = _ref.size, spacing = _ref.spacing, styler = _ref.styler; return styler.append(size, _defineProperty({}, (spacing !== 'auto' ? spacing : size || 'none') + 'Spacing', true)); }, Tag: function Tag(_ref2) { var size = _ref2.size; switch (size) { case 'title': return 'h1'; case 'subtitle': return 'h2'; case 'large': return 'h3'; case 'medium': return 'h4'; case 'small': return 'h5'; case 'tiny': return 'h6'; } } }, render: function render(_ref3) { var Tag = _ref3.Tag, componentRef = _ref3.componentRef, rest = _objectWithoutProperties(_ref3, _excluded); delete rest.size; delete rest.spacing; return /*#__PURE__*/(0, _jsxRuntime.jsx)(Tag, _objectSpread(_objectSpread({}, rest), {}, { ref: componentRef })); } }); /** * A higher-order component that adds behavior to {@link ui/Heading.HeadingBase|Heading}. * * @hoc * @memberof ui/Heading * @mixes ui/ForwardRef.ForwardRef * @public */ var HeadingDecorator = exports.HeadingDecorator = (0, _compose["default"])((0, _ForwardRef["default"])({ prop: 'componentRef' })); /** * A labeled Heading component. * * @class Heading * @memberof ui/Heading * @extends ui/Heading.HeadingBase * @mixes ui/Heading.HeadingDecorator * @omit componentRef * @ui * @public */ var Heading = exports.Heading = HeadingDecorator(HeadingBase); var _default = exports["default"] = Heading;