@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
116 lines (91 loc) • 4.86 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _Heading = _interopRequireDefault(require("../Heading"));
var _Checkbox = _interopRequireWildcard(require("../Checkbox"));
var _Text = _interopRequireDefault(require("../Text"));
var _defaultTheme = _interopRequireDefault(require("../defaultTheme"));
var _Icon = require("../Icon");
var _rtl = require("../utils/rtl");
var _handleKeyDown = _interopRequireDefault(require("../utils/handleKeyDown"));
const _excluded = ["disabled", "theme"];
const StyledListChoiceIcon = _styledComponents.default.div.withConfig({
displayName: "ListChoice__StyledListChoiceIcon",
componentId: "sc-obcnak-0"
})(["", ""], ({
theme
}) => (0, _styledComponents.css)(["display:flex;align-self:flex-start;flex:0 0 auto;margin-", ":", ";height:", ";svg{align-self:center;width:", ";height:", ";color:", ";transition:color ", " ease-in-out;}"], _rtl.right, theme.orbit.spaceXSmall, theme.orbit.lineHeightTextNormal, (0, _Icon.getSize)("medium"), (0, _Icon.getSize)("medium"), theme.orbit.colorIconPrimary, theme.orbit.durationFast)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledListChoiceIcon.defaultProps = {
theme: _defaultTheme.default
};
const StyledListChoice = (0, _styledComponents.default)((_ref) => {
let {
disabled,
theme
} = _ref,
props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
return /*#__PURE__*/React.createElement("div", props);
}).withConfig({
displayName: "ListChoice__StyledListChoice",
componentId: "sc-obcnak-1"
})(["", ""], ({
theme,
disabled
}) => (0, _styledComponents.css)(["display:flex;align-items:center;box-sizing:border-box;width:100%;padding:", ";border-bottom:1px solid ", ";background-color:", ";transition:background-color 0.15s ease-in-out;cursor:", ";&:last-child{border:none;}&:focus,&:hover{outline:none;button{background:none;}", ";}", "{width:auto;}"], `${theme.orbit.spaceSmall} ${theme.orbit.spaceMedium}`, theme.orbit.paletteCloudNormal, theme.orbit.paletteWhite, disabled ? "not-allowed" : "pointer", !disabled && (0, _styledComponents.css)(["background:", ";", " svg{color:", ";}"], theme.orbit.paletteCloudLight, StyledListChoiceIcon, theme.orbit.colorIconPrimary), _Checkbox.Label)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledListChoice.defaultProps = {
theme: _defaultTheme.default
};
const StyledListChoiceContent = _styledComponents.default.div.withConfig({
displayName: "ListChoice__StyledListChoiceContent",
componentId: "sc-obcnak-2"
})(["", ""], ({
theme
}) => (0, _styledComponents.css)(["display:flex;flex-direction:column;justify-content:center;width:100%;padding-", ":", ";"], _rtl.right, theme.orbit.spaceSmall)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledListChoiceContent.defaultProps = {
theme: _defaultTheme.default
};
const ListChoice = ({
dataTest,
icon,
action,
title,
description,
selectable,
onClick,
selected,
disabled
}) => {
const conditionalProps = (0, _objectSpread2.default)({}, selectable ? {
"aria-checked": selected
} : null);
return /*#__PURE__*/React.createElement(StyledListChoice, (0, _extends2.default)({
onClick: !disabled ? onClick : null,
"data-test": dataTest,
onKeyDown: !disabled ? (0, _handleKeyDown.default)(onClick) : null,
tabIndex: disabled ? "-1" : "0",
disabled: disabled,
"aria-disabled": disabled,
role: selectable ? "checkbox" : "button"
}, conditionalProps), icon && /*#__PURE__*/React.createElement(StyledListChoiceIcon, null, icon), /*#__PURE__*/React.createElement(StyledListChoiceContent, null, /*#__PURE__*/React.createElement(_Heading.default, {
type: "title4"
}, title), description && /*#__PURE__*/React.createElement(_Text.default, {
type: "secondary",
size: "small"
}, description)), selectable && /*#__PURE__*/React.createElement(_Checkbox.default, {
checked: selected,
readOnly: true,
disabled: disabled,
tabIndex: "-1"
}), !selectable && action);
};
var _default = ListChoice;
exports.default = _default;