-
Notifications
You must be signed in to change notification settings - Fork 1
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
- Loading branch information
Showing
7 changed files
with
225 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module ImprovedInput.State | ||
|
||
open Elmish | ||
open Types | ||
open Fable.Core.JsInterop | ||
open Fable.Import.Browser | ||
|
||
let init inputId = { | ||
Value = "" | ||
CursorStart = 1 | ||
CursorEnd = 1 | ||
InputId = inputId | ||
} | ||
|
||
let update msg model = | ||
match msg with | ||
| ChangeInput e -> | ||
{ model with Value = e.target?value; CursorStart = e.target?selectionStart; CursorEnd = e.target?selectionEnd}, Cmd.none | ||
| SetInput s -> | ||
{ model with Value = s}, Cmd.none | ||
| AddSymbol c -> | ||
let input : HTMLInputElement = !!document.getElementById(model.InputId) | ||
let cursorStart = int input.selectionStart | ||
let cursorEnd = int input.selectionEnd | ||
let startSection = model.Value.[0..cursorStart-1] | ||
let endSection = model.Value.[cursorEnd..] | ||
{ model with Value = startSection + string c + endSection; CursorStart = cursorStart; CursorEnd = cursorEnd }, Cmd.none | ||
| FocusInput -> | ||
document.getElementById(model.InputId).focus() | ||
model, Cmd.none | ||
| Reset -> | ||
init model.InputId, Cmd.none |
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,16 @@ | ||
module ImprovedInput.Types | ||
open Fable.Import.React | ||
|
||
type Model = { | ||
Value: string | ||
CursorStart: int | ||
CursorEnd: int | ||
InputId: string | ||
} | ||
|
||
type Msg = | ||
| ChangeInput of FormEvent | ||
| SetInput of string | ||
| AddSymbol of char | ||
| FocusInput | ||
| Reset |
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,34 @@ | ||
module ImprovedInput.View | ||
|
||
open Fable.Import.React | ||
open Fable.Helpers.React | ||
open Fable.Helpers.React.Props | ||
open Fulma | ||
|
||
open Types | ||
|
||
type Props = { | ||
InputSize: ISize | ||
OnKeyDownHandler: KeyboardEvent -> unit | ||
AutoCapitalize: string | ||
AutoFocus: bool | ||
AutoComplete: string | ||
} | ||
|
||
let inputView props model dispatch = | ||
Input.text | ||
[ | ||
Input.Id model.InputId | ||
Input.Props [ | ||
OnChange (ChangeInput >> dispatch) | ||
OnKeyDown props.OnKeyDownHandler | ||
AutoCapitalize props.AutoCapitalize | ||
AutoFocus props.AutoFocus | ||
AutoComplete props.AutoComplete | ||
] | ||
Input.ValueOrDefault model.Value | ||
Input.Size props.InputSize | ||
] | ||
|
||
let root props model dispatch = | ||
inputView props model dispatch |
Oops, something went wrong.