-
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
Feat i18n support for DatePicker and DateRangePicker #1398
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ingred-ui": minor | ||
--- | ||
|
||
Feat i18n support for DatePicker and DateRangePicker |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,2 @@ | ||
// for `<ScrollArea />` | ||
export const HEIGHT = "400px"; | ||
|
||
export const weekList = { | ||
en: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], | ||
ja: ["日", "月", "火", "水", "木", "金", "土"], | ||
}; | ||
|
||
export const monthList = { | ||
en: [ | ||
"Jan", | ||
"Feb", | ||
"Mar", | ||
"Apr", | ||
"May", | ||
"June", | ||
"July", | ||
"Aug", | ||
"Sept", | ||
"Oct", | ||
"Nov", | ||
"Dec", | ||
], | ||
ja: [ | ||
"1月", | ||
"2月", | ||
"3月", | ||
"4月", | ||
"5月", | ||
"6月", | ||
"7月", | ||
"8月", | ||
"9月", | ||
"10月", | ||
"11月", | ||
"12月", | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import dayjs, { Dayjs } from "dayjs"; | |
import { Icon, ScrollArea } from "../../.."; | ||
import { useTheme } from "styled-components"; | ||
import { useScrollCalendar } from "../../hooks/useScrollCalendar"; | ||
import { HEIGHT, weekList } from "../../constants"; | ||
import { HEIGHT } from "../../constants"; | ||
import { | ||
CalendarContainer, | ||
CalendarMonth, | ||
|
@@ -16,6 +16,8 @@ import { Day } from "../../Calendar/internal/Day"; | |
|
||
type Props = { | ||
date: Dayjs; | ||
monthFormat?: string; | ||
weekList?: string[]; | ||
Comment on lines
17
to
+20
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. 率直な疑問ですが、この辺のフォーマットは現状型を強く縛らない方針なのでしょうか? この辺の話で一旦リテラル型にしているのか /**
* カレンダーに表示する曜日のリスト
* @memo dayjs().format("ddd") で対応したいが、階層が深くなったりするので一旦静的な値で対処
*/ 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. ここは useLocaleProps を通じて曜日のリストを管理するための暫定的なものであり、実質ユーザーから渡される想定ではないのであまり強く縛る必要もないかなと思ってこのようにしてます! たしかに英語と日本語くらいしか対応するつもりもないので言われてみたら縛ってもいいかな?と思ったのですが、一旦このままでも良いかなとも思います。 |
||
current: Dayjs; | ||
yearIsOpen: boolean; | ||
onYearIsOpen: (yearIsOpen: boolean) => void; | ||
|
@@ -24,6 +26,8 @@ type Props = { | |
}; | ||
export const InnerCalendar: React.FC<Props> = ({ | ||
date, | ||
weekList, | ||
monthFormat, | ||
current, | ||
yearIsOpen, | ||
onYearIsOpen, | ||
|
@@ -51,7 +55,7 @@ export const InnerCalendar: React.FC<Props> = ({ | |
{/* 年月の表示 */} | ||
<CalendarMonth expanded={yearIsOpen}> | ||
<TitleContainer expanded={yearIsOpen} weight="bold" size="xl"> | ||
{m.format("YYYY年MM月")} | ||
{m.format(monthFormat)} | ||
</TitleContainer> | ||
<IconButton | ||
expanded={yearIsOpen} | ||
|
@@ -68,9 +72,7 @@ export const InnerCalendar: React.FC<Props> = ({ | |
{/* カレンダーの表示 */} | ||
<CalendarContainer> | ||
{/* 曜日の表示 */} | ||
{weekList["ja"].map((week) => ( | ||
<DayStyle key={week}>{week}</DayStyle> | ||
))} | ||
{weekList?.map((week) => <DayStyle key={week}>{week}</DayStyle>)} | ||
|
||
{/* 開始曜日まで空白をセット */} | ||
{Array.from(new Array(m.startOf("month").day()), (_, i) => ( | ||
|
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 から受け取るようにした。
dayjs を使えば指定した locale で曜日を取得することもできるけど、階層が深くなることでどこで何を扱っているかが不明瞭になったりするので、一旦 props 経由で受け取り上から流すだけの構成にする。
この PR では対応しないだけで、後でいい構成に変更するかも。