Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove types from Utils that can be represented by [@mel.unwrap] #60

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For closed object type, the definition is just {. "fill": option(string) ...} without the preceding Js.t. I'll fix it in a bit.

.
"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);
};
Loading