Skip to content

Commit

Permalink
Merge pull request #71 from purescript-contrib/topic/issue-70
Browse files Browse the repository at this point in the history
Aria and data props now prefix sub-props
  • Loading branch information
ethul committed Mar 14, 2016
2 parents fbdd2da + 0b862a2 commit cadcbe9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/React/DOM/Props.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ unsafeMkProps :: forall val. String -> val -> Props
unsafeUnfoldProps :: forall vals. String -> { | vals } -> Props
```

#### `unsafePrefixProps`

``` purescript
unsafePrefixProps :: forall vals. String -> { | vals } -> Props
```

#### `unsafeFromPropsArray`

``` purescript
Expand Down
17 changes: 16 additions & 1 deletion src/React/DOM/Props.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function unsafeUnfoldProps(key) {

for (var subprop in value) {
if (value.hasOwnProperty(subprop)) {
result[subprop] = value[subprop];
result[subprop] = value[subprop];
}
}

Expand All @@ -31,6 +31,21 @@ function unsafeUnfoldProps(key) {
}
exports.unsafeUnfoldProps = unsafeUnfoldProps;

function unsafePrefixProps(prefix) {
return function(value){
var result = {};

for (var prop in value) {
if (value.hasOwnProperty(prop)) {
result[prefix + prop] = value[prop];
}
}

return result;
};
}
exports.unsafePrefixProps = unsafePrefixProps;

function unsafeFromPropsArray(props) {
var result = {};

Expand Down
6 changes: 4 additions & 2 deletions src/React/DOM/Props.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ foreign import unsafeMkProps :: forall val. String -> val -> Props

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

foreign import unsafePrefixProps :: forall vals. String -> { | vals } -> Props

foreign import unsafeFromPropsArray :: forall props. Array Props -> props

aria :: forall ariaAttrs. { | ariaAttrs } -> Props
aria = unsafeUnfoldProps "aria"
aria = unsafePrefixProps "aria-"

_data :: forall dataAttrs. { | dataAttrs } -> Props
_data = unsafeUnfoldProps "data"
_data = unsafePrefixProps "data-"

style :: forall style. { | style } -> Props
style = unsafeUnfoldProps "style"
Expand Down

0 comments on commit cadcbe9

Please sign in to comment.