Skip to content

Commit

Permalink
Move styleList and classList into attr module, fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-Ajaj committed Jul 22, 2019
1 parent 38d6757 commit 0f7f12b
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,5 @@ docs/tools/FSharp.Formatting.svclog
project.lock.json
bundle.js
bundle.js.map
.ionide
.ionide
dist
2 changes: 1 addition & 1 deletion demo/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let render state dispatch =

Html.button [
attr.className "btn btn-danger"
attr.style [ style.marginLeft 5 ]
attr.styleList [ true, [ style.marginLeft 5 ] ]
attr.onClick (fun _ -> dispatch Decrement)
attr.content "Decrement"
]
Expand Down
63 changes: 32 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
{
"private": true,
"scripts": {
"build": "webpack --mode production",
"start": "webpack-dev-server"
},
"repository": {
"type": "git",
"url": "https://github.com/Zaid-Ajaj/Elmish.Toastr.git"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-loader": "^8.0.0",
"css-loader": "^0.28.8",
"fable-compiler": "^2.3.3",
"fable-loader": "^2.1.6",
"gh-pages": "^1.1.0",
"loglevel": "^1.6.0",
"qunitjs": "^2.4.1",
"react": "^16.8.5",
"react-dom": "^16.8.5",
"remotedev": "^0.2.7",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"toastr": "^2.1.2",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.2.1"
}
}
"private": true,
"scripts": {
"build": "webpack --mode production",
"start": "webpack-dev-server",
"compile-demo-raw": "fable-splitter demo -o ./dist"
},
"repository": {
"type": "git",
"url": "https://github.com/Zaid-Ajaj/Elmish.Toastr.git"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-loader": "^8.0.0",
"css-loader": "^0.28.8",
"fable-compiler": "^2.3.3",
"fable-loader": "^2.1.6",
"gh-pages": "^1.1.0",
"loglevel": "^1.6.0",
"qunitjs": "^2.4.1",
"react": "^16.8.5",
"react-dom": "^16.8.5",
"remotedev": "^0.2.7",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"toastr": "^2.1.2",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.2.1"
}
}
25 changes: 14 additions & 11 deletions src/Attributes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ open Browser.Types
open Fable.Core.JsInterop
open Fable.Core

type attr() =
[<Erase>]
type attr =
static member inline id(value: string) = Interop.mkAttr "id" value
static member inline id(value: int) = Interop.mkAttr "id" (string value)
static member inline className(value: string) = Interop.mkAttr "className" value
static member inline classList (classes: (bool * string) list) =
classes
|> List.filter fst
|> List.map snd
|> String.concat " "
|> Interop.mkAttr "className"

static member inline key(value: string) = Interop.mkAttr "key" value
static member inline key(value: int) = Interop.mkAttr "key" value
static member inline defaultChecked(value: bool) = Interop.mkAttr "defaultChecked" value
Expand Down Expand Up @@ -69,7 +63,7 @@ type attr() =
static member inline start(value: string) = Interop.mkAttr "start" value
static member inline readOnly (value: bool) = Interop.mkAttr "readOnly" value
static member inline custom(key: string, value: 't) = Interop.mkAttr key value
static member children (elems: ReactElement list) = Interop.mkAttr "children" (Array.ofList elems)
static member inline children (elems: ReactElement list) = Interop.mkAttr "children" (Array.ofList elems)
static member inline onCut (handler: ClipboardEvent -> unit) = Interop.mkAttr "onCut" handler
static member inline onPaste (handler: ClipboardEvent -> unit) = Interop.mkAttr "onPaste" handler
static member inline onCompositionEnd (handler: CompositionEvent -> unit) = Interop.mkAttr "onCompositionEnd" handler
Expand Down Expand Up @@ -139,9 +133,18 @@ type attr() =
static member inline onAnimationIteration (handler: AnimationEvent -> unit) = Interop.mkAttr "onAnimationIteration" handler
static member inline onTransitionEnd (handler: TransitionEvent -> unit) = Interop.mkAttr "onTransitionEnd" handler
static member inline style (properties: IStyleAttribute list) = Interop.mkAttr "style" (keyValueList CaseRules.LowerFirst properties)
static member styleList (properties: (bool * IStyleAttribute list) list) =

module attr =
let styleList (properties: (bool * IStyleAttribute list) list) =
properties
|> List.filter fst
|> List.collect snd
|> keyValueList CaseRules.LowerFirst
|> Interop.mkAttr "style"
|> Interop.mkAttr "style"

let classList (classes: (bool * string) list) =
classes
|> List.filter fst
|> List.map snd
|> String.concat " "
|> Interop.mkAttr "className"
2 changes: 1 addition & 1 deletion src/Feliz.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageIconUrl></PackageIconUrl>
<PackageTags>fsharp;fable;react;html</PackageTags>
<Authors>Zaid Ajaj</Authors>
<Version>0.7.0</Version>
<Version>0.8.0</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
Expand Down
Loading

0 comments on commit 0f7f12b

Please sign in to comment.