Skip to content

Commit

Permalink
style(suite): Container query in Sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaclavik committed Jul 11, 2024
1 parent 510ba01 commit 293f311
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const ResizableBox: StoryObj<ResizableBoxProps> = {
height: 100,
minHeight: 50,
maxHeight: 300,
disabledWidthIntervals: [[51, 100]],
disabledHeightIntervals: undefined,
updateWidthOnWindowResize: false,
updateHeightOnWindowResize: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export type ResizableBoxProps = {
updateWidthOnWindowResize?: boolean;
updateHeightOnWindowResize?: boolean;
zIndex?: ZIndexValues;
disabledWidthIntervals?: Array<Array<number>>;
disabledHeightIntervals?: Array<Array<number>>;
};

type ResizerHandlersProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { borders, spacingsPx } from '@trezor/theme';
import { focusStyleTransition, getFocusShadowStyle } from '@trezor/components/src/utils/utils';
import { SidebarDeviceStatus } from './SidebarDeviceStatus';
import { ViewOnlyTooltip } from 'src/views/view-only/ViewOnlyTooltip';
import { ExpandedSidebarOnly } from '../Sidebar/ExpandedSidebarOnly';

const CaretContainer = styled.div`
background: transparent;
Expand Down Expand Up @@ -111,11 +112,13 @@ export const DeviceSelector = () => {
>
<SidebarDeviceStatus />

{selectedDevice && selectedDevice.state && (
<CaretContainer>
<Icon size={20} icon="CARET_CIRCLE_DOWN" />
</CaretContainer>
)}
<ExpandedSidebarOnly>
{selectedDevice && selectedDevice.state && (
<CaretContainer>
<Icon size={20} icon="CARET_CIRCLE_DOWN" />
</CaretContainer>
)}
</ExpandedSidebarOnly>
</InnerContainer>
</ViewOnlyTooltip>
</Wrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TrezorDevice } from 'src/types/suite';
import { spacingsPx } from '@trezor/theme';
import { RotateDeviceImage } from '@trezor/components';
import { DeviceStatusText } from 'src/views/suite/SwitchDevice/DeviceItem/DeviceStatusText';
import { ExpandedSidebarOnly } from '../Sidebar/ExpandedSidebarOnly';

type DeviceStatusProps = {
deviceModel: DeviceModelInternal;
Expand Down Expand Up @@ -53,15 +54,17 @@ export const DeviceStatus = ({
/>
</DeviceWrapper>

{device && (
<DeviceDetail label={device.label}>
<DeviceStatusText
onRefreshClick={handleRefreshClick}
device={device}
forceConnectionInfo={forceConnectionInfo}
/>
</DeviceDetail>
)}
<ExpandedSidebarOnly>
{device && (
<DeviceDetail label={device.label}>
<DeviceStatusText
onRefreshClick={handleRefreshClick}
device={device}
forceConnectionInfo={forceConnectionInfo}
/>
</DeviceDetail>
)}
</ExpandedSidebarOnly>
</Container>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import styled from 'styled-components';
import { isExpandedSidebar } from './consts';

const Container = styled.div`
@container ${isExpandedSidebar} {
display: none;
}
`;

type Props = {
children: React.ReactNode;
};

export const CollapsedSidebarOnly = ({ children }: Props) => {
return <Container>{children}</Container>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import styled from 'styled-components';
import { isCollapsedSidebar } from './consts';

const Container = styled.div`
@container ${isCollapsedSidebar} {
display: none;
}
`;

type Props = {
children: React.ReactNode;
};

export const ExpandedSidebarOnly = ({ children }: Props) => {
return <Container>{children}</Container>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { borders, spacingsPx } from '@trezor/theme';
import { useDispatch, useSelector, useTranslation } from 'src/hooks/suite';
import { goto } from 'src/actions/suite/routerActions';
import { SettingsAnchor } from 'src/constants/suite/anchors';
import { ExpandedSidebarOnly } from './ExpandedSidebarOnly';

const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -68,24 +69,26 @@ export const HelperIcons = () => {

return (
<Container>
{showExperimental && (
<ExperimentalIcon
onClick={handleEapClick}
$isEapEnabled={isEapEnabled}
$isExperimental={isExperimental}
>
<Tooltip cursor="pointer" content={experimentalTooltip}>
<Icon icon="EXPERIMENTAL" size={16} color={theme.iconOnSecondary} />
</Tooltip>
</ExperimentalIcon>
)}
{showDebugMode && (
<DebugModeIcon>
<Tooltip content="Debug mode active">
<Icon icon="FLAG" size={16} color={theme.iconOnSecondary} />
</Tooltip>
</DebugModeIcon>
)}
<ExpandedSidebarOnly>
{showExperimental && (
<ExperimentalIcon
onClick={handleEapClick}
$isEapEnabled={isEapEnabled}
$isExperimental={isExperimental}
>
<Tooltip cursor="pointer" content={experimentalTooltip}>
<Icon icon="EXPERIMENTAL" size={16} color={theme.iconOnSecondary} />
</Tooltip>
</ExperimentalIcon>
)}
{showDebugMode && (
<DebugModeIcon>
<Tooltip content="Debug mode active">
<Icon icon="FLAG" size={16} color={theme.iconOnSecondary} />
</Tooltip>
</DebugModeIcon>
)}
</ExpandedSidebarOnly>
</Container>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { useDispatch, useSelector } from 'src/hooks/suite';
import { goto } from 'src/actions/suite/routerActions';
import { MouseEvent } from 'react';
import { selectRouteName } from 'src/reducers/suite/routerReducer';
import { useElevation } from '@trezor/components';
import { Tooltip, useElevation } from '@trezor/components';
import { ExpandedSidebarOnly } from './ExpandedSidebarOnly';
import { CollapsedSidebarOnly } from './CollapsedSidebarOnly';

const StyledIcon = styled(Icon)`
pointer-events: none;
Expand Down Expand Up @@ -104,7 +106,8 @@ export const NavigationItem = ({

const isActiveRoute = routes?.some(route => route === activeRoute);

return (
const Title = () => <Translation id={nameId} values={values} />;
const NavItem = () => (
<Container
$isActive={isActive || isActiveRoute}
onClick={handleClick}
Expand All @@ -114,8 +117,23 @@ export const NavigationItem = ({
$elevation={elevation}
>
<StyledIcon name={icon} size={iconSize} color="iconSubdued" />
<Translation id={nameId} values={values} />
<ExpandedSidebarOnly>
<Title />
</ExpandedSidebarOnly>
{itemsCount && <Count>{itemsCount}</Count>}
</Container>
);

return (
<>
<ExpandedSidebarOnly>
<NavItem />
</ExpandedSidebarOnly>
<CollapsedSidebarOnly>
<Tooltip content={<Title />} placement="right" hasArrow>
<NavItem />
</Tooltip>
</CollapsedSidebarOnly>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ActionButton } from './ActionButton';
import { NavBackends } from './NavBackends';
import { HelperIcons } from './HelperIcons';
import { useEnabledBackends } from '../utils';
import { ExpandedSidebarOnly } from './ExpandedSidebarOnly';

const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -88,7 +89,9 @@ export const QuickActions = () => {
{!isCustomBackendIconVisible && !isTorIconVisible ? (
<DescreetContainer onClick={handleDiscreetModeClick}>
<Icon size={16} icon={isDiscreetModeActive ? 'HIDE' : 'SHOW'} />
<Label>{translationString(translationLabel)} </Label>
<ExpandedSidebarOnly>
<Label>{translationString(translationLabel)} </Label>
</ExpandedSidebarOnly>
</DescreetContainer>
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Elevation, mapElevationToBackground, mapElevationToBorder, zIndices } f

const Container = styled.nav<{ $elevation: Elevation }>`
display: flex;
container-type: inline-size;
flex-direction: column;
flex: 0 0 auto;
height: 100%;
Expand All @@ -29,8 +30,8 @@ export const Sidebar = () => {
<ResizableBox
directions={['right']}
width={SIDEBAR_WIDTH_NUMERIC}
minWidth={230}
maxWidth={400}
minWidth={84}
maxWidth={600}
zIndex={zIndices.draggableComponent}
updateHeightOnWindowResize
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const SIDEBAR_COLLAPSED_WIDTH = 200;

export const isCollapsedSidebar = `(max-width: ${SIDEBAR_COLLAPSED_WIDTH}px)`;
export const isExpandedSidebar = `(min-width: ${SIDEBAR_COLLAPSED_WIDTH + 1}px)`;
Loading

0 comments on commit 293f311

Please sign in to comment.