Skip to content

Commit

Permalink
Merge pull request #60 from ahrefs/use-mel-unwrap
Browse files Browse the repository at this point in the history
Remove types from Utils that can be represented by [@mel.unwrap]
  • Loading branch information
johnhaley81 authored Dec 2, 2024
2 parents 46db576 + 57cc635 commit d5be141
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unpublished

- *[breaking]* improve bindings for XYZ axes, Treemap, Pie and Cell components [#59](https://github.com/ahrefs/melange-recharts/pull/59)
- *[breaking]* remove `TooltipCursor` module [#60](https://github.com/ahrefs/melange-recharts/pull/60)

## 4.0.7 (2024-11-23)

Expand Down
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,16 @@ module PxOrPrc = {
| Prc(float);
...
};
module StrOrNode = {
...
type arg =
| Str(string)
| Node(ReasonReact.reactElement);
...
};
```

you will use it like this:

```reason
<XAxis
interval=PreserveStart
label=Str("text")
/>
<XAxis
interval=Num(12)
label=Node(
<span>
(ReasonReact.stringToElement("text"))
</span>
)
/>
```

Expand Down
20 changes: 14 additions & 6 deletions src/Tooltip.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// http://recharts.org/en-US/api/Tooltip
open Utils;

[@mel.module "recharts"] [@react.component]
external make:
(
Expand All @@ -20,7 +18,20 @@ external make:
~className: string=?,
~content: 'content=?,
~position: Js.t({..})=?,
~cursor: TooltipCursor.t=?,
~cursor:
[@mel.unwrap] [
| `Bool(bool)
| `Obj(
Js.t({
.
"fill": option(string),
"stroke": option(string),
"strokeWidth": option(int),
}),
)
| `Element(React.element)
]
=?,
~filterNull: bool=?,
~formatter: 'formatter=?,
~isAnimationActive: bool=?,
Expand All @@ -37,6 +48,3 @@ external make:
) =>
React.element =
"Tooltip";

let makeProps = (~cursor=?) =>
makeProps(~cursor=?cursor->TooltipCursor.encodeOpt);
36 changes: 0 additions & 36 deletions src/Utils.re
Original file line number Diff line number Diff line change
Expand Up @@ -131,39 +131,3 @@ module PxOrPrc = {
| Prc(v) => Obj.magic(Js.Float.toString(v) ++ "%");
let encodeOpt = Option.map(encode);
};

module StrOrNode = {
type t;
type arg =
| Str(string)
| Node(React.element);
let encode: arg => t =
fun
| Str(v) => Obj.magic(v)
| Node(v) => Obj.magic(v);
let encodeOpt = Option.map(encode);
};

module TooltipCursor = {
[@deriving jsProperties]
type config = {
[@mel.optional]
fill: option(string),
[@mel.optional]
stroke: option(string),
[@mel.optional]
strokeWidth: option(int),
};

type t;
type arg =
| Bool(bool)
| Config(config)
| Component(React.element);
let encode: arg => t =
fun
| Bool(v) => Obj.magic(v)
| Config(v) => Obj.magic(v)
| Component(v) => Obj.magic(v);
let encodeOpt = Option.map(encode);
};

0 comments on commit d5be141

Please sign in to comment.