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: MessageDialogの内部ロジックを整理する #5320

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ export const MessageDialogContent: React.FC<Props & ElementProps> = ({
const { createPortal } = useDialogPortal(portalParent)

const handleClickClose = useCallback(() => {
if (!active) {
return
if (active) {
onClickClose()
}
onClickClose()
Comment on lines -27 to -30
Copy link
Member Author

Choose a reason for hiding this comment

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

早期returnに意味があるほど複雑なロジックではなく、逆に分かりづらいのでifの条件を整えています

}, [active, onClickClose])
const titleId = useId()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { type FC } from 'react'
import React, { type FC, useMemo } from 'react'

import { Button } from '../../Button'
import { Cluster, Stack } from '../../Layout'
import { Cluster } from '../../Layout'
import { Section } from '../../SectioningContent'
import { DialogBody, Props as DialogBodyProps } from '../DialogBody'
import { DialogHeader, Props as DialogHeaderProps } from '../DialogHeader'
import { dialogContentInner } from '../dialogInnerStyle'
Expand Down Expand Up @@ -33,20 +34,44 @@ export const MessageDialogContentInner: FC<MessageDialogContentInnerProps> = ({
onClickClose,
decorators,
}) => {
const { wrapper, actionArea } = dialogContentInner()
const styles = useMemo(() => {
const { wrapper, actionArea } = dialogContentInner()

return {
wrapper: wrapper(),
actionArea: actionArea(),
}
}, [])

return (
// eslint-disable-next-line smarthr/best-practice-for-layouts, smarthr/a11y-heading-in-sectioning-content
<Stack gap={0} as="section" className={wrapper()}>
// eslint-disable-next-line smarthr/a11y-heading-in-sectioning-content
Copy link
Member Author

Choose a reason for hiding this comment

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

<Stack gap={0} as="section"> は実質 <Section> と同義であり、余計な内部ロジックが実行されるだけだったので置き換えています

<Section className={styles.wrapper}>
<DialogHeader title={title} subtitle={subtitle} titleTag={titleTag} titleId={titleId} />
<DialogBody contentPadding={contentPadding} contentBgColor={contentBgColor}>
{description}
</DialogBody>
<Cluster as="footer" justify="flex-end" className={actionArea()}>
<Button onClick={onClickClose} className="smarthr-ui-Dialog-closeButton">
{decorators?.closeButtonLabel?.(CLOSE_BUTTON_LABEL) || CLOSE_BUTTON_LABEL}
</Button>
</Cluster>
</Stack>
<FooterCluster
onClickClose={onClickClose}
decorators={decorators}
className={styles.actionArea}
/>
</Section>
)
}

const FooterCluster = React.memo<
Pick<MessageDialogContentInnerProps, 'onClickClose' | 'decorators'> & { className: string }
>(({ onClickClose, decorators, className }) => {
const children = useMemo(
() => decorators?.closeButtonLabel?.(CLOSE_BUTTON_LABEL) || CLOSE_BUTTON_LABEL,
[decorators],
)

return (
<Cluster as="footer" justify="flex-end" className={className}>
<Button onClick={onClickClose} className="smarthr-ui-Dialog-closeButton">
{children}
</Button>
</Cluster>
)
})
Loading