Skip to content

Commit bcb83eb

Browse files
committed
0.6.2 position, stack, ListItem, Layer
1 parent 110c758 commit bcb83eb

File tree

12 files changed

+238
-115
lines changed

12 files changed

+238
-115
lines changed

bin/dev

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ watchexec -e hs,yaml cabal test &
2222

2323
# Autoreload on save. Show errors and warnings
2424
# run even if warnings
25+
cd example
2526
ghcid --command "cabal repl example" -T Main.main -W

example/app/Main.hs

+35-4
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,46 @@ stacks = layout id $ do
8585
col (pad 10 . gap 10) $ do
8686
el_ "Stacks put contents on top of each other"
8787
stack (border 1) $ do
88-
row (bg Light) $ el (pad 10) "In the background"
89-
row (pad 10) $ do
88+
layer $ el (bg Light . pad 10) "In the background"
89+
layer $ row (pad 10) $ do
9090
space
9191
el (bg SecondaryLight . grow . pad 5) "Above"
92-
row (pad (XY 15 5)) $ do
92+
layer $ row (pad (XY 15 5)) $ do
9393
space
9494
el (bg Primary . pad 10 . color White) "Max Above!"
9595

96+
el_ "We can collapse items in a stack so they don't affect the width"
97+
stack (bg Light . pad 10) $ do
98+
layer $ el_ "WOOT"
99+
popout (offset (R 0) . offset (B 0)) $ col (pad 10 . bg SecondaryLight) $ do
100+
el_ "One"
101+
el_ "Two"
102+
el_ "Three"
103+
el_ "Four"
104+
105+
el_ "Example Popup Search"
106+
stack (border 1) $ do
107+
layer $ row (bg Light . pad 10) "This is a search bar"
108+
popout (offset (TRBL 43 5 5 5) . border 1) $ do
109+
col (bg SecondaryLight . pad (L 50) . pad (R 50)) $ do
110+
el (hover (bg White) . pointer) "I am a popup"
111+
el_ "I am a popup"
112+
el_ "I am a popup"
113+
el_ "I am a popup"
114+
115+
col (gap 10) $ do
116+
el_ "Content asldkjfalsdk jjklasd flkajsd flkjasd lfkjalskdfj alsdkjf "
117+
el_ "Content asldkjfalsdk jjklasd flkajsd flkjasd lfkjalskdfj alsdkjf "
118+
el_ "Content asldkjfalsdk jjklasd flkajsd flkjasd lfkjalskdfj alsdkjf "
119+
el_ "Content asldkjfalsdk jjklasd flkajsd flkjasd lfkjalskdfj alsdkjf "
120+
el_ "Content asldkjfalsdk jjklasd flkajsd flkjasd lfkjalskdfj alsdkjf "
121+
el_ "Content asldkjfalsdk jjklasd flkajsd flkjasd lfkjalskdfj alsdkjf "
122+
el_ "Content asldkjfalsdk jjklasd flkajsd flkjasd lfkjalskdfj alsdkjf "
123+
el_ "Content asldkjfalsdk jjklasd flkajsd flkjasd lfkjalskdfj alsdkjf "
124+
el_ "Content asldkjfalsdk jjklasd flkajsd flkjasd lfkjalskdfj alsdkjf "
125+
126+
col (border 1 . position Absolute . offset (R 0) . offset (T 0)) "I AM AN ELEMENT"
127+
96128

97129
tests :: View c ()
98130
tests = col (gap 10 . pad 20) $ do
@@ -112,7 +144,6 @@ tests = col (gap 10 . pad 20) $ do
112144
li nums "first"
113145
li nums "second"
114146
li nums "third"
115-
col id "HELLO"
116147

117148
ul id $ do
118149
li (list Disc) "first"

package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: web-view
2-
version: 0.6.1
2+
version: 0.6.2
33
synopsis: Type-safe HTML and CSS with intuitive layouts and composable styles.
44
homepage: https://github.com/seanhess/web-view
55
github: seanhess/web-view

