-
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
1 parent
e0cfc86
commit 33c9cbc
Showing
4 changed files
with
100 additions
and
56 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,63 +1,57 @@ | ||
import { | ||
PiSelectionSlashLight, | ||
PiSelectionLight, | ||
PiSquareBold, | ||
PiSquareLight, | ||
PiSelectionSlashLight, | ||
PiSelectionLight, | ||
PiSquareBold, | ||
PiSquareLight, | ||
} from "react-icons/pi"; | ||
import { useSearchParams } from "@remix-run/react"; | ||
|
||
import { ButtonGroup } from "@chakra-ui/react"; | ||
|
||
|
||
import { ToolbarButton } from "~/components/ToolbarButton"; | ||
import { IconType } from "react-icons"; | ||
|
||
interface IProps { | ||
boxSize: string; | ||
size: string; | ||
boxSize: string; | ||
size: string; | ||
} | ||
|
||
export const BorderButtons = ({ size, boxSize }: IProps) => { | ||
const [searchParams] = useSearchParams(); | ||
const currentBorder = searchParams.get("border") || "dash"; | ||
|
||
return ( | ||
<ButtonGroup isAttached> | ||
<ToolbarButton | ||
ariaLabel="No border" | ||
boxSize={boxSize} | ||
param="border" | ||
value="none" | ||
icon={PiSelectionSlashLight} | ||
isActive={currentBorder === "none"} | ||
size={size} | ||
/> | ||
<ToolbarButton | ||
ariaLabel="Dash border" | ||
boxSize={boxSize} | ||
param="border" | ||
value="dash" | ||
icon={PiSelectionLight} | ||
isActive={currentBorder === "dash"} | ||
size={size} | ||
/> | ||
<ToolbarButton | ||
ariaLabel="Thin border" | ||
boxSize={boxSize} | ||
param="border" | ||
value="thin" | ||
icon={PiSquareLight} | ||
isActive={currentBorder === "thin"} | ||
size={size} | ||
/> | ||
<ToolbarButton | ||
ariaLabel="Thick border" | ||
boxSize={boxSize} | ||
param="border" | ||
value="thick" | ||
icon={PiSquareBold} | ||
isActive={currentBorder === "thick"} | ||
size={size} | ||
/> | ||
</ButtonGroup> | ||
); | ||
type BorderDefinition = { | ||
value: string; | ||
icon: IconType; | ||
label: string; | ||
} | ||
|
||
const borders: BorderDefinition[] = [ | ||
{ value: "none", icon: PiSelectionSlashLight, label: "No border" }, | ||
{ value: "dash", icon: PiSelectionLight, label: "Dash border" }, | ||
{ value: "thin", icon: PiSquareLight, label: "Thin border" }, | ||
{ value: "thick", icon: PiSquareBold, label: "Thick border" }, | ||
]; | ||
|
||
const BorderButtons = ({ size, boxSize }: IProps) => { | ||
const [searchParams] = useSearchParams(); | ||
const currentBorder = searchParams.get("border") || "dash"; | ||
|
||
return ( | ||
<ButtonGroup isAttached> | ||
{borders.map((border) => ( | ||
<ToolbarButton | ||
ariaLabel={border.label} | ||
boxSize={boxSize} | ||
icon={border.icon} | ||
isActive={currentBorder === border.value} | ||
key={border.value} | ||
param="border" | ||
size={size} | ||
value={border.value} | ||
/>))} | ||
</ButtonGroup> | ||
); | ||
}; | ||
|
||
export { | ||
BorderButtons, | ||
borders | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
import { borders } from './BorderButtons' | ||
|
||
|
||
function nextBorder(current: string): string { | ||
const currentIndex = borders.findIndex((border) => border.value === current); | ||
const nextIndex = (currentIndex + 1) % borders.length; | ||
return borders[nextIndex].value; | ||
} | ||
|
||
function KeyHandler(searchParams: URLSearchParams, border: string, currentZoom: number, e: KeyboardEvent): URLSearchParams | null { | ||
|
||
|
||
|
||
console.log(e); | ||
|
||
switch (e.key.toLocaleLowerCase()) { | ||
case '1': | ||
searchParams.set('zoom', '1'); | ||
return searchParams; | ||
case 'b': | ||
searchParams.set('border', nextBorder(border)); | ||
return searchParams; | ||
case 'i': | ||
searchParams.set('zoom', 'icons'); | ||
return searchParams; | ||
case 'm': | ||
searchParams.set('zoom', 'max'); | ||
return searchParams; | ||
case 'x': | ||
searchParams.set('debug', searchParams.get('debug') === '1' ? '0' : '1'); | ||
return searchParams; | ||
case '+': | ||
searchParams.set('zoom', (currentZoom + 1).toString()); | ||
return searchParams; | ||
case '-': | ||
searchParams.set('zoom', (currentZoom > 1 ? currentZoom - 1 : currentZoom * 0.5).toString()); | ||
return searchParams; | ||
} | ||
return null; | ||
} | ||
|
||
export { KeyHandler }; |
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