Skip to content

Commit

Permalink
Merge pull request #46 from shefing/reload
Browse files Browse the repository at this point in the history
Reload
  • Loading branch information
RachelBra authored Feb 20, 2024
2 parents e45f26e + 2451a10 commit 0a5390c
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 36 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions library/math/numbersLine/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Toolbar from "./components/Toolbar";
import ShowElements from "./components/ShowElements";
import { useNumbersLineContext } from "./context/numbersLineContext";
import { useEffect } from "react";
import Reload from "./components/Reload";

const App = () => {
const { setIdDraggElementClick } = useNumbersLineContext();
Expand All @@ -23,6 +24,7 @@ const App = () => {
return (
<>
<ShowElements />
<Reload />
<div className="flex flex-col h-full justify-between">
<Toolbar />
<div>
Expand Down
4 changes: 2 additions & 2 deletions library/math/numbersLine/src/components/MoveableElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ const MoveableElement = ({ moveableRef, element, unit }: IProps) => {
if (matchX) {
const xPosition = parseFloat(matchX[1]);
const xXPositionString = matchX[0];
//change position when jump out of bounds:
//Change position when jump out of bounds:
if (xPosition + newWidth > windowSize.width - RulerPadding) {
const range = xPosition + newWidth - windowSize.width + RulerPadding;
const newXTransform = "(" + (xPosition - range) + "px";
e.target.style.transform = e.target.style.transform.replace(xXPositionString, newXTransform);
updateDragElements(element.id, { ...element, transform: e.target.style.transform });
}
//change position when jump reSize on the left:
//Change position when jump reSize on the left:
if (e.clientX < xPosition) {
const range = e.lastEvent.width - newWidth;
const newXTransform = "(" + (xPosition + range) + "px";
Expand Down
32 changes: 32 additions & 0 deletions library/math/numbersLine/src/components/Reload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { useNumbersLineContext } from "@/context/numbersLineContext";

const Reload = () => {
const { initializationDialog, setInitializationDialog, initialization } = useNumbersLineContext();

return (
<>
<AlertDialog open={initializationDialog} onOpenChange={setInitializationDialog}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>?אתם רוצים להתחיל מחדש</AlertDialogTitle>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>הישארו</AlertDialogCancel>
<AlertDialogAction onClick={initialization}>מחק הכל</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
);
};

export default Reload;
21 changes: 16 additions & 5 deletions library/math/numbersLine/src/components/toolbar/ActionIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { calculatUnitsAmount, getImageSrc } from "@/lib/utils";
import DisplayNumbers from "./DisplayNumbers";
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu";
import { useNumbersLineContext } from "../../context/numbersLineContext";
import { TypeActionIconsToolbar } from "../../type/elements";
import { TypeActionIconsToolbar, TypeCover } from "../../type/elements";
import { TypesElement } from "../../type/moveable";
import { v4 as uuidv4 } from "uuid";
import { calcHeightStartPosition, calcWidthStartPosition } from "@/lib/stylesUtils";
Expand All @@ -16,7 +16,8 @@ const IconsToolbar = ({ typeAction, iconUrl }: IProps) => {
const [isHovered, setIsHovered] = useState(false);
const [isOpen, setIsOpen] = useState(false);
const [newJumpPixels, setNewJumpPixels] = useState(0);
const { windowSize, typeRuler, dragElements, setDragElements, idDraggElementClick } = useNumbersLineContext();
const { windowSize, typeRuler, dragElements, setDragElements, idDraggElementClick, initializationDialog, setInitializationDialog, visitableDisplayButton } =
useNumbersLineContext();
const wrapperRef = useRef<HTMLDivElement>(null);

useEffect(() => {
Expand Down Expand Up @@ -52,21 +53,31 @@ const IconsToolbar = ({ typeAction, iconUrl }: IProps) => {
};

const actionButtonClick = () => {
typeAction == TypeActionIconsToolbar.jump || typeAction == TypeActionIconsToolbar.text ? addDraggableElement() : setIsOpen(!isOpen);
if (typeAction == TypeActionIconsToolbar.jump || typeAction == TypeActionIconsToolbar.text) addDraggableElement();
else {
if (typeAction == TypeActionIconsToolbar.reload) {
setInitializationDialog(true);
} else setIsOpen(!isOpen);
}
};

return (
<div className="flex flex-col items-center" ref={wrapperRef}>
<img
className="m-3 cursor-pointer"
src={getImageSrc(iconUrl, isHovered, isOpen)}
src={getImageSrc(
iconUrl,
isHovered,
typeAction === TypeActionIconsToolbar.reload ? initializationDialog : isOpen,
typeAction === TypeActionIconsToolbar.reload && dragElements.length == 0 && visitableDisplayButton == TypeCover.allDiscover
)}
alt={typeAction + " Toolbar"}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onClick={() => actionButtonClick()}
/>
<div className="relative">
<DropdownMenu open={isOpen} onOpenChange={(open) => setIsOpen(open)}>
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
<DropdownMenuTrigger />
<DropdownMenuContent>{typeAction === TypeActionIconsToolbar.displayNumbersLine && <DisplayNumbers setOpen={setIsOpen} />}</DropdownMenuContent>
</DropdownMenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const DisplayNumbers = ({ setOpen }: IProps) => {
};

return (
<div className="relative flex flex-col items-center">
<div className="relative flex flex-col items-center bg-white relative">
<img className="absolute top-0 " src={triangleToMenu} alt="triple for menu" />
<div className="m-[18px] flex flex-col items-end shadow-2xl rounded-[6px] border border-solid border-[#009FDE] p-2">
{displayRulerButtonDetials.map((item: IDisplayRuller, i: number) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { useNumbersLineContext } from "../../context/numbersLineContext";
import openMenu from "/assets/icons/menuButtonOpen.svg";
import closeMenu from "/assets/icons/menuButtonClose.svg";
import { rulerDefinitionButtonDetials } from "../../consts/elementConsts";
import { IRulerDefinition } from "../../type/elements";
import { IRulerDefinition, TypeCover } from "../../type/elements";

const LineDefinition = () => {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const { typeRuler, setTypeRuler } = useNumbersLineContext();
const { typeRuler, setTypeRuler, dragElements, visitableDisplayButton, setInitializationDialog, setInitializationTypeRuler } = useNumbersLineContext();
const wrapperRef = useRef<HTMLDivElement>(null);

useEffect(() => {
Expand All @@ -30,8 +30,14 @@ const LineDefinition = () => {
};

const handleMenuButtonClick = (type: LineRange) => {
setTypeRuler(type);
if (type == typeRuler) return;
setIsMenuOpen(false);
if (dragElements.length == 0 && visitableDisplayButton == TypeCover.allDiscover) {
setTypeRuler(type);
} else {
setInitializationTypeRuler(type);
setInitializationDialog(true);
}
};

return (
Expand Down
98 changes: 98 additions & 0 deletions library/math/numbersLine/src/components/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import * as React from "react";
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";

import { cn } from "@/lib/utils";
import { buttonVariants } from "@/components/ui/button";

const AlertDialog = AlertDialogPrimitive.Root;

const AlertDialogTrigger = AlertDialogPrimitive.Trigger;

const AlertDialogPortal = AlertDialogPrimitive.Portal;

const AlertDialogOverlay = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Overlay
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
ref={ref}
/>
));
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;

const AlertDialogContent = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
>(({ className, ...props }, ref) => (
<AlertDialogPortal>
<AlertDialogOverlay />
<AlertDialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] h-[146px] z-50 grid w-[350px] max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg border border-radius-[5px] border-[#009FDE]",
className
)}
{...props}
/>
</AlertDialogPortal>
));
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName;

const AlertDialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn("flex flex-col space-y-2 text-center sm:text-center", className)} {...props} />
);
AlertDialogHeader.displayName = "AlertDialogHeader";

const AlertDialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn("sm:flex-row sm:justify-center sm:space-x-2", className)} {...props} />
);
AlertDialogFooter.displayName = "AlertDialogFooter";

const AlertDialogTitle = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Title ref={ref} className={cn("text-lg font-semibold text-[26px] font-[400] font-[Abraham] ", className)} {...props} />
));
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName;

const AlertDialogDescription = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
>(({ className, ...props }, ref) => <AlertDialogPrimitive.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />);
AlertDialogDescription.displayName = AlertDialogPrimitive.Description.displayName;

const AlertDialogAction = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Action>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Action ref={ref} className={cn(buttonVariants({ variant: "action" }), "mt-2 sm:mt-0", className)} {...props} />
));
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;

const AlertDialogCancel = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Cancel ref={ref} className={cn(buttonVariants({ variant: "cancel" }), "mt-2 sm:mt-0", className)} {...props} />
));
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName;

export {
AlertDialog,
AlertDialogPortal,
AlertDialogOverlay,
AlertDialogTrigger,
AlertDialogContent,
AlertDialogHeader,
AlertDialogFooter,
AlertDialogTitle,
AlertDialogDescription,
AlertDialogAction,
AlertDialogCancel,
};
3 changes: 3 additions & 0 deletions library/math/numbersLine/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const buttonVariants = cva(
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
icon: "w-12 h-12 m-3 cursor-pointer rounded-full ",
action: `h-[25px] w-[100px] px-4 py-4 ml-[2rem] mr-[2rem] bg-[#009FDE] hover:bg-[#7BC8EF] transition rounded-[20px] text-white text-[22px] font-[400] font-[Abraham] `,
cancel: `h-[25px] w-[100px] px-4 py-4 ml-[2rem] mr-[2rem] bg-[#E1F4FD] hover:bg-[#7BC8EF] transition rounded-[20px] text-[#009FDE] text-[22px] font-[400] font-[Abraham] `,
linedefinition: `h-[48px] px-4 py-2 m-[0.5rem] bg-white hover:bg-[#E1F4FD] transition rounded-[20px] text-[24px] font-[400] font-[Abraham] border border-solid border-[#009FDE]`,
displayRulerNumber:
"h-[33px] px-4 py-2 m-[0.5rem] ml-[1rem] mr-[1rem] hover:bg-[#E1F4FD] transition rounded-[20px] text-[26px] font-[400] font-[Abraham] border border-solid border-[#009FDE] ",
Expand Down
31 changes: 25 additions & 6 deletions library/math/numbersLine/src/context/numbersLineContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ interface INumbersLineContextProps {
setCoverSituation: (v: TypeCover) => void;
visitableDisplayButton: TypeCover;
setVisitableDisplayButton: (v: TypeCover) => void;
initializationDialog: boolean;
setInitializationDialog: (v: boolean) => void;
initializationTypeRuler: LineRange;
setInitializationTypeRuler: (v: LineRange) => void;
initialization: () => void;
}

export const NumbersLineContext = React.createContext({
Expand All @@ -35,6 +40,11 @@ export const NumbersLineContext = React.createContext({
setCoverSituation: () => null,
visitableDisplayButton: {} as TypeCover,
setVisitableDisplayButton: () => null,
initializationDialog: {} as boolean,
setInitializationDialog: () => null,
initializationTypeRuler: {} as LineRange,
setInitializationTypeRuler: () => null,
initialization: () => null,
} as INumbersLineContextProps);

export const NumbersLineContexProvider = (props: any) => {
Expand All @@ -47,6 +57,16 @@ export const NumbersLineContexProvider = (props: any) => {
const [coverSituation, setCoverSituation] = useState(TypeCover.allDiscover);
const [visitableDisplayButton, setVisitableDisplayButton] = useState(TypeCover.allDiscover);

const [initializationDialog, setInitializationDialog] = useState(false);
const [initializationTypeRuler, setInitializationTypeRuler] = useState(LineRange.ten);
const initialization = () => {
setTypeRuler(initializationTypeRuler);
setDragElements([]);
setCoverSituation(TypeCover.allDiscover);
setVisitableDisplayButton(TypeCover.allDiscover);
setLeftPosition(0);
};

const Resize = () => {
setWindowSize({ height: window.innerHeight, width: window.innerWidth });
};
Expand All @@ -58,12 +78,6 @@ export const NumbersLineContexProvider = (props: any) => {
};
}, []);

useEffect(() => {
setDragElements([]);
setCoverSituation(TypeCover.allDiscover);
setLeftPosition(0);
}, [typeRuler]);

return (
<NumbersLineContext.Provider
value={{
Expand All @@ -81,6 +95,11 @@ export const NumbersLineContexProvider = (props: any) => {
setCoverSituation,
visitableDisplayButton,
setVisitableDisplayButton,
initializationDialog,
setInitializationDialog,
initializationTypeRuler,
setInitializationTypeRuler,
initialization,
}}
>
{props.children}
Expand Down
36 changes: 17 additions & 19 deletions library/math/numbersLine/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { LineRange, RulerLenth, unitAmount } from "../type/ruler"
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
import { LineRange, RulerLenth, unitAmount } from "../type/ruler";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
return twMerge(clsx(inputs));
}

export const calculatScreenWidth = (windowWidth:number)=>{
return -windowWidth*((LineRange.hundred-RulerLenth.hundred)/RulerLenth.hundred)
}
export const calculatScreenWidth = (windowWidth: number) => {
return -windowWidth * ((LineRange.hundred - RulerLenth.hundred) / RulerLenth.hundred);
};

export const calculatRulerWidth = (windowWidth:number, RulerPadding:number)=>{
return windowWidth - RulerPadding*2;
}
export const calculatRulerWidth = (windowWidth: number, RulerPadding: number) => {
return windowWidth - RulerPadding * 2;
};

export const getImageSrc = (url: string,isHovered:boolean , isOpen:boolean) => {
const dotIndex = url.indexOf('.');
export const getImageSrc = (url: string, isHovered: boolean, isOpen: boolean, isDisable?: boolean) => {
const dotIndex = url.indexOf(".");
const beforeDot = url.substring(0, dotIndex);
return isOpen? beforeDot+'Open.svg': isHovered ? beforeDot+'Hover.svg' : url;
}

export const calculatUnitsAmount = (type: LineRange)=>{
return type == LineRange.hundred || type == LineRange.twenty? unitAmount.twenty: unitAmount.ten;
}

return isOpen ? beforeDot + "Open.svg" : isHovered ? beforeDot + "Hover.svg" : isDisable ? beforeDot + "Disable.svg" : url;
};

export const calculatUnitsAmount = (type: LineRange) => {
return type == LineRange.hundred || type == LineRange.twenty ? unitAmount.twenty : unitAmount.ten;
};

0 comments on commit 0a5390c

Please sign in to comment.