src/Web/View.hs

+24-15
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ module Web.View
3636
, root
3737
, col
3838
, row
39-
, stack
40-
, grow
4139
, space
42-
, collapse
43-
, scroll
4440
, nav
41+
, stack
42+
, Layer
43+
, layer
44+
, popout
45+
, scroll
46+
, grow
47+
, flexRow
48+
, flexCol
49+
, hide
50+
, truncate
4551

4652
-- ** Content
4753
, text
@@ -82,15 +88,12 @@ module Web.View
8288
, height
8389
, minWidth
8490
, minHeight
85-
, flexRow
86-
, flexCol
87-
, display
8891
, pad
8992
, gap
90-
, hide
9193
, opacity
92-
, truncate
9394
, shadow
95+
, Shadow
96+
, Inner (..)
9497
, rounded
9598
, fontSize
9699
, color
@@ -101,16 +104,27 @@ module Web.View
101104
, border
102105
, borderColor
103106
, pointer
104-
, transition
107+
, position
108+
, Position (..)
109+
, offset
110+
, zIndex
105111
, textAlign
112+
, Align (..)
106113
, list
114+
, ListType (..)
115+
, display
116+
, Display (..)
117+
, transition
118+
, TransitionProperty (..)
119+
, Ms
107120

108121
-- ** Selector States
109122
, hover
110123
, active
111124
, even
112125
, odd
113126
, media
127+
, Media (..)
114128
, parent
115129

116130
-- * View Context
@@ -123,15 +137,10 @@ module Web.View
123137

124138
-- * Types
125139
, Sides (..)
126-
, Media (..)
127140
, PxRem
128141
, Length (..)
129-
, TransitionProperty (..)
130-
, Ms
131142
, ToColor (..)
132143
, HexColor (..)
133-
, Align (..)
134-
, ListType (..)
135144
, None (..)
136145

137146
-- * Url

src/Web/View/Element.hs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DerivingStrategies #-}
3+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
24

35
module Web.View.Element where
46

@@ -74,7 +76,7 @@ link u f = tag "a" (att "href" (renderUrl u) . f)
7476

7577

7678
form :: Mod c -> View c () -> View c ()
77-
form f = tag "form" (f . flexCol)
79+
form = tag "form"
7880

7981

8082
input :: Mod c -> View c ()
@@ -172,7 +174,8 @@ data TableColumn c dt = TableColumn
172174
-- * Lists
173175

174176

175-
data ListItem c = ListItem
177+
newtype ListItem c a = ListItem (View c a)
178+
deriving newtype (Functor, Applicative, Monad)
176179

177180

178181
{- | List elements do not include any inherent styling but are useful for accessibility. See 'Web.View.Style.list'.
@@ -183,13 +186,16 @@ data ListItem c = ListItem
183186
> li nums "two"
184187
> li nums "three"
185188
-}
186-
ol :: Mod c -> View (ListItem c) () -> View c ()
187-
ol f cnt = tag "ol" f $ addContext ListItem cnt
189+
ol :: Mod c -> ListItem c () -> View c ()
190+
ol f (ListItem cnt) = do
191+
tag "ol" f cnt
188192

189193

190-
ul :: Mod c -> View (ListItem c) () -> View c ()
191-
ul f cnt = tag "ul" f $ addContext ListItem cnt
194+
ul :: Mod c -> ListItem c () -> View c ()
195+
ul f (ListItem cnt) = do
196+
tag "ul" f cnt
192197

193198

194-
li :: Mod (ListItem c) -> View (ListItem c) () -> View (ListItem c) ()
195-
li = tag "li"
199+
li :: Mod c -> View c () -> ListItem c ()
200+
li f cnt = ListItem $ do
201+
tag "li" f cnt

src/Web/View/Layout.hs

