grommet
Version:
focus on the essential experience
74 lines (63 loc) • 2.76 kB
JavaScript
import styled, { css } from 'styled-components';
import { breakpointStyle, genericStyles, normalizeColor } from '../../utils';
import { defaultProps } from '../../default-props';
var sizeStyle = function sizeStyle(props) {
// size is a combination of the level and size properties
var size = props.size || 'medium';
var headingTheme = props.theme.heading;
var levelStyle = headingTheme.level[props.level];
if (levelStyle) {
var data = levelStyle[size];
var styles = [css(["font-size:", ";line-height:", ";max-width:", ";font-weight:", ";"], data ? data.size : size, data ? data.height : 'normal', data ? data.maxWidth : levelStyle.medium.maxWidth, levelStyle.font.weight || headingTheme.weight)];
if (props.responsive && headingTheme.responsiveBreakpoint) {
var breakpoint = props.theme.global.breakpoints[headingTheme.responsiveBreakpoint];
if (breakpoint) {
var responsiveData = headingTheme.level[Math.min(props.level + 1, 4)][size];
if (responsiveData) {
styles.push(breakpointStyle(breakpoint, "\n font-size: " + responsiveData.size + ";\n line-height: " + responsiveData.height + ";\n max-width: " + responsiveData.maxWidth + ";\n "));
}
}
}
return styles;
}
console.warn("Heading level " + props.level + " is not defined in your theme.");
return '';
};
var fontFamily = function fontFamily(props) {
var font = props.theme.heading.level[props.level].font;
if (font && font.family) {
return css(["font-family:", ";"], font.family);
}
return props.theme.heading.font ? css(["font-family:", ";"], props.theme.heading.font.family) : '';
};
var TEXT_ALIGN_MAP = {
center: 'center',
end: 'right',
start: 'left'
};
var textAlignStyle = css(["text-align:", ";"], function (props) {
return TEXT_ALIGN_MAP[props.textAlign];
});
var truncateStyle = "\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n";
var colorStyle = css(["color:", ";"], function (props) {
return normalizeColor(props.colorProp, props.theme);
});
var StyledHeading = styled.h1.withConfig({
displayName: "StyledHeading",
componentId: "sc-1rdh4aw-0"
})(["", " ", " ", " ", " ", " ", " ", ""], genericStyles, function (props) {
return fontFamily(props);
}, function (props) {
return sizeStyle(props);
}, function (props) {
return props.textAlign && textAlignStyle;
}, function (props) {
return props.truncate && truncateStyle;
}, function (props) {
return props.colorProp && colorStyle;
}, function (props) {
return props.theme.heading && props.theme.heading.extend;
});
StyledHeading.defaultProps = {};
Object.setPrototypeOf(StyledHeading.defaultProps, defaultProps);
export { StyledHeading };