@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
170 lines (168 loc) • 6.25 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextStyled = exports.applyVariantStyles = void 0;
const styled_components_1 = __importStar(require("styled-components"));
const truncate_mixin_1 = require("../../styles/mixins/truncate.mixin");
const getStyles_1 = require("../../utils/getStyles/getStyles");
const applyDevicePropsTextStyles = (props) => (0, styled_components_1.css) `
color: ${props.color};
cursor: ${props.cursor};
display: ${props.display};
text-decoration: ${props.decoration};
text-transform: ${props.$transform};
text-align: ${props.align};
font-weight: ${props.weight};
filter: ${props.filter};
${props.isDisabled &&
(0, styled_components_1.css) `
pointer-events: none;
`}
${!props.$maxTruncatedLines &&
props.$truncate &&
(0, styled_components_1.css) `
${truncate_mixin_1.truncateMixin}
`}
${props.$maxTruncatedLines &&
(0, styled_components_1.css) `
${(0, truncate_mixin_1.maxTruncatedLinesMixin)(props.$maxTruncatedLines)}
`}
`;
const applyPropsTextStyles = (props) => (0, styled_components_1.css) `
${applyDevicePropsTextStyles(props)}
${({ theme: { MEDIA_QUERIES: { onlyDesktop, onlyTablet, onlyMobile }, }, }) => (0, styled_components_1.css) `
${onlyDesktop} {
${applyDevicePropsTextStyles(props)}
}
${onlyTablet} {
${applyDevicePropsTextStyles(props)}
}
${onlyMobile} {
${applyDevicePropsTextStyles(props)}
}
`}
`;
const applyVariantStyles = (textStyles) => {
return (0, styled_components_1.css) `
font-family: ${textStyles?.font_family};
font-weight: ${textStyles?.font_weight};
font-size: ${textStyles?.typography?.DESKTOP?.font_size};
line-height: ${textStyles?.typography?.DESKTOP?.line_height};
sup {
font-size: ${textStyles?.typography?.DESKTOP?.sup?.font_size};
vertical-align: super;
}
sub {
font-size: ${textStyles?.typography?.DESKTOP?.sub?.font_size};
vertical-align: sub;
}
${({ theme: { MEDIA_QUERIES: { onlyDesktop, onlyTablet, onlyMobile }, }, }) => (0, styled_components_1.css) `
${onlyDesktop} {
font-size: ${textStyles?.typography?.DESKTOP?.font_size};
line-height: ${textStyles?.typography?.DESKTOP?.line_height};
sup {
font-size: ${textStyles?.typography?.DESKTOP?.sup?.font_size};
}
sub {
font-size: ${textStyles?.typography?.DESKTOP?.sub?.font_size};
}
}
${onlyTablet} {
font-size: ${textStyles?.typography?.TABLET?.font_size};
line-height: ${textStyles?.typography?.TABLET?.line_height};
sup {
font-size: ${textStyles?.typography?.TABLET?.sup?.font_size};
}
sub {
font-size: ${textStyles?.typography?.TABLET?.sub?.font_size};
}
}
${onlyMobile} {
font-size: ${textStyles?.typography?.MOBILE?.font_size};
line-height: ${textStyles?.typography?.MOBILE?.line_height};
sup {
font-size: ${textStyles?.typography?.MOBILE?.sup?.font_size};
}
sub {
font-size: ${textStyles?.typography?.MOBILE?.sub?.font_size};
}
}
`}
`;
};
exports.applyVariantStyles = applyVariantStyles;
const TEXT_STYLED_TRANSIENT_PROPS = [
'color',
'styles',
'weight',
'isDisabled',
'align',
'decoration',
'cursor',
'customTypography',
'display',
];
exports.TextStyled = styled_components_1.default.p.withConfig({
shouldForwardProp: prop => !TEXT_STYLED_TRANSIENT_PROPS.includes(prop),
}) `
// Apply prop customTypography styles
// In this case, when font_variant in customTypography is specified, apply font_variant theme. font_variant may change for each device
// Then, apply the rest of the tokens in customTypography
${({ customTypography, theme: { TEXT_STYLES } }) => {
if (!customTypography) {
return;
}
return (0, styled_components_1.css) `
${(0, exports.applyVariantStyles)(TEXT_STYLES[customTypography.font_variant || 0])}
${({ theme: { MEDIA_QUERIES: { onlyDesktop, onlyTablet, onlyMobile }, }, }) => (0, styled_components_1.css) `
${onlyDesktop} {
${(0, exports.applyVariantStyles)(TEXT_STYLES[customTypography.DESKTOP?.font_variant || 0])}
}
${onlyTablet} {
${(0, exports.applyVariantStyles)(TEXT_STYLES[customTypography.TABLET?.font_variant || 0])}
}
${onlyMobile} {
${(0, exports.applyVariantStyles)(TEXT_STYLES[customTypography.MOBILE?.font_variant || 0])}
}
`}
${(0, getStyles_1.getTypographyStyles)(customTypography)}
`;
}}
// Apply theme generated by the variant
${({ styles }) => (0, exports.applyVariantStyles)(styles)}
// Apply props tokens
${props => applyPropsTextStyles(props)}
`;
//# sourceMappingURL=text.styled.js.map