@@ -3,7 +3,15 @@ import * as React from 'react';
33import classNames from 'classnames' ;
44import { injectIntl } from 'react-intl' ;
55import type { IntlShape } from 'react-intl' ;
6- import { Tooltip as BPTooltip } from '@box/blueprint-web' ;
6+
7+ import { IconButton , Tooltip as BPTooltip , useBreakpoint , Breakpoint } from '@box/blueprint-web' ;
8+ import {
9+ ChevronDown ,
10+ ChevronUp ,
11+ RightSidebarChevronClose ,
12+ RightSidebarChevronOpen ,
13+ } from '@box/blueprint-web-assets/icons/Medium' ;
14+
715import IconHide from '../../icons/general/IconHide' ;
816import IconShow from '../../icons/general/IconShow' ;
917import PlainButton from '../plain-button' ;
@@ -32,21 +40,20 @@ const SidebarToggleButton = ({
3240 onClick,
3341 ...rest
3442} : Props ) => {
43+ const breakpoint = useBreakpoint ( ) ;
3544 const { enabled : isPreviewModernizationEnabled } = useFeatureConfig ( 'previewModernization' ) ;
45+
3646 const isCollapsed = ! isOpen ? 'collapsed' : '' ;
3747 const intlMessage = isOpen ? messages . sidebarHide : messages . sidebarShow ;
3848 const intlText = intl . formatMessage ( intlMessage ) ;
39- const classes = classNames ( className , 'bdl-SidebarToggleButton' , {
49+ const classes = classNames ( className , {
4050 'bdl-is-collapsed' : isCollapsed ,
51+ 'bdl-SidebarToggleButton' : ! isPreviewModernizationEnabled ,
4152 'bdl-SidebarToggleButton--modernized' : isPreviewModernizationEnabled ,
4253 } ) ;
43- const tooltipPosition = direction === DIRECTION_LEFT ? 'middle-right' : 'middle-left' ;
44- const renderButton = ( ) => {
45- if ( direction === DIRECTION_LEFT ) {
46- return isOpen ? < IconShow height = { 16 } width = { 16 } /> : < IconHide height = { 16 } width = { 16 } /> ;
47- }
48- return isOpen ? < IconHide height = { 16 } width = { 16 } /> : < IconShow height = { 16 } width = { 16 } /> ;
49- } ;
54+
55+ const isDirectionLeft = direction === DIRECTION_LEFT ;
56+ const tooltipPosition = isDirectionLeft ? 'middle-right' : 'middle-left' ;
5057
5158 // Adding this to stop the mousedown event from being propagated up to box-annotations as
5259 // that will cause the active annotation to no longer be active which means that it will not be displayed.
@@ -56,26 +63,43 @@ const SidebarToggleButton = ({
5663 } ;
5764
5865 if ( isPreviewModernizationEnabled ) {
59- const tooltipPositionModernized = direction === DIRECTION_LEFT ? DIRECTION_RIGHT : DIRECTION_LEFT ;
66+ const isBelowMediumView = breakpoint <= Breakpoint . Medium ;
67+ const tooltipPositionModernized = isDirectionLeft ? DIRECTION_RIGHT : DIRECTION_LEFT ;
68+
69+ const renderModernizedIcon = ( ) => {
70+ if ( isBelowMediumView ) {
71+ return isOpen ? ChevronDown : ChevronUp ;
72+ }
73+
74+ if ( isDirectionLeft ) {
75+ return isOpen ? RightSidebarChevronOpen : RightSidebarChevronClose ;
76+ }
77+
78+ return isOpen ? RightSidebarChevronClose : RightSidebarChevronOpen ;
79+ } ;
6080
6181 return (
6282 < BPTooltip content = { intlText } side = { tooltipPositionModernized } >
63- { /* Workaround to attach BP tooltip to legacy button, remove span when buttons are migrated to BP */ }
64- < span onMouseDown = { mouseDownHandler } role = "presentation" >
65- < PlainButton
66- aria-label = { intlText }
67- className = { classes }
68- onClick = { onClick }
69- onMouseDown = { mouseDownHandler }
70- type = "button"
71- { ...rest }
72- >
73- { renderButton ( ) }
74- </ PlainButton >
75- </ span >
83+ < IconButton
84+ aria-label = { intlText }
85+ className = { classes }
86+ icon = { renderModernizedIcon ( ) }
87+ onClick = { onClick }
88+ onMouseDown = { mouseDownHandler }
89+ size = { isBelowMediumView ? 'small' : 'large' }
90+ { ...rest }
91+ />
7692 </ BPTooltip >
7793 ) ;
7894 }
95+
96+ const renderIcon = ( ) => {
97+ if ( isDirectionLeft ) {
98+ return isOpen ? < IconShow height = { 16 } width = { 16 } /> : < IconHide height = { 16 } width = { 16 } /> ;
99+ }
100+ return isOpen ? < IconHide height = { 16 } width = { 16 } /> : < IconShow height = { 16 } width = { 16 } /> ;
101+ } ;
102+
79103 return (
80104 < Tooltip position = { tooltipPosition } text = { intlText } >
81105 < PlainButton
@@ -86,7 +110,7 @@ const SidebarToggleButton = ({
86110 type = "button"
87111 { ...rest }
88112 >
89- { renderButton ( ) }
113+ { renderIcon ( ) }
90114 </ PlainButton >
91115 </ Tooltip >
92116 ) ;
0 commit comments