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
80 lines (79 loc) • 5.11 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("../../components/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 _ref$id = _ref.id,
id = _ref$id === void 0 ? "Modal" : _ref$id,
_ref$onClose = _ref.onClose,
onClose = _ref$onClose === void 0 ? function () {} : _ref$onClose,
_ref$returnModal = _ref.returnModal,
returnModal = _ref$returnModal === void 0 ? function () {} : _ref$returnModal,
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 () {
refContainer.current.focus();
}, [stateOpen]);
(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 (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 handleClik = function handleClik(e) {
if (e.target.id === id) onClose();
};
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_styles.Overlay, {
id: id,
onClick: handleClik,
open: stateOpen
}, /*#__PURE__*/_react.default.createElement(_styles.ModalContainer, {
open: stateOpen,
ref: refContainer,
width: width,
type: type
}, children, /*#__PURE__*/_react.default.createElement(_styles.FooterModal, null, /*#__PURE__*/_react.default.createElement(_Button.default, {
density: "small",
id: "button01",
onClick: onClose,
variant: "secondary"
}, "Cancelar"), /*#__PURE__*/_react.default.createElement(_Button.default, {
density: "small",
id: "button01",
onClick: returnModal,
variant: "primary"
}, "Retornar")))));
};
Modal.propTypes = {
width: _propTypes.default.string,
type: _propTypes.default.string,
stateOpen: _propTypes.default.bool,
setState: _propTypes.default.func
};
var _default = Modal;
exports.default = _default;