Skip to content

Commit 5cc0164

Browse files
authored
icon helper and ReactComponent (#3)
Issue: ReactComponent with constraint didn't work Change: * Add `icon` and `icon_` helper functions (suggested by natefaubion) * Going with a react component without constraints for icons * Fix `children` prop type (Array)
1 parent de7520e commit 5cc0164

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ Search for an icon on [`react-icons`](https://react-icons.github.io/react-icons)
1919
and see these examples on how to import in PureScript.
2020

2121
```purescript
22-
import React.Basic (element)
22+
import React.Icons (icon, icon_)
2323
import React.Icons.Fa (faGithub)
2424
import React.Icons.Md (mdCrop)
2525
26-
element faGithub {}
27-
element mdCrop { size: "24px", className: "my-class" }
26+
icon_ faGithub
27+
icon mdCrop { id: "0", className: "my-class", size: "24px", color: "#ff0000" }
2828
```
2929

3030
## Libraries

spago.dhall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{ name = "react-icons"
2-
, dependencies = [ "react-basic", "react-basic-dom" ]
2+
, dependencies = [ "react-basic", "react-basic-dom", "unsafe-coerce" ]
33
, packages = ./packages.dhall
44
, sources = [ "src/**/*.purs" ]
55
, license = "MIT-0"

src/React/Icons.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module React.Icons (icon, icon_) where
2+
3+
import Prim.Row (class Union)
4+
import React.Basic (JSX, element)
5+
import React.Icons.Types (ReactIcon, PropsIcon)
6+
import Unsafe.Coerce (unsafeCoerce)
7+
8+
icon :: forall a b. Union a b PropsIcon => ReactIcon -> Record a -> JSX
9+
icon reactIcon props = element (unsafeCoerce reactIcon) props
10+
11+
icon_ :: forall a b. Union a b PropsIcon => ReactIcon -> JSX
12+
icon_ reactIcon = icon reactIcon {}

src/React/Icons/Types.purs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
module React.Icons.Types where
1+
module React.Icons.Types (ReactIcon, PropsIcon) where
22

3-
import Prim.Row (class Union)
43
import React.Basic (JSX, ReactComponent)
54
import React.Basic.DOM (CSS)
65

7-
type ReactIcon = forall a b. Union a b PropsIcon => ReactComponent (Record a)
6+
type ReactIcon = ReactComponent (Record PropsIcon)
87

98
type PropsIcon =
10-
( children :: JSX
9+
( children :: Array JSX
1110
, size :: String
1211
, color :: String
1312
, title :: String

0 commit comments

Comments
 (0)