-
Notifications
You must be signed in to change notification settings - Fork 10
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
<Button />微調整 #28
<Button />微調整 #28
Conversation
youchann
commented
May 18, 2020
- aタグとしても機能するように
- box-shadowを調整
src/components/Button/Button.tsx
Outdated
as={href ? "a" : "button"} | ||
href={href} | ||
{...(href ? {} : rest)} |
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.
aタグにすると...rest
は入れないようにしています。(型がうまく通らない...)
なんかもっと良い方法ありそうなきが...
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.
next.jsのコードなのでちょっと違うけどinlineじゃなくて先に定義した方がいいと思う!
const isLink = href != null
let props: any
if (isLink && disabled) {
props = { "aria-disabled": disabled }
} else if (isLink) {
props = { href }
} else {
props = { type, disabled }
}
return isLink ? (
<Link href={href!} passHref>
<StyledBaseButton {...props} {...rest} />
</Link>
) : (
<StyledBaseButton {...props} {...rest} />
)
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.
あ、prop先に定義します!!
aタグで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.
あ、そこがnextっぽいところ
ingred-uiではasで大丈夫!
src/components/Button/Button.tsx
Outdated
const restProps = href ? {} : rest; | ||
|
||
return ( | ||
<Styled.ButtonContainer | ||
as={href ? "a" : "button"} | ||
href={href} | ||
{...(href ? {} : rest)} | ||
{...restProps} |
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.
@kinokoruumu
rest
に関しては先に定義しました。
書いてて思ったのですが、以前のcommentで言っていたことはこのような書き方ではなく「props全体を先に定義させる」みたいな意図でしたかね...?
src/components/Button/Button.tsx
Outdated
let props: Styled.ContainerProps & { as?: "a" | "button" } = { | ||
inline, | ||
horizontalPadding: size === "small" ? `10px` : `${theme.spacing * 2}px`, | ||
normal: { ...colorStyle.normal }, | ||
hover: { ...colorStyle.hover }, | ||
active: { ...colorStyle.active }, | ||
fontWeight: color === "cancel" ? "normal" : "bold", | ||
fontSize: size === "small" ? `${fontSize["xs"]}px` : `${fontSize["md"]}px`, | ||
height: buttonSize[size].height, | ||
minWidth: buttonSize[size].minWidth, | ||
} | ||
|
||
if (isLink) { | ||
props.as = "a"; | ||
props.href = href; | ||
} |
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.
@kinokoruumu
href
が存在するときだけ、as
とhref
をpropsに入れるようにしました!!
src/components/Button/Button.tsx
Outdated
size === "small" ? `10px` : `${theme.spacing * 2}px`; | ||
const isLink = !!href; | ||
|
||
let props: Styled.ContainerProps & { as?: "a" | "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.
asに"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.
デフォルトが`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.
それなら型定義にもなくていいんじゃないかな?
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.
BaseButton = styled.button
なのでas
をpropsに含めない場合は勝手に<button />
タグになるという意味での
デフォルトが`button
でした!!
& { as?: "a" | "button" }
の部分を消してしまうと、�props.as = "a";
の部分で型エラーになってしまいます。
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.
そうそう
さっきのvcはそれを見越してのpropsはanyでもいいよ〜だったw
で、今のはasにbuttonを入れることがないのであれば | "button"
が不要なのでは?という意味だったw
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.
なんと...w:bow:
let props: any
にして、as
の型定義を外しました!!
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.
ごめん、なんども往復して申し訳ないんだけど、
let propsはhrefとasだけでいいと思う
ContainerPropsの内容も含めたいのであれば量が多いので型定義はあった方がいいかと
曖昧でごめん。。
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.
d991892
こんな感じの実装でどうでしょう!?
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.
LGTMです!