Skip to content

Commit fed0a40

Browse files
authored
v0.1.5
2 parents 6f538b3 + 3efedf8 commit fed0a40

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
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.1.4",
3+
"version": "0.1.5",
44
"description": "Design System by Channel",
55
"repository": {
66
"type": "git",

src/layout/Navigation/Navigation.stories.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React, { useRef, useCallback } from 'react'
33
import { addDecorator } from '@storybook/react'
44
import { withKnobs, select, number, text, boolean } from '@storybook/addon-knobs'
5+
import { action } from '@storybook/addon-actions'
56

67
/* Internal dependencies */
78
import { GNB } from '../GNB'
@@ -23,7 +24,14 @@ addDecorator(decorator)
2324

2425
export const Default = () => (
2526
<ThemeProvider theme={LightTheme}>
26-
<Navigation />
27+
<Navigation
28+
title={text('title', 'Title')}
29+
fixedTitle={boolean('fixed title', false)}
30+
width={number('width', 240)}
31+
minWidth={number('minWidth', 240)}
32+
maxWidth={number('maxWidth', 540)}
33+
onChangeWidth={action('onChangeWidth')}
34+
/>
2735
</ThemeProvider>
2836
)
2937

@@ -48,7 +56,7 @@ export const WithRef = () => {
4856
height: '100%',
4957
}}
5058
>
51-
<Navigation ref={navigationRef}>
59+
<Navigation ref={navigationRef} width={number('width', 300)}>
5260
Guess my width!
5361
</Navigation>
5462
<button type="button" onClick={handleClick}>click me</button>

src/layout/Navigation/Navigation.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function Navigation(
2929
className,
3030
title,
3131
fixedTitle = false,
32+
width = 240,
3233
minWidth = 240,
3334
maxWidth = 540,
3435
disableResize = false,
@@ -39,13 +40,13 @@ function Navigation(
3940
) {
4041
const navigationRef = useRef<HTMLDivElement | null>(null)
4142
const mergedRef = useMergeRefs<HTMLDivElement>(navigationRef, forwardedRef)
42-
const [width, setWidth] = useState<number>(minWidth)
43+
const [currentWidth, setCurrentWidth] = useState<number>(_.clamp(width, minWidth, maxWidth))
4344
const [isDragging, setIsDragging] = useState(false)
4445

4546
const handleMouseMove = useCallback((e: MouseEvent) => {
4647
if (disableResize) { return }
4748

48-
window.requestAnimationFrame(() => setWidth(
49+
window.requestAnimationFrame(() => setCurrentWidth(
4950
_.clamp(
5051
e.pageX - navigationRef.current?.offsetLeft,
5152
minWidth,
@@ -68,8 +69,12 @@ function Navigation(
6869
}, [])
6970

7071
useEffect(() => {
71-
onChangeWidth(width)
72-
}, [width, onChangeWidth])
72+
onChangeWidth(currentWidth)
73+
}, [currentWidth, onChangeWidth])
74+
75+
useEffect(() => {
76+
setCurrentWidth(_.clamp(width, minWidth, maxWidth))
77+
}, [width, minWidth, maxWidth])
7378

7479
useEffect(() => {
7580
if (isDragging) {
@@ -86,7 +91,7 @@ function Navigation(
8691
ref={mergedRef}
8792
style={style}
8893
className={className}
89-
width={width}
94+
width={currentWidth}
9095
data-testid={testId}
9196
isDragging={isDragging}
9297
>

src/layout/Navigation/Navigation.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ChildrenComponentProps } from '../../types/ComponentProps'
44
export default interface NavigationProps extends Omit<ChildrenComponentProps, 'as'> {
55
title?: string
66
fixedTitle?: boolean
7+
width?: number
78
minWidth?: number
89
maxWidth?: number
910
disableResize?: boolean

0 commit comments

Comments
 (0)