-
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
Showing
11 changed files
with
2,191 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { test, expect } from "vitest" | ||
import { render } from "@solidjs/testing-library" | ||
import userEvent from "@testing-library/user-event" | ||
import { MobileEvent } from "./circles" | ||
|
||
const user = userEvent.setup() | ||
|
||
test("increments value", async () => { | ||
const result = render(() => ( | ||
<MobileEvent | ||
event={{ | ||
space: { | ||
title: "Test Space", | ||
slug: "test-space", | ||
date_created: "2023-01-01T00:00:00.000Z", | ||
date_modified: "2023-01-01T00:00:00.000Z", | ||
author: { | ||
name: "Test User", | ||
profile_avatar_type: "TD", | ||
}, | ||
subtitle: "Test Subtitle", | ||
}, | ||
url: "https://totem.org", | ||
start: "2023-01-01T00:00:00.000Z", | ||
slug: "test-event", | ||
date_created: "2023-01-01T00:00:00.000Z", | ||
date_modified: "2023-01-01T00:00:00.000Z", | ||
title: "Test Event", | ||
}} | ||
/> | ||
)) | ||
const html = result.container.innerHTML | ||
expect(html).toContain("Test Space") | ||
expect(html).toContain("Test Event") | ||
expect(html).not.toContain("Invalid") | ||
}) |
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,188 @@ | ||
// from https://github.com/lxsmnsyc/solid-tippy | ||
import { | ||
createComputed, | ||
createEffect, | ||
createSignal, | ||
onCleanup, | ||
untrack, | ||
} from "solid-js" | ||
import makeTippy, { type Instance, type Props } from "tippy.js" | ||
import makeHeadlessTippy from "tippy.js/headless" | ||
|
||
export interface TippyOptions { | ||
disabled?: boolean | ||
hidden?: boolean | ||
props?: Partial<Props> | ||
} | ||
|
||
export function tippy<T extends Element>( | ||
target: T, | ||
opts: () => TippyOptions | undefined | ||
): void { | ||
createEffect(() => { | ||
const options = opts() | ||
const instance = makeTippy( | ||
target, | ||
untrack(() => options?.props) | ||
) | ||
|
||
createComputed(() => { | ||
if (options?.disabled) { | ||
instance.disable() | ||
} else { | ||
instance.enable() | ||
} | ||
}) | ||
|
||
createComputed(() => { | ||
if (options?.hidden) { | ||
instance.hide() | ||
} else { | ||
instance.show() | ||
} | ||
}) | ||
|
||
createComputed(() => { | ||
instance.setProps({ | ||
...(options?.props ?? {}), | ||
}) | ||
}) | ||
|
||
onCleanup(() => { | ||
instance.destroy() | ||
}) | ||
}) | ||
} | ||
|
||
export function tippyHeadless<T extends Element>( | ||
target: T, | ||
opts: () => TippyOptions | undefined | ||
): void { | ||
createEffect(() => { | ||
const options = opts() | ||
const instance = makeHeadlessTippy( | ||
target, | ||
untrack(() => options?.props) | ||
) | ||
|
||
createComputed(() => { | ||
if (options?.disabled) { | ||
instance.disable() | ||
} else { | ||
instance.enable() | ||
} | ||
}) | ||
|
||
createComputed(() => { | ||
if (options?.hidden) { | ||
instance.hide() | ||
} else { | ||
instance.show() | ||
} | ||
}) | ||
|
||
createComputed(() => { | ||
instance.setProps({ | ||
...(options?.props ?? {}), | ||
}) | ||
}) | ||
|
||
onCleanup(() => { | ||
instance.destroy() | ||
}) | ||
}) | ||
} | ||
|
||
export function useTippy<T extends Element>( | ||
target: () => T | undefined | null, | ||
options?: TippyOptions | ||
): () => Instance | undefined { | ||
const [current, setCurrent] = createSignal<Instance>() | ||
|
||
createEffect(() => { | ||
const currentTarget = target() | ||
if (currentTarget) { | ||
const instance = makeTippy( | ||
currentTarget, | ||
untrack(() => options?.props) | ||
) | ||
|
||
setCurrent(instance) | ||
|
||
createComputed(() => { | ||
if (options?.disabled) { | ||
instance.disable() | ||
} else { | ||
instance.enable() | ||
} | ||
}) | ||
|
||
createComputed(() => { | ||
if (options?.hidden) { | ||
instance.hide() | ||
} else { | ||
instance.show() | ||
} | ||
}) | ||
|
||
createComputed(() => { | ||
instance.setProps({ | ||
...(options?.props ?? {}), | ||
}) | ||
}) | ||
|
||
onCleanup(() => { | ||
instance.destroy() | ||
}) | ||
} | ||
}) | ||
|
||
return () => current() | ||
} | ||
|
||
export function useTippyHeadless<T extends Element>( | ||
target: () => T | undefined | null, | ||
options?: TippyOptions | ||
): () => Instance | undefined { | ||
const [current, setCurrent] = createSignal<Instance>() | ||
|
||
createEffect(() => { | ||
const currentTarget = target() | ||
if (currentTarget) { | ||
const instance = makeHeadlessTippy( | ||
currentTarget, | ||
untrack(() => options?.props) | ||
) | ||
|
||
setCurrent(instance) | ||
|
||
createComputed(() => { | ||
if (options?.disabled) { | ||
instance.disable() | ||
} else { | ||
instance.enable() | ||
} | ||
}) | ||
|
||
createComputed(() => { | ||
if (options?.hidden) { | ||
instance.hide() | ||
} else { | ||
instance.show() | ||
} | ||
}) | ||
|
||
createComputed(() => { | ||
instance.setProps({ | ||
...(options?.props ?? {}), | ||
}) | ||
}) | ||
|
||
onCleanup(() => { | ||
instance.destroy() | ||
}) | ||
} | ||
}) | ||
|
||
return () => current() | ||
} |
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
Oops, something went wrong.