Skip to content

icon helper and ReactComponent #3

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

Merged
merged 4 commits into from
Jul 11, 2022
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ Search for an icon on [`react-icons`](https://react-icons.github.io/react-icons)
and see these examples on how to import in PureScript.

```purescript
import React.Basic (element)
import React.Icons (icon, icon_)
import React.Icons.Fa (faGithub)
import React.Icons.Md (mdCrop)

element faGithub {}
element mdCrop { size: "24px", className: "my-class" }
icon_ faGithub
icon mdCrop { id: "0", className: "my-class", size: "24px", color: "#ff0000" }
```

## Libraries
Expand Down
2 changes: 1 addition & 1 deletion spago.dhall
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ name = "react-icons"
, dependencies = [ "react-basic", "react-basic-dom" ]
, dependencies = [ "react-basic", "react-basic-dom", "unsafe-coerce" ]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs" ]
, license = "MIT-0"
Expand Down
12 changes: 12 additions & 0 deletions src/React/Icons.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module React.Icons (icon, icon_) where

import Prim.Row (class Union)
import React.Basic (JSX, element)
import React.Icons.Types (ReactIcon, PropsIcon)
import Unsafe.Coerce (unsafeCoerce)

icon :: forall a b. Union a b PropsIcon => ReactIcon -> Record a -> JSX
icon reactIcon props = element (unsafeCoerce reactIcon) props

icon_ :: forall a b. Union a b PropsIcon => ReactIcon -> JSX
icon_ reactIcon = icon reactIcon {}
7 changes: 3 additions & 4 deletions src/React/Icons/Types.purs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module React.Icons.Types where
module React.Icons.Types (ReactIcon, PropsIcon) where

import Prim.Row (class Union)
import React.Basic (JSX, ReactComponent)
import React.Basic.DOM (CSS)

type ReactIcon = forall a b. Union a b PropsIcon => ReactComponent (Record a)
type ReactIcon = ReactComponent (Record PropsIcon)

type PropsIcon =
( children :: JSX
( children :: Array JSX
, size :: String
, color :: String
, title :: String
Expand Down