Skip to content

Commit 78e57b8

Browse files
committed
[REFACTOR] Convert centering to flex
- vs absolute positioning/transforms Doing this has two major benefits: - The hover/focus animations were broken on Safari in production, and this fixes that - CSS transform do not respect logical properties and flex does, so this automatically makes the component fully direction/writing-mode compatible for less code :)
1 parent 86ea8e5 commit 78e57b8

1 file changed

Lines changed: 22 additions & 41 deletions

File tree

src/components/resizable_container/resizable_button.styles.ts

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const euiResizableButtonStyles = (euiThemeContext: UseEuiTheme) => {
1717
const buttonSize = euiTheme.size.base;
1818
const grabHandleWidth = euiTheme.size.m;
1919
const grabHandleHeight = euiTheme.border.width.thin;
20-
const grabHandleFocusHeight = mathWithUnits(grabHandleHeight, (x) => x * 2); // This is the thick border width by default, but we should re-use the thin width in case consumers customize both tokens
2120

2221
const transitionSpeed = euiTheme.animation.fast;
2322
const transition = `${transitionSpeed} ease`;
@@ -26,22 +25,36 @@ export const euiResizableButtonStyles = (euiThemeContext: UseEuiTheme) => {
2625
// Mimics the "grab" icon with CSS psuedo-elements.
2726
// 1. The "grab" icon transforms into a thicker straight line on :hover and :focus
2827
euiResizableButton: css`
29-
position: relative;
30-
flex-shrink: 0;
3128
z-index: 1;
29+
flex-shrink: 0;
30+
display: flex;
31+
align-items: center;
32+
justify-content: center;
33+
gap: ${mathWithUnits(grabHandleHeight, (x) => x * 2)};
34+
35+
/* 1 */
36+
&:hover,
37+
&:focus {
38+
gap: 0;
39+
justify-content: center;
40+
}
41+
42+
${euiCanAnimate} {
43+
transition: gap ${transition}, justify-content ${transition};
44+
}
3245
3346
&::before,
3447
&::after {
3548
content: '';
3649
display: block;
37-
position: absolute;
38-
${logicalCSS('top', '50%')}
39-
${logicalCSS('left', '50%')}
4050
background-color: ${euiTheme.colors.darkestShade};
4151
52+
/* CSS hack to smooth out/anti-alias the 1px wide handles at various zoom levels */
53+
transform: translateZ(0);
54+
4255
${euiCanAnimate} {
4356
transition: width ${transition}, height ${transition},
44-
transform ${transition}, background-color ${transition};
57+
background-color ${transition};
4558
}
4659
}
4760
@@ -69,8 +82,7 @@ export const euiResizableButtonStyles = (euiThemeContext: UseEuiTheme) => {
6982
7083
/* Overrides default transition so that "grab" icon background-color doesn't animate */
7184
${euiCanAnimate} {
72-
transition: width ${transition}, height ${transition},
73-
transform ${transition};
85+
transition: width ${transition}, height ${transition};
7486
transition-delay: ${mathWithUnits(transitionSpeed, (x) => x / 2)};
7587
}
7688
}
@@ -87,32 +99,17 @@ export const euiResizableButtonStyles = (euiThemeContext: UseEuiTheme) => {
8799
${logicalCSS('height', grabHandleWidth)}
88100
}
89101
90-
&::before {
91-
transform: translate(-${grabHandleFocusHeight}, -50%);
92-
}
93-
94-
&::after {
95-
transform: translate(${grabHandleHeight}, -50%);
96-
}
97-
98102
/* 1 */
99103
&:hover,
100104
&:focus {
101105
&::before,
102106
&::after {
103107
${logicalCSS('height', '100%')}
104108
}
105-
106-
&::before {
107-
transform: translate(-${grabHandleHeight}, -50%);
108-
}
109-
110-
&::after {
111-
transform: translate(0, -50%);
112-
}
113109
}
114110
`,
115111
vertical: css`
112+
flex-direction: column;
116113
cursor: row-resize;
117114
${logicalCSS('height', buttonSize)}
118115
margin-block: ${mathWithUnits(buttonSize, (x) => x / -2)};
@@ -123,29 +120,13 @@ export const euiResizableButtonStyles = (euiThemeContext: UseEuiTheme) => {
123120
${logicalCSS('width', grabHandleWidth)}
124121
}
125122
126-
&::before {
127-
transform: translate(-50%, -${grabHandleFocusHeight});
128-
}
129-
130-
&::after {
131-
transform: translate(-50%, ${grabHandleHeight});
132-
}
133-
134123
/* 1 */
135124
&:hover,
136125
&:focus {
137126
&::before,
138127
&::after {
139128
${logicalCSS('width', '100%')}
140129
}
141-
142-
&::before {
143-
transform: translate(-50%, -${grabHandleHeight});
144-
}
145-
146-
&::after {
147-
transform: translate(-50%, 0);
148-
}
149130
}
150131
`,
151132
};

0 commit comments

Comments
 (0)