-
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
4cf73b4
commit 126bda3
Showing
4 changed files
with
7 additions
and
81 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,8 +1,5 @@ | ||
$schema: 'https://moonrepo.dev/schemas/tasks.json' | ||
|
||
implicitDeps: | ||
- '^:build' | ||
|
||
implicitInputs: | ||
- 'package.json' | ||
|
||
|
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,40 +1,7 @@ | ||
import { type Accessor, type JSX, createEffect, createRenderEffect, splitProps } from 'solid-js'; | ||
|
||
declare module 'solid-js' { | ||
namespace JSX { | ||
interface DirectiveFunctions { | ||
field: typeof field; | ||
} | ||
} | ||
} | ||
import { type JSX } from 'solid-js'; | ||
|
||
export type InputProps = JSX.InputHTMLAttributes<HTMLInputElement>; | ||
type DirectiveProps = Pick<InputProps, 'value' | 'onInput' | 'onBlur'>; | ||
|
||
function field(element: HTMLInputElement, props: Accessor<DirectiveProps>) { | ||
createRenderEffect(() => { | ||
element.value = (props().value ?? '')?.toString(); | ||
}); | ||
|
||
createEffect(() => { | ||
const onInput = props().onInput; | ||
if (onInput) { | ||
element.addEventListener<'beforeinput'>( | ||
'beforeinput', | ||
onInput as (this: HTMLInputElement, ev: InputEvent) => unknown | ||
); | ||
} | ||
}); | ||
|
||
createEffect(() => { | ||
const onBlur = props().onBlur; | ||
if (onBlur) { | ||
element.addEventListener<'blur'>('blur', onBlur as (this: HTMLInputElement, ev: FocusEvent) => unknown); | ||
} | ||
}); | ||
} | ||
|
||
export function Input(initialProps: InputProps) { | ||
const [directiveProps, props] = splitProps(initialProps, ['value', 'onInput', 'onBlur']); | ||
return <input use:field={directiveProps} {...props} />; | ||
export function Input(props: InputProps) { | ||
return <input {...props} />; | ||
} |
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,43 +1,7 @@ | ||
import { type Accessor, type JSX, createEffect, createRenderEffect, splitProps } from 'solid-js'; | ||
|
||
declare module 'solid-js' { | ||
namespace JSX { | ||
interface DirectiveFunctions { | ||
textareaField: typeof textareaField; | ||
} | ||
} | ||
} | ||
import { type JSX } from 'solid-js'; | ||
|
||
export type TextareaElementProps = JSX.TextareaHTMLAttributes<HTMLTextAreaElement>; | ||
type DirectiveProps = Pick<TextareaElementProps, 'value' | 'onInput' | 'onBlur'>; | ||
|
||
function textareaField(element: HTMLTextAreaElement, props: Accessor<DirectiveProps>) { | ||
createRenderEffect(() => { | ||
element.value = (props().value ?? '')?.toString(); | ||
}); | ||
|
||
createEffect(() => { | ||
const onInput = props().onInput; | ||
if (onInput) { | ||
element.addEventListener<'beforeinput'>( | ||
'beforeinput', | ||
onInput as (this: HTMLTextAreaElement, ev: InputEvent) => unknown | ||
); | ||
} | ||
}); | ||
|
||
createEffect(() => { | ||
const onBlur = props().onBlur; | ||
if (onBlur) { | ||
element.addEventListener<'blur'>( | ||
'blur', | ||
onBlur as (this: HTMLTextAreaElement, ev: FocusEvent) => unknown | ||
); | ||
} | ||
}); | ||
} | ||
|
||
export function Textarea(initialProps: TextareaElementProps) { | ||
const [directiveProps, props] = splitProps(initialProps, ['value', 'onInput', 'onBlur']); | ||
return <textarea use:textareaField={directiveProps} {...props} />; | ||
export function Textarea(props: TextareaElementProps) { | ||
return <textarea {...props} />; | ||
} |
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