Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiResizableButton] Add new prop to allow consumers to account for overlap with scrollbars #8021

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/eui/changelogs/upcoming/8021.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Updated `EuiResizableButton` with a new `accountForScrollbars` prop
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default () => (
<EuiText>{text}</EuiText>
</EuiResizablePanel>

<EuiResizableButton indicator="border" />
<EuiResizableButton indicator="border" accountForScrollbars="before" />

<EuiResizablePanel
initialSize={50}
Expand All @@ -33,10 +33,13 @@ export default () => (
{(EuiResizablePanel, EuiResizableButton) => (
<>
<EuiResizablePanel initialSize={50} minSize="50px" tabIndex={0}>
<EuiText>{text}</EuiText>
<EuiText style={{ width: '110%' }}>{text}</EuiText>
</EuiResizablePanel>

<EuiResizableButton indicator="border" />
<EuiResizableButton
indicator="border"
accountForScrollbars="both"
/>

<EuiResizablePanel initialSize={50} minSize="50px" tabIndex={0}>
<EuiText>{text}</EuiText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default () => (
</EuiText>
</EuiResizablePanel>

<EuiResizableButton />
<EuiResizableButton accountForScrollbars="before" />

<EuiResizablePanel initialSize={50} minSize="200px" tabIndex={0}>
<EuiText>{text}</EuiText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default () => {
</EuiText>
</EuiResizablePanel>

<EuiResizableButton />
<EuiResizableButton accountForScrollbars="before" />

<EuiResizablePanel
id={secondPanelId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default () => {
</EuiText>
</EuiResizablePanel>

<EuiResizableButton />
<EuiResizableButton accountForScrollbars="before" />

<EuiResizablePanel
id={secondPanelId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default () => (
</EuiText>
</EuiResizablePanel>

<EuiResizableButton />
<EuiResizableButton accountForScrollbars="both" />

<EuiResizablePanel initialSize={40} minSize="10%" tabIndex={0}>
<EuiText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default () => {
));
return (
<EuiPage paddingSize="none">
<EuiResizableContainer style={{ height: '320px' }}>
<EuiResizableContainer>
{(EuiResizablePanel, EuiResizableButton) => (
<>
<EuiResizablePanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`EuiResizableButton renders 1`] = `
<div>
<button
aria-label="aria-label"
class="euiResizableButton testClass1 testClass2 emotion-euiResizableButton-handle-vertical-vertical-center-euiTestCss"
class="euiResizableButton testClass1 testClass2 emotion-euiResizableButton-handle-vertical-vertical-center-none-euiTestCss"
data-test-subj="test subject string"
type="button"
/>
Expand All @@ -15,7 +15,7 @@ exports[`EuiResizableButton renders different indicator styles and directions 1`
<div>
<button
aria-label="Press the left or right arrow keys to adjust panels size"
class="euiResizableButton emotion-euiResizableButton-border-horizontal-horizontal"
class="euiResizableButton emotion-euiResizableButton-border-horizontal-horizontal-none"
data-test-subj="euiResizableButton"
type="button"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports[`EuiResizableContainer can adjust panel props 1`] = `
</div>
<button
aria-label="Press the left or right arrow keys to adjust panels size"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center-none"
data-test-subj="euiResizableButton"
id="resizable-button_generated-id"
type="button"
Expand Down Expand Up @@ -60,7 +60,7 @@ exports[`EuiResizableContainer can be controlled externally 1`] = `
</div>
<button
aria-label="Press the left or right arrow keys to adjust panels size"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center-none"
data-test-subj="euiResizableButton"
id="resizable-button_generated-id"
type="button"
Expand Down Expand Up @@ -100,7 +100,7 @@ exports[`EuiResizableContainer can be vertical 1`] = `
</div>
<button
aria-label="Press the up or down arrow keys to adjust panels size"
class="euiResizableButton emotion-euiResizableButton-handle-vertical-vertical-center"
class="euiResizableButton emotion-euiResizableButton-handle-vertical-vertical-center-none"
data-test-subj="euiResizableButton"
id="resizable-button_generated-id"
type="button"
Expand Down Expand Up @@ -140,7 +140,7 @@ exports[`EuiResizableContainer can have more than two panels 1`] = `
</div>
<button
aria-label="Press the left or right arrow keys to adjust panels size"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center-none"
data-test-subj="euiResizableButton"
id="resizable-button_generated-id"
type="button"
Expand All @@ -159,7 +159,7 @@ exports[`EuiResizableContainer can have more than two panels 1`] = `
</div>
<button
aria-label="Press the left or right arrow keys to adjust panels size"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center-none"
data-test-subj="euiResizableButton"
id="resizable-button_generated-id"
type="button"
Expand Down Expand Up @@ -199,7 +199,7 @@ exports[`EuiResizableContainer can have scrollable panels 1`] = `
</div>
<button
aria-label="Press the left or right arrow keys to adjust panels size"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center-none"
data-test-subj="euiResizableButton"
id="resizable-button_generated-id"
type="button"
Expand Down Expand Up @@ -251,7 +251,7 @@ exports[`EuiResizableContainer can have toggleable panels 1`] = `
</div>
<button
aria-label="Press the left or right arrow keys to adjust panels size"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center-none"
data-test-subj="euiResizableButton"
id="resizable-button_generated-id"
type="button"
Expand Down Expand Up @@ -291,7 +291,7 @@ exports[`EuiResizableContainer is rendered 1`] = `
</div>
<button
aria-label="Press the left or right arrow keys to adjust panels size"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center-none"
data-test-subj="euiResizableButton"
id="resizable-button_generated-id"
type="button"
Expand Down Expand Up @@ -344,7 +344,7 @@ exports[`EuiResizableContainer toggleable panels can be configurable 1`] = `
</div>
<button
aria-label="Press the left or right arrow keys to adjust panels size"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center"
class="euiResizableButton emotion-euiResizableButton-handle-horizontal-horizontal-center-none"
data-test-subj="euiResizableButton"
id="resizable-button_generated-id"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import {
const meta: Meta<EuiResizableButtonProps> = {
title: 'Layout/EuiResizableContainer/Subcomponents/EuiResizableButton',
component: EuiResizableButton,
argTypes: {
accountForScrollbars: {
options: [undefined, 'both', 'before', 'after'],
},
},
args: {
// Component defaults
indicator: 'handle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const euiResizableButtonStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;

const buttonSize = euiTheme.size.base;
const negativeMargin = mathWithUnits(buttonSize, (x) => x / -2);
const grabHandleWidth = euiTheme.size.m;
const grabHandleHeight = euiTheme.border.width.thin;

Expand Down Expand Up @@ -77,15 +78,27 @@ export const euiResizableButtonStyles = (euiThemeContext: UseEuiTheme) => {
cursor: col-resize;
${logicalCSS('height', '100%')}
${logicalCSS('width', buttonSize)}
margin-inline: ${mathWithUnits(buttonSize, (x) => x / -2)};
`,
vertical: css`
flex-direction: column;
cursor: row-resize;
${logicalCSS('width', '100%')}
${logicalCSS('height', buttonSize)}
margin-block: ${mathWithUnits(buttonSize, (x) => x / -2)};
`,
accountForScrollbars: {
horizontal: {
both: css``,
before: css(logicalCSS('margin-right', negativeMargin)),
after: css(logicalCSS('margin-left', negativeMargin)),
none: css(logicalCSS('margin-horizontal', negativeMargin)),
},
vertical: {
both: css``,
before: css(logicalCSS('margin-bottom', negativeMargin)),
after: css(logicalCSS('margin-top', negativeMargin)),
none: css(logicalCSS('margin-vertical', negativeMargin)),
},
},

border: css`
&::before,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export type EuiResizableButtonProps = ButtonHTMLAttributes<HTMLButtonElement> &
* tall content that scrolls off-screen
*/
alignIndicator?: 'center' | 'start' | 'end';
/**
* By default, EuiResizableButton will overlap into the panels before/after it.
* This can occasionally occlude interactive elements like scrollbars. To prevent
* this overlap, use this prop to remove the overlap for the specified side.
*/
accountForScrollbars?: 'before' | 'after' | 'both';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very open to feedback on this prop name/API - I'm not 100% sold on it or anything but it was the best I could come up with 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah it's kind of very specific but at the same time it might be not clear enough otherwise ...
Maybe accountForOverlap? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to opt to merge this in as-is if that's okay! Overlap also feels a little vague to me, at least Scrollbars hints as to the purpose of the prop? 😅

/**
* When disabled, the resizer button will be completely hidden
*/
Expand All @@ -66,6 +72,7 @@ export const EuiResizableButton = forwardRef<
isHorizontal,
indicator = 'handle',
alignIndicator = 'center',
accountForScrollbars,
className,
...rest
},
Expand All @@ -82,6 +89,9 @@ export const EuiResizableButton = forwardRef<
styles[`${indicator}Direction`][resizeDirection],
styles[resizeDirection],
indicator === 'handle' && styles.alignIndicator[alignIndicator],
styles.accountForScrollbars[resizeDirection][
accountForScrollbars ?? 'none'
],
];

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const TwoColumns: EuiResizableContainerProps['children'] = (
<EuiText>{placeholderText}</EuiText>
</EuiResizablePanel>

<EuiResizableButton />
<EuiResizableButton accountForScrollbars="both" />

<EuiResizablePanel initialSize={50} tabIndex={0}>
<EuiText>{placeholderText}</EuiText>
Expand All @@ -53,13 +53,13 @@ const ThreeColumns: EuiResizableContainerProps['children'] = (
<EuiText>{placeholderText}</EuiText>
</EuiResizablePanel>

<EuiResizableButton />
<EuiResizableButton accountForScrollbars="both" />

<EuiResizablePanel initialSize={40} tabIndex={0}>
<EuiText>{placeholderText}</EuiText>
</EuiResizablePanel>

<EuiResizableButton />
<EuiResizableButton accountForScrollbars="both" />

<EuiResizablePanel initialSize={20} tabIndex={0}>
<EuiText>{placeholderText}</EuiText>
Expand All @@ -80,7 +80,7 @@ const WithMinSize: EuiResizableContainerProps['children'] = (
</EuiText>
</EuiResizablePanel>

<EuiResizableButton alignIndicator="center" />
<EuiResizableButton accountForScrollbars="both" />

<EuiResizablePanel initialSize={50} minSize="200px" tabIndex={0}>
<EuiText>
Expand All @@ -105,7 +105,7 @@ const SingleCollapsible: EuiResizableContainerProps['children'] = (
</EuiText>
</EuiResizablePanel>

<EuiResizableButton alignIndicator="center" />
<EuiResizableButton accountForScrollbars="both" />

<EuiResizablePanel initialSize={70} mode="main">
<EuiText>
Expand All @@ -130,7 +130,7 @@ const MultiCollapsible: EuiResizableContainerProps['children'] = (
</EuiText>
</EuiResizablePanel>

<EuiResizableButton />
<EuiResizableButton accountForScrollbars="both" />

<EuiResizablePanel initialSize={60} mode="main">
<EuiText>
Expand All @@ -140,7 +140,7 @@ const MultiCollapsible: EuiResizableContainerProps['children'] = (
</EuiText>
</EuiResizablePanel>

<EuiResizableButton />
<EuiResizableButton accountForScrollbars="both" />

<EuiResizablePanel initialSize={20} mode="collapsible">
<EuiText>
Expand Down
Loading