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

DatePicker, DateRangePickerをdayjsでやりとりするようにwrap #1080

Merged
merged 19 commits into from
Nov 11, 2022

Conversation

maktak1995
Copy link
Contributor

Check List (If️ you added new component in this PR)

  • Export the component in src/components/index.ts
  • Add example to .storybook/documents/Information/Samples/Samples.stories.tsx
  • Localize added component

ref #975

@maktak1995 maktak1995 self-assigned this Oct 31, 2022
@netlify
Copy link

netlify bot commented Oct 31, 2022

Deploy Preview for ingred-ui ready!

Name Link
🔨 Latest commit 95dbf97
🔍 Latest deploy log https://app.netlify.com/sites/ingred-ui/deploys/636e134e2b70de000a64b12e
😎 Deploy Preview https://deploy-preview-1080--ingred-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

if (!renderMonthTextProps || !dayjsize) return;
return renderMonthTextProps(dayjsize);
};

Copy link
Contributor Author

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 を渡すやり方にしてみた

@maktak1995 maktak1995 marked this pull request as ready for review November 10, 2022 07:47
@takurinton
Copy link
Contributor

漏れがありそうです
https://github.com/voyagegroup/ingred-ui/blob/master/src/components/LocaleProvider/LocaleProvider.stories.tsx#L173

@maktak1995
Copy link
Contributor Author

@takurinton 漏れてたとこ直しました〜

Copy link
Contributor

@takurinton takurinton left a 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",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// eslint-disable-next-line react/jsx-handler-names

Comment on lines 7 to 8
},
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
Copy link
Contributor

Choose a reason for hiding this comment

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

この差分はミスってるだけですかね?

Copy link
Contributor Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

renderMonthTextProps だと複数を指しているように見えてしまうので単数にするのが良さそうなのと、XXXProps だと名前が関数っぽくないので何か違う名前がつけられると良さそう。
あとは、これ今の構成だとそもそも別名つけなくても良さそうに見えるのですがどうでしょう。

Comment on lines 62 to 66
const handleRenderMonthText = (month: moment.Moment) => {
const dayjsize = momentToDayjs(month);
if (!renderMonthTextProps || !dayjsize) return;
return renderMonthTextProps(dayjsize);
};
Copy link
Contributor

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 確認は別の条件分岐で書いた方がよさそうです。

Copy link
Contributor

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 判定はあまり行儀が良くない気がします。

Copy link
Contributor

Choose a reason for hiding this comment

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

そこまで気にすることでもないので falsy に関しては任せます

@maktak1995
Copy link
Contributor Author

@takurinton 修正いれたんで確認お願いします〜

package.json Outdated
Comment on lines 37 to 38
"react": "17.0.0 || 18.0.0",
"react-dom": "17.0.0 || 18.0.0",
Copy link
Contributor

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 の決めうちになってしまいます。

Copy link
Contributor Author

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;
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

momentToDayjs の戻り値は Dayjs | null なので厳密に比較しとくのが吉です。

maktak1995 added 2 commits November 11, 2022 18:08
@maktak1995 maktak1995 merged commit e6c42f3 into master Nov 11, 2022
@maktak1995 maktak1995 deleted the replaceMomentToDayjs branch November 11, 2022 09:25
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