Skip to content

Commit d7dadc1

Browse files
andrevidelaepost
authored andcommitted
extract clzz function (#136)
1 parent 8f58686 commit d7dadc1

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

src/View/Common.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ styleStr kvs = HP.attr (HC.AttrName "style") (intercalate ";" <<< map (\(k /\ v)
1515

1616
emptyHtml :: a b. HTML b a
1717
emptyHtml = text ""
18+
19+
classesWithNames :: r i. Array String -> HP.IProp (class :: String | r) i
20+
classesWithNames names = HP.classes (HC.ClassName <$> names)

src/View/Petrinet/TransitionEditor.purs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Halogen.HTML.Properties (classes, disabled, src, width, height, type_, va
2020
import Data.Auth (Role(..), Roles(..), Privilege(..), RoleInfo, rolesElem, isPrivileged, toPrivilege, CSSColor(..))
2121
import Data.Auth as Auth
2222
import View.Petrinet.Model (TransitionQueryF(..), Typedef(..))
23-
import View.Common (styleStr)
23+
import View.Common (styleStr, classesWithNames)
2424

2525
type TransitionEditorFormModel tid =
2626
{ tid :: tid
@@ -38,14 +38,14 @@ form allRoleInfos mm =
3838
titledPanel "Transition properties" $
3939
formContainer
4040
[ fieldContainer "name" "grid-label-name" $
41-
input [ clzz inputClasses1
41+
input [ classesWithNames inputClasses1
4242
, value (maybe "" (_.label) mm)
4343
, maybe (disabled true)
4444
(\tid -> onValueChange (HE.input (UpdateTransitionName tid)))
4545
(mm <#> _.tid)
4646
]
4747
, fieldContainer "type" "grid-label-type" $
48-
input [ clzz inputClasses1
48+
input [ classesWithNames inputClasses1
4949
, value (maybe "" (un Typedef <<< _.typedef) mm)
5050
, maybe (disabled true)
5151
(\tid -> onValueChange (HE.input (UpdateTransitionType tid <<< Typedef)))
@@ -56,27 +56,27 @@ form allRoleInfos mm =
5656
]
5757
where
5858
titledPanel title content =
59-
div [ clzz [ "mb-2", "border-solid", "border-grey-light", "rounded", "border", "shadow-sm" ] ]
60-
[ div [ clzz [ "bg-grey-lighter", "px-2", "py-3", "border-solid", "border-grey-light", "border-b", "text-grey-darker" ] ]
59+
div [ classesWithNames [ "mb-2", "border-solid", "border-grey-light", "rounded", "border", "shadow-sm" ] ]
60+
[ div [ classesWithNames [ "bg-grey-lighter", "px-2", "py-3", "border-solid", "border-grey-light", "border-b", "text-grey-darker" ] ]
6161
[ text title ]
6262
, content
6363
]
6464

6565
formContainer formContent =
66-
div [ clzz [ "bg-white", "rounded", "flex", "flex-col", "px-4", "pt-6" ] ]
66+
div [ classesWithNames [ "bg-white", "rounded", "flex", "flex-col", "px-4", "pt-6" ] ]
6767
formContent
6868

6969
fieldContainer :: String -> String -> HTML _ _ -> HTML _ _
7070
fieldContainer labelText forInputId content =
71-
div [ clzz [ "-mx-3", "md:flex", "mb-6" ] ]
72-
[ div [ clzz [ "md:w-full", "px-3" ] ]
71+
div [ classesWithNames [ "-mx-3", "md:flex", "mb-6" ] ]
72+
[ div [ classesWithNames [ "md:w-full", "px-3" ] ]
7373
[ label1 forInputId labelText
7474
, content
7575
]
7676
]
7777

7878
label1 forInputId labelText =
79-
HH.label [ clzz [ "block", "uppercase", "tracking-wide", "text-grey-darker", "text-xs", "font-bold", "mb-2" ]
79+
HH.label [ classesWithNames [ "block", "uppercase", "tracking-wide", "text-grey-darker", "text-xs", "font-bold", "mb-2" ]
8080
, HP.for forInputId
8181
]
8282
[ text labelText ]
@@ -91,7 +91,7 @@ form allRoleInfos mm =
9191
authCheckboxes :: Roles -> Array (HTML _ _)
9292
authCheckboxes roles = checkboxContainer <<< (\roleInfo -> roleCheckbox allRoleInfosDict roleInfo $ priv roles roleInfo.id) <$> allRoleInfos
9393
where
94-
checkboxContainer html = div [ clzz [ "mt-4", "mb-4" ] ] [ html ]
94+
checkboxContainer html = div [ classesWithNames [ "mt-4", "mb-4" ] ] [ html ]
9595

9696
priv :: Roles -> Role -> Privilege
9797
priv privilegedRoles role = toPrivilege <<< rolesElem role $ privilegedRoles
@@ -121,6 +121,3 @@ roleTagHtml roleInfosDict role =
121121
backgroundColor = maybe (CSSColor "#ddd") _.bgColor roleInfoMaybe
122122
textColor = maybe (CSSColor "#666") _.textColor roleInfoMaybe
123123
roleInfoMaybe = Map.lookup role roleInfosDict
124-
125-
clzz :: Array String -> H.IProp _ _
126-
clzz strs = classes (ClassName <$> strs)

src/View/Studio/ObjectTree.purs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Halogen.HTML.Properties (classes, src, href)
1919
import Halogen.HTML.Properties.ARIA as ARIA
2020

2121
import View.Studio.Route (Route, RouteF(..))
22+
import View.Common (classesWithNames)
2223

2324
--------------------------------------------------------------------------------
2425

@@ -97,29 +98,29 @@ menuComponent isSelected =
9798

9899
render :: State -> HTML Void (Query Unit)
99100
render state = fromMaybe (div [] []) $ state.tree <#> \tree ->
100-
nav [ clzz [ componentCssClassNameStr, "p-4" ] ]
101-
[ ul [ clzz [ "list-reset" ] ] $
101+
nav [ classesWithNames [ componentCssClassNameStr, "p-4" ] ]
102+
[ ul [ classesWithNames [ "list-reset" ] ] $
102103
if state.hideRoot then (semifoldCofree menuItemHtml <$> tail tree)
103104
else [semifoldCofree menuItemHtml $ tree]
104105
]
105106
where
106107
menuItemHtml :: Item -> Array (HTML Void (Query Unit)) -> HTML Void (Query Unit)
107108
menuItemHtml treeNode kids =
108-
li [ clzz ([ "block", "flex", "cursor-pointer", "px-2", "py-2", "text-grey-darkest" ] <> activeClasses)]
109+
li [ classesWithNames ([ "block", "flex", "cursor-pointer", "px-2", "py-2", "text-grey-darkest" ] <> activeClasses)]
109110
[ div []
110111
[ arrowIcon
111-
, span [ clzz [ "pl-2" ]
112+
, span [ classesWithNames [ "pl-2" ]
112113
, onClick (HE.input_ clickQuery)
113114
]
114115
[ text treeNode.label ]
115-
, if isExpanded then ul [ clzz [ "list-reset", "mt-2" ] ] kids
116-
else span [ clzz [ "no-children" ] ] []
116+
, if isExpanded then ul [ classesWithNames [ "list-reset", "mt-2" ] ] kids
117+
else span [ classesWithNames [ "no-children" ] ] []
117118
]
118119
]
119120
where
120121
activeClasses = if isActive then [ "is-active", "bg-purple-darker", "text-purple-lighter", "rounded" ] else []
121122
arrowIcon = if null kids then text ""
122-
else span [ clzz [ "fas" , "fa-xs"
123+
else span [ classesWithNames [ "fas" , "fa-xs"
123124
, "fa-caret-" <> if isExpanded then "down" else "right"
124125
]
125126
, onClick (HE.input_ clickQuery)
@@ -131,8 +132,5 @@ menuComponent isSelected =
131132
isExpanded = not null kids && (fromMaybe true $ Map.lookup treeNode.id state.expansion)
132133
isActive = state.activeItem == pure treeNode.id
133134

134-
clzz :: Array String -> _
135-
clzz classStrs = classes (ClassName <$> classStrs)
136-
137135
semifoldCofree :: forall f a b. Functor f => (a -> f b -> b) -> Cofree f a -> b
138136
semifoldCofree f1 tree = f1 (head tree) (semifoldCofree f1 <$> tail tree)

0 commit comments

Comments
 (0)