@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.
115 lines (104 loc) • 5.5 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import * as React from "react";
import styled, { css } from "styled-components";
import Heading from "../Heading";
import Checkbox, { Label } from "../Checkbox";
import Text from "../Text";
import defaultTheme from "../defaultTheme";
import { getSize } from "../Icon";
import { right } from "../utils/rtl";
import handleKeyDown from "../utils/handleKeyDown";
var StyledListChoiceIcon = styled.div.withConfig({
displayName: "ListChoice__StyledListChoiceIcon",
componentId: "sc-1y53xes-0"
})(["display:flex;align-self:flex-start;flex:0 0 auto;margin-", ":", ";height:", ";svg{align-self:center;width:", ";height:", ";color:", ";transition:color ", " ease-in-out;}"], right, function (_ref) {
var theme = _ref.theme;
return theme.orbit.spaceSmall;
}, function (_ref2) {
var theme = _ref2.theme;
return theme.orbit.lineHeightTextNormal;
}, getSize("small"), getSize("small"), function (_ref3) {
var theme = _ref3.theme;
return theme.orbit.colorIconPrimary;
}, function (_ref4) {
var theme = _ref4.theme;
return theme.orbit.durationFast;
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledListChoiceIcon.defaultProps = {
theme: defaultTheme
};
var StyledListChoice = styled(function (_ref5) {
var disabled = _ref5.disabled,
theme = _ref5.theme,
props = _objectWithoutProperties(_ref5, ["disabled", "theme"]);
return /*#__PURE__*/React.createElement("div", props);
}).withConfig({
displayName: "ListChoice__StyledListChoice",
componentId: "sc-1y53xes-1"
})(["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;", ";}", "{width:auto;}"], function (_ref6) {
var theme = _ref6.theme;
return "".concat(theme.orbit.spaceSmall, " ").concat(theme.orbit.spaceMedium);
}, function (_ref7) {
var theme = _ref7.theme;
return theme.orbit.paletteCloudNormal;
}, function (_ref8) {
var theme = _ref8.theme;
return theme.orbit.paletteWhite;
}, function (_ref9) {
var disabled = _ref9.disabled;
return disabled ? "not-allowed" : "pointer";
}, function (_ref10) {
var disabled = _ref10.disabled,
theme = _ref10.theme;
return !disabled && css(["background-color:", ";", " svg{color:", ";}"], theme.orbit.paletteCloudLight, StyledListChoiceIcon, theme.orbit.colorIconPrimary);
}, Label); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledListChoice.defaultProps = {
theme: defaultTheme
};
var StyledListChoiceContent = styled.div.withConfig({
displayName: "ListChoice__StyledListChoiceContent",
componentId: "sc-1y53xes-2"
})(["display:flex;flex-direction:column;justify-content:center;width:100%;padding-", ":", ";"], right, function (_ref11) {
var theme = _ref11.theme;
return theme.orbit.spaceSmall;
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledListChoiceContent.defaultProps = {
theme: defaultTheme
};
var ListChoice = function ListChoice(_ref12) {
var dataTest = _ref12.dataTest,
icon = _ref12.icon,
title = _ref12.title,
description = _ref12.description,
selectable = _ref12.selectable,
onClick = _ref12.onClick,
selected = _ref12.selected,
disabled = _ref12.disabled;
var conditionalProps = _objectSpread({}, selectable ? {
"aria-checked": selected
} : null);
return /*#__PURE__*/React.createElement(StyledListChoice, _extends({
onClick: !disabled ? onClick : null,
"data-test": dataTest,
onKeyDown: !disabled ? handleKeyDown(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, {
type: "title4"
}, title), description && /*#__PURE__*/React.createElement(Text, {
type: "secondary",
size: "small"
}, description)), selectable && /*#__PURE__*/React.createElement(Checkbox, {
checked: selected,
readOnly: true,
disabled: disabled,
tabIndex: "-1"
}));
};
export default ListChoice;