@enact/sandstone
Version:
Large-screen/TV support library for Enact, containing a variety of UI components.
171 lines (170 loc) • 11.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.AccessibilityDecorator = void 0;
var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
var _Registry = _interopRequireDefault(require("@enact/core/internal/Registry"));
var _Resizable = require("@enact/ui/Resizable");
var _util = require("@enact/ui/Skinnable/util");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = require("react");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["className", "focusRing", "highContrast", "skinVariants", "textSize"];
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 _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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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 _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /**
* A higher-order component that classifies an application with a target set of font sizing rules.
*
* @class AccessibilityDecorator
* @memberof sandstone/ThemeDecorator
* @hoc
* @public
*/
var AccessibilityDecorator = exports.AccessibilityDecorator = (0, _hoc["default"])(function (config, Wrapped) {
var _class;
return _class = /*#__PURE__*/function (_Component) {
_inherits(_class, _Component);
var _super = _createSuper(_class);
function _class() {
var _this;
_classCallCheck(this, _class);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_this.resizeRegistry = _Registry["default"].create();
return _this;
}
_createClass(_class, [{
key: "componentDidMount",
value: function componentDidMount() {
this.resizeRegistry.parent = this.context;
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (prevProps.textSize !== this.props.textSize) {
this.resizeRegistry.notify({});
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.resizeRegistry.parent = null;
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
className = _this$props.className,
focusRing = _this$props.focusRing,
highContrast = _this$props.highContrast,
skinVariants = _this$props.skinVariants,
textSize = _this$props.textSize,
props = _objectWithoutProperties(_this$props, _excluded);
var accessibilityClassName = highContrast ? "enact-a11y-high-contrast enact-text-".concat(textSize) : "enact-text-".concat(textSize);
accessibilityClassName = focusRing ? "enact-a11y-focus-ring ".concat(accessibilityClassName) : "".concat(accessibilityClassName);
var combinedClassName = className ? "".concat(className, " ").concat(accessibilityClassName) : accessibilityClassName;
var variants = (0, _util.objectify)(skinVariants);
if (highContrast) variants.highContrast = true;
if (textSize === 'large') variants.largeText = true;
if (focusRing) variants.focusRing = true;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Resizable.ResizeContext.Provider, {
value: this.resizeRegistry.register,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread({
className: combinedClassName,
skinVariants: variants
}, props))
});
}
}]);
return _class;
}(_react.Component), _class.contextType = _Resizable.ResizeContext, _class.displayName = 'AccessibilityDecorator', _class.propTypes = /** @lends sandstone/ThemeDecorator.AccessibilityDecorator.prototype */{
/**
* Enables additional features to help users visually differentiate components.
*
* The UI library will be responsible for using this information to add focus ring
* to some components.
*
* @type {Boolean}
* @default false
* @public
*/
focusRing: _propTypes["default"].bool,
/**
* Enables additional features to help users visually differentiate components.
*
* The UI library will be responsible for using this information to adjust
* the components' contrast to this preset.
*
* @type {Boolean}
* @default false
* @public
*/
highContrast: _propTypes["default"].bool,
/**
* The variant(s) on a skin that a component should use when rendering. These will
* typically alter the appearance of a skin's existing definition in a way that does not
* override that skin's general styling.
*
* Multiple data types are supported by this prop, which afford different conveniences
* and abilities. String and Array are effectively the same, supporting just additions
* to the variants being applied to a component, and are much more convenient. Objects
* may also be used, and have the ability to disable variants being passed by their
* ancestors. Objects take the format of a basic hash, with variants as key names and
* true/false Booleans as values, depicting their state. If a variant is excluded from
* any version of data type used to set this prop, that variant will ignored, falling
* back to the defaultVariant or parent variant, in that order.
*
* skinVariants examples:
* ```
* // String
* skinVariants="highContrast"
*
* // Array
* skinVariants={['highContrast']}
*
* // Object
* skinVariants={{
* highContrast: true,
* grayscale: false
* }}
* ```
*
* @type {String|String[]|Object}
* @public
*/
skinVariants: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].array, _propTypes["default"].object]),
/**
* Sets the goal size of the text.
*
* The UI library will be responsible for using this
* information to adjust the components' text sizes to this preset.
* Current presets are `'normal'` (default), and `'large'`.
*
* @type {('normal'|'large')}
* @default 'normal'
* @public
*/
textSize: _propTypes["default"].oneOf(['normal', 'large'])
}, _class.defaultProps = {
textSize: 'normal'
}, _class;
});
var _default = exports["default"] = AccessibilityDecorator;