Skip to content

Commit a604386

Browse files
committed
review changes
1 parent e97306a commit a604386

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

packages/gamut/src/Tip/shared/styles.tsx

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
export const tooltipBackgroundColor = `background-contrast`;
1515
export const tooltipArrowHeight = `1rem`;
1616
const containerOffsetVertical = 12;
17+
const borderColor = 'border-primary';
1718

1819
export const narrowWidth = 64;
1920
export const centerWidths = { minWidth: 64, maxWidth: 128 } as const;
@@ -31,16 +32,26 @@ export const topStyles = {
3132
pb: containerOffsetVertical,
3233
} as const;
3334

34-
const beforeStyles = {
35+
const beforeStylesVert = {
3536
content: '""',
3637
position: 'absolute',
3738
width: '100%',
3839
};
3940

40-
export const topStylesBefore = { ...beforeStyles, height: 16, bottom: '-4px' };
41+
const beforeStylesHorizontal = {
42+
content: '""',
43+
position: 'absolute',
44+
height: '100%',
45+
};
46+
47+
export const topStylesBefore = {
48+
...beforeStylesVert,
49+
height: 16,
50+
bottom: '-4px',
51+
};
4152

4253
export const topStylesAfter = {
43-
borderColor: 'border-primary',
54+
borderColor,
4455
borderWidth: '0 1px 1px 0',
4556
bottom: '0.25rem',
4657
} as const;
@@ -51,13 +62,31 @@ export const bottomStyles = {
5162
} as const;
5263

5364
export const bottomStylesBefore = {
54-
...beforeStyles,
65+
...beforeStylesVert,
5566
height: 24,
5667
top: '-8px',
5768
};
5869

5970
export const bottomStylesAfter = {
60-
borderColor: 'border-primary',
71+
borderColor,
72+
borderWidth: '1px 0 0 1px',
73+
top: '0.25rem',
74+
} as const;
75+
76+
export const rightAlignStyles = {
77+
top: 'calc(100% + 4px)',
78+
pt: containerOffsetVertical,
79+
} as const;
80+
81+
export const rightAlignStylesBefore = {
82+
...beforeStylesHorizontal,
83+
height: 24,
84+
left: '-8px',
85+
bg: 'red',
86+
};
87+
88+
export const rightAlignStylesAfter = {
89+
borderColor,
6190
borderWidth: '1px 0 0 1px',
6291
top: '0.25rem',
6392
} as const;
@@ -84,6 +113,10 @@ export const verticalCenterStylesAfter = {
84113
left: 'calc(50% - 0.5rem)',
85114
} as const;
86115

116+
export const horizontalCenterStylesAfter = {
117+
left: 'calc(50% - 0.5rem)',
118+
} as const;
119+
87120
// This halfway fills the square we use to create the 'beak' of the tip so it does not overlap the tip text on the 'center' alignments
88121
export const topCenterStylesAfter = {
89122
backgroundImage: `linear-gradient(to top left, ${theme.colors[tooltipBackgroundColor]} 55%, rgba(0,0,0,0) 20%)`,

packages/gamut/src/Tip/shared/types.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ const tipCenterAlignmentArray = [
1414
'left-center',
1515
'right-center',
1616
'top-center',
17-
'center-right',
18-
'center-left',
1917
] as const;
2018

2119
export const tipAlignmentArray = [

packages/gamut/src/Tip/shared/utils.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ import {
1111
bottomStylesAfter,
1212
bottomStylesBefore,
1313
horizontalCenterStyles,
14+
horizontalCenterStylesAfter,
1415
horizontalLeftStyles,
1516
horizontalRightStyles,
1617
leftStyles,
1718
leftStylesAfter,
19+
rightAlignStyles,
20+
rightAlignStylesAfter,
21+
rightAlignStylesBefore,
1822
rightStyles,
1923
rightStylesAfter,
2024
topCenterStylesAfter,
@@ -96,17 +100,23 @@ export const createToolTipVariantFromAlignment = (alignment: string) => {
96100
styleObject = { ...topStyles };
97101
styleObjectAfter = { ...topStylesAfter };
98102
styleObjectBefore = { ...topStylesBefore };
99-
} else {
103+
} else if (alignment.includes('bottom')) {
100104
styleObject = { ...bottomStyles };
101105
styleObjectAfter = { ...bottomStylesAfter };
102106
styleObjectBefore = { ...bottomStylesBefore };
107+
} else if (alignment.startsWith('right')) {
108+
styleObject = { ...rightAlignStyles };
109+
styleObjectAfter = { ...rightAlignStylesAfter };
110+
styleObjectBefore = { ...rightAlignStylesBefore };
111+
} else {
103112
}
104113

105-
const isHorizontallyAligned =
106-
alignment.includes('left-') || alignment.includes('right-');
114+
const isLRAligned =
115+
alignment.startsWith('right') || alignment.startsWith('left');
116+
107117
const isRightAligned = alignment.includes('right');
108118

109-
if (alignment.includes('center') && !isHorizontallyAligned) {
119+
if (alignment.includes('center') && !isLRAligned) {
110120
styleObject = { ...styleObject, ...verticalCenterStyles };
111121
styleObjectAfter = { ...styleObjectAfter, ...verticalCenterStylesAfter };
112122
if (alignment.includes('top')) {
@@ -122,9 +132,9 @@ export const createToolTipVariantFromAlignment = (alignment: string) => {
122132
styleObjectAfter = { ...styleObjectAfter, ...leftStylesAfter };
123133
}
124134

125-
if (alignment.includes('center') && isHorizontallyAligned) {
135+
if (isLRAligned) {
126136
styleObject = { ...styleObject, ...horizontalCenterStyles };
127-
styleObjectAfter = { ...styleObjectAfter, ...verticalCenterStylesAfter };
137+
styleObjectAfter = { ...styleObjectAfter, ...horizontalCenterStylesAfter };
128138
if (isRightAligned) {
129139
styleObject = { ...styleObject, ...horizontalRightStyles };
130140
} else {

0 commit comments

Comments
 (0)