Skip to content

Commit bc3dfe8

Browse files
authored
feat: Add option to always show collapse button (#31)
1 parent 5f2fd99 commit bc3dfe8

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ It's a common need to want to collapse the left or initial panel to give more ro
9393

9494
* `beforeToggleButton` - the element displayed as the collapse button **before** the panel is collapsed. This is an purely aesthetic component.
9595
* `afterToggleButton` - the element displayed as the collapse button **after** the panel is collapsed. This is an purely aesthetic component.
96-
* `buttonTransition` - the animation applied to the button appear/disappear. Possible options are `zoom`, `grow`, or `fade`
96+
* `buttonTransition` - the animation applied to the button appear/disappear. Possible options are `zoom`, `grow`, `fade`, or `none`. You can try them out in the storybook. `none` indicates to keep the button always visible.
9797
* `buttonTransitionTimeout` - the time (in millisecons) that the animation for the appear/disappear of the button will take place
9898
* `buttonPositionOffset` - a positive or negative number that will either add or subtract the flex-basis (starting at 100) of an invisible div before or after the button. e.g. 50 would make the "before" 150 and the "after" 50
9999
* `collapseDirection` - `'left' | 'right' | 'up' | 'down'` - this is used to indicate the direction that it should collapse. By default collapsing happens left and up for the vertical and horizontal splits respectively. Valid values for a vertical split are `left` or `right` and valid values for a horizontal split are `up` or `down`

src/components/Resizer/hooks/useTransition.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const transitionComponentMap: {
88
fade: Fade,
99
grow: Grow,
1010
zoom: Zoom,
11+
none: Fade,
1112
};
1213

1314
export function useTransition(collapseOptions?: CollapseOptions) {

src/components/Resizer/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@ export const Resizer = ({
101101
() => Math.max(100 + (collapseOptions?.buttonPositionOffset ?? 0), 0),
102102
[collapseOptions]
103103
);
104+
const isTransition = collapseOptions?.buttonTransition !== 'none';
104105
const collapseButton = collapseOptions ? (
105106
<ButtonContainer $isVertical={isVertical} grabberSize={grabberSizeWithUnit} isLtr={isLtr}>
106107
<ButtonPositionOffset style={{ flexBasis: preButtonFlex }} />
107108
<Transition
108-
in={isHovered}
109-
timeout={collapseOptions.buttonTransitionTimeout}
109+
in={isTransition ? isHovered : true}
110+
timeout={isTransition ? collapseOptions.buttonTransitionTimeout : 0}
110111
style={{ flex: '0 0 0', position: 'relative' }}
111112
>
112113
<ButtonWrapper

src/components/SplitPane/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type SplitPaneHooks = {
2121
onCollapse?: (collapsedSizes: Nullable<number>[]) => void;
2222
};
2323

24-
export type TransitionType = 'fade' | 'grow' | 'zoom';
24+
export type TransitionType = 'fade' | 'grow' | 'zoom' | 'none';
2525
export type CollapseDirection = 'left' | 'right' | 'up' | 'down';
2626

2727
export interface CollapseOptions {
@@ -32,7 +32,7 @@ export interface CollapseOptions {
3232
buttonPositionOffset?: number;
3333
collapseDirection?: CollapseDirection;
3434
collapseTransitionTimeout?: number;
35-
collapsedSize: number;
35+
collapsedSize?: number;
3636
overlayCss?: React.CSSProperties;
3737
}
3838

stories/Collapse.stories.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ storiesOf('Collapsable Panes', module)
6262
const collapseDirection = select('Direction', { left: 'left', right: 'right' }, 'left');
6363
const minSizes = object('Minimum Sizes', [50, 50, 50, 50]);
6464
const collapseTransition = number('Collapse Transition Speed (ms)', 500);
65+
const buttonTransition = select(
66+
'Button Transition',
67+
{
68+
fade: 'fade',
69+
zoom: 'zoom',
70+
grow: 'grow',
71+
none: 'none',
72+
},
73+
'grow'
74+
);
6575

6676
return (
6777
<Header>
@@ -70,8 +80,8 @@ storiesOf('Collapsable Panes', module)
7080
collapseOptions={{
7181
beforeToggleButton: <Button>{collapseDirection === 'left' ? '⬅' : '➡'}</Button>,
7282
afterToggleButton: <Button>{collapseDirection === 'left' ? '➡' : '⬅'}</Button>,
73-
collapsedSize: 40,
7483
collapseTransitionTimeout: collapseTransition,
84+
buttonTransition,
7585
collapseDirection,
7686
buttonPositionOffset,
7787
}}
@@ -119,7 +129,6 @@ storiesOf('Collapsable Panes', module)
119129
collapseOptions={{
120130
beforeToggleButton: <Button>{collapseDirection === 'up' ? '⬆' : '⬇'}</Button>,
121131
afterToggleButton: <Button>{collapseDirection === 'up' ? '⬇' : '⬆'}</Button>,
122-
collapsedSize: 40,
123132
collapseDirection,
124133
}}
125134
resizerOptions={{

0 commit comments

Comments
 (0)