| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
React.Flux.PropertiesAndEvents
Description
This module contains the definitions for creating properties to pass to javascript elements and foreign javascript classes. In addition, it contains definitions for the React Event System.
- data PropertyOrHandler handler
- property :: ToJSVal val => JSString -> val -> PropertyOrHandler handler
- elementProperty :: JSString -> ReactElementM handler () -> PropertyOrHandler handler
- nestedProperty :: JSString -> [PropertyOrHandler handler] -> PropertyOrHandler handler
- class CallbackFunction handler a | a -> handler
- callback :: CallbackFunction handler func => JSString -> func -> PropertyOrHandler handler
- callbackView :: JSString -> ReactView () -> PropertyOrHandler handler
- class ArgumentsToProps props a | a -> props
- newtype ReturnProps props = ReturnProps props
- callbackViewWithProps :: (Typeable props, ArgumentsToProps props func) => JSString -> ReactView props -> func -> PropertyOrHandler handler
- (@=) :: ToJSON a => JSString -> a -> PropertyOrHandler handler
- ($=) :: JSString -> JSString -> PropertyOrHandler handler
- (&=) :: ToJSVal a => JSString -> a -> PropertyOrHandler handler
- classNames :: [(Text, Bool)] -> PropertyOrHandler handler
- data Event = Event {}
- newtype EventTarget = EventTarget JSVal
- eventTargetProp :: FromJSVal val => EventTarget -> JSString -> val
- target :: FromJSVal val => Event -> JSString -> val
- preventDefault :: Event -> SomeStoreAction
- stopPropagation :: Event -> SomeStoreAction
- capturePhase :: PropertyOrHandler handler -> PropertyOrHandler handler
- on :: JSString -> (Event -> handler) -> PropertyOrHandler handler
- data KeyboardEvent = KeyboardEvent {
- keyEvtAltKey :: Bool
- keyEvtCharCode :: Int
- keyEvtCtrlKey :: Bool
- keyGetModifierState :: Text -> Bool
- keyKey :: Text
- keyCode :: Int
- keyLocale :: Maybe Text
- keyLocation :: Int
- keyMetaKey :: Bool
- keyRepeat :: Bool
- keyShiftKey :: Bool
- keyWhich :: Int
- onKeyDown :: (Event -> KeyboardEvent -> handler) -> PropertyOrHandler handler
- onKeyPress :: (Event -> KeyboardEvent -> handler) -> PropertyOrHandler handler
- onKeyUp :: (Event -> KeyboardEvent -> handler) -> PropertyOrHandler handler
- data FocusEvent = FocusEvent {}
- onBlur :: (Event -> FocusEvent -> handler) -> PropertyOrHandler handler
- onFocus :: (Event -> FocusEvent -> handler) -> PropertyOrHandler handler
- onChange :: (Event -> handler) -> PropertyOrHandler handler
- onInput :: (Event -> handler) -> PropertyOrHandler handler
- onSubmit :: (Event -> handler) -> PropertyOrHandler handler
- data MouseEvent = MouseEvent {
- mouseAltKey :: Bool
- mouseButton :: Int
- mouseButtons :: Int
- mouseClientX :: Int
- mouseClientY :: Int
- mouseCtrlKey :: Bool
- mouseGetModifierState :: Text -> Bool
- mouseMetaKey :: Bool
- mousePageX :: Int
- mousePageY :: Int
- mouseRelatedTarget :: EventTarget
- mouseScreenX :: Int
- mouseScreenY :: Int
- mouseShiftKey :: Bool
- onClick :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onContextMenu :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onDoubleClick :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onDrag :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onDragEnd :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onDragEnter :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onDragExit :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onDragLeave :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onDragOver :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onDragStart :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onDrop :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onMouseDown :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onMouseEnter :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onMouseLeave :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onMouseMove :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onMouseOut :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onMouseOver :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- onMouseUp :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler
- initializeTouchEvents :: IO ()
- data Touch = Touch {
- touchIdentifier :: Int
- touchTarget :: EventTarget
- touchScreenX :: Int
- touchScreenY :: Int
- touchClientX :: Int
- touchClientY :: Int
- touchPageX :: Int
- touchPageY :: Int
- data TouchEvent = TouchEvent {
- touchAltKey :: Bool
- changedTouches :: [Touch]
- touchCtrlKey :: Bool
- touchGetModifierState :: Text -> Bool
- touchMetaKey :: Bool
- touchShiftKey :: Bool
- touchTargets :: [Touch]
- touches :: [Touch]
- onTouchCancel :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler
- onTouchEnd :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler
- onTouchMove :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler
- onTouchStart :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler
- onScroll :: (Event -> handler) -> PropertyOrHandler handler
- data WheelEvent = WheelEvent {
- wheelDeltaMode :: Int
- wheelDeltaX :: Int
- wheelDeltaY :: Int
- wheelDeltaZ :: Int
- onWheel :: (Event -> MouseEvent -> WheelEvent -> handler) -> PropertyOrHandler handler
- onLoad :: (Event -> handler) -> PropertyOrHandler handler
- onError :: (Event -> handler) -> PropertyOrHandler handler
Documentation
data PropertyOrHandler handler Source #
Either a property or an event handler.
The combination of all properties and event handlers are used to create the javascript object
passed as the second argument to React.createElement.
Instances
| Functor PropertyOrHandler Source # | |
| (~) * child (ReactElementM eventHandler a) => Term eventHandler [PropertyOrHandler eventHandler] (child -> ReactElementM eventHandler a) Source # | |
Creating Properties
property :: ToJSVal val => JSString -> val -> PropertyOrHandler handler Source #
Create a property from anything that can be converted to a JSVal
elementProperty :: JSString -> ReactElementM handler () -> PropertyOrHandler handler Source #
Some third-party React classes allow passing React elements as properties. This function
will first run the given ReactElementM to obtain an element or elements, and then use that
element as the value for a property with the given key.
nestedProperty :: JSString -> [PropertyOrHandler handler] -> PropertyOrHandler handler Source #
Allows you to create nested object properties. The list of properties passed in will be converted to an object which is then set as the value for a property with the given name. For example,
[ nestedProperty "Hello" [ "a" @= (100 :: Int), "b" $= "World" ] , "c" $= "!!!" ]
would create a javascript object
{"Hello": {a: 100, b: "World"}, "c": "!!!"}class CallbackFunction handler a | a -> handler Source #
A class which is used to implement variable argument functions.
Any function where each argument implements FromJSVal and the result is either
ViewEventHandler or StatefulViewEventHandler is an instance of this class.
Minimal complete definition
applyFromArguments
Instances
| CallbackFunction ViewEventHandler ViewEventHandler Source # | |
| (FromJSVal a, CallbackFunction handler b) => CallbackFunction handler (a -> b) Source # | |
| CallbackFunction (StatefulViewEventHandler s) (StatefulViewEventHandler s) Source # | |
callback :: CallbackFunction handler func => JSString -> func -> PropertyOrHandler handler Source #
Create a callback property. This is primarily intended for foreign React classes which expect callbacks to be passed to them as properties. For events on DOM elements, you should instead use the handlers below.
The function func can be any function, as long as each argument to the function is an instance
of FromJSVal and the result of the function is handler. Internally, callback creates a
javascript function which accesses the arguments javascript object and then matches entries in
arguments to the parameters of func. If func has more parameters than the javascript
arguments object, a javascript null is used for the conversion. Since the Maybe instance of
FromJSVal converts a null reference to Nothing, you can exploit this to create
variable-argument javascript callbacks.
For example, all three of the following functions could be passed as func inside a view.
foo :: Int -> Maybe String -> ViewEventHandler bar :: Aeson.Value -> ViewEventHandler baz :: ViewEventHandler
For another example, see the haddock comments in React.Flux.Addons.Bootstrap.
callbackView :: JSString -> ReactView () -> PropertyOrHandler handler Source #
Create a zero-argument callback property. When this callback function is executed, it
will render the given view and return the resulting React element. If you need to
create a callback which expects arguments, use callbackViewWithProps instead.
class ArgumentsToProps props a | a -> props Source #
A class which is used to implement variable argument functions.
These variable argument functions are used to convert from a JavaScript
arguments array
to a Haskell value of type props.
Any function where each argument implements FromJSVal and the result is ReturnProps is an
instance of this class. Entries from the JavaScript arguments array are matched one-by-one to
the arguments before ReturnProps value. If the Haskell function has more parameters than the
javascript arguments object, a javascript null is used for the conversion. Since the Maybe
instance of FromJSVal converts null references to Nothing, you can exploit this to handle
arguments not given to the JavaScript function.
Minimal complete definition
returnViewFromArguments
Instances
| ArgumentsToProps props (ReturnProps props) Source # | |
| (FromJSVal a, ArgumentsToProps props b) => ArgumentsToProps props (a -> b) Source # | |
newtype ReturnProps props Source #
A type needed to make GHC happy when solving for instances of ArgumentsToProps.
Constructors
| ReturnProps props |
Instances
| ArgumentsToProps props (ReturnProps props) Source # | |
callbackViewWithProps :: (Typeable props, ArgumentsToProps props func) => JSString -> ReactView props -> func -> PropertyOrHandler handler Source #
Create a callback that when called will render a view. This is useful for interacting with third-party React classes that expect a property which is a function which when called returns a React element. The way this works is as follows:
You create a Haskell function which translates the javascript arguments of the callback into a Haskell value of type
ReturnProps props. This is a variable-argument function using theArgumentsToPropsclass. For example,data MyProps = MyProps { theInt :: Int, theString :: String } myArgsToProps :: Int -> String -> ReturnProps MyProps myArgsToProps i s = ReturnProps $ MyProps i sYou create a view which receives these properties and renders itself. This view will not receive any children.
myView :: ReactView MyProps mYView = defineView "my view" $ \myProps -> ...
You can then use
callbackViewWithPropsto create a property which is a JavaScript function. When this JavaScript function is executed, the JavaScript arguments are converted to the props, the view is rendered using the props, and the resulting React element is returned from the JavaScript function.someOtherView :: ReactView () someOtherView = defineView "some other view" $ \() -> div_ $ foreignClass_ "theForeginThing" [ callbackViewWithProps "the_propname_to_pass_to_theForeignThing" myView myArgsToProps , "hello" $= "world" ] memptytheForeignThingReact class will receive a property calledthe_propname_to_pass_to_theForeignThing. The value of this property is a JavaScript function which when executed will convert the arguments toprops, render the view, and return the resulting React element.
Combinators
(@=) :: ToJSON a => JSString -> a -> PropertyOrHandler handler Source #
Create a property from any aeson value (the at sign looks like A for aeson)
($=) :: JSString -> JSString -> PropertyOrHandler handler Source #
Create a text-valued property. This is here to avoid problems when OverloadedStrings extension is enabled
(&=) :: ToJSVal a => JSString -> a -> PropertyOrHandler handler Source #
Create a property for anything that can be converted to a javascript value using the ToJSVal
class from the ghcjs-base package.. This is just an infix version of property.
classNames :: [(Text, Bool)] -> PropertyOrHandler handler Source #
Set the className property to consist of all the names which are matched with True, allowing you to easily toggle class names based on a computation.
Creating Events
Every event in React is a synthetic event, a cross-browser wrapper around the native event.
Constructors
| Event | |
Fields
| |
newtype EventTarget Source #
A reference to the object that dispatched the event. https://developer.mozilla.org/en-US/docs/Web/API/Event/target
Constructors
| EventTarget JSVal |
Instances
eventTargetProp :: FromJSVal val => EventTarget -> JSString -> val Source #
Access a property in an event target
target :: FromJSVal val => Event -> JSString -> val Source #
A version of eventTargetProp which accesses the property of evtTarget in the event. This
is useful for example:
div_ $
input_ [ "type" @= "checked"
, onChange $ \evt -> let val = target evt "value" in ...
]In this case, val would coorespond to the javascript expression evt.target.value.
preventDefault :: Event -> SomeStoreAction Source #
Prevent the default browser action from occuring in response to this event.
stopPropagation :: Event -> SomeStoreAction Source #
Stop propagating this event, either down the DOM tree during the capture phase or up the DOM tree during the bubbling phase.
capturePhase :: PropertyOrHandler handler -> PropertyOrHandler handler Source #
By default, the handlers below are triggered during the bubbling phase. Use this to switch them to trigger during the capture phase.
on :: JSString -> (Event -> handler) -> PropertyOrHandler handler Source #
Use this to create an event handler for an event not covered by the rest of this module.
(Events are not covered if they don't have extra arguments that require special handling.)
For example, onPlay and onPause are events you could use with on.
Keyboard
data KeyboardEvent Source #
The data for the keyboard events
Constructors
| KeyboardEvent | |
Fields
| |
Instances
onKeyDown :: (Event -> KeyboardEvent -> handler) -> PropertyOrHandler handler Source #
onKeyPress :: (Event -> KeyboardEvent -> handler) -> PropertyOrHandler handler Source #
onKeyUp :: (Event -> KeyboardEvent -> handler) -> PropertyOrHandler handler Source #
Focus
onBlur :: (Event -> FocusEvent -> handler) -> PropertyOrHandler handler Source #
onFocus :: (Event -> FocusEvent -> handler) -> PropertyOrHandler handler Source #
Form
onChange :: (Event -> handler) -> PropertyOrHandler handler Source #
The onChange event is special in React and should be used for all input change events. For details, see https://facebook.github.io/react/docs/forms.html
onInput :: (Event -> handler) -> PropertyOrHandler handler Source #
onSubmit :: (Event -> handler) -> PropertyOrHandler handler Source #
Mouse
data MouseEvent Source #
Constructors
| MouseEvent | |
Fields
| |
Instances
onClick :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onContextMenu :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onDoubleClick :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onDrag :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onDragEnd :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onDragEnter :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onDragExit :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onDragLeave :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onDragOver :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onDragStart :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onDrop :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onMouseDown :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onMouseEnter :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onMouseLeave :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onMouseMove :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onMouseOut :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onMouseOver :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
onMouseUp :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source #
Touch
initializeTouchEvents :: IO () Source #
Initialize touch events is only needed with React 0.13, in version 0.14 it was removed.
Constructors
| Touch | |
Fields
| |
data TouchEvent Source #
Constructors
| TouchEvent | |
Fields
| |
Instances
onTouchCancel :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler Source #
onTouchEnd :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler Source #
onTouchMove :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler Source #
onTouchStart :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler Source #
UI
onScroll :: (Event -> handler) -> PropertyOrHandler handler Source #
Wheel
data WheelEvent Source #
Constructors
| WheelEvent | |
Fields
| |
Instances
onWheel :: (Event -> MouseEvent -> WheelEvent -> handler) -> PropertyOrHandler handler Source #
Image
onLoad :: (Event -> handler) -> PropertyOrHandler handler Source #
onError :: (Event -> handler) -> PropertyOrHandler handler Source #