+67-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{-# LANGUAGE DerivingStrategies #-}
2+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3+
14
module Web.View.Layout where
25

36
import Data.Function
@@ -94,11 +97,6 @@ space :: View c ()
9497
space = el grow none
9598

9699

97-
-- | Allow items to become smaller than their contents. This is not the opposite of `grow`!
98-
collapse :: Mod c
99-
collapse = addClass $ cls "collapse" & prop @Int "min-width" 0
100-
101-
102100
{- | Make a fixed 'layout' by putting 'scroll' on a child-element
103101
104102
> document = row root $ do
@@ -114,24 +112,83 @@ nav :: Mod c -> View c () -> View c ()
114112
nav f = tag "nav" (f . flexCol)
115113

116114

117-
{- | Stack children on top of each other. Each child has the full width
115+
{- | Stack children on top of each other. Each child has the full width. See 'popout'
118116
119117
> stack id $ do
120118
> row id "Background"
121119
> row (bg Black . opacity 0.5) "Overlay"
122120
-}
123-
stack :: Mod c -> View c () -> View c ()
124-
stack f =
125-
tag "div" (f . container . absChildren)
121+
stack :: Mod c -> Layer c () -> View c ()
122+
stack f (Layer children) = do
123+
tag "div" (f . container . absChildren) children
126124
where
127125
container =
128126
addClass $
129127
cls "stack"
130128
& prop @Text "position" "relative"
131129
& prop @Text "display" "grid"
130+
& prop @Text "overflow" "visible"
132131
absChildren =
133132
addClass $
134133
Class absSelector mempty
135-
& prop @Text "position" "relative"
136134
& prop @Text "grid-area" "1 / 1"
135+
& prop @Text "min-height" "fit-content"
137136
absSelector = (selector "abs-childs"){child = Just AllChildren}
137+
138+
139+
-- | A popout does not
140+
newtype Layer c a = Layer (View c a)
141+
deriving newtype (Functor, Applicative, Monad)
142+
143+
144+
-- | A normal layer contributes to the size of the parent
145+
layer :: View c () -> Layer c ()
146+
layer = Layer
147+
148+
149+
{- | This child of a 'stack' can pop out of the parent, covering content outside of it. Only usable inside 'stack'
150+
151+
> stack id $ do
152+
> layer id $ input (value "Autocomplete Box")
153+
> layer (popout (TRBL 50 0 0 0)) $ do
154+
> el_ "Item 1"
155+
> el_ "Item 2"
156+
> el_ "Item 3"
157+
> el_ "This is covered by the menu"
158+
-}
159+
popout :: Mod c -> View c () -> Layer c () -- Sides Length -> Mod (Stack c)
160+
popout f cnt = Layer $ do
161+
el (position Absolute . zIndex 1 . f) cnt
162+
163+
164+
-- | Hide an element. See 'display'
165+
hide :: Mod c
166+
hide = display None
167+
168+
169+
-- | Set container to be a row. Favor 'Web.View.Layout.row' when possible
170+
flexRow :: Mod c
171+
flexRow =
172+
addClass $
173+
cls "row"
174+
& prop @Text "display" "flex"
175+
& prop @Text "flex-direction" "row"
176+
177+
178+
-- | Set container to be a column. Favor 'Web.View.Layout.col' when possible
179+
flexCol :: Mod c
180+
flexCol =
181+
addClass $
182+
cls "col"
183+
& prop @Text "display" "flex"
184+
& prop @Text "flex-direction" "column"
185+
186+
187+
-- | Cut off the contents of the element
188+
truncate :: Mod c
189+
truncate =
190+
addClass $
191+
cls "truncate"
192+
& prop @Text "white-space" "nowrap"
193+
& prop @Text "overflow" "hidden"
194+
& prop @Text "text-overflow" "ellipsis"

src/Web/View/Render.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Web.View.Render where
99
import Data.ByteString.Lazy qualified as BL
1010
import Data.Function ((&))
1111
import Data.List (foldl')
12-
import Data.Map qualified as M
12+
import Data.Map.Strict qualified as M
1313
import Data.Maybe (mapMaybe)
1414
import Data.String (fromString)
1515
import Data.String.Interpolate (i)

0 commit comments

Comments
 (0)