This module contains a simple chat component that you can easily add to your Elm user interface.
CustomSettings () msg
Old, uncustomizable Settings for the chat component.
Make one of these with makeSettings
, and store it in your model.
{ chatTable : List (Html.Attribute msg)
, sizeButtons : List (Html.Attribute msg)
, sizeColumn : List (Html.Attribute msg)
, textColumn : List (Html.Attribute msg)
, textArea : List (Html.Attribute msg)
}
Extra attributes for the UI components.
This is the initial value of Settings.attributes
.
You'll usually create one by changing defaultExtraAttributes
.
CustomSettings state msg -> Platform.Cmd.Cmd msg -> msg
A function to turn a Settings
record and a Cmd
into a msg
.
String -> CustomSettings state msg -> msg
A function to turn an input string and a Settings
record into a msg
.
Represents a single line in a chat.
A wrapper around Updater to prevent type recursion.
{ fontSize : Basics.Int
, lines : List (LineSpec state)
, customRenderers : Maybe (CustomRenderers state msg)
, input : String
, scroll : Basics.Float
, attributes : ExtraAttributes msg
, id : String
, defaultFontSize : Basics.Int
, showSizeControls : Basics.Bool
, updater : TheUpdater state msg
, zone : Time.Zone
}
Customizable Settings.
Make one of these with makeSettings
, optionally customize the customRenderers
field, and store it in your model.
makeSettings : String -> Basics.Int -> Basics.Bool -> Updater state msg -> CustomSettings state msg
Make a settings record to add to your Model.
Args are id initialFontSize showSizeControls updater
.
id
is the Html id for the div showing the chat.
initialFontSize
is the initial font size of the div in pt
.
showSizeControls
is True
to show the font size controls to the left of the text area.
updater
will be called to generate messages to update the settings in your Model.
chat : CustomSettings state msg -> Html msg
Create a chat component.
addChat : CustomSettings state msg -> String -> ( CustomSettings state msg, Platform.Cmd.Cmd msg )
Add a string to the chat box.
inputBox : Basics.Int -> String -> Sender state msg -> CustomSettings state msg -> Html msg
Create a text input control.
Args are textSize buttonText sender settings
.
textSize
is the width in characters of the input control.
buttonText
is the text for the button that sends the input.
sender
is a function to turn an input string and settings into a
msg`.
settings
is your Settings
record.
styledInputBox : List (Html.Attribute msg) -> List (Html.Attribute msg) -> Basics.Int -> String -> Sender state msg -> CustomSettings state msg -> Html msg
Same as inputBox
, but takes two additional lists of attributes.
The first list is for the input
box. The second is for the button
.
addLineSpec : CustomSettings state msg -> LineSpec state -> ( CustomSettings state msg, Platform.Cmd.Cmd msg )
Add a line to the chat box.
makeLineSpec : String -> Maybe String -> Maybe Time.Posix -> LineSpec state
Make a LineSpec
including a message and an optional user and time.
encodeSettings : CustomSettings state msg -> String
Turn chat Settings
into a JSON string.
Does not encode the attributes
or updater
properties.
settingsEncoder : CustomSettings state msg -> Json.Encode.Value
The JSON encoder for encodeSettings
.
decodeSettings : Updater state msg -> String -> Result String (CustomSettings state msg)
Turn a JSON string back into a CustomSettings
record.
Updater
is as to makeSettings
.
Restores with default attributes
, so you'll need to change those
after decoding, if you customize them.
settingsDecoder : Updater state msg -> Json.Decode.Decoder (CustomSettings state msg)
The JSON Decoder for decodeSettings
.
restoreScroll : CustomSettings state msg -> Platform.Cmd.Cmd msg
Restore the scroll position after restoring from a JSON string.
timeString : Time.Zone -> Time.Posix -> String
Convert a zoned time to a string in the format "HH:MM"
timestampString : Time.Zone -> Time.Posix -> String
Convert a zoned time to a string in the format "HH:MM:SS"
parseOutUrl : String -> Maybe ( String, String, String )
Parse the first URL out of a string.
The result is Just (prefix, url, suffix)
, if there is a URL, or Nothing
otherwise.
"foo.com" is interpreted as a URL, but is returned as just "foo.com". You have to prepend the http:// yourself, if that's what you need.
Used to customize rendering.
Set the customRenderers
field of your settings record to one of these, if you want to override the default rendering, or render your own CustomLineSpec.
The overrider
can provide an alternate to the default renderers for StringLineSpec
, UserLineSpec
, and TimeLineSpec
.
The renderer
will be called on CustomLineSpec
s.
CustomSettings state msg -> LineSpec state -> Maybe (Html msg)
User function to override rendering of standard LineSpec
options.
state -> CustomSettings state msg -> Html msg
User function to render CustomLineSpec
state.
encodeCustomSettings : CustomSettings state msg -> (state -> Json.Encode.Value) -> String
Turn CustomSettings
into a JSON string.
Use the (state -> Value)
function to encode CustomLineSpec
s.
Does not encode the attributes
or updater
properties.
customSettingsEncoder : CustomSettings state msg -> (state -> Json.Encode.Value) -> Json.Encode.Value
The JSON encoder for encodeSettings
.
decodeCustomSettings : Updater state msg -> Json.Decode.Decoder state -> String -> Result String (CustomSettings state msg)
Turn a JSON string that may contain CustomLineSpec
s back into a CustomSettings
record.
Updater
is as to makeSettings
.
The state
decoder turns a Value
into your state.
Restores with default attributes
, so you'll need to change those
after decoding, if you customize them.
customSettingsDecoder : Updater state msg -> Json.Decode.Decoder state -> Json.Decode.Decoder (CustomSettings state msg)
The JSON Decoder for decodeCustomSettings
.
defaultExtraAttributes : ExtraAttributes msg
The default value of the Settings.attributes
property.