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
110 lines (109 loc) • 5.35 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _styles = require("./styles");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Tag = function Tag(_ref) {
var bgColor = _ref.bgColor,
color = _ref.color,
density = _ref.density,
iconProps = _ref.iconProps,
inputProps = _ref.inputProps,
label = _ref.label,
type = _ref.type,
txtColor = _ref.txtColor;
var renderRadioTag = function renderRadioTag() {
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_styles.Input, {
id: inputProps === null || inputProps === void 0 ? void 0 : inputProps.id,
name: inputProps === null || inputProps === void 0 ? void 0 : inputProps.name,
type: inputProps === null || inputProps === void 0 ? void 0 : inputProps.type,
value: inputProps === null || inputProps === void 0 ? void 0 : inputProps.value,
"aria-label": inputProps === null || inputProps === void 0 ? void 0 : inputProps.ariaLabel,
defaultChecked: inputProps === null || inputProps === void 0 ? void 0 : inputProps.checked,
density: density
}), /*#__PURE__*/_react.default.createElement(_styles.Label, {
density: density,
htmlFor: inputProps === null || inputProps === void 0 ? void 0 : inputProps.id
}, (iconProps === null || iconProps === void 0 ? void 0 : iconProps.icon) && /*#__PURE__*/_react.default.createElement(_styles.TagIcon, {
"aria-label": iconProps === null || iconProps === void 0 ? void 0 : iconProps.ariaLabel,
icon: iconProps === null || iconProps === void 0 ? void 0 : iconProps.icon
}), /*#__PURE__*/_react.default.createElement("span", null, label)));
};
var renderCheckBoxTag = function renderCheckBoxTag() {
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_styles.Input, {
id: inputProps === null || inputProps === void 0 ? void 0 : inputProps.id,
name: inputProps === null || inputProps === void 0 ? void 0 : inputProps.name,
type: inputProps === null || inputProps === void 0 ? void 0 : inputProps.type,
value: inputProps === null || inputProps === void 0 ? void 0 : inputProps.value,
"aria-label": inputProps === null || inputProps === void 0 ? void 0 : inputProps.ariaLabel,
defaultChecked: inputProps === null || inputProps === void 0 ? void 0 : inputProps.checked
}), /*#__PURE__*/_react.default.createElement(_styles.Label, {
density: density,
htmlFor: inputProps === null || inputProps === void 0 ? void 0 : inputProps.id
}, (iconProps === null || iconProps === void 0 ? void 0 : iconProps.icon) && /*#__PURE__*/_react.default.createElement(_styles.TagIcon, {
"aria-label": iconProps === null || iconProps === void 0 ? void 0 : iconProps.ariaLabel,
icon: iconProps === null || iconProps === void 0 ? void 0 : iconProps.icon
}), /*#__PURE__*/_react.default.createElement("span", null, label)));
};
var renderTextTag = function renderTextTag() {
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (iconProps === null || iconProps === void 0 ? void 0 : iconProps.icon) && /*#__PURE__*/_react.default.createElement(_styles.TagIcon, {
"aria-hidden": "true",
"aria-label": iconProps === null || iconProps === void 0 ? void 0 : iconProps.ariaLabel,
icon: iconProps === null || iconProps === void 0 ? void 0 : iconProps.icon
}), /*#__PURE__*/_react.default.createElement("span", null, label));
};
var renderTag = function renderTag() {
return /*#__PURE__*/_react.default.createElement("label", null, label);
};
var renderIconTag = function renderIconTag() {
return /*#__PURE__*/_react.default.createElement(_styles.TagIcon, {
"aria-hidden": "true",
"aria-label": iconProps === null || iconProps === void 0 ? void 0 : iconProps.ariaLabel,
icon: iconProps === null || iconProps === void 0 ? void 0 : iconProps.icon
});
};
var renderTags = function renderTags(type) {
switch (type) {
case "radio":
return renderRadioTag();
case "text":
return renderTextTag();
case "status":
return renderTag();
case "count":
return renderTag();
case "icon":
return renderIconTag();
case "checkbox":
return renderCheckBoxTag();
default:
return renderTextTag();
}
};
return /*#__PURE__*/_react.default.createElement(_styles.Wrapper, {
type: type,
bgColor: bgColor,
txtColor: txtColor,
color: color,
density: density
}, renderTags(type));
};
Tag.propTypes = {
bgColor: _propTypes.default.string,
color: _propTypes.default.string,
density: _propTypes.default.string,
iconProps: _propTypes.default.shape({
icon: _propTypes.default.object,
ariaLabel: _propTypes.default.string
}),
label: _propTypes.default.string,
type: _propTypes.default.string.isRequired,
txtColor: _propTypes.default.string,
inputProps: _propTypes.default.object
};
var _default = Tag;
exports.default = _default;