Skip to content

Commit

Permalink
Fix types (#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
takurinton committed Aug 22, 2023
1 parent c6edba5 commit c25dcbe
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-kings-walk.md
@@ -0,0 +1,5 @@
---
"ingred-ui": patch
---

fix types
10 changes: 10 additions & 0 deletions src/components/Calendar/Calendar/Calendar.tsx
Expand Up @@ -15,7 +15,14 @@ import { useScroll } from "../hooks/useScroll";
import { Action, Actions } from "../internal/Actions";

export type CalendarProps = React.HTMLAttributes<HTMLDivElement> & {
/**
* 日付
* @default dayjs()
*/
date: Dayjs;
/**
* カレンダーの左に表示するアクション
*/
actions?: Action[];
/**
* 閉じるボタンを押したときの振る舞い
Expand All @@ -28,6 +35,9 @@ export type CalendarProps = React.HTMLAttributes<HTMLDivElement> & {
* @default () => false
*/
isOutsideRange?: (date: Dayjs) => boolean;
/**
* 日付が変更されたときに呼ばれる関数
*/
onDateChange: (value: Dayjs) => void;
};

Expand Down
20 changes: 17 additions & 3 deletions src/components/Calendar/CalendarRange/CalendarRange.tsx
@@ -1,5 +1,5 @@
import dayjs, { Dayjs } from "dayjs";
import { Card, Icon, ScrollArea, Typography } from "../..";
import { Card, Icon, ScrollArea, Typography, DateRange } from "../..";
import React, { forwardRef, memo, useCallback, useRef, useState } from "react";
import { Day } from "./internal/Day";
import { HEIGHT, weekList } from "../constants";
Expand All @@ -15,11 +15,21 @@ import { useScroll } from "../hooks/useScroll";
import { getDayState } from "./utils";
import { Action, Actions } from "../internal/Actions";
import { ClickState, ClickStateType } from "./constants";
import { DateRange } from "./types";

export type CalendarRangeProps = React.HTMLAttributes<HTMLDivElement> & {
/**
* 開始日
* @default dayjs()
*/
startDate: Dayjs;
/**
* 終了日
* @default dayjs()
*/
endDate: Dayjs;
/**
* カレンダーの左に表示するアクション
*/
actions?: Action[];
/**
* 親コンポーネントで calendar を任意のタイミングで閉じたい場合に使用する
Expand All @@ -36,7 +46,10 @@ export type CalendarRangeProps = React.HTMLAttributes<HTMLDivElement> & {
* @default () => false
*/
isOutsideRange?: (date: Dayjs) => boolean;
onDatesChange: ({ startDate, endDate }: DateRange) => void;
/**
* 日付が変更されたときに呼ばれる関数
*/
onDatesChange: (dates: DateRange) => void;
};

/**
Expand Down Expand Up @@ -162,4 +175,5 @@ export const CalendarRange = forwardRef<HTMLDivElement, CalendarRangeProps>(
},
);

export type { DateRange };
export default memo(CalendarRange);
2 changes: 1 addition & 1 deletion src/components/Calendar/CalendarRange/index.ts
@@ -1,2 +1,2 @@
export { default } from "./CalendarRange";
export type { CalendarRangeProps } from "./CalendarRange";
export type { CalendarRangeProps, DateRange } from "./CalendarRange";
6 changes: 0 additions & 6 deletions src/components/Calendar/CalendarRange/types.ts

This file was deleted.

33 changes: 31 additions & 2 deletions src/components/DateField/DateField/DateField.tsx
Expand Up @@ -3,7 +3,37 @@ import { ErrorText, Icon, Input, Spacer } from "../..";
import { useDateField } from "../useDateField";
import { useMergeRefs } from "../../../hooks/useMergeRefs";
import { CalendarIcon, InputContainer } from "./styled";
import { DateFieldProps } from "../types";
import { Dayjs } from "dayjs";

export type DateFieldProps = {
/**
* 日付
* @default dayjs()
*/
date: Dayjs;
/**
* 指定したい format
* @default YYYY-MM-DD
*/
format?: string;
/**
* エラーメッセージのテキスト
*/
errorText?: string;
/**
* 入力を無効にする
* @default false
*/
disabled?: boolean;
/**
* 日付が変更されたときに呼ばれる関数
*/
onDateChange?: (date: Dayjs) => void;
/**
* カレンダーアイコンをクリックした時に呼ばれる関数
*/
onClick: () => void;
};

