Skip to content

Commit cb3c773

Browse files
authored
v0.3.1
2 parents 316b3e8 + 6781cc6 commit cb3c773

File tree

19 files changed

+240
-171
lines changed

19 files changed

+240
-171
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@channel.io/design-system",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "Design System by Channel",
55
"repository": {
66
"type": "git",

src/components/Overlay/Overlay.stories.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default {
5353
const Container = styled.div`
5454
width: 600px;
5555
height: 500px;
56+
position: relative;
5657
overflow: scroll;
5758
border: 1px solid ${props => props.foundation?.theme?.['bg-black-dark']};
5859
`
@@ -93,16 +94,18 @@ const ScrollContent = styled.div`
9394

9495
const Template = (props) => {
9596
const targetRef = useRef<any>()
97+
const containerRef = useRef<any>()
9698

9799
return (
98-
<Container>
100+
<Container ref={containerRef}>
99101
<Wrapper>
100102
<Target ref={targetRef}>
101103
target
102104
</Target>
103105
<Overlay
104106
{...props}
105107
target={targetRef.current}
108+
container={containerRef.current}
106109
>
107110
<Children>
108111
<ScrollContent>

src/components/Overlay/Overlay.tsx

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,24 @@ const rootElement =
3333
document.getElementById!('root') ||
3434
document.getElementById!('__next') as HTMLElement
3535

36-
function getOverlayPosition({ target }: GetOverlayPositionProps): React.CSSProperties {
36+
function getOverlayPosition({ container, target }: GetOverlayPositionProps): React.CSSProperties {
3737
if (target) {
3838
const { top: targetTop, left: targetLeft } = target.getBoundingClientRect()
3939

40-
const top = targetTop - target.clientTop
41-
const left = targetLeft - target.clientLeft
40+
const top = container ?
41+
targetTop - target.clientTop - container.getBoundingClientRect().top + container.scrollTop :
42+
targetTop - target.clientTop
43+
const left = container ?
44+
targetLeft - target.clientLeft - container.getBoundingClientRect().left + container.scrollLeft :
45+
targetLeft - target.clientLeft
4246

4347
return { top, left }
4448
}
4549
return {}
4650
}
4751

4852
function getOverlayTranslation({
53+
container,
4954
target,
5055
overlay,
5156
placement,
@@ -54,12 +59,13 @@ function getOverlayTranslation({
5459
keepInContainer,
5560
}: GetOverlayTranslatationProps): React.CSSProperties {
5661
if (target) {
62+
const containerElement = container || rootElement as HTMLElement
5763
const {
5864
width: rootWidth,
5965
height: rootHeight,
6066
top: rootTop,
6167
left: rootLeft,
62-
} = rootElement.getBoundingClientRect()
68+
} = containerElement.getBoundingClientRect()
6369
const { width: targetWidth, height: targetHeight, top: targetTop, left: targetLeft } = target.getBoundingClientRect()
6470
const { width: overlayWidth, height: overlayHeight } = overlay.getBoundingClientRect()
6571

@@ -134,6 +140,7 @@ function getOverlayTranslation({
134140
}
135141

136142
function getOverlayStyle({
143+
container,
137144
target,
138145
overlay,
139146
placement,
@@ -142,8 +149,16 @@ function getOverlayStyle({
142149
keepInContainer,
143150
}: GetOverlayStyleProps): React.CSSProperties {
144151
if (target) {
145-
const overlayPositionStyle = getOverlayPosition({ target })
146-
const overlayTranslateStyle = getOverlayTranslation({ target, overlay, placement, marginX, marginY, keepInContainer })
152+
const overlayPositionStyle = getOverlayPosition({ container, target })
153+
const overlayTranslateStyle = getOverlayTranslation({
154+
container,
155+
target,
156+
overlay,
157+
placement,
158+
marginX,
159+
marginY,
160+
keepInContainer,
161+
})
147162

148163
const combinedStyle = {
149164
...overlayPositionStyle,
@@ -167,6 +182,7 @@ function Overlay(
167182
style,
168183
containerClassName = '',
169184
containerStyle,
185+
container,
170186
target,
171187
placement = OverlayPosition.LeftCenter,
172188
marginX = 0,
@@ -181,7 +197,7 @@ function Overlay(
181197
const [overlayStyle, setOverlayStyle] = useState<React.CSSProperties>()
182198
const [isHidden, setIsHidden] = useState<boolean>(true)
183199
const overlayRef = useRef<HTMLDivElement>(null)
184-
const [containerRef, setContainerRef] = useState<HTMLDivElement | null>(null)
200+
const containerRef = useRef<HTMLDivElement>(null)
185201
const mergedRef = useMergeRefs<HTMLDivElement>(overlayRef, forwardedRef)
186202

187203
const handleBlockMouseWheel = useCallback((event: HTMLElementEventMap['wheel']) => {
@@ -205,14 +221,9 @@ function Overlay(
205221
}
206222
}, [onHide])
207223

208-
const overlay = useMemo(() => (
209-
<Container
210-
ref={setContainerRef}
211-
className={containerClassName}
212-
style={containerStyle}
213-
data-testid={containerTestId}
214-
>
215-
<Wrapper data-testid={wrapperTestId}>
224+
const overlay = useMemo(() => {
225+
if (container) {
226+
return (
216227
<StyledOverlay
217228
as={as}
218229
className={className}
@@ -227,14 +238,40 @@ function Overlay(
227238
>
228239
{ children }
229240
</StyledOverlay>
230-
</Wrapper>
231-
</Container>
232-
), [
241+
)
242+
}
243+
return (
244+
<Container
245+
ref={containerRef}
246+
className={containerClassName}
247+
style={containerStyle}
248+
data-testid={containerTestId}
249+
>
250+
<Wrapper data-testid={wrapperTestId}>
251+
<StyledOverlay
252+
as={as}
253+
className={className}
254+
isHidden={isHidden}
255+
style={{
256+
...(style || {}),
257+
...(overlayStyle || {}),
258+
}}
259+
ref={mergedRef}
260+
data-testid={testId}
261+
{...otherProps}
262+
>
263+
{ children }
264+
</StyledOverlay>
265+
</Wrapper>
266+
</Container>
267+
)
268+
}, [
233269
as,
234270
className,
235271
style,
236272
containerClassName,
237273
containerStyle,
274+
container,
238275
isHidden,
239276
overlayStyle,
240277
children,
@@ -248,11 +285,12 @@ function Overlay(
248285
useEventHandler(document, 'click', handleHideOverlay, show)
249286
useEventHandler(document, 'keyup', handleKeydown, show)
250287
useEventHandler(target, 'click', handleClickTarget, show)
251-
useEventHandler(containerRef, 'wheel', handleBlockMouseWheel, show)
288+
useEventHandler(containerRef.current, 'wheel', handleBlockMouseWheel, show)
252289

253290
useEffect(() => {
254291
if (show) {
255292
const tempOverlayStyle = getOverlayStyle({
293+
container,
256294
target,
257295
overlay: overlayRef.current as HTMLElement,
258296
placement,
@@ -269,11 +307,11 @@ function Overlay(
269307
}
270308
}
271309
return noop
272-
}, [show, marginX, marginY, placement, target, keepInContainer])
310+
}, [show, container, marginX, marginY, placement, target, keepInContainer])
273311

274312
if (!show) return null
275313

276-
return ReactDOM.createPortal(overlay, rootElement as HTMLElement)
314+
return ReactDOM.createPortal(overlay, container || rootElement as HTMLElement)
277315
}
278316

279317
export default forwardRef(Overlay)

src/components/Overlay/Overlay.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default interface OverlayProps extends UIComponentProps, ChildrenComponen
88
show?: boolean
99
containerClassName?: string
1010
containerStyle?: React.CSSProperties
11+
container?: HTMLElement | null
1112
target?: HTMLElement | null
1213
placement?: OverlayPosition
1314
marginX?: number
@@ -17,6 +18,7 @@ export default interface OverlayProps extends UIComponentProps, ChildrenComponen
1718
}
1819

1920
export interface GetOverlayStyleProps {
21+
container?: HTMLElement | null
2022
target?: HTMLElement | null
2123
overlay: HTMLElement
2224
placement: OverlayPosition
@@ -26,10 +28,12 @@ export interface GetOverlayStyleProps {
2628
}
2729

2830
export interface GetOverlayPositionProps {
31+
container?: HTMLElement | null
2932
target: HTMLElement
3033
}
3134

3235
export interface GetOverlayTranslatationProps {
36+
container?: HTMLElement | null
3337
target: HTMLElement
3438
overlay: HTMLElement
3539
placement: OverlayPosition

src/components/Switch/Switch.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Switch from './Switch'
88

99
export default {
1010
title: getTitle(base),
11+
component: Switch,
1112
argTypes: {
1213
onClick: { action: 'onClick' },
1314
},

src/contexts/NavigationContext.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* External dependencies */
2+
import { createContext } from 'react'
3+
import { noop } from 'lodash-es'
4+
5+
export interface NavigationContextProps {
6+
optionIndex: number
7+
showChevron: boolean
8+
allowMouseMove: boolean
9+
isHoveringOnPresenter: boolean
10+
onClickClose: () => void
11+
}
12+
13+
export const NavigationContext = createContext<NavigationContextProps>({
14+
optionIndex: -1,
15+
showChevron: false,
16+
allowMouseMove: false,
17+
isHoveringOnPresenter: false,
18+
onClickClose: noop,
19+
})

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export * from './components/Header'
2828
export * from './layout/GNB'
2929
export * from './layout/GlobalHeader'
3030
export * from './layout/Client'
31-
export * from './layout/HeaderContent'
3231
export * from './layout/Main'
3332
export * from './layout/Navigations'
3433

src/layout/Client/utils/LayoutReducer.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { insertItem, removeItem } from '../../../utils/utils'
2+
13
export interface NavigationState {
24
initialWidth: number
35
maxWidth: number
@@ -10,21 +12,24 @@ export interface LayoutState {
1012
sideWidth: number | null
1113
showSideView: boolean
1214
showNavigation: boolean
15+
navOptions: NavigationState[]
1316
}
1417

1518
export const defaultState: LayoutState = {
1619
sideWidth: null,
1720
showSideView: false,
1821
showNavigation: true,
22+
navOptions: [],
1923
}
2024

2125
export enum ActionType {
2226
SET_SIDE_WIDTH,
2327
OPEN_SIDE_VIEW,
2428
CLOSE_SIDE_VIEW,
2529
SET_SHOW_NAVIGATION,
26-
ADD_NAVIGATION,
27-
CLEAR_NAVIGATIONS,
30+
ADD_NAV_OPTION,
31+
REMOVE_NAV_OPTION,
32+
CLEAR_NAV_OPTION,
2833
}
2934

3035
interface SetSideWidthAction {
@@ -45,11 +50,28 @@ interface SetShowNavigationAction {
4550
payload: boolean
4651
}
4752

53+
interface AddNavOptionAction {
54+
type: ActionType.ADD_NAV_OPTION
55+
payload: { index: number, option: NavigationState }
56+
}
57+
58+
interface RemoveNavOptionAction {
59+
type: ActionType.REMOVE_NAV_OPTION
60+
payload: { index: number }
61+
}
62+
63+
interface ClearNavOptionAction {
64+
type: ActionType.CLEAR_NAV_OPTION
65+
}
66+
4867
export type LayoutAction = (
4968
SetSideWidthAction |
5069
OpenSideViewAction |
5170
CloseSideViewAction |
52-
SetShowNavigationAction
71+
SetShowNavigationAction |
72+
AddNavOptionAction |
73+
RemoveNavOptionAction |
74+
ClearNavOptionAction
5375
)
5476

5577
function LayoutReducer(state: LayoutState = defaultState, action: LayoutAction): LayoutState {
@@ -82,6 +104,27 @@ function LayoutReducer(state: LayoutState = defaultState, action: LayoutAction):
82104
}
83105
}
84106

107+
case ActionType.ADD_NAV_OPTION: {
108+
return {
109+
...state,
110+
navOptions: insertItem(state.navOptions, action.payload.index, action.payload.option),
111+
}
112+
}
113+
114+
case ActionType.REMOVE_NAV_OPTION: {
115+
return {
116+
...state,
117+
navOptions: removeItem(state.navOptions, action.payload.index),
118+
}
119+
}
120+
121+
case ActionType.CLEAR_NAV_OPTION: {
122+
return {
123+
...state,
124+
navOptions: [],
125+
}
126+
}
127+
85128
default:
86129
return state
87130
}

src/layout/HeaderArea/HeaderArea.styled.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ export const HeaderWrapper = styled.div.attrs(({ showSideView, sideWidth }: Head
1818
grid-column: 1 / 3;
1919
`
2020

21-
export const LeftHeader = styled.div`
21+
export const ContentHeader = styled.div`
2222
grid-row: 1 / 2;
2323
grid-column: 1 / 2;
2424
`
2525

26-
export const RightHeader = styled.div`
26+
export const CoverableHeader = styled.div`
2727
grid-row: 1 / 2;
2828
grid-column: 2 / 3;
2929
`

0 commit comments

Comments
 (0)