Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(ui): Improve QInput.nativeEl types Also exposing QInputNativeElement type with generics for more flexibility * feat(ui): Improve QFile.nativeEl types Also exposing QFileNativeElement type * feat(ui): Improve QInputNativeElement with file type handling
- Loading branch information
1 parent
904ba20
commit ee25829
Showing
5 changed files
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Error on "quasar" import shown in IDE is normal, as we only have Components/Directives/Plugins types after the build step | ||
// The import will work correctly at runtime | ||
import { QInputProps } from "quasar"; | ||
|
||
type QInputType = NonNullable<QInputProps["type"]>; | ||
|
||
type WithKnownType< | ||
TElement extends HTMLInputElement | HTMLTextAreaElement, | ||
TType extends QInputType | ||
> = Omit<TElement, "type"> & { type: TType }; | ||
|
||
/** | ||
* @example | ||
* ```ts | ||
* QInputNativeElement // HTMLInputElement | HTMLTextAreaElement | ||
* QInputNativeElement<"textarea"> // HTMLTextAreaElement | ||
* QInputNativeElement<"text"> // Omit<HTMLInputElement, "type"> & { type: "text" } | ||
* QInputNativeElement<"text" | "number"> // Omit<HTMLInputElement, "type"> & { type: "text" | "number" } | ||
* QInputNativeElement<"text" | "textarea"> // (Omit<HTMLInputElement, "type"> & { type: "text" }) | HTMLTextAreaElement | ||
* ``` | ||
*/ | ||
export type QInputNativeElement<T extends QInputType = QInputType> = | ||
T extends "textarea" | ||
? WithKnownType<HTMLTextAreaElement, "textarea"> | ||
: Omit<WithKnownType<HTMLInputElement, T>, "files"> & { | ||
files: T extends "file" ? FileList : null; | ||
}; |