-
Notifications
You must be signed in to change notification settings - Fork 0
Add IconButton and SelectedCutsDialog components with Storybook stories #62
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,15 @@ | ||
import { action } from "@storybook/addon-actions"; | ||
import IconButton from "./IconButton"; | ||
|
||
export default { | ||
title: "Atoms/IconButton", | ||
component: IconButton, | ||
tags: ["atoms"], | ||
}; | ||
|
||
export const Default = { | ||
args: { | ||
children: "IconButton", | ||
onClick: action("onClick"), | ||
}, | ||
}; |
This file contains hidden or 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,21 @@ | ||
import type React from "react"; | ||
|
||
function IconButton({ | ||
icon, | ||
className, | ||
...props | ||
}: React.ComponentPropsWithoutRef<"button"> & { | ||
className?: string; | ||
icon: string; | ||
}) { | ||
return ( | ||
<button | ||
className={`rounded bg-gray-300 dark:bg-gray-400 hover:bg-gray-400 active:bg-gray-500 dark:hover:bg-gray-500 dark:active:bg-gray-600 hover:text-white active:text-white dark:hover:text-white dark:active:text-white ${className}`} | ||
{...props} | ||
> | ||
<span className="material-symbols-outlined size-5 m-2">{icon}</span> | ||
</button> | ||
); | ||
} | ||
|
||
export default IconButton; |
This file contains hidden or 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 { action } from "@storybook/addon-actions"; | ||
|
||
import SelectedCutsDialog from "./SelectedCutsDialog"; | ||
|
||
export default { | ||
title: "Molecules/SelectedCutsDialog", | ||
component: SelectedCutsDialog, | ||
tags: ["molecules"], | ||
decorators: [ | ||
(story: () => React.ReactNode) => ( | ||
<div className="h-[70vh] flex justify-center items-center">{story()}</div> | ||
), | ||
], | ||
}; | ||
|
||
export const Default = () => { | ||
return ( | ||
<SelectedCutsDialog | ||
cuts={[ | ||
{ | ||
id: "1", | ||
start: 0, | ||
end: 10, | ||
}, | ||
]} | ||
onClose={action("onClose")} | ||
onClear={action("onClear")} | ||
onRemove={action("onRemove")} | ||
onReorder={action("onReorder")} | ||
/> | ||
); | ||
}; | ||
|
||
export const MultipleCuts = () => { | ||
return ( | ||
<SelectedCutsDialog | ||
cuts={[ | ||
{ | ||
id: "1", | ||
start: 0, | ||
end: 10, | ||
}, | ||
{ | ||
id: "2", | ||
start: 10, | ||
end: 20, | ||
}, | ||
{ | ||
id: "3", | ||
start: 20, | ||
end: 30, | ||
}, | ||
]} | ||
onClose={action("onClose")} | ||
onClear={action("onClear")} | ||
onRemove={action("onRemove")} | ||
onReorder={action("onReorder")} | ||
/> | ||
); | ||
}; |
This file contains hidden or 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,93 @@ | ||
import Button from "components/atoms/Button"; | ||
import IconButton from "components/atoms/IconButton"; | ||
|
||
import DEFAULT_KEYFRAME_SRC from "assets/logo.svg"; | ||
|
||
type Cut = { | ||
id: string; | ||
start: number; | ||
end: number; | ||
keyframeSrc?: string; | ||
}; | ||
|
||
interface Props { | ||
cuts: Cut[]; | ||
onClose: () => void; | ||
onClear: () => void; | ||
onRemove: (id: string) => void; | ||
onReorder: (cuts: Cut[]) => void; | ||
} | ||
|
||
export default function SelectedCutsDialog({ | ||
cuts, | ||
onClose, | ||
onClear, | ||
onRemove, | ||
onReorder, | ||
}: Props) { | ||
const handleRemove = (id: string) => { | ||
onRemove(id); | ||
}; | ||
|
||
const handleReorder = (index: number, direction: "up" | "down") => { | ||
const newCuts = [...cuts]; | ||
const [removed] = newCuts.splice(index, 1); | ||
newCuts.splice(direction === "up" ? index - 1 : index + 1, 0, removed); | ||
onReorder(newCuts); | ||
}; | ||
|
||
return ( | ||
<div className="fixed w-96 bg-white shadow-lg p-4 flex flex-col space-y-4 right-0 bottom-0"> | ||
<div className="flex items-center justify-between mb-4"> | ||
<h2 className="text-xl font-bold">Selected Cuts</h2> | ||
<Button onClick={onClose}>Close</Button> | ||
<Button | ||
className="bg-red-500 | ||
dark:bg-red-600 hover:bg-red-600 active:bg-red-700 dark:hover:bg-red-700 dark:active:bg-red-800 hover:text-white active:text-white dark:hover:text-white dark:active:text-white | ||
" | ||
onClick={onClear} | ||
> | ||
Clear | ||
</Button> | ||
</div> | ||
<ul className="flex-grow overflow-y-auto space-y-1"> | ||
{cuts.map((cut, index) => ( | ||
<li | ||
key={cut.id} | ||
className="border border-gray-200 rounded p-1 flex items-center" | ||
> | ||
<img | ||
src={cut.keyframeSrc || DEFAULT_KEYFRAME_SRC} | ||
width={48} | ||
height={45} | ||
alt={`Keyframe for cut ${cut.id}`} | ||
className="mr-2" | ||
/> | ||
<div className="flex-grow"> | ||
Cut {cut.id}: {cut.start}s - {cut.end}s | ||
</div> | ||
<div className="flex space-x-1"> | ||
<IconButton | ||
onClick={() => handleRemove(cut.id)} | ||
icon="close" | ||
title="Remove" | ||
/> | ||
<IconButton | ||
onClick={() => handleReorder(index, "up")} | ||
disabled={index === 0} | ||
icon="arrow_upward" | ||
title="Move up" | ||
/> | ||
<IconButton | ||
onClick={() => handleReorder(index, "down")} | ||
disabled={index === cuts.length - 1} | ||
icon="arrow_downward" | ||
title="Move down" | ||
/> | ||
</div> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.