"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FieldSet = void 0;

var _react = _interopRequireDefault(require("react"));

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _spacing = require("../../../mixins/spacing");

var _stacking = require("../../../mixins/stacking");

var _stackee = require("../../../mixins/stackee");

var _fieldLabel = require("../../typography/field-label");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var StyledFieldSet = _styledComponents["default"].fieldset.withConfig({
  displayName: "StyledFieldSet",
  componentId: "swyjv0-0"
})(["border:none;padding:0.01em 0 0 0;margin:0;min-width:0;", " ", ";", ";"], _spacing.getSpacingRules, _stacking.getStackedRules, _stackee.getStackeeRules);

var InvisibleLegend = _styledComponents["default"].legend.withConfig({
  displayName: "InvisibleLegend",
  componentId: "swyjv0-1"
})(["&&&{position:absolute;overflow:hidden;clip:rect(0 0 0 0);height:1px;width:1px;margin:-1px;padding:0;border:0;}"]); // Legend is needed for screen readers, but it's impossible to style.
// So we render it invisibly for screen readers and also render a visible
// version with custom styling. The visible version has `aria-hidden` to stop
// the text from being announced twice.


var FieldSet = function FieldSet(_ref) {
  var label = _ref.label,
      hideLabel = _ref.hideLabel,
      children = _ref.children,
      props = _objectWithoutProperties(_ref, ["label", "hideLabel", "children"]);

  return /*#__PURE__*/_react["default"].createElement(StyledFieldSet, props, /*#__PURE__*/_react["default"].createElement(InvisibleLegend, null, label), !hideLabel && /*#__PURE__*/_react["default"].createElement(_fieldLabel.FieldLabel, {
    "aria-hidden": true,
    spacing: "mb2"
  }, label), children);
};

exports.FieldSet = FieldSet;
FieldSet.displayName = 'FieldSet';