Skip to content

Commit 0b862a2

Browse files
committed
Aria and data props now prefix sub-props
Resolves #70
1 parent fbdd2da commit 0b862a2

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

docs/React/DOM/Props.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ unsafeMkProps :: forall val. String -> val -> Props
1818
unsafeUnfoldProps :: forall vals. String -> { | vals } -> Props
1919
```
2020

21+
#### `unsafePrefixProps`
22+
23+
``` purescript
24+
unsafePrefixProps :: forall vals. String -> { | vals } -> Props
25+
```
26+
2127
#### `unsafeFromPropsArray`
2228

2329
``` purescript

src/React/DOM/Props.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function unsafeUnfoldProps(key) {
2222

2323
for (var subprop in value) {
2424
if (value.hasOwnProperty(subprop)) {
25-
result[subprop] = value[subprop];
25+
result[subprop] = value[subprop];
2626
}
2727
}
2828

@@ -31,6 +31,21 @@ function unsafeUnfoldProps(key) {
3131
}
3232
exports.unsafeUnfoldProps = unsafeUnfoldProps;
3333

34+
function unsafePrefixProps(prefix) {
35+
return function(value){
36+
var result = {};
37+
38+
for (var prop in value) {
39+
if (value.hasOwnProperty(prop)) {
40+
result[prefix + prop] = value[prop];
41+
}
42+
}
43+
44+
return result;
45+
};
46+
}
47+
exports.unsafePrefixProps = unsafePrefixProps;
48+
3449
function unsafeFromPropsArray(props) {
3550
var result = {};
3651

src/React/DOM/Props.purs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ foreign import unsafeMkProps :: forall val. String -> val -> Props
88

99
foreign import unsafeUnfoldProps :: forall vals. String -> { | vals } -> Props
1010

11+
foreign import unsafePrefixProps :: forall vals. String -> { | vals } -> Props
12+
1113
foreign import unsafeFromPropsArray :: forall props. Array Props -> props
1214

1315
aria :: forall ariaAttrs. { | ariaAttrs } -> Props
14-
aria = unsafeUnfoldProps "aria"
16+
aria = unsafePrefixProps "aria-"
1517

1618
_data :: forall dataAttrs. { | dataAttrs } -> Props
17-
_data = unsafeUnfoldProps "data"
19+
_data = unsafePrefixProps "data-"
1820

1921
style :: forall style. { | style } -> Props
2022
style = unsafeUnfoldProps "style"

0 commit comments

Comments
 (0)