UNPKG

storybook-addon-rtl-direction

Version:

A Storybook tool add-on to toggle html dir attribute between LTR and RTL.

59 lines (42 loc) 4.73 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports.Tool = void 0; var _react = _interopRequireWildcard(require("react")); var _api = require("@storybook/api"); var _components = require("@storybook/components"); var _constants = require("./constants"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } var Tool = function Tool() { var _useGlobals = (0, _api.useGlobals)(), _useGlobals2 = _slicedToArray(_useGlobals, 2), rtlDirection = _useGlobals2[0].rtlDirection, updateGlobals = _useGlobals2[1]; var toggleMyTool = (0, _react.useCallback)(function () { return updateGlobals({ rtlDirection: rtlDirection ? undefined : true }); }, [rtlDirection]); return /*#__PURE__*/_react["default"].createElement(_components.IconButton, { key: _constants.TOOL_ID, active: rtlDirection, title: "Turn ".concat(rtlDirection ? "off" : "on", " RTL"), onClick: toggleMyTool }, /*#__PURE__*/_react["default"].createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 14 14", fill: "currentColor" }, /*#__PURE__*/_react["default"].createElement("path", { d: rtlDirection ? "M4.2 10.9 2.9 7.4H2v3.5H1V3.1h2.9l.6.4.5.6a3.1 3.1 0 0 1 .1 1A2.8 2.8 0 0 1 5 6l-.3.6-.4.4-.5.2 1.5 3.7zm0-5.6a1.4 1.4 0 0 0-.2-.7.5.5 0 0 0-.2-.4L3.4 4H2v2.6h.9a1.2 1.2 0 0 0 .9-.3 1.8 1.8 0 0 0 .4-1zM7.7 4v6.9h-1V4H5.2v-.9h4V4zm2.1 6.9V3.1h1V10H13v.9z" : "M1.3 10.9V3.1h.9V10h2.2v.9zM6.4 4v6.9h-1V4H4v-.9h3.9V4zm5.3 6.9-1.3-3.5h-.9v3.5h-1V3.1h2.8l.7.4.4.6a3 3 0 0 1 .2 1 2.8 2.8 0 0 1-.1.9l-.3.6-.5.3-.4.2 1.4 3.7zm-.1-5.6a1.5 1.5 0 0 0-.1-.7l-.3-.4-.4-.2H9.5v2.6h.9l.9-.3a1.7 1.7 0 0 0 .3-1z" }))); }; exports.Tool = Tool;