@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.
83 lines • 3.53 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from "react";
import styled, { css } from "styled-components";
import Heading from "../Heading";
import Checkbox, { StyledLabel as 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";
const StyledListChoiceIcon = styled.div.withConfig({
displayName: "ListChoice__StyledListChoiceIcon",
componentId: "sc-1cy9msg-0"
})(["", ""], ({
theme
}) => css(["display:flex;align-items:center;align-self:flex-start;flex:0 0 auto;margin-", ":", ";height:", ";svg{align-self:center;width:", ";height:", ";color:", ";transition:color ", " ease-in-out;}"], right, theme.orbit.spaceXSmall, theme.orbit.lineHeightTextNormal, getSize("medium"), getSize("medium"), theme.orbit.colorIconPrimary, theme.orbit.durationFast));
StyledListChoiceIcon.defaultProps = {
theme: defaultTheme
};
export const StyledListChoice = styled.div.withConfig({
displayName: "ListChoice__StyledListChoice",
componentId: "sc-1cy9msg-1"
})(["", ""], ({
theme,
disabled
}) => 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:", ";&: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 && css(["background:", ";", " svg{color:", ";}"], theme.orbit.paletteCloudLight, StyledListChoiceIcon, theme.orbit.colorIconPrimary), Label));
StyledListChoice.defaultProps = {
theme: defaultTheme
};
const StyledListChoiceContent = styled.div.withConfig({
displayName: "ListChoice__StyledListChoiceContent",
componentId: "sc-1cy9msg-2"
})(["", ""], ({
theme
}) => css(["display:flex;flex-direction:column;justify-content:center;width:100%;padding-", ":", ";"], right, theme.orbit.spaceSmall));
StyledListChoiceContent.defaultProps = {
theme: defaultTheme
};
const ListChoice = /*#__PURE__*/React.forwardRef(({
dataTest,
id,
icon,
action,
title,
description,
selectable,
role,
onClick,
tabIndex = 0,
selected,
disabled
}, ref) => {
const conditionalProps = {
...(selectable ? {
"aria-checked": selected
} : null)
};
return /*#__PURE__*/React.createElement(StyledListChoice, _extends({
onClick: !disabled ? onClick : undefined,
"data-test": dataTest,
id: id,
ref: ref,
onKeyDown: !disabled ? handleKeyDown(onClick) : undefined,
tabIndex: tabIndex || disabled ? -1 : 0,
disabled: disabled,
"data-title": title,
"aria-disabled": disabled,
"aria-selected": selected,
role: 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
}), !selectable && action);
});
ListChoice.displayName = "ListChoice";
export default ListChoice;