function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useState } from 'react';
import styled from 'styled-components';
import { actions } from '@storybook/addon-actions';
import { Box, Flexbox, FormField, Input } from '../../..';
import { Display } from '../../../common/Display';
var handlers = actions('onBlur', 'onClick', 'onFocus', 'onKeyDown', 'onKeyUp', 'onKeyPress', 'onChange');
var StyledRadioLabel = styled.label.withConfig({
  displayName: "Radiostories__StyledRadioLabel",
  componentId: "sc-4carwh-0"
})(["display:flex;justify-content:center;align-items:center;width:52px;height:52px;background-color:", ";&:hover{cursor:pointer;", "}", ""], function (p) {
  return p.theme.color.background;
}, function (p) {
  return !p.checked && "background-color: ".concat(p.theme.color.cta, "; color: white");
}, function (p) {
  return p.checked && "background-color: ".concat(p.theme.color.cta, "; color: white");
});
export default {
  title: 'Molecules / Input / Radio',
  parameters: {
    component: Input.Radio
  }
};
export var Default = {
  render: function render() {
    return React.createElement(Input.Radio, {
      name: "example",
      value: "green",
      label: "Green"
    });
  }
};
export var WithDefaultChecked = {
  render: function render() {
    return React.createElement(Input.Radio, {
      name: "example",
      value: "green",
      label: "Green",
      defaultChecked: true
    });
  },
  name: 'With default checked'
};
export var WithCheckedControlledBehaviour = {
  render: function render() {
    var Component = function Component() {
      var _useState = useState(false),
        _useState2 = _slicedToArray(_useState, 2),
        checked = _useState2[0],
        setChecked = _useState2[1];
      var toggleCheckbox = function toggleCheckbox() {
        return setChecked(!checked);
      };
      return React.createElement(React.Fragment, null, React.createElement(Input.Radio, {
        name: "example",
        value: "green",
        label: "Green",
        checked: checked,
        onChange: toggleCheckbox
      }), React.createElement("button", {
        type: "button",
        onClick: toggleCheckbox
      }, "Toggle Checkbox"));
    };
    return React.createElement(Component, null);
  },
  name: 'With checked (Controlled behaviour)'
};
export var RequiredStory = {
  render: function render() {
    return React.createElement(Display, {
      title: "Required",
      items: [{
        component: React.createElement(Input.Radio, {
          name: "example",
          value: "green",
          label: "Green",
          required: true
        }),
        title: 'Default (without star)'
      }, {
        component: React.createElement(Input.Radio, {
          name: "example",
          value: "green",
          label: "Green",
          required: true,
          visuallyEmphasiseRequired: true
        }),
        title: 'With star'
      }]
    });
  },
  name: 'Required'
};
export var WithAnErrorIfNotChecked = {
  render: function render() {
    var Component = function Component() {
      var _useState3 = useState(false),
        _useState4 = _slicedToArray(_useState3, 2),
        checked = _useState4[0],
        setChecked = _useState4[1];
      var toggleCheckbox = function toggleCheckbox() {
        return setChecked(!checked);
      };
      return React.createElement(Input.Radio, _extends({
        name: "example",
        value: "green",
        label: "Green",
        required: true,
        onChange: toggleCheckbox
      }, !checked ? {
        error: 'This field is required'
      } : {}));
    };
    return React.createElement(Component, null);
  },
  name: 'With an error if not checked'
};
export var InAGroup = {
  render: function render() {
    return React.createElement(FormField, {
      label: "Colors",
      group: true
    }, React.createElement(Flexbox, {
      container: true,
      gap: 5
    }, React.createElement(Input.Radio, {
      name: "example",
      value: "green",
      label: "Green"
    }), React.createElement(Input.Radio, {
      name: "example",
      value: "blue",
      label: "Blue"
    }), React.createElement(Input.Radio, {
      name: "example",
      value: "yellow",
      label: "Yellow"
    })));
  },
  name: 'In a group'
};
export var InAGroupWithTooltip = {
  render: function render() {
    return React.createElement(FormField, {
      label: "Colors",
      labelTooltip: "Checkbox tooltip",
      group: true
    }, React.createElement(Flexbox, {
      container: true,
      gap: 5
    }, React.createElement(Input.Radio, {
      name: "example",
      value: "green",
      label: "Green"
    }), React.createElement(Input.Radio, {
      name: "example",
      value: "blue",
      label: "Blue"
    }), React.createElement(Input.Radio, {
      name: "example",
      value: "yellow",
      label: "Yellow"
    })));
  },
  name: 'In a group with tooltip'
};
export var InAGroupWithTooltipPositionTop = {
  render: function render() {
    return React.createElement(React.Fragment, null, React.createElement("br", null), React.createElement("br", null), React.createElement(FormField, {
      label: "Colors",
      labelTooltip: "Checkbox tooltip",
      labelTooltipPosition: "top",
      group: true
    }, React.createElement(Flexbox, {
      container: true,
      gap: 5
    }, React.createElement(Input.Radio, {
      name: "example",
      value: "green",
      label: "Green"
    }), React.createElement(Input.Radio, {
      name: "example",
      value: "blue",
      label: "Blue"
    }), React.createElement(Input.Radio, {
      name: "example",
      value: "yellow",
      label: "Yellow"
    }))));
  },
  name: 'In a group with tooltip (position top)'
};
export var InAGroupWithError = {
  render: function render() {
    var Component = function Component() {
      var _useState5 = useState(false),
        _useState6 = _slicedToArray(_useState5, 2),
        oneChecked = _useState6[0],
        setOneChecked = _useState6[1];
      var _useState7 = useState(false),
        _useState8 = _slicedToArray(_useState7, 2),
        twoChecked = _useState8[0],
        setTwoChecked = _useState8[1];
      var _useState9 = useState(false),
        _useState10 = _slicedToArray(_useState9, 2),
        threeChecked = _useState10[0],
        setThreeChecked = _useState10[1];
      var hasGroupError = !oneChecked && !twoChecked && !threeChecked;
      return React.createElement(FormField, _extends({
        label: "Colors",
        group: true
      }, hasGroupError ? {
        error: 'This field is required'
      } : {}), React.createElement(Flexbox, {
        container: true,
        gap: 5
      }, React.createElement(Input.Radio, {
        name: "example",
        value: "green",
        label: "Green",
        hasError: hasGroupError,
        onChange: function onChange() {
          return setOneChecked(!oneChecked);
        },
        required: true
      }), React.createElement(Input.Radio, {
        name: "example",
        value: "blue",
        label: "Blue",
        hasError: hasGroupError,
        onChange: function onChange() {
          return setTwoChecked(!twoChecked);
        },
        required: true
      }), React.createElement(Input.Radio, {
        name: "example",
        value: "yellow",
        label: "Yellow",
        hasError: hasGroupError,
        onChange: function onChange() {
          return setThreeChecked(!threeChecked);
        },
        required: true
      })));
    };
    return React.createElement(Component, null);
  },
  name: 'In a group with error'
};
export var DisabledStory = {
  render: function render() {
    return React.createElement(Display, {
      title: "Disabled",
      items: [{
        component: React.createElement(Input.Radio, {
          name: "example",
          value: "green",
          label: "Green",
          defaultChecked: true,
          disabled: true
        }),
        title: 'Checked'
      }, {
        component: React.createElement(Input.Radio, {
          name: "example",
          value: "blue",
          label: "Blue",
          disabled: true
        }),
        title: 'Not Checked'
      }]
    });
  },
  name: 'Disabled'
};
export var WithAutoFocus = {
  render: function render() {
    return React.createElement(Input.Radio, {
      name: "example",
      value: "green",
      label: "Green",
      autoFocus: true
    });
  },
  name: 'With auto focus'
};
export var WithAllActions = {
  render: function render() {
    return React.createElement(Input.Radio, _extends({
      name: "example6",
      value: "green",
      label: "Green"
    }, handlers));
  },
  name: 'With all actions'
};
export var OnAColouredBackground = {
  render: function render() {
    return React.createElement(Box, {
      p: 5,
      backgroundColor: function backgroundColor(t) {
        return t.color.disabledBackground;
      }
    }, React.createElement(Input.Radio, {
      name: "background",
      value: "background",
      label: "On a colored background"
    }));
  },
  name: 'On a coloured background'
};
export var InAGroupWithCustomLabel = {
  render: function render() {
    return React.createElement(FormField, {
      label: "Colors",
      labelTooltip: "Checkbox tooltip",
      group: true
    }, React.createElement(Flexbox, {
      container: true,
      gap: 5
    }, React.createElement(Input.Radio, {
      id: "Green",
      name: "example",
      value: "green",
      label: "Green",
      noRadioCircle: true
    }, React.createElement(StyledRadioLabel, {
      htmlFor: "Green",
      checked: true
    }, "Green")), React.createElement(Input.Radio, {
      id: "Blue",
      name: "example",
      value: "blue",
      label: "Blue",
      noRadioCircle: true
    }, React.createElement(StyledRadioLabel, {
      htmlFor: "Blue",
      checked: false
    }, "Blue")), React.createElement(Input.Radio, {
      id: "Yellow",
      name: "example",
      value: "yellow",
      label: "Yellow",
      noRadioCircle: true
    }, React.createElement(StyledRadioLabel, {
      htmlFor: "Yellow",
      checked: false
    }, "Yellow"))));
  },
  name: 'In a group with custom label'
};
export var WithHideLabel = {
  render: function render() {
    return React.createElement(Input.Radio, {
      name: "example",
      value: "green",
      hideLabel: true,
      label: "This label is hidden"
    });
  }
};