reflex-dom-contrib-0.3: A playground for experimenting with infrastructure and common code for reflex applications

Safe HaskellNone
LanguageHaskell2010

Reflex.Dom.Contrib.Widgets.Common

Description

Infrastructure common to a wide variety of widgets. WidgetConfig holds the core inputs needed by most widgets, while HtmlWidget holds the core Dynamics and Events returned by most widgets. Encapsulating widget inputs and outputs this way makes it easier to compose and transform widgets.

Synopsis

Documentation

class HasChange a where Source

Associated Types

type Change a :: * Source

Methods

change :: a -> Change a Source

data WidgetConfig t a Source

Generic config structure common to most widgets. The attributes field may not be used for all widgets, but in that case it can just be ignored. We may want to change this in the future, but it seems like a reasonable start for now.

class IsWidget w where Source

Minimal complete definition

constWidget, mapWidget, combineWidgets, extractWidget

Methods

constWidget :: Reflex t => a -> w t a Source

HtmlWidget with a constant value that never fires any events.

mapWidget :: MonadWidget t m => (a -> b) -> w t a -> m (w t b) Source

We can't make a Functor instance until Dynamic gets a Functor instance.

combineWidgets :: MonadWidget t m => (a -> b -> c) -> w t a -> w t b -> m (w t c) Source

wconcat :: (MonadWidget t m, Foldable f, Monoid a) => f (w t a) -> m (w t a) Source

Combines multiple widgets over a Monoid operation.

extractWidget :: MonadWidget t m => Dynamic t (w t a) -> m (w t a) Source

Since widgets contain Dynamics and Events inside them, we can pull Dynamic widgets out of the Dynamic.

data Widget0 t a Source

A general-purpose widget return value.

Constructors

Widget0 

Fields

_widget0_value :: Dynamic t a

The authoritative value for this widget.

_widget0_change :: Event t a

Event that fires when the widget changes internally (not via a setValue event).

Instances

widget0_value :: forall t a. Lens' (Widget0 t a) (Dynamic t a) Source

widget0_change :: forall t a. Lens' (Widget0 t a) (Event t a) Source

data HtmlWidget t a Source

A general-purpose widget return value.

Constructors

HtmlWidget 

Fields

_hwidget_value :: Dynamic t a

The authoritative value for this widget.

_hwidget_change :: Event t a

Event that fires when the widget changes internally (not via a setValue event).

_hwidget_keypress :: Event t Int
 
_hwidget_keydown :: Event t Int
 
_hwidget_keyup :: Event t Int
 
_hwidget_hasFocus :: Dynamic t Bool
 

hwidget_value :: forall t a. Lens' (HtmlWidget t a) (Dynamic t a) Source

hwidget_keyup :: forall t a. Lens' (HtmlWidget t a) (Event t Int) Source

hwidget_keypress :: forall t a. Lens' (HtmlWidget t a) (Event t Int) Source

hwidget_keydown :: forall t a. Lens' (HtmlWidget t a) (Event t Int) Source

hwidget_change :: forall t a. Lens' (HtmlWidget t a) (Event t a) Source

type GWidget t m a = WidgetConfig t a -> m (HtmlWidget t a) Source

Generalized form of many widget functions.

dateTimeWidget :: MonadWidget t m => GWidget t m (Maybe UTCTime) Source

Input widget for datetime values.

dateWidget :: MonadWidget t m => GWidget t m (Maybe Day) Source

Input widget for dates.

htmlCheckbox :: MonadWidget t m => GWidget t m Bool Source

HtmlWidget version of reflex-dom's checkbox.

htmlTextInput :: MonadWidget t m => String -> GWidget t m String Source

HtmlWidget version of reflex-dom's textInput.

htmlTextInput' :: MonadWidget t m => String -> WidgetConfig t String -> m (HTMLInputElement, HtmlWidget t String) Source

HtmlWidget version of reflex-dom's textInput that also returns the HTMLInputElement.

readableWidget :: (MonadWidget t m, Show a, Readable a) => GWidget t m (Maybe a) Source

NOTE: You should probably not use this function with string types because the Show instance will quote strings.

doubleWidget :: MonadWidget t m => GWidget t m (Maybe Double) Source

Widget that parses its input to a Double.

integerWidget :: MonadWidget t m => GWidget t m (Maybe Integer) Source

Widget that parses its input to an Integer.

intWidget :: MonadWidget t m => GWidget t m (Maybe Int) Source

Widget that parses its input to an Int.

htmlDropdown :: (MonadWidget t m, Eq b) => Dynamic t [a] -> (a -> String) -> (a -> b) -> WidgetConfig t b -> m (Widget0 t b) Source

Dropdown widget that takes a dynamic list of items and a function generating a String representation of those items.

htmlDropdownStatic :: (MonadWidget t m, Eq b) => [a] -> (a -> String) -> (a -> b) -> WidgetConfig t b -> m (Widget0 t b) Source

Dropdown widget that takes a list of items and a function generating a String representation of those items.

This widget doesn't require your data type to have Read and Show instances like reflex-dom's dropdown function. It does this by using Int indices into your static list of items in the actual rendered dropdown element.

But this comes with a price--it has unexpected behavior under insertions, deletions, and reorderings of the list of options. Because of this, you should probably only use this for static dropdowns where the list of options never changes.

blurOrEnter :: Reflex t => HtmlWidget t a -> Event t a Source

Returns an event that fires when the widget loses focus or enter is pressed.

restrictWidget :: MonadWidget t m => (HtmlWidget t a -> Event t a) -> GWidget t m a -> GWidget t m a Source

Allows you to restrict when a widget fires. For instance, restrictWidget blurOrEnter restricts a widget so it only fires on blur or when enter is pressed.

inputOnEnter :: MonadWidget t m => (WidgetConfig t a -> m (HtmlWidget t a)) -> WidgetConfig t a -> m (Dynamic t a) Source

Like readableWidget but only generates change events on blur or when enter is pressed.

listDropdown :: MonadWidget t m => Dynamic t [a] -> (a -> String) -> Dynamic t (Map String String) -> String -> m (Dynamic t (Maybe a)) Source

A list dropdown widget.