Skip to content

Commit

Permalink
Rename useScroll to useScrollCalendar (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
takurinton committed Aug 23, 2023
1 parent e69e7c9 commit 88a9b1f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-points-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ingred-ui": patch
---

rename `useScroll` to `useScrollCalendar`
4 changes: 2 additions & 2 deletions src/components/Calendar/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
CalendarMonth,
IconContainer,
} from "../styled";
import { useScroll } from "../hooks/useScroll";
import { useScrollCalendar } from "../hooks/useScrollCalendar";
import { Action, Actions } from "../internal/Actions";

export type CalendarProps = React.HTMLAttributes<HTMLDivElement> & {
Expand Down Expand Up @@ -53,7 +53,7 @@ const Calendar = forwardRef<HTMLDivElement, CalendarProps>(function Calendar(
ref,
) {
const scrollRef = useRef<HTMLDivElement>(null);
const { monthList } = useScroll(date, scrollRef);
const { monthList } = useScrollCalendar(date, scrollRef);

return (
<Card ref={ref} display="flex" style={{ width: "fit-content" }} {...rest}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Calendar/CalendarRange/CalendarRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
DayStyle,
IconContainer,
} from "../styled";
import { useScroll } from "../hooks/useScroll";
import { useScrollCalendar } from "../hooks/useScrollCalendar";
import { getDayState } from "./utils";
import { Action, Actions } from "../internal/Actions";
import { ClickState, ClickStateType } from "./constants";
Expand Down Expand Up @@ -72,7 +72,7 @@ export const CalendarRange = forwardRef<HTMLDivElement, CalendarRangeProps>(
ref,
) {
const scrollRef = useRef<HTMLDivElement>(null);
const { monthList } = useScroll(startDate ?? dayjs(), scrollRef);
const { monthList } = useScrollCalendar(startDate ?? dayjs(), scrollRef);
const [clickState, setClickState] = useState<ClickStateType>(
ClickState.START,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { renderHook, act } from "@testing-library/react";
import dayjs, { Dayjs } from "dayjs";
import { useScroll, getNextMonthList, getPrevMonthList } from "../useScroll";
import {
useScrollCalendar,
getNextMonthList,
getPrevMonthList,
} from "../useScrollCalendar";

(global as any).IntersectionObserver = jest.fn().mockImplementation(() => ({
observe: () => jest.fn(),
Expand All @@ -18,7 +22,7 @@ describe("useScroll hook", () => {
});

test("loads next six months when reaching the bottom 10% of ScrollArea", () => {
const { result } = renderHook(() => useScroll(date, ref));
const { result } = renderHook(() => useScrollCalendar(date, ref));

act(() => {
// const targets = document.getElementsByClassName(date.format("YYYY-MM"));
Expand All @@ -33,7 +37,7 @@ describe("useScroll hook", () => {
});

test("loads previous six months when reaching the top 10% of ScrollArea", () => {
const { result } = renderHook(() => useScroll(date, ref));
const { result } = renderHook(() => useScrollCalendar(date, ref));

act(() => {
// const targets = document.getElementsByClassName(date.format("YYYY-MM"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getPrevMonthList = (date: Dayjs) =>
* @param ref カレンダーの親要素のref、IntersectionObserverのrootに使う
* @return monthList 表示する月のリスト
*/
export const useScroll = (
export const useScrollCalendar = (
date: Dayjs,
ref: React.RefObject<HTMLDivElement>,
) => {
Expand Down

0 comments on commit 88a9b1f

Please sign in to comment.