-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
2,225 additions
and
189 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
20 changes: 20 additions & 0 deletions
20
src/第6章_Tailwind_CSSでコンポーネントを設計する/src/components/framer-motion/AnimatedList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, { useEffect } from "react"; | ||
import { useAnimate } from "framer-motion"; | ||
import { animate } from "framer-motion/dom"; | ||
|
||
export function AnimatedList({ children }: React.PropsWithChildren) { | ||
const [scope, animate] = useAnimate(); | ||
|
||
useEffect(() => { | ||
animate("li", { opacity: 1 }, { duration: 1 }); | ||
}); | ||
|
||
return <ul ref={scope}>{children}</ul>; | ||
} | ||
|
||
export function fadeout() { | ||
const box = document.getElementById("box"); | ||
if (box) { | ||
animate(box, { opacity: 0 }, { duration: 0.5 }); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/第6章_Tailwind_CSSでコンポーネントを設計する/src/components/headlessui/MyDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useState, useCallback } from "react"; | ||
import classNames from "classnames"; | ||
import { Dialog } from "@headlessui/react"; | ||
|
||
interface Props { | ||
title: string; | ||
description: string; | ||
okLabel?: string; | ||
cancelLabel?: string; | ||
} | ||
|
||
export function MyDialog({ | ||
title, | ||
description, | ||
okLabel = "OK", | ||
cancelLabel = "キャンセル", | ||
}: Props) { | ||
const [isOpen, setIsOpen] = useState(true); | ||
const onClose = useCallback(() => setIsOpen(false), []); | ||
|
||
return ( | ||
<Dialog | ||
open={isOpen} | ||
onClose={onClose} | ||
className={classNames("relative", "z-50")} | ||
> | ||
{/* 背景(バックドロップ) */} | ||
<div className="fixed inset-0 bg-black/30" aria-hidden="true" /> | ||
|
||
{/* モーダル本体部分 */} | ||
<div | ||
className={classNames( | ||
"fixed", | ||
"inset-0", | ||
"flex", | ||
"items-center", | ||
"justify-center", | ||
"p-4", | ||
)} | ||
> | ||
<Dialog.Panel | ||
className={classNames( | ||
"w-full", | ||
"max-w-sm", | ||
"rounded", | ||
"bg-white", | ||
"p-6", | ||
)} | ||
> | ||
<Dialog.Title className="font-bold">{title}</Dialog.Title> | ||
<Dialog.Description>{description}</Dialog.Description> | ||
|
||
<div className="space-x-2 mt-3"> | ||
<button | ||
className="bg-blue-500 text-white py-2 px-3 rounded-md" | ||
onClick={onClose} | ||
> | ||
{okLabel} | ||
</button> | ||
<button | ||
className="bg-gray-200 text-gray-500 py-2 px-3 rounded-md" | ||
onClick={onClose} | ||
> | ||
{cancelLabel} | ||
</button> | ||
</div> | ||
</Dialog.Panel> | ||
</div> | ||
</Dialog> | ||
); | ||
} |
60 changes: 60 additions & 0 deletions
60
src/第6章_Tailwind_CSSでコンポーネントを設計する/src/components/headlessui/Transition.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useState, useCallback } from "react"; | ||
import { Transition } from "@headlessui/react"; | ||
|
||
export function MyComponent() { | ||
const [isShowing, setIsShowing] = useState(false); | ||
const onToggle = useCallback(() => { | ||
setIsShowing((prev) => !prev); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<button onClick={onToggle}>押すと</button> | ||
<Transition | ||
show={isShowing} | ||
enter="transition-opacity duration-75" | ||
enterFrom="opacity-0" | ||
enterTo="opacity-100" | ||
leave="transition-opacity duration-150" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
フェードインする | ||
</Transition> | ||
</> | ||
); | ||
} | ||
|
||
interface SidebarProps { | ||
isShowing?: boolean; | ||
} | ||
|
||
export function Sidebar({ isShowing }: SidebarProps) { | ||
return ( | ||
<Transition show={isShowing}> | ||
{/* 背景の暗い部分はフェードする */} | ||
<Transition.Child | ||
enter="transition-opacity ease-linear duration-300" | ||
enterFrom="opacity-0" | ||
enterTo="opacity-100" | ||
leave="transition-opacity ease-linear duration-300" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
{/* ... */} | ||
</Transition.Child> | ||
|
||
{/* サイドバーの本体はスライドする */} | ||
<Transition.Child | ||
enter="transition ease-in-out duration-300 transform" | ||
enterFrom="-translate-x-full" | ||
enterTo="translate-x-0" | ||
leave="transition ease-in-out duration-300 transform" | ||
leaveFrom="translate-x-0" | ||
leaveTo="-translate-x-full" | ||
> | ||
{/* ... */} | ||
</Transition.Child> | ||
</Transition> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/第6章_Tailwind_CSSでコンポーネントを設計する/src/components/react-aria/Dialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useRef } from "react"; | ||
import { useDialog, AriaDialogProps } from "react-aria"; | ||
|
||
interface Props extends AriaDialogProps { | ||
title?: React.ReactNode; | ||
children: React.ReactNode; | ||
} | ||
|
||
export function Dialog({ title, children, ...props }: Props) { | ||
const ref = useRef<HTMLDivElement>(null); | ||
const { dialogProps, titleProps } = useDialog(props, ref); | ||
|
||
return ( | ||
<div {...dialogProps} ref={ref} className="p-8"> | ||
{title && ( | ||
<h3 {...titleProps} className="mt-0"> | ||
{title} | ||
</h3> | ||
)} | ||
{children} | ||
</div> | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/第6章_Tailwind_CSSでコンポーネントを設計する/src/components/react-aria/DialogWithComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Button, Dialog, DialogTrigger, Modal } from "react-aria-components"; | ||
|
||
interface Props { | ||
title?: React.ReactNode; | ||
children: React.ReactNode; | ||
} | ||
|
||
export function DialogWithComponents({ title, children }: Props) { | ||
return ( | ||
<DialogTrigger> | ||
<Button>開く</Button> | ||
<Modal> | ||
<Dialog> | ||
{({ close }) => ( | ||
<div> | ||
<h1>{title}</h1> | ||
{children} | ||
<Button onPress={close}>閉じる</Button> | ||
</div> | ||
)} | ||
</Dialog> | ||
</Modal> | ||
</DialogTrigger> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/第6章_Tailwind_CSSでコンポーネントを設計する/src/components/react-aria/Popover.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Popover } from "react-aria-components"; | ||
|
||
interface Props {} | ||
|
||
export function PopoverAnimation({}: Props) { | ||
return ( | ||
<Popover className="data-[entering]:animate-[fadeIn_300ms_ease]"> | ||
It's popover | ||
</Popover> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/第6章_Tailwind_CSSでコンポーネントを設計する/src/components/react-spring/FadeIn.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useSpring, animated } from "@react-spring/web"; | ||
|
||
export function FadeIn() { | ||
const [props] = useSpring( | ||
() => ({ | ||
from: { opacity: 0 }, | ||
to: { opacity: 1 }, | ||
}), | ||
[], | ||
); | ||
|
||
return <animated.div style={props}>Hello World</animated.div>; | ||
} |
Oops, something went wrong.