design-system-govbr-rnp
Version:
## Padrão Digital de Governo - React Biblioteca de componentes React que implementa o [Padrão Visual digital do governo](https://www.gov.br/ds/). O objetivo da biblioteca é facilitar a implementação e promover a padronização das interfaces de sistemas do
78 lines (77 loc) • 5.15 kB
JavaScript
;
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _Button = _interopRequireDefault(require("../Button/Button"));
var _UseKeyPress = require("./UseKeyPress");
var _styles = require("./styles");
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Modal = function Modal(_ref) {
var children = _ref.children,
width = _ref.width,
type = _ref.type,
stateOpen = _ref.stateOpen,
setState = _ref.setState;
var refContainer = (0, _react.useRef)(null);
var keyPress = (0, _UseKeyPress.useKeyPress)("Tab", window);
(0, _react.useEffect)(function () {
var _refContainer$current;
var focusable = (_refContainer$current = refContainer.current) === null || _refContainer$current === void 0 ? void 0 : _refContainer$current.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]');
if (stateOpen) {
focusable[1].focus();
}
}, [stateOpen]);
(0, _react.useEffect)(function () {
var _refContainer$current2;
var focusable = (_refContainer$current2 = refContainer.current) === null || _refContainer$current2 === void 0 ? void 0 : _refContainer$current2.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]');
if (keyPress !== null && keyPress !== void 0 && keyPress.keyPressed && !(keyPress !== null && keyPress !== void 0 && keyPress.shiftPressed) && keyPress.srcElement === focusable[focusable.length - 2]) {
var _focusable$;
(_focusable$ = focusable[0]) === null || _focusable$ === void 0 ? void 0 : _focusable$.focus();
}
if (keyPress !== null && keyPress !== void 0 && keyPress.shiftPressed && keyPress !== null && keyPress !== void 0 && keyPress.keyPressed && keyPress.srcElement === focusable[1]) {
var _focusable;
(_focusable = focusable[focusable.length - 1]) === null || _focusable === void 0 ? void 0 : _focusable.focus();
}
if (keyPress !== null && keyPress !== void 0 && keyPress.shiftPressed && keyPress !== null && keyPress !== void 0 && keyPress.keyPressed && keyPress.srcElement === focusable[focusable.length - 1]) {
var _focusable$2;
(_focusable$2 = focusable[0]) === null || _focusable$2 === void 0 ? void 0 : _focusable$2.focus();
}
}, [keyPress]);
var RenderModal = function RenderModal() {
return /*#__PURE__*/_react.default.createElement(_styles.Container, {
open: stateOpen,
ref: refContainer
}, /*#__PURE__*/_react.default.createElement("div", {
tabIndex: "0"
}), /*#__PURE__*/_react.default.createElement(_styles.ModalContainer, {
width: width,
type: type
}, children), /*#__PURE__*/_react.default.createElement("div", {
tabIndex: "0"
}));
};
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_styles.Overlay, {
open: stateOpen
}), RenderModal(), /*#__PURE__*/_react.default.createElement(_Button.default, {
density: "small",
id: "button01",
onClick: function onClick() {
setState(true);
},
variant: "primary"
}, "Abrir Modal"));
};
Modal.propTypes = {
width: _propTypes.default.string,
type: _propTypes.default.string,
stateOpen: _propTypes.default.bool,
setState: _propTypes.default.func
};
var _default = Modal;
exports.default = _default;