-
Notifications
You must be signed in to change notification settings - Fork 148
fix(ModelessDialog): title propsがReactNodeを受け取れるように修正 #5907
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| 'use client' | ||
|
|
||
| import { | ||
| type ComponentProps, | ||
| type ComponentPropsWithoutRef, | ||
| type FC, | ||
| type KeyboardEvent, | ||
| type MouseEvent, | ||
|
|
@@ -22,7 +22,7 @@ import { type VariantProps, tv } from 'tailwind-variants' | |
| import { useHandleEscape } from '../../../hooks/useHandleEscape' | ||
| import { useIntl } from '../../../intl' | ||
| import { dialogSize } from '../../../themes/tailwind' | ||
| import { Base, type BaseElementProps } from '../../Base' | ||
| import { Base } from '../../Base' | ||
| import { Button } from '../../Button' | ||
| import { Heading } from '../../Heading' | ||
| import { FaGripIcon, FaXmarkIcon } from '../../Icon' | ||
|
|
@@ -31,6 +31,7 @@ import { DialogOverlap } from '../DialogOverlap' | |
| import { useDialogPortal } from '../useDialogPortal' | ||
|
|
||
| import type { DecoratorsType } from '../../../hooks/useDecorators' | ||
| import type { PropsWithHTMLAttributes } from '../../../types/ComponentTypes' | ||
| import type { DialogSize } from '../types' | ||
|
|
||
| type Props = PropsWithChildren<{ | ||
|
|
@@ -135,9 +136,12 @@ const classNameGenerator = tv({ | |
| }, | ||
| }) | ||
|
|
||
| export const ModelessDialog: FC< | ||
| Props & BaseElementProps & VariantProps<typeof classNameGenerator> | ||
| > = ({ | ||
| type ComponentProps = PropsWithHTMLAttributes< | ||
| Props & VariantProps<typeof classNameGenerator>, | ||
| 'div' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. もともとはBaseElementProps (HTMLDivElementのAttributesからBaseのPropsをOmitしたもの) を設定していたが、
ため、'div' を直接使用しています。 |
||
| > | ||
|
|
||
| export const ModelessDialog: FC<ComponentProps> = ({ | ||
| title, | ||
| children, | ||
| contentBgColor, | ||
|
|
@@ -193,7 +197,7 @@ export const ModelessDialog: FC< | |
| y: 0, | ||
| }) | ||
| const [draggableBounds, setDraggableBounds] = | ||
| useState<ComponentProps<typeof Draggable>['bounds']>() | ||
| useState<ComponentPropsWithoutRef<typeof Draggable>['bounds']>() | ||
|
|
||
| const decoratorDefaultTexts = useMemo( | ||
| () => ({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,10 @@ | ||||||
| import type { ComponentPropsWithRef, ElementType } from 'react' | ||||||
| import type { ComponentPropsWithRef, ComponentPropsWithoutRef, ElementType, FC } from 'react' | ||||||
|
|
||||||
| export type ElementRef<T extends ElementType> = ComponentPropsWithRef<T>['ref'] | ||||||
|
|
||||||
| export type ElementRefProps<T extends ElementType> = { ref?: ElementRef<T> } | ||||||
|
|
||||||
| export type PropsWithHTMLAttributes< | ||||||
| Props extends Parameters<FC>[0], | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| E extends ElementType, | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. いい感じの被らない型パラメーター名が思いつかなかったので… |
||||||
| > = Props & Omit<ComponentPropsWithoutRef<E>, 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.
React の ComponentProps と見間違うかも。
FC<>に直接書いちゃうかModelessDialogPropsとするかかと思いました。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.
reactのComponentProps型はrefを受け取れるかどうか明確ではないため事故の原因になりやすく、慣習的に基本的に使わないべきはずです!あとここはrefを受け取ることが明確ではないため、やるならModelessDialogPropsWithoutRefになりますが、ほかのコンポーネントでも同様の書き方のパターンが出てくるのでComponentPropsが1番良いのではと思っての判断でした
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を FC に渡してることが一番多い気がします。ModelessDialog の Props の名前を変えて、ここを Props とする手もありそうです。
React の ComponentProps 型を使わないのはわかるけど、
FC<ComponentProps>だけ見るとうーんってなりました。