storybook-addon-rtl-direction
Version:
A Storybook tool add-on to toggle html dir attribute between LTR and RTL.
40 lines (33 loc) • 2.99 kB
JavaScript
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; }
import React, { useCallback } from "react";
import { useGlobals } from "@storybook/api";
import { IconButton } from "@storybook/components";
import { TOOL_ID } from "./constants";
export var Tool = function Tool() {
var _useGlobals = useGlobals(),
_useGlobals2 = _slicedToArray(_useGlobals, 2),
rtlDirection = _useGlobals2[0].rtlDirection,
updateGlobals = _useGlobals2[1];
var toggleMyTool = useCallback(function () {
return updateGlobals({
rtlDirection: rtlDirection ? undefined : true
});
}, [rtlDirection]);
return /*#__PURE__*/React.createElement(IconButton, {
key: TOOL_ID,
active: rtlDirection,
title: "Turn ".concat(rtlDirection ? "off" : "on", " RTL"),
onClick: toggleMyTool
}, /*#__PURE__*/React.createElement("svg", {
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 14 14",
fill: "currentColor"
}, /*#__PURE__*/React.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"
})));
};