-
Notifications
You must be signed in to change notification settings - Fork 5
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
1e4f9f9
commit b3bfe4c
Showing
33 changed files
with
862 additions
and
192 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
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
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
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,19 @@ | ||
import { Color } from "@/utils/common"; | ||
import { cn } from "@/utils/css"; | ||
|
||
export const ColorSetting = (props: { | ||
value: Color; | ||
onChange: (newValue: Color) => void; | ||
className?: string; | ||
}) => { | ||
const { value, onChange, className } = props; | ||
return ( | ||
<input | ||
className={cn("w-[40px] rounded-md h-input-thin", className)} | ||
type="color" | ||
value={value} | ||
onChange={(e) => onChange(e.target.value)} | ||
></input> | ||
); | ||
}; | ||
|
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,39 @@ | ||
import { cn } from "@/utils/css"; | ||
import { | ||
Select, | ||
SelectTrigger, | ||
SelectValue, | ||
SelectContent, | ||
SelectItem, | ||
} from "../ui/select"; | ||
|
||
export const OptionSetting = <T extends number | string>(props: { | ||
value: T; | ||
onChange: (newValue: T) => void; | ||
options: { | ||
value: T; | ||
label: string; | ||
}[]; | ||
placeholder?: string; | ||
className?: string; | ||
}) => { | ||
const { value, onChange, options, placeholder, className } = props; | ||
return ( | ||
<Select | ||
value={value as string} | ||
onValueChange={(value) => onChange(value as T)} | ||
> | ||
<SelectTrigger className={cn("text-xs h-input-thin", className)}> | ||
<SelectValue placeholder={placeholder} /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{options.map((option) => ( | ||
<SelectItem key={option.value} value={option.value as string}> | ||
{option.label} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
); | ||
}; | ||
|
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,31 @@ | ||
import { DrawToolSettingType } from "@/tools/draw-tools/drawTool"; | ||
import { ColorSetting } from "./colorSetting"; | ||
import { ToolId, toolsMetadata } from "@/tools"; | ||
import { OptionSetting } from "./optionSetting"; | ||
|
||
export const ToolSetting = (props: { | ||
toolId: ToolId; | ||
settingKey: string; | ||
type: DrawToolSettingType; | ||
value: unknown; | ||
onChange: (newValue: unknown) => void; | ||
}) => { | ||
const { type, value, onChange, toolId, settingKey } = props; | ||
|
||
if (type === "color") { | ||
return <ColorSetting value={value as string} onChange={onChange} />; | ||
} | ||
if (type === "size") { | ||
const options = toolsMetadata[toolId].settings[settingKey].options; | ||
return ( | ||
<OptionSetting | ||
value={value as number} | ||
onChange={onChange} | ||
options={options as { value: number; label: string }[]} | ||
/> | ||
); | ||
} | ||
|
||
return null; | ||
}; | ||
|
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 { useToolStore } from "@/store/toolState"; | ||
import { toolsMetadata } from "@/tools"; | ||
import { ToolSetting } from "./tool-settings/toolSetting"; | ||
import { Separator } from "@radix-ui/react-separator"; | ||
|
||
export const ToolSettingsBar = () => { | ||
const selectedToolId = useToolStore((state) => state.selectedToolId); | ||
const settings = useToolStore((state) => state.toolSettings[selectedToolId]); | ||
const updateToolSettings = useToolStore((state) => state.updateToolSettings); | ||
|
||
return ( | ||
<div className="h-10 border-b px-2 flex flex-row gap-big items-center"> | ||
{Object.entries(settings).map(([id, value]) => { | ||
const label = toolsMetadata[selectedToolId].settings[id].name; | ||
return ( | ||
<div | ||
key={id} | ||
className="flex flex-row items-center gap-small text-xs" | ||
> | ||
{label} | ||
<ToolSetting | ||
toolId={selectedToolId} | ||
settingKey={id} | ||
type={toolsMetadata[selectedToolId].settings[id].type} | ||
value={value} | ||
onChange={(newValue) => { | ||
updateToolSettings(selectedToolId, { | ||
...settings, | ||
[id]: newValue, | ||
}); | ||
}} | ||
></ToolSetting> | ||
<Separator | ||
orientation="vertical" | ||
className="h-6 w-px bg-border mx-1" | ||
/> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
Oops, something went wrong.