const DateField = forwardRef<HTMLInputElement, DateFieldProps>(
function DateField(
Expand Down Expand Up @@ -38,5 +68,4 @@ const DateField = forwardRef<HTMLInputElement, DateFieldProps>(
},
);

export type { DateFieldProps } from "../types";
export default memo(DateField);
28 changes: 20 additions & 8 deletions src/components/DateField/DateRangeField/DateRangeField.tsx
@@ -1,5 +1,5 @@
import React, { forwardRef, memo, useMemo } from "react";
import { ErrorText, Icon, Input, Spacer } from "../..";
import { ErrorText, Icon, Input, Spacer, DateRange } from "../..";
import { useMergeRefs } from "../../../hooks/useMergeRefs";
import { CalendarIcon, InputContainer } from "./styled";
import { Dayjs } from "dayjs";
Expand All @@ -9,22 +9,34 @@ import {
ClickStateType,
} from "../../Calendar/CalendarRange/constants";

type Range = {
startDate: Dayjs;
endDate: Dayjs;
};

export type DateRangeFieldProps = {
date: Range;
/**
* 日付
* @default { startDate: dayjs(), endDate: dayjs() }
*/
date: DateRange;
/**
* 指定したい format
* @default YYYY-MM-DD
*/
format?: string;
/**
* エラーメッセージのテキスト
*/
errorText?: string;
/**
* 入力を無効にする
* @default false
*/
disabled?: boolean;
/**
* カレンダーアイコンをクリックした時に呼ばれる関数
*/
onClickCalendarIcon?: () => void;
onDatesChange?: (date: Range) => void;
/**
* 日付が変更されたときに呼ばれる関数
*/
onDatesChange?: (date: DateRange) => void;
};

const DateRangeField = forwardRef<HTMLInputElement, DateRangeFieldProps>(
Expand Down
32 changes: 1 addition & 31 deletions src/components/DateField/types.ts
@@ -1,34 +1,4 @@
import { Dayjs } from "dayjs";

export type DateFieldProps = {
/**
* 日付
* @default dayjs()
*/
date: Dayjs;
/**
* 指定したい format
* @default YYYY-MM-DD
*/
format?: string;
/**
* エラーメッセージのテキスト
*/
errorText?: string;
/**
* 入力を無効にする
* @default false
*/
disabled?: boolean;
/**
* 日付が変更されたときに呼ばれる関数
*/
onDateChange?: (date: Dayjs) => void;
/**
* カレンダーアイコンをクリックした時に呼ばれる関数
*/
onClick: () => void;
};
import { DateFieldProps } from "./DateField/DateField";

export type UseDateFieldProps = Omit<DateFieldProps, "onClick">;

Expand Down
21 changes: 21 additions & 0 deletions src/components/NewDatePicker/NewDatePicker.tsx
Expand Up @@ -12,17 +12,38 @@ import {
} from "@floating-ui/react";

export type NewDatePickerProps = {
/**
* 日付
* @default dayjs()
*/
date: Dayjs;
/**
* カレンダーの左に表示するアクション
*/
actions?: Action[];
/**
* 指定したい format
* @default YYYY-MM-DD
*/
format?: string;
/**
* エラーメッセージのテキスト
*/
errorText?: string;
/**
* 入力を無効にする
* @default false
*/
disabled?: boolean;
/**
* 選択可能なカレンダーの領域を制限する
* true が返る場合は、選択不可となる
* @default () => false
*/
isOutsideRange?: (date: Dayjs) => boolean;
/**
* 日付が変更されたときに呼ばれる関数
*/
onDateChange: (date: Dayjs) => void;
};

Expand Down
29 changes: 27 additions & 2 deletions src/components/NewDateRangePicker/NewDateRangePicker.tsx
Expand Up @@ -15,21 +15,46 @@ import {
ClickState,
ClickStateType,
} from "../Calendar/CalendarRange/constants";
import { DateRange } from "../Calendar/CalendarRange/types";

export type DateRange = {
startDate: Dayjs;
endDate: Dayjs;
};

export type NewDateRangePickerProps = {
/**
* 開始日
* @default dayjs()
*/
startDate: Dayjs;
/**
* 終了日
* @default dayjs()
*/
endDate: Dayjs;
/**
* エラーメッセージのテキスト
*/
errorText?: string;
/**
* カレンダーの左に表示するアクション
*/
actions?: Action[];
/**
* 入力を無効にする
* @default false
*/
disabled?: boolean;
/**
* 選択可能なカレンダーの領域を制限する
* true が返る場合は、選択不可となる
* @default () => false
*/
isOutsideRange?: (date: Dayjs) => boolean;
onDatesChange: (date: DateRange) => void;
/**
* 日付が変更されたときに呼ばれる関数
*/
onDatesChange: (dates: DateRange) => void;
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/components/NewDateRangePicker/index.ts
@@ -1 +1,2 @@
export { default } from "./NewDateRangePicker";
export type { NewDateRangePickerProps, DateRange } from "./NewDateRangePicker";

0 comments on commit c25dcbe

Please sign in to comment.