Skip to content
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

chore: InformationPanelの内部ロジックをリファクタリングする #5289

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

AtsushiM
Copy link
Member

関連URL

概要

変更内容

確認方法

@yagimushi yagimushi force-pushed the chore-refactoring-InformationPanel branch from 7692615 to 19857fc Compare January 16, 2025 00:39
Copy link

pkg-pr-new bot commented Jan 16, 2025

Open in Stackblitz

npm i https://pkg.pr.new/kufu/smarthr-ui@5289

commit: e1a7585

@yagimushi yagimushi force-pushed the chore-refactoring-InformationPanel branch from 19857fc to e1a7585 Compare January 16, 2025 00:43
title,
titleTag,
type = 'info',
togglable = false,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

比較にしか利用されていないため、初期値代入をする必要がありませんでした

Comment on lines -121 to -127
const handleClickTrigger = useCallback(() => {
if (onClickTrigger) {
onClickTrigger(active)
} else {
setActive(!active)
}
}, [active, onClickTrigger])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TogglableButton内に移動しています

Comment on lines +135 to +165
const styles = useMemo(() => {
const withActive = informationPanel({
type,
active: true,
bold,
})
const withInactive = informationPanel({
type,
active: false,
bold,
})

const wrapperProps = { className }

return {
active: {
wrapper: withActive.wrapper(wrapperProps),
header: withActive.header(),
heading: withActive.heading(),
togglableButton: withActive.togglableButton(),
content: withActive.content(),
},
inactive: {
wrapper: withInactive.wrapper(wrapperProps),
header: withInactive.header(),
heading: withInactive.heading(),
togglableButton: withInactive.togglableButton(),
content: withInactive.content(),
},
}
}, [bold, type, className])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再生成する必要がないよう、active, inactiveのパターン両方を事前に生成しています

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

またコンポーネントを分割する関係上、関数を渡すよりstringを渡すほうがmemo化が適切に動作する可能性が高いためこのようなロジックにしています

Comment on lines +173 to +175
<MemoizedHeading tag={titleTag} id={titleId} className={currentStyles.heading} type={type}>
{title}
</MemoizedHeading>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Headingは再生成が必要になるパターンが少ないことが予想されるため、丸ごとmemo化しています

suffix={active ? <FaCaretUpIcon /> : <FaCaretDownIcon />}
size="s"
onClick={handleClickTrigger}
aria-expanded={active}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もともとはtogglableのようなロジックでundefinedが設定される可能性がありましたが、このボタンが表示されている場合、togglableがfalsyになる場合はありえないため、調整しています

@AtsushiM AtsushiM marked this pull request as ready for review January 16, 2025 00:51
@AtsushiM AtsushiM requested a review from a team as a code owner January 16, 2025 00:51
@AtsushiM AtsushiM requested review from oti and uknmr and removed request for a team January 16, 2025 00:51
@oti oti requested review from Qs-F and removed request for oti January 16, 2025 03:14
@oti
Copy link
Contributor

oti commented Jan 16, 2025

@Qs-F レビューできる自信なく…レビュワー差し替えました🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants