-
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
DatePicker, DateRangePickerをdayjsでやりとりするようにwrap #1080
Conversation
✅ Deploy Preview for ingred-ui ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
…ngred-ui into replaceMomentToDayjs
if (!renderMonthTextProps || !dayjsize) return; | ||
return renderMonthTextProps(dayjsize); | ||
}; | ||
|
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.
SingleDatePickerはmomentなので、外側でdayjsでlocaleを設定しても影響しない。
外からdayjsのlocale設定をコンポーネントへ持ち込むことはできなかったので locale と(必要なら) weekdayShort を渡すやり方にしてみた
@takurinton 漏れてたとこ直しました〜 |
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.
どれも細かい点ですがコメントしました。
大まかなやり方は良さそう、:thx:
package.json
Outdated
@@ -26,6 +26,7 @@ | |||
}, | |||
"dependencies": { | |||
"@popperjs/core": "^2.4.0", | |||
"dayjs": "^1.11.6", |
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.
"dayjs": "^1.11.6", | |
"dayjs": "1.11.6", |
@@ -61,7 +97,13 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>( | |||
</Spacer> | |||
</Styled.NavNext> | |||
} | |||
// eslint-disable-next-line react/jsx-handler-names |
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.
// eslint-disable-next-line react/jsx-handler-names |
.vscode/settings.json
Outdated
}, | ||
"editor.defaultFormatter": "dbaeumer.vscode-eslint" |
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.
ミスですね
date, | ||
error = false, | ||
onDateChange, | ||
renderMonthText: renderMonthTextProps, |
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.
renderMonthTextProps
だと複数を指しているように見えてしまうので単数にするのが良さそうなのと、XXXProps
だと名前が関数っぽくないので何か違う名前がつけられると良さそう。
あとは、これ今の構成だとそもそも別名つけなくても良さそうに見えるのですがどうでしょう。
const handleRenderMonthText = (month: moment.Moment) => { | ||
const dayjsize = momentToDayjs(month); | ||
if (!renderMonthTextProps || !dayjsize) return; | ||
return renderMonthTextProps(dayjsize); | ||
}; |
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.
renderMonthTextProps
の有無に関わらず dayjsize
が作られてしまうので renderMonthTextProps
の存在確認と dayjsize
の null 確認は別の条件分岐で書いた方がよさそうです。
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.
nits
linter 案件ではありますが(自分の惰性が働き strict-boolean-expressions を有効にしていないのが原因です...。)、論理否定を使った falsy 判定はあまり行儀が良くない気がします。
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.
そこまで気にすることでもないので falsy に関しては任せます
@takurinton 修正いれたんで確認お願いします〜 |
package.json
Outdated
"react": "17.0.0 || 18.0.0", | ||
"react-dom": "17.0.0 || 18.0.0", |
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.
peerDependencies は変えないほうがいいです。
これだと 17.0.0 or 18.0.0 の決めうちになってしまいます。
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.
はい
onDateChange(dayjsize); | ||
}; | ||
const handleRenderMonthText = (month: moment.Moment) => { | ||
if (renderMonthText == undefined || null) return; |
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.
これだと
- renderMonthText が undefined だった場合
- 早期 return される
- renderMonthText が undefined ではなかった場合
- if (null) が評価されて falsy になるので次に処理が進む
となるはずで、一見挙動としては正しいように見えますが自分が nits レビューで指摘した falsy をなくしたいは達成できてないように見えます。
また、推測ですが renderMonthText == undefined || renderMonthText == null
を書きたかった感じですかね?
JavaScript の式で null や undefined を扱う際は厳密な比較だと null と undefined は区別する、曖昧な比較だと区別しないというようになっているので単純に
if (renderMonthText == undefined) return;
でいいように感じます。
const handleRenderMonthText = (month: moment.Moment) => { | ||
if (renderMonthText == undefined || null) return; | ||
const dayjsize = momentToDayjs(month); | ||
if (dayjsize == null) return; |
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.
momentToDayjs
の戻り値は Dayjs | null
なので厳密に比較しとくのが吉です。
Check List (If️ you added new component in this PR)
src/components/index.ts
.storybook/documents/Information/Samples/Samples.stories.tsx
ref #975