Skip to content

Commit 8f0cfeb

Browse files
authored
Add utility functions (#37)
* Add syntheticEvent EventFn * Add mergeStyles
1 parent 2379543 commit 8f0cfeb

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

generated-docs/React/Basic/DOM.md

+14
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ E.g.
3838
div { style: css { padding: "5px" } } [ text "This text is padded." ]
3939
```
4040

41+
#### `mergeStyles`
42+
43+
``` purescript
44+
mergeStyles :: Array CSS -> CSS
45+
```
46+
47+
Merge styles from right to left. Uses `Object.assign`.
48+
49+
E.g.
50+
51+
```
52+
style: mergeCSS [ (css { padding: "5px" }), props.style ]
53+
```
54+
4155
#### `SharedProps`
4256

4357
``` purescript

generated-docs/React/Basic/Events.md

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ input { onChange: handler_ (setState \_ -> { value })
8484
}
8585
```
8686

87+
#### `syntheticEvent`
88+
89+
``` purescript
90+
syntheticEvent :: EventFn SyntheticEvent SyntheticEvent
91+
```
92+
8793
#### `merge`
8894

8995
``` purescript

src/React/Basic/DOM.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
exports.mergeStyles = function(styles) {
4+
return Object.assign.apply(null, [ {} ].concat(styles));
5+
};

src/React/Basic/DOM.purs

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ foreign import data CSS :: Type
2929
css :: forall css. { | css } -> CSS
3030
css = unsafeCoerce
3131

32+
-- | Merge styles from right to left. Uses `Object.assign`.
33+
-- |
34+
-- | E.g.
35+
-- |
36+
-- | ```
37+
-- | style: mergeCSS [ (css { padding: "5px" }), props.style ]
38+
-- | ```
39+
foreign import mergeStyles :: Array CSS -> CSS
40+
3241
-- | Standard props which are shared by all DOM elements.
3342
type SharedProps specific =
3443
-- | `key` is not really a DOM attribute - React intercepts it

src/React/Basic/Events.purs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module React.Basic.Events
55
, unsafeEventFn
66
, handler
77
, handler_
8+
, syntheticEvent
89
, merge
910
, class Merge
1011
, mergeImpl
@@ -72,6 +73,9 @@ handler (EventFn fn) cb = mkEffFn1 $ fn >>> cb
7273
handler_ :: Eff (react :: ReactFX) Unit -> EventHandler
7374
handler_ = mkEffFn1 <<< const
7475

76+
syntheticEvent :: EventFn SyntheticEvent SyntheticEvent
77+
syntheticEvent = id
78+
7579
class Merge (rl :: RowList) fns a r | rl -> fns, rl a -> r where
7680
mergeImpl :: RLProxy rl -> Record fns -> EventFn a (Record r)
7781

0 commit comments

Comments
 (0)