diff --git a/package-lock.json b/package-lock.json index 990062b00b..8641deb679 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@channel.io/design-system", - "version": "0.3.8", + "version": "0.3.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 71b9e24d69..1b0ae8f530 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@channel.io/design-system", - "version": "0.3.8", + "version": "0.3.9", "description": "Design System by Channel", "repository": { "type": "git", diff --git a/src/foundation/Mixins.ts b/src/foundation/Mixins.ts index 445b7e6ecd..6f69aaf12b 100644 --- a/src/foundation/Mixins.ts +++ b/src/foundation/Mixins.ts @@ -7,6 +7,11 @@ export const absoluteCenter = (otherTransforms: any) => ` transform: translate(-50%, -50%) ${otherTransforms}; ` +export const disableAutoMinimum = css` + min-width: 0; + min-height: 0; +` + export const hideScrollbars = () => css` -ms-overflow-style: none; diff --git a/src/hooks/useSideWidth.ts b/src/hooks/useSideWidth.ts index b1d30b4cea..642ac06f0f 100644 --- a/src/hooks/useSideWidth.ts +++ b/src/hooks/useSideWidth.ts @@ -5,28 +5,15 @@ import { useEffect } from 'react' import { SIDE_FALLBACK_WIDTH } from '../constants/LayoutSizes' import { ActionType } from '../layout/Client/utils/LayoutReducer' import useLayoutDispatch from './useLayoutDispatch' -import useLayoutState from './useLayoutState' export default function useSideWidth(width: number = SIDE_FALLBACK_WIDTH) { const dispatch = useLayoutDispatch() - const { showSideView } = useLayoutState() - useEffect(() => { dispatch({ type: ActionType.SET_SIDE_WIDTH, payload: width, }) - - return function cleanUp() { - if (!showSideView) { - dispatch({ - type: ActionType.SET_SIDE_WIDTH, - payload: 0, - }) - } - } - /* eslint-disable-next-line react-hooks/exhaustive-deps */ }, []) diff --git a/src/layout/Client/utils/LayoutReducer.ts b/src/layout/Client/utils/LayoutReducer.ts index c5c81933ca..a799975aed 100644 --- a/src/layout/Client/utils/LayoutReducer.ts +++ b/src/layout/Client/utils/LayoutReducer.ts @@ -5,6 +5,11 @@ import { omit } from 'lodash-es' import { insertItem, removeItem } from '../../../utils/arrayUtils' import ColumnType from '../../../types/ColumnType' +interface SetShowSideActionPayload { + showSideView?: boolean + showSidePanel?: boolean +} + type ColumnRef = { target: HTMLDivElement minWidth: number @@ -21,9 +26,10 @@ export interface ColumnState { } export interface LayoutState { - /* Side View related */ + /* Side related */ sideWidth: number showSideView: boolean + showSidePanel: boolean /* Navigations related */ showNavigation: boolean /* Resizing related */ @@ -35,6 +41,7 @@ export interface LayoutState { export const defaultState: LayoutState = { sideWidth: 0, showSideView: false, + showSidePanel: false, showNavigation: true, orderedColumnKeys: [], columnRefs: {}, @@ -43,6 +50,7 @@ export const defaultState: LayoutState = { export enum ActionType { SET_SIDE_WIDTH = 'SET_SIDE_WIDTH', + SET_SHOW_SIDE = 'SET_SHOW_SIDE', OPEN_SIDE_VIEW = 'OPEN_SIDE_VIEW', CLOSE_SIDE_VIEW = 'CLOSE_SIDE_VIEW', SET_SHOW_NAVIGATION = 'SET_SHOW_NAVIGATION', @@ -58,6 +66,11 @@ interface SetSideWidthAction { payload: number } +interface SetShowSideAction { + type: ActionType.SET_SHOW_SIDE + payload: SetShowSideActionPayload +} + interface OpenSideViewAction { type: ActionType.OPEN_SIDE_VIEW } @@ -101,6 +114,7 @@ interface RemoveColumnRefAction { export type LayoutAction = ( SetSideWidthAction | + SetShowSideAction | OpenSideViewAction | CloseSideViewAction | SetShowNavigationAction | @@ -120,6 +134,13 @@ function LayoutReducer(state: LayoutState = defaultState, action: LayoutAction): } } + case ActionType.SET_SHOW_SIDE: { + return { + ...state, + ...action.payload, + } + } + case ActionType.OPEN_SIDE_VIEW: { return { ...state, diff --git a/src/layout/ContentArea/ContentArea.styled.ts b/src/layout/ContentArea/ContentArea.styled.ts index 777031ca22..ffd6e6e48c 100644 --- a/src/layout/ContentArea/ContentArea.styled.ts +++ b/src/layout/ContentArea/ContentArea.styled.ts @@ -1,9 +1,11 @@ /* Internal dependencies */ -import { styled } from '../../foundation' +import { styled, disableAutoMinimum } from '../../foundation' export const ContentAreaWrapper = styled.div` position: relative; grid-row: 2; grid-column: 1; background-color: ${({ foundation }) => foundation?.theme?.['bg-white-normal']}; + + ${disableAutoMinimum} ` diff --git a/src/layout/HeaderArea/HeaderArea.styled.ts b/src/layout/HeaderArea/HeaderArea.styled.ts index 6b8260f5cd..384c865d0a 100644 --- a/src/layout/HeaderArea/HeaderArea.styled.ts +++ b/src/layout/HeaderArea/HeaderArea.styled.ts @@ -1,5 +1,5 @@ /* Internal dependencies */ -import { styled } from '../../foundation' +import { styled, disableAutoMinimum } from '../../foundation' interface HeaderWrapperProps { showSideView: boolean @@ -17,14 +17,20 @@ export const HeaderWrapper = styled.div.attrs(({ showSideView, sideWidth }: Head grid-column: 1 / 3; background-color: ${({ foundation }) => foundation?.theme?.['bg-header']}; border-bottom: 1px solid ${({ foundation }) => foundation?.theme?.['bdr-black-light']}; + + ${disableAutoMinimum} ` export const ContentHeader = styled.div` grid-row: 1 / 2; grid-column: 1 / 2; + + ${disableAutoMinimum} ` export const CoverableHeader = styled.div` grid-row: 1 / 2; grid-column: 2 / 3; + + ${disableAutoMinimum} ` diff --git a/src/layout/Main/Main.tsx b/src/layout/Main/Main.tsx index b2c69a4ae8..54e8397e89 100644 --- a/src/layout/Main/Main.tsx +++ b/src/layout/Main/Main.tsx @@ -24,9 +24,9 @@ function Main( }: MainProps, forwardedRef: React.Ref, ) { - const { sideWidth, showSideView } = useLayoutState() + const { sideWidth, showSideView, showSidePanel } = useLayoutState() - const hasSide = !isNil(SidePanelComponent) || showSideView + const hasSide = showSideView || showSidePanel const hasHeader = !isNil(ContentHeaderComponent || CoverableHeaderComponent) return ( @@ -47,8 +47,8 @@ function Main( { children } - - + + ) } diff --git a/src/layout/Navigations/NavigationContent/NavigationContent.styled.ts b/src/layout/Navigations/NavigationContent/NavigationContent.styled.ts index 1535d958d1..53d28d2c30 100644 --- a/src/layout/Navigations/NavigationContent/NavigationContent.styled.ts +++ b/src/layout/Navigations/NavigationContent/NavigationContent.styled.ts @@ -35,10 +35,6 @@ export const StyledContentWrapper = styled.div` height: 100%; overflow-x: hidden; overflow-y: ${({ withScroll }) => (withScroll ? 'auto' : 'hidden')}; - - & > *:last-child { - margin-bottom: 40px !important; - } ` export const StyledFooterWrapper = styled.div` diff --git a/src/layout/Side/SideArea/SideArea.styled.ts b/src/layout/Side/SideArea/SideArea.styled.ts index f0011a6255..fb83107abe 100644 --- a/src/layout/Side/SideArea/SideArea.styled.ts +++ b/src/layout/Side/SideArea/SideArea.styled.ts @@ -1,5 +1,5 @@ /* Internal dependencies */ -import { css, styled } from '../../../foundation' +import { css, styled, disableAutoMinimum } from '../../../foundation' import LayoutSideType from '../../../constants/LayoutSideType' interface SideAreaWrapperProps { @@ -12,10 +12,11 @@ export const SideAreaWrapper = styled.div` grid-row: ${({ sideType }) => (sideType === LayoutSideType.SidePanel ? '2 / 3' : '1 / 3')}; grid-column: 2; background-color: ${({ foundation }) => foundation?.theme?.['bg-grey-lightest']}; - ${({ showSideView, sideType }) => showSideView && sideType === LayoutSideType.SidePanel && css` display: none; `} + + ${disableAutoMinimum} ` export const ScrollWrapper = styled.div` diff --git a/src/layout/Side/SideArea/SideArea.tsx b/src/layout/Side/SideArea/SideArea.tsx index c17c0b76ff..5b823e4bdc 100644 --- a/src/layout/Side/SideArea/SideArea.tsx +++ b/src/layout/Side/SideArea/SideArea.tsx @@ -4,7 +4,6 @@ import { noop, clamp } from 'lodash-es' import { document } from 'ssr-window' /* Internal dependencies */ -import LayoutSideType from '../../../constants/LayoutSideType' import useEventHandler from '../../../hooks/useEventHandler' import useLayoutState from '../../../hooks/useLayoutState' import useResizingHandlers from '../../../hooks/useResizingHandlers' @@ -40,10 +39,6 @@ function SideArea( const contentKey = useMemo(() => (orderedColumnKeys[orderedColumnKeys.length - 1]), [orderedColumnKeys]) const contentRef = useMemo(() => (columnRefs[contentKey]?.target), [columnRefs, contentKey]) - const hideSideView = useMemo(() => ( - sideType === LayoutSideType.SideView && !showSideView - ), [showSideView, sideType]) - const handleResizerMouseMove = useCallback((e: HTMLElementEventMap['mousemove']) => { if ( handleResizing(e) && @@ -89,10 +84,6 @@ function SideArea( useEventHandler(document, 'mousemove', handleResizerMouseMove, isDragging) useEventHandler(document, 'mouseup', handleResizerMouseUp) - if (hideSideView) { - return null - } - return ( { + dispatch({ + type: ActionType.SET_SHOW_SIDE, + payload: { + showSidePanel: true, + }, + }) + + return function cleanup() { + dispatch({ + type: ActionType.SET_SHOW_SIDE, + payload: { + showSidePanel: false, + }, + }) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + return ( { + dispatch({ + type: ActionType.SET_SHOW_SIDE, + payload: { + showSideView: true, + }, + }) + + return function cleanup() { + dispatch({ + type: ActionType.SET_SHOW_SIDE, + payload: { + showSideView: false, + }, + }) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + return ( +
+ { `sideWidth: ${sideWidth}px` } + { `showSideView: ${showSideView ? 'true' : 'false'}` } + { `showSidePanel: ${showSidePanel ? 'true' : 'false'}` } +
diff --git a/src/layout/stories/LayoutPlayground/LayoutPlayGround.stories.tsx b/src/layout/stories/LayoutPlayground/LayoutPlayGround.stories.tsx index aac08768fa..429501b43b 100644 --- a/src/layout/stories/LayoutPlayground/LayoutPlayGround.stories.tsx +++ b/src/layout/stories/LayoutPlayground/LayoutPlayGround.stories.tsx @@ -17,6 +17,7 @@ import Navigations from '../../Navigations/Navigations' import { SidePanelContent } from '../../Side/SidePanelContent' import { SideViewContent } from '../../Side/SideViewContent' import { NavigationContent } from '../../Navigations/NavigationContent' +import useLayoutState from '../../../hooks/useLayoutState' import Content from './Content' export default { @@ -72,13 +73,29 @@ function UserChatSidePanel({ onChangeWidth }) { -
+
Another SidePanel
) } +function SideViewRoute({ onChangeWidth }) { + const { showSideView } = useLayoutState() + + if (!showSideView) { + return null + } + + return ( + +
SideView
+
+ ) +} + const Template = ({ onChangeWidth }) => { const [route, setRoute] = useState(RouteKeys.UserChat) @@ -239,12 +256,9 @@ const Template = ({ onChangeWidth }) => { }, [onChangeWidth, route]) const SideViewComponent = useCallback(() => ( - -
SideView
-
+ ), [onChangeWidth]) + return ( <>