@scality/core-ui 0.185.0 → 0.186.0
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/.storybook/preview.js +1 -7
- package/dist/components/tooltip/Tooltip.component.d.ts.map +1 -1
- package/dist/components/tooltip/Tooltip.component.js +16 -29
- package/package.json +1 -1
- package/src/lib/components/tooltip/Tooltip.component.tsx +37 -47
- package/stories/common.tsx +1 -1
- package/stories/tablev2.stories.tsx +1 -1
package/.storybook/preview.js
CHANGED
|
@@ -45,13 +45,7 @@ const withThemeProvider = (Story, context) => {
|
|
|
45
45
|
<QueryClientProvider client={new QueryClient()}>
|
|
46
46
|
<CoreUiThemeProvider theme={theme}>
|
|
47
47
|
{/* Wrapper to make the stories take the full screen but not in docs */}
|
|
48
|
-
<div
|
|
49
|
-
style={
|
|
50
|
-
viewMode === 'story'
|
|
51
|
-
? { height: 100 + 'vh', overflow: 'scroll' }
|
|
52
|
-
: null
|
|
53
|
-
}
|
|
54
|
-
>
|
|
48
|
+
<div style={viewMode === 'story' ? { height: 100 + 'vh' } : null}>
|
|
55
49
|
<ToastProvider>
|
|
56
50
|
<Wrapper style={{ backgroundColor: background }}>
|
|
57
51
|
<Story {...context} />
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/tooltip/Tooltip.component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"Tooltip.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/tooltip/Tooltip.component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAY,MAAM,OAAO,CAAC;AAMhD,eAAO,MAAM,GAAG,QAAQ,CAAC;AACzB,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,eAAO,MAAM,IAAI,SAAS,CAAC;AAC3B,eAAO,MAAM,QAAQ,cAAc,CAAC;AACpC,eAAO,MAAM,MAAM,YAAY,CAAC;AAChC,eAAO,MAAM,KAAK,UAAU,CAAC;AAC7B,eAAO,MAAM,UAAU,gBAAgB,CAAC;AACxC,eAAO,MAAM,QAAQ,cAAc,CAAC;AACpC,eAAO,MAAM,SAAS,eAAe,CAAC;AACtC,eAAO,MAAM,WAAW,iBAAiB,CAAC;AAC1C,eAAO,MAAM,SAAS,eAAe,CAAC;AACtC,eAAO,MAAM,OAAO,aAAa,CAAC;AAClC,MAAM,MAAM,QAAQ,GAChB,OAAO,GAAG,GACV,OAAO,MAAM,GACb,OAAO,IAAI,GACX,OAAO,KAAK,GACZ,OAAO,QAAQ,GACf,OAAO,MAAM,GACb,OAAO,UAAU,GACjB,OAAO,QAAQ,GACf,OAAO,SAAS,GAChB,OAAO,WAAW,GAClB,OAAO,OAAO,GACd,OAAO,SAAS,CAAC;AACrB,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AA0CF,iBAAS,OAAO,CAAC,EACf,SAAe,EACf,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,GAAG,IAAI,EACR,EAAE,KAAK,2CAsCP;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { flip, offset, shift, useFloating } from '@floating-ui/react';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
4
5
|
import styled from 'styled-components';
|
|
5
6
|
import { spacing } from '../../spacing';
|
|
6
7
|
import { fontSize, zIndex } from '../../style/theme';
|
|
@@ -23,8 +24,6 @@ const TooltipContainer = styled.div `
|
|
|
23
24
|
`;
|
|
24
25
|
const TooltipOverLayContainer = styled.div `
|
|
25
26
|
display: inline-block;
|
|
26
|
-
opacity: 0;
|
|
27
|
-
position: fixed;
|
|
28
27
|
width: max-content;
|
|
29
28
|
border: 1px solid ${getThemePropSelector('border')};
|
|
30
29
|
background-color: ${(props) => (props && props.style && props.style.backgroundColor) ||
|
|
@@ -53,30 +52,18 @@ const TooltipText = styled.div `
|
|
|
53
52
|
}
|
|
54
53
|
`;
|
|
55
54
|
function Tooltip({ placement = TOP, overlayStyle, children, overlay, ...rest }) {
|
|
56
|
-
const childrenRef = useRef(null);
|
|
57
|
-
const tooltipRef = useRef(null);
|
|
58
55
|
const [isTooltipVisible, setIsTooltipVisible] = useState(false);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}, [tooltipRef.current, childrenRef.current, isTooltipVisible]);
|
|
76
|
-
return (_jsxs(TooltipContainer, { className: "sc-tooltip", onPointerEnter: () => {
|
|
77
|
-
setIsTooltipVisible(true);
|
|
78
|
-
}, onPointerLeave: () => {
|
|
79
|
-
setIsTooltipVisible(false);
|
|
80
|
-
}, children: [isTooltipVisible && overlay ? (_jsx(TooltipOverLayContainer, { ref: tooltipRef, className: "sc-tooltip-overlay", placement: placement, style: overlayStyle, children: _jsx(TooltipText, { className: "sc-tooltip-overlay-text", children: overlay }) })) : null, _jsx("div", { ref: childrenRef, children: children })] }));
|
|
56
|
+
const { refs, floatingStyles } = useFloating({
|
|
57
|
+
placement,
|
|
58
|
+
open: isTooltipVisible,
|
|
59
|
+
middleware: [offset(5), shift(), flip()],
|
|
60
|
+
});
|
|
61
|
+
return (_jsxs(_Fragment, { children: [_jsx(TooltipContainer, { className: "sc-tooltip", onPointerEnter: () => {
|
|
62
|
+
setIsTooltipVisible(true);
|
|
63
|
+
}, onPointerLeave: () => {
|
|
64
|
+
setIsTooltipVisible(false);
|
|
65
|
+
}, children: _jsx("div", { ref: refs.setReference, children: children }) }), isTooltipVisible &&
|
|
66
|
+
overlay &&
|
|
67
|
+
createPortal(_jsx(TooltipOverLayContainer, { ref: refs.setFloating, className: "sc-tooltip-overlay", placement: placement, style: { ...floatingStyles, ...overlayStyle }, children: _jsx(TooltipText, { className: "sc-tooltip-overlay-text", children: overlay }) }), document.body)] }));
|
|
81
68
|
}
|
|
82
69
|
export { Tooltip };
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CSSProperties,
|
|
1
|
+
import { flip, offset, shift, useFloating } from '@floating-ui/react';
|
|
2
|
+
import { CSSProperties, useState } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
3
4
|
import styled from 'styled-components';
|
|
4
5
|
import { spacing } from '../../spacing';
|
|
5
6
|
import { fontSize, zIndex } from '../../style/theme';
|
|
@@ -44,8 +45,6 @@ const TooltipOverLayContainer = styled.div<{
|
|
|
44
45
|
style?: CSSProperties;
|
|
45
46
|
}>`
|
|
46
47
|
display: inline-block;
|
|
47
|
-
opacity: 0;
|
|
48
|
-
position: fixed;
|
|
49
48
|
width: max-content;
|
|
50
49
|
border: 1px solid ${getThemePropSelector('border')};
|
|
51
50
|
background-color: ${(props) =>
|
|
@@ -85,51 +84,42 @@ function Tooltip({
|
|
|
85
84
|
overlay,
|
|
86
85
|
...rest
|
|
87
86
|
}: Props) {
|
|
88
|
-
const childrenRef = useRef<HTMLDivElement | null>(null);
|
|
89
|
-
const tooltipRef = useRef<HTMLDivElement | null>(null);
|
|
90
|
-
|
|
91
87
|
const [isTooltipVisible, setIsTooltipVisible] = useState(false);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (tooltipRef.current) {
|
|
99
|
-
Object.assign(tooltipRef.current.style, {
|
|
100
|
-
opacity: '1',
|
|
101
|
-
// we set opacity to 1 to make sure the tooltip is not displayed before the position is computed
|
|
102
|
-
left: `${x}px`,
|
|
103
|
-
top: `${y}px`,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}, [tooltipRef.current, childrenRef.current, isTooltipVisible]);
|
|
88
|
+
|
|
89
|
+
const { refs, floatingStyles } = useFloating({
|
|
90
|
+
placement,
|
|
91
|
+
open: isTooltipVisible,
|
|
92
|
+
middleware: [offset(5), shift(), flip()],
|
|
93
|
+
});
|
|
109
94
|
return (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
<
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
95
|
+
<>
|
|
96
|
+
<TooltipContainer
|
|
97
|
+
className="sc-tooltip"
|
|
98
|
+
onPointerEnter={() => {
|
|
99
|
+
setIsTooltipVisible(true);
|
|
100
|
+
}}
|
|
101
|
+
onPointerLeave={() => {
|
|
102
|
+
setIsTooltipVisible(false);
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
<div ref={refs.setReference}>{children}</div>
|
|
106
|
+
</TooltipContainer>
|
|
107
|
+
{isTooltipVisible &&
|
|
108
|
+
overlay &&
|
|
109
|
+
createPortal(
|
|
110
|
+
<TooltipOverLayContainer
|
|
111
|
+
ref={refs.setFloating}
|
|
112
|
+
className="sc-tooltip-overlay"
|
|
113
|
+
placement={placement}
|
|
114
|
+
style={{ ...floatingStyles, ...overlayStyle }}
|
|
115
|
+
>
|
|
116
|
+
<TooltipText className="sc-tooltip-overlay-text">
|
|
117
|
+
{overlay}
|
|
118
|
+
</TooltipText>
|
|
119
|
+
</TooltipOverLayContainer>,
|
|
120
|
+
document.body,
|
|
121
|
+
)}
|
|
122
|
+
</>
|
|
133
123
|
);
|
|
134
124
|
}
|
|
135
125
|
|
package/stories/common.tsx
CHANGED