diginet-core-ui 1.3.76-beta.2 → 1.3.76-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/typography/index.js +71 -81
- package/package.json +1 -1
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
|
-
import {
|
|
4
|
+
import { css, jsx } from '@emotion/core';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
-
import {
|
|
7
|
-
import { classNames, renderHTML } from '../../utils';
|
|
6
|
+
import { forwardRef, Fragment, memo, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
8
7
|
import { Popover } from '..';
|
|
9
|
-
import { cursorPointer, displayBlock, displayInlineBlock, overflowHidden, positionRelative, textCapitalize, textCenter, textUppercase } from '../../styles/general';
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
8
|
+
import { breakAll, breakWord, cursorPointer, displayBlock, displayInlineBlock, overflowHidden, pointerEventsNone, positionRelative, textCapitalize, textCenter, textUppercase } from '../../styles/general';
|
|
9
|
+
import { useColor as colors, useTheme, useTypography as typography } from '../../theme';
|
|
10
|
+
import { classNames, renderHTML } from '../../utils';
|
|
12
11
|
const {
|
|
13
12
|
colors: {
|
|
14
13
|
system: {
|
|
15
|
-
rest
|
|
14
|
+
rest: systemRest
|
|
16
15
|
},
|
|
17
16
|
text: {
|
|
18
|
-
main,
|
|
17
|
+
main: textMain,
|
|
19
18
|
tooltip: textTooltip
|
|
20
19
|
},
|
|
21
20
|
fill: {
|
|
@@ -23,24 +22,11 @@ const {
|
|
|
23
22
|
}
|
|
24
23
|
},
|
|
25
24
|
typography: {
|
|
26
|
-
|
|
27
|
-
title2,
|
|
28
|
-
title3,
|
|
29
|
-
title4,
|
|
30
|
-
heading1,
|
|
31
|
-
heading2,
|
|
32
|
-
heading3,
|
|
33
|
-
heading4,
|
|
34
|
-
heading5,
|
|
35
|
-
heading6,
|
|
36
|
-
paragraph1,
|
|
37
|
-
paragraph2,
|
|
38
|
-
paragraph3
|
|
25
|
+
paragraph1
|
|
39
26
|
},
|
|
40
27
|
spacing
|
|
41
|
-
} =
|
|
42
|
-
const
|
|
43
|
-
const colorMap = new Map([['default', main], ['secondary', rest]]);
|
|
28
|
+
} = useTheme();
|
|
29
|
+
const colorMap = new Map([['default', textMain], ['secondary', systemRest]]);
|
|
44
30
|
|
|
45
31
|
const isTextClamped = elm => (elm === null || elm === void 0 ? void 0 : elm.scrollHeight) > (elm === null || elm === void 0 ? void 0 : elm.clientHeight);
|
|
46
32
|
|
|
@@ -61,10 +47,28 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
61
47
|
uppercase,
|
|
62
48
|
...props
|
|
63
49
|
}, reference) => {
|
|
50
|
+
var _ref$current;
|
|
51
|
+
|
|
64
52
|
const ref = useRef(null);
|
|
65
53
|
const [openTooltip, setOpenTooltip] = useState(false);
|
|
66
54
|
|
|
67
|
-
const _TextRootCSS = TextRootCSS(color, type, lineClamp, onClick);
|
|
55
|
+
const _TextRootCSS = TextRootCSS(color, type, lineClamp, onClick, hoverTooltip);
|
|
56
|
+
|
|
57
|
+
const showTooltip = () => {
|
|
58
|
+
if (!hoverTooltip) return;
|
|
59
|
+
|
|
60
|
+
if (isTextClamped(ref.current)) {
|
|
61
|
+
setOpenTooltip(true);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const hideTooltip = () => {
|
|
66
|
+
if (!hoverTooltip) return;
|
|
67
|
+
|
|
68
|
+
if (isTextClamped(ref.current)) {
|
|
69
|
+
setOpenTooltip(false);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
68
72
|
|
|
69
73
|
useImperativeHandle(reference, () => {
|
|
70
74
|
const currentRef = ref.current || {};
|
|
@@ -78,90 +82,76 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
78
82
|
return currentRef;
|
|
79
83
|
});
|
|
80
84
|
|
|
81
|
-
const classes = inTooltip => classNames('DGN-UI-Typography', center && 'DGN-Typography-center', fullWidth && 'DGN-Typography-fullWidth', `DGN-Typography-${type}`, uppercase && `DGN-Typography-Uppercase`, capitalize && 'DGN-Typography-Capitalize', !inTooltip && lineClamp && 'DGN-Typography-Clamp', className);
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
open: openTooltip,
|
|
100
|
-
pressESCToClose: false,
|
|
101
|
-
bgColor: fillTooltip,
|
|
102
|
-
anchor: ref,
|
|
103
|
-
fullScreen: false,
|
|
104
|
-
width: ((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientWidth) || 'max-content',
|
|
105
|
-
style: {
|
|
106
|
-
color: textTooltip
|
|
107
|
-
},
|
|
108
|
-
onMouseEnter: () => setHoverTooltip(true, true),
|
|
109
|
-
onMouseLeave: () => setHoverTooltip(false, true),
|
|
110
|
-
direction: tooltipDirection
|
|
111
|
-
}, renderHTML(renderChildren(), mapping, {
|
|
85
|
+
const classes = (inTooltip = false) => classNames('DGN-UI-Typography', center && 'DGN-Typography-center', fullWidth && 'DGN-Typography-fullWidth', `DGN-Typography-${type}`, uppercase && `DGN-Typography-Uppercase`, capitalize && 'DGN-Typography-Capitalize', !inTooltip && lineClamp && 'DGN-Typography-Clamp', className);
|
|
86
|
+
|
|
87
|
+
const content = Array.isArray(children) && !children.some(node => node && String(node.$$typeof) === 'Symbol(react.element)') ? children.join('') : children;
|
|
88
|
+
const renderTooltip = hoverTooltip ? jsx(Popover, {
|
|
89
|
+
css: PopoverCSS,
|
|
90
|
+
open: openTooltip,
|
|
91
|
+
pressESCToClose: false,
|
|
92
|
+
bgColor: fillTooltip,
|
|
93
|
+
anchor: ref,
|
|
94
|
+
width: ((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientWidth) || 'max-content',
|
|
95
|
+
direction: tooltipDirection
|
|
96
|
+
}, renderHTML(content, mapping, {
|
|
97
|
+
css: [_TextRootCSS, PopoverContentCSS],
|
|
98
|
+
className: classes(true)
|
|
99
|
+
})) : null;
|
|
100
|
+
return useMemo(() => {
|
|
101
|
+
return jsx(Fragment, null, renderHTML(content, mapping, {
|
|
102
|
+
ref: ref,
|
|
112
103
|
css: _TextRootCSS,
|
|
113
|
-
className: classes(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}, [openTooltip, capitalize, center, children, className, color, fullWidth, hoverTooltip, lineClamp, mapping, onClick, tooltipDirection, type, uppercase]);
|
|
121
|
-
return jsx(Fragment, null, renderHTML(renderChildren(), mapping, {
|
|
122
|
-
ref: ref,
|
|
123
|
-
css: _TextRootCSS,
|
|
124
|
-
className: classes(false),
|
|
125
|
-
onMouseEnter: () => setHoverTooltip(true),
|
|
126
|
-
onMouseLeave: () => setHoverTooltip(false),
|
|
127
|
-
onClick: onClick,
|
|
128
|
-
...props
|
|
129
|
-
}), hoverTooltip && renderTooltip);
|
|
104
|
+
className: classes(),
|
|
105
|
+
onMouseEnter: showTooltip,
|
|
106
|
+
onMouseLeave: hideTooltip,
|
|
107
|
+
onClick: onClick,
|
|
108
|
+
...props
|
|
109
|
+
}), renderTooltip);
|
|
110
|
+
}, [capitalize, center, children, className, color, fullWidth, hoverTooltip, lineClamp, mapping, onClick, tooltipDirection, type, uppercase, props, openTooltip]);
|
|
130
111
|
}));
|
|
131
112
|
|
|
132
|
-
const TextRootCSS = (color, type, lineClamp, onClick) => css`
|
|
113
|
+
const TextRootCSS = (color, type, lineClamp, onClick, hoverTooltip) => css`
|
|
133
114
|
${displayInlineBlock};
|
|
134
115
|
${positionRelative};
|
|
135
116
|
${paragraph1};
|
|
136
117
|
${onClick && cursorPointer};
|
|
137
|
-
|
|
118
|
+
${hoverTooltip && lineClamp === 1 ? breakAll : breakWord};
|
|
138
119
|
white-space: break-spaces;
|
|
139
120
|
color: ${colorMap.get(color) || colors[color] || color};
|
|
140
121
|
max-width: max-content;
|
|
141
122
|
&.DGN-Typography-${type} {
|
|
142
|
-
${
|
|
123
|
+
${typography[type]};
|
|
143
124
|
}
|
|
144
125
|
&.DGN-Typography-center {
|
|
145
|
-
${textCenter}
|
|
126
|
+
${textCenter};
|
|
146
127
|
}
|
|
147
128
|
&.DGN-Typography-fullWidth {
|
|
148
|
-
${displayBlock}
|
|
129
|
+
${displayBlock};
|
|
149
130
|
max-width: initial;
|
|
150
131
|
}
|
|
151
132
|
&.DGN-Typography-Uppercase {
|
|
152
|
-
${textUppercase}
|
|
133
|
+
${textUppercase};
|
|
153
134
|
}
|
|
154
135
|
&.DGN-Typography-Capitalize {
|
|
155
|
-
${textCapitalize}
|
|
136
|
+
${textCapitalize};
|
|
156
137
|
}
|
|
157
138
|
&.DGN-Typography-Clamp {
|
|
158
|
-
${overflowHidden}
|
|
139
|
+
${overflowHidden};
|
|
159
140
|
display: -webkit-box;
|
|
160
141
|
-webkit-line-clamp: ${lineClamp};
|
|
161
142
|
-webkit-box-orient: vertical;
|
|
162
143
|
}
|
|
163
144
|
`;
|
|
164
145
|
|
|
146
|
+
const PopoverCSS = css`
|
|
147
|
+
${pointerEventsNone};
|
|
148
|
+
color: ${textTooltip};
|
|
149
|
+
`;
|
|
150
|
+
const PopoverContentCSS = css`
|
|
151
|
+
color: ${textTooltip};
|
|
152
|
+
padding: ${spacing([1, 1.5])};
|
|
153
|
+
height: 'fit-content';
|
|
154
|
+
`;
|
|
165
155
|
Typography.defaultProps = {
|
|
166
156
|
center: false,
|
|
167
157
|
className: '',
|