Skip to content

Commit 927beb4

Browse files
Marwanarturbien
Marwan
authored andcommitted
feat: tooltip position
added direction to the tooltip fixed default direction fixed default direction revesed the package-lock to the original fix
1 parent 27f53c7 commit 927beb4

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/Tooltip/Tooltip.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,33 @@ import styled from 'styled-components';
44

55
import { shadow } from '../common';
66

7+
const positioningStyles = {
8+
top: `top: -4px;
9+
left: 50%;
10+
transform: translate(-50%, -100%);`,
11+
bottom: `bottom: -4px;
12+
left: 50%;
13+
transform: translate(-50%, 100%);`,
14+
left: `left: -4px;
15+
top: 50%;
16+
transform: translate(-100%, -50%);`,
17+
right: `right: -4px;
18+
top: 50%;
19+
transform: translate(100%, -50%);`
20+
};
21+
722
const Tip = styled.span`
823
position: absolute;
9-
bottom: -4px;
10-
left: 50%;
24+
1125
z-index: 1;
12-
transform: translate(-50%, 100%);
1326
display: ${props => (props.show ? 'block' : 'none')};
1427
padding: 4px;
1528
border: 2px solid ${({ theme }) => theme.borderDarkest};
1629
background: ${({ theme }) => theme.tooltip};
1730
box-shadow: ${shadow};
1831
text-align: center;
1932
font-size: 1rem;
33+
${props => positioningStyles[props.position]}
2034
`;
2135

2236
const Wrapper = styled.div`
@@ -152,7 +166,8 @@ Tooltip.defaultProps = {
152166
onMouseEnter: undefined,
153167
onMouseLeave: undefined,
154168
onOpen: undefined,
155-
style: {}
169+
style: {},
170+
position: 'top'
156171
};
157172

158173
Tooltip.propTypes = {
@@ -169,7 +184,8 @@ Tooltip.propTypes = {
169184
onMouseLeave: propTypes.func,
170185
onOpen: propTypes.func,
171186
style: propTypes.shape({}),
172-
text: propTypes.string.isRequired
187+
text: propTypes.string.isRequired,
188+
position: propTypes.oneOf(['top', 'bottom', 'left', 'right'])
173189
};
174190

175191
export default Tooltip;

0 commit comments

Comments
 (0)