Skip to content
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

Update tilemap/image/animation editor to use react common components #10317

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion react-common/components/controls/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ButtonViewProps extends ContainerProps {

export interface ButtonProps extends ButtonViewProps {
onClick: () => void;
onRightClick?: () => void;
onBlur?: () => void;
onKeydown?: (e: React.KeyboardEvent) => void;
}
Expand All @@ -49,6 +50,7 @@ export const Button = (props: ButtonProps) => {
ariaPressed,
role,
onClick,
onRightClick,
onKeydown,
onBlur,
buttonRef,
Expand Down Expand Up @@ -78,7 +80,8 @@ export const Button = (props: ButtonProps) => {
);

let clickHandler = (ev: React.MouseEvent) => {
if (onClick) onClick();
if (onRightClick && ev.button !== 0) onRightClick();
else if (onClick) onClick();
if (href) window.open(href, target || "_blank", "noopener,noreferrer")
ev.stopPropagation();
ev.preventDefault();
Expand Down
62 changes: 62 additions & 0 deletions react-common/components/controls/CarouselNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { classList } from "../util";
import { Button } from "./Button";

export interface CarouselNavProps {
pages: number;
selected: number;
maxDisplayed?: number;
onPageSelected: (page: number) => void;
}

export const CarouselNav = (props: CarouselNavProps) => {
const { pages, selected, maxDisplayed, onPageSelected } = props;

const displayedPages: number[] = [];
let start = 0;
let end = pages;

if (maxDisplayed) {
start = Math.min(
Math.max(0, selected - (maxDisplayed >> 1)),
Math.max(0, start + pages - maxDisplayed)
);
end = Math.min(start + maxDisplayed, pages);
}

for (let i = start; i < end; i++) {
displayedPages.push(i);
}

return (
<div className="common-carousel-nav">
<Button
className="common-carousel-nav-arrow"
title={lf("Previous page")}
leftIcon="fas fa-chevron-circle-left"
onClick={() => onPageSelected(selected - 1)}
disabled={selected === 0}
/>
<ul className="common-carousel-nav">
{displayedPages.map(page =>
<li key={page} onClick={() => onPageSelected(page)}>
<Button
className={classList(selected === page && "selected")}
title={lf("Jump to page {0}", page + 1)}
onClick={() => onPageSelected(page)}
label={
<span className="common-carousel-nav-button-handle" />
}
/>
</li>
)}
</ul>
<Button
className="common-carousel-nav-arrow"
title={lf("Next page")}
leftIcon="fas fa-chevron-circle-right"
onClick={() => onPageSelected(selected + 1)}
disabled={selected === pages - 1}
/>
</div>
)
}
128 changes: 0 additions & 128 deletions react-common/components/controls/FocusTrap.tsx

This file was deleted.

Loading
Loading