UNPKG

1.42 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = ellipsis;
5function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
6/**
7 * CSS to represent truncated text with an ellipsis. You can optionally pass a max-width and number of lines before truncating.
8 *
9 * @example
10 * // Styles as object usage
11 * const styles = {
12 * ...ellipsis('250px')
13 * }
14 *
15 * // styled-components usage
16 * const div = styled.div`
17 * ${ellipsis('250px')}
18 * `
19 *
20 * // CSS as JS Output
21 *
22 * div: {
23 * 'display': 'inline-block',
24 * 'maxWidth': '250px',
25 * 'overflow': 'hidden',
26 * 'textOverflow': 'ellipsis',
27 * 'whiteSpace': 'nowrap',
28 * 'wordWrap': 'normal'
29 * }
30 */
31function ellipsis(width, lines) {
32 if (lines === void 0) {
33 lines = 1;
34 }
35 var styles = {
36 display: 'inline-block',
37 maxWidth: width || '100%',
38 overflow: 'hidden',
39 textOverflow: 'ellipsis',
40 whiteSpace: 'nowrap',
41 wordWrap: 'normal'
42 };
43 return lines > 1 ? _extends({}, styles, {
44 WebkitBoxOrient: 'vertical',
45 WebkitLineClamp: lines,
46 display: '-webkit-box',
47 whiteSpace: 'normal'
48 }) : styles;
49}
50module.exports = exports.default;
\No newline at end of file