-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(SideNav): Composition できるように修正 #5157
base: master
Are you sure you want to change the base?
Conversation
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
諸々コメントしましたが、items を deprecated し、SideNav と SideNavItem という composition で使う状態にしてから Story を書いたほうが良さそうに思いました(書き直しになってしまいそう)。
packages/smarthr-ui/src/components/SideNav/stories/SideNav.stories.tsx
Outdated
Show resolved
Hide resolved
packages/smarthr-ui/src/components/SideNav/stories/SideNav.stories.tsx
Outdated
Show resolved
Hide resolved
packages/smarthr-ui/src/components/SideNav/stories/SideNav.stories.tsx
Outdated
Show resolved
Hide resolved
packages/smarthr-ui/src/components/SideNav/stories/SideNav.stories.tsx
Outdated
Show resolved
Hide resolved
packages/smarthr-ui/src/components/SideNav/stories/SideNav.stories.tsx
Outdated
Show resolved
Hide resolved
packages/smarthr-ui/src/components/SideNav/stories/SideNav.stories.tsx
Outdated
Show resolved
Hide resolved
packages/smarthr-ui/src/components/SideNav/stories/VRTSideNav.stories.tsx
Outdated
Show resolved
Hide resolved
packages/smarthr-ui/src/components/SideNav/stories/VRTSideNav.stories.tsx
Outdated
Show resolved
Hide resolved
@uknmr |
React.cloneElement( | ||
child as React.ReactElement<ComponentPropsWithoutRef<typeof SideNavItemButton>>, | ||
{ | ||
onClick, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo: Composition pattern の場合、SideNavItemButton に onClick を個別で渡せるので、onClick や id の仕組みを見直しても良さそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idについていい仕組みを思いつかなかったんですが
SideNav
の onClick
も持たせつつだとcontext
とか使うイメージですかね?
export const SideNavItemButton: FC<Props & ElementProps> = ({
id,
onClick,
isSelected = false,
children,
}) => {
const context = useContext(SideNavContext)
const handleClick = onClick ?? context?.onClick
? (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) =>
(onClick ?? context?.onClick)?.(e, id)
: undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppNavi や SideMenu と同じような扱いで、管理はプロダクト側でやるでも良いのではと思いました!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
propsにonClickがある場合はそちらを優先するようにしてみました
18492f4
@@ -22,9 +24,11 @@ type Props = { | |||
onClick?: OnClick | |||
} | |||
|
|||
type ElementProps = Omit<ComponentPropsWithoutRef<'li'>, keyof Props> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SideNavItemButton という名前を持っているのに li
なのが気になる(上述の SideNav の方で組み立てれば解決しそう)
export const OnClick: StoryObj<typeof SideNav> = { | ||
args: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
漏れ
export const OnClick: StoryObj<typeof SideNav> = { | |
args: { | |
export const OnClick: StoryObj<typeof SideNav> = { | |
name: 'onClick', | |
args: { |
export const ClassName = { | ||
args: { | ||
className: 'shr-bg-white', | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ElementProps で型として定義されたので、Props からは消し & Story からも消しでよさそう。
export const ClassName = { | |
args: { | |
className: 'shr-bg-white', | |
}, | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
classname消しました!
}, | ||
}, | ||
args: { | ||
items: _sideItems.notSelected, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
効いてなさそう(消してもよさそう
args: { | ||
items: _sideItems.notSelected, | ||
}, | ||
render: (args) => <SideNav items={args.items} />, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo: items より SideNavItemButton の Story に見えるので、items={_items}
とする Story でもよさそうです。
(default の render で items ?? _items.map((item) => <SIdeNavItemButton />)
とするイメージ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修正しました!
argTypes: { | ||
items: { | ||
control: 'radio', | ||
options: Object.keys(_sideItems), | ||
mapping: _sideItems, | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この Story 以外で items の「Set object」を押すとエラーがでてしまうので、default に記述したい。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultではitemのControlはfalseにして
itemsのstoryのみobjectとしました
objectいじるとエラーにはなるけど他もそうなので 🤔
parameters: { | ||
chromatic: { disableSnapshot: true }, | ||
}, | ||
tags: ['skip-test-runner'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: li
で怒られる?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<ul>
をrenderに追加して対応
hover: ['li'], | ||
focusVisible: ['button'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hover と focusVisible が同時に発火してしまっているので分けたいです。
AppNavi などを見ると 1Story の中で分けるイメージがつかめるかも。 https://github.com/kufu/smarthr-ui/blob/master/packages/smarthr-ui/src/components/AppNavi/stories/VRTAppNavi.stories.tsx#L18
関連URL
https://smarthr.atlassian.net/browse/SHRUI-1143
概要
SideNavのstoryの見直しをしました。
変更内容
確認方法
Chromaticで確認