-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add util function createSettings
- Loading branch information
1 parent
1027a12
commit 62a51f5
Showing
4 changed files
with
39 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useLine } from "@/composables/tools/useLine/useLine"; | ||
import { createSettings } from "./createSettings"; | ||
import { describe, expect, it } from "vitest"; | ||
import { useBackground } from "@/composables/tools/useBackground/useBackground"; | ||
|
||
|
||
describe('createSettings', () => { | ||
it('should return defaultSettings', () => { | ||
const settings = createSettings([]) | ||
expect(settings.value.color).toBe("#c82d2d") | ||
}) | ||
|
||
it('should pick the first usable tool', () => { | ||
const settings = createSettings([useBackground({blob: new Blob()}), useLine()]) | ||
expect(settings.value.tool).toBe("line") | ||
}) | ||
}) |
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,20 @@ | ||
import type { Settings, Tool } from "@/types"; | ||
import { ref, type Ref } from "vue"; | ||
|
||
export const defaultSettings: Settings = { | ||
tool: 'freehand', | ||
thickness: 5, | ||
color: '#c82d2d' | ||
} | ||
|
||
/** Use this function to create your settings ref. It will use the default settings as a base and merge in the settings you provide. */ | ||
export function createSettings<Tools extends Tool<any>[]>(tools: Tools, settings: Partial<Settings> = {}): Ref<Settings> { | ||
// TODO: let the tools declare what settings they need, and merge them in here | ||
const usableTool = tools.find(t => t.icon) | ||
return ref(Object.assign( | ||
{}, | ||
defaultSettings, | ||
{ tool: usableTool?.type ?? 'freehand'}, | ||
settings | ||
)) | ||
} |