UNPKG

@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.

74 lines (71 loc) 2.78 kB
import * as React from "react"; import styled, { css } from "styled-components"; import defaultTheme from "../defaultTheme"; import AlertCircle from "../icons/AlertCircle"; import InformationCircle from "../icons/InformationCircle"; import { rtlSpacing } from "../utils/rtl"; const StyledAsterisk = styled.span.withConfig({ displayName: "FormLabel__StyledAsterisk", componentId: "sc-qbinms-0" })(["", ""], ({ theme, filled }) => css(["font-weight:", ";color:", ";font-size:", ";vertical-align:top;"], theme.orbit.fontWeightBold, !filled ? theme.orbit.colorTextError : theme.orbit.colorFormLabelFilled, theme.orbit.fontSizeFormLabel)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198 StyledAsterisk.defaultProps = { theme: defaultTheme }; const StyledInputErrorIcWrapper = styled.span.withConfig({ displayName: "FormLabel__StyledInputErrorIcWrapper", componentId: "sc-qbinms-1" })(["margin:", ";display:inline-flex;align-items:center;"], ({ theme }) => rtlSpacing(`0 ${theme.orbit.spaceXXSmall} 0 0`)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198 StyledInputErrorIcWrapper.defaultProps = { theme: defaultTheme }; const FormLabel = styled(({ className, children, required, filled, dataTest, id, error, help, onMouseEnter, onMouseLeave, iconRef, inlineLabel, labelRef }) => /*#__PURE__*/React.createElement("span", { className: className, "data-test": dataTest, id: id, ref: labelRef }, !inlineLabel && (error || help) && /*#__PURE__*/React.createElement(StyledInputErrorIcWrapper, { ref: iconRef, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, error && /*#__PURE__*/React.createElement(AlertCircle, { ariaLabel: "error", color: "critical", size: "small" }), !error && help && /*#__PURE__*/React.createElement(InformationCircle, { ariaLabel: "help", color: "info", size: "small" })), required && !error && /*#__PURE__*/React.createElement(StyledAsterisk, { "aria-hidden": "true", filled: filled }, "*"), /*#__PURE__*/React.createElement("span", null, children))).withConfig({ displayName: "FormLabel", componentId: "sc-qbinms-2" })(["", ""], ({ theme, filled, disabled }) => css(["display:flex;font-family:", ";font-size:", ";font-weight:", ";color:", ";line-height:", ";margin-bottom:", ";"], theme.orbit.fontFamily, theme.orbit.fontSizeFormLabel, theme.orbit.fontWeightMedium, !filled || disabled ? theme.orbit.colorFormLabel : theme.orbit.colorFormLabelFilled, theme.orbit.lineHeightTextSmall, theme.orbit.spaceXXSmall)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198 FormLabel.defaultProps = { theme: defaultTheme }; export default FormLabel;