@retailmenot/anchor
Version:
A React UI Library by RetailMeNot
43 lines • 2.23 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
// REACT
import * as React from 'react';
// VENDOR
import styled, { css } from '@xstyled/styled-components';
import classnames from 'classnames';
// ANCHOR
import { cloneWithProps } from '../../utils/cloneWithProps/cloneWithProps';
import { Typography, } from '../../Typography/Typography.component';
import { space as spaceStyles } from '@xstyled/system';
const StyledLabel = styled(Typography) `
position: relative;
display: inline-flex;
${spaceStyles}
${({ labelPlacement, disabled }) => css({
flexDirection: labelPlacement === 'right' ? 'row' : 'row-reverse',
cursor: disabled ? 'not-allowed' : 'pointer',
})}
`;
export const ControlLabel = (_a) => {
var { id, label, className, labelPlacement = 'right', labelSpacing = '0.5rem', marginBottom = '1rem', lineHeight = 1.375, value, disabled, control, name } = _a, props = __rest(_a, ["id", "label", "className", "labelPlacement", "labelSpacing", "marginBottom", "lineHeight", "value", "disabled", "control", "name"]);
return (React.createElement(StyledLabel, Object.assign({ className: classnames('anchor-control-label', className), as: "label", htmlFor: id, color: disabled ? 'text.disabled' : undefined, value: value, label: label, disabled: disabled, control: control, name: name, labelPlacement: labelPlacement, marginBottom: marginBottom, lineHeight: lineHeight }, props),
control &&
cloneWithProps(control, {
value,
disabled,
name,
marginLeft: labelPlacement === 'left' ? labelSpacing : undefined,
marginRight: labelPlacement === 'right' ? labelSpacing : undefined,
}),
label));
};
//# sourceMappingURL=ControlLabel.component.js.map