Skip to content

Commit da9e455

Browse files
committed
factored overflow, whiteSpace, instead of clip & scroll. Docs
asdf
1 parent 4e8dd65 commit da9e455

10 files changed

Lines changed: 167 additions & 124 deletions

File tree

README.md

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,86 @@ Atomic CSS
33

44
[![Hackage](https://img.shields.io/hackage/v/atomic-css.svg)][hackage]
55

6-
Type-safe HTML and CSS with intuitive layout and composable styles. Inspired by Tailwindcss and Elm-UI
6+
Type-safe, composable CSS utility functions. Inspired by Tailwindcss and Elm-UI
7+
78

89
### Write Haskell instead of CSS
910

10-
Type-safe utility functions to generate styled HTML.
11+
Style your html with composable CSS utility functions:
1112

1213
```haskell
13-
myPage = col (gap 10) $ do
14-
el (bold . fontSize 32) "My page"
15-
button (border 1) "Click Me"
14+
el ~ bold . pad 8 $ "Hello World"
15+
```
16+
17+
This renders as the following HTML with embedded CSS utility classes:
18+
19+
```html
20+
<style type='text/css'>
21+
.bold { font-weight:bold }
22+
.p-8 { padding:0.500rem }
23+
</style>
24+
25+
<div class='bold p-8'>Hello World</div>
1626
```
1727

18-
Leverage the full power of Haskell functions for reuse, instead of relying on CSS.
28+
Instead of relying on the fickle cascade, factor and compose styles with the full power of Haskell functions!
1929

2030
```haskell
2131
header = bold
2232
h1 = header . fontSize 32
2333
h2 = header . fontSize 24
24-
page = gap 10
34+
page = flexCol . gap 10 . pad 10
2535

26-
myPage = col page $ do
27-
el h1 "My Page"
28-
...
36+
example = el ~ page $ do
37+
el ~ h1 $ "My Page"
38+
el ~ h2 $ "Introduction"
39+
el "lorem ipsum..."
2940
```
3041

31-
This approach is inspired by Tailwindcss' [Utility Classes](https://tailwindcss.com/docs/utility-first)
42+
This approach is inspired by Tailwindcss' [Utility Classes](https://tailwindcss.com/docs/styling-with-utility-classes)
43+
3244

33-
### Intuitive Layouts
45+
### Intuitive Flexbox Layouts
3446

35-
Easily create layouts with `row`, `col`, `grow`, and `space`
47+
Create complex layouts with `row`, `col`, `grow`, and `space`
3648

3749
```haskell
38-
holygrail :: View c ()
39-
holygrail = layout id $ do
40-
row section "Top Bar"
41-
row grow $ do
42-
col section "Left Sidebar"
43-
col (section . grow) "Main Content"
44-
col section "Right Sidebar"
45-
row section "Bottom Bar"
46-
where section = 'border' 1
50+
holygrail = do
51+
col ~ grow $ do
52+
row "Top Bar"
53+
row ~ grow $ do
54+
col "Left Sidebar"
55+
col ~ grow $ "Main Content"
56+
col "Right Sidebar"
57+
row "Bottom Bar"
4758
```
4859

49-
### Embedded CSS
50-
51-
Views track which styles are used in any child node, and automatically embed all CSS when rendered.
52-
53-
>>> renderText $ el bold "Hello"
54-
55-
<style type='text/css'>.bold { font-weight:bold }</style>
56-
<div class='bold'>Hello</div>
57-
58-
5960
### Stateful Styles
6061

61-
We can apply styles when certain states apply. For example, to change the background on hover:
62+
We can apply utilities when certain states apply. For example, to change the background on hover:
6263

6364
```haskell
64-
button (bg Primary . hover (bg PrimaryLight)) "Hover Me"
65+
button ~ bg Primary . hover (bg PrimaryLight) $ "Hover Me"
6566
```
6667

6768
Media states allow us to create responsive designs
6869

6970
```haskell
70-
el (width 100 . media (MinWidth 800) (width 400))
71+
el ~ width 100 . media (MinWidth 800) (width 400) $ do
7172
"Big if window > 800"
7273
```
7374

75+
76+
### Embedded CSS
77+
78+
Only the utilities used in a given html fragment are rendered:
79+
80+
>>> renderText $ el ~ bold $ "Hello"
81+
82+
<style type='text/css'>.bold { font-weight:bold }</style>
83+
<div class='bold'>Hello</div>
84+
85+
7486
### Try Example Project with Nix
7587

7688
If you want to get a feel for atomic-css without cloning the project run `nix run github:seanhess/atomic-css` to run the example webserver locally

atomic-css.cabal

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ cabal-version: 2.2
66

77
name: atomic-css
88
version: 0.1.0
9-
synopsis: Type-safe Atomic CSS with intuitive layouts and composable css utility classes. Inspired by Tailwindcss and Elm-UI
10-
description: Type-safe Atomic CSS with intuitive layouts and composable css utility classes. Inspired by Tailwindcss and Elm-UI . See documentation for the @Web.Atomic@ module below
9+
synopsis: Type-safe, composable CSS utility functions. Inspired by Tailwindcss and Elm-UI
10+
description: Type-safe, composable CSS utility functions. Inspired by Tailwindcss and Elm-UI . See documentation for the @Web.Atomic@ module below
1111
category: Web
1212
homepage: https://github.com/seanhess/atomic-css
1313
bug-reports: https://github.com/seanhess/atomic-css/issues
@@ -20,7 +20,7 @@ tested-with:
2020
GHC == 9.8.2
2121
, GHC == 9.6.6
2222
extra-source-files:
23-
embed/preflight.css
23+
embed/reset.css
2424
extra-doc-files:
2525
README.md
2626
CHANGELOG.md
@@ -41,6 +41,7 @@ library
4141
Web.Atomic.CSS.Text
4242
Web.Atomic.CSS.Transition
4343
Web.Atomic.Html
44+
Web.Atomic.Html.Tag
4445
Web.Atomic.Render
4546
Web.Atomic.Types
4647
Web.Atomic.Types.Attributable

example/app/Main.hs

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ main = do
1818
Warp.run 3010 app
1919

2020

21-
col :: Html () -> Html ()
22-
col = tag "div" ~ flexCol
23-
24-
25-
row :: Html () -> Html ()
26-
row = tag "div" ~ flexRow
27-
28-
29-
space :: Html ()
30-
space = tag "div" ~ grow $ none
31-
32-
3321
nav :: Html () -> Html ()
3422
nav = tag "nav"
3523

@@ -73,38 +61,41 @@ buttons = col ~ gap 10 . pad 20 $ do
7361

7462
inputs :: Html ()
7563
inputs = do
76-
col ~ fillViewport . pad 20 . gap 10 $ do
64+
col ~ grow . pad 20 . gap 10 $ do
7765
el ~ bold $ "INPUT"
7866
input @ placeholder "Not Focused" ~ border 1 . pad 10 . bg White
7967
input @ placeholder "Should Focus" @ autofocus ~ border 1 . pad 10 . bg White
8068

8169

8270
responsive :: Html ()
8371
responsive = do
84-
col ~ fillViewport . big flexRow $ do
85-
nav ~ gap 10 . pad 20 . bg Primary . color White . small topbar . big sidebar $ do
86-
el ~ bold $ "SIDEBAR"
87-
el "One"
88-
el "Two"
89-
el "Three"
90-
91-
col ~ scroll . grow . pad 20 . gap 20 . bg White $ do
92-
el ~ bold . fontSize 24 $ "Make the window smaller"
93-
el "This demonstrates how to create a responsive design. Resize the window under 800px wide and the nav bar will switch to a top bar"
94-
95-
col ~ color Gray . gap 20 $ do
96-
el $ text lorem
97-
el $ text lorem
98-
el $ text lorem
99-
el $ text lorem
100-
el $ text lorem
101-
el $ text lorem
102-
el $ text lorem
72+
nav ~ pad 20 . gap 10 . bg Primary . color White . menu $ do
73+
el ~ bold $ "MENU"
74+
el "One"
75+
el "Two"
76+
el "Three"
77+
78+
col ~ content . grow . pad 20 . gap 20 . bg White $ do
79+
el ~ bold . fontSize 24 $ "Make the window smaller"
80+
el "This demonstrates how to create a responsive design. Resize the window under 800px wide and the nav bar will switch to a top bar"
81+
82+
col ~ color Gray . gap 20 $ do
83+
el $ text lorem
84+
el $ text lorem
85+
el $ text lorem
86+
el $ text lorem
87+
el $ text lorem
88+
el $ text lorem
89+
el $ text lorem
10390
where
104-
-- oh no@ the @ operator converts everythign to attributes@
105-
-- and I need them to be CSS only@
106-
sidebar = width 250 <> flexCol
107-
topbar = height 100 <> flexRow
91+
menuWidth = 250
92+
menuHeight = 70
93+
94+
menu = big sidebar . small topbar
95+
sidebar = width menuWidth . position Fixed . flexCol . top 0 . bottom 0 . left 0
96+
topbar = height menuHeight . position Fixed . flexRow . top 0 . left 0 . right 0
97+
98+
content = big (margin (L menuWidth)) . small (margin (T menuHeight))
10899

109100
big :: (Styleable c) => (CSS c -> CSS c) -> (CSS c -> CSS c)
110101
big = media (MinWidth 800)
@@ -114,7 +105,7 @@ responsive = do
114105

115106

116107
holygrail :: Html ()
117-
holygrail = col ~ fillViewport $ do
108+
holygrail = col ~ grow $ do
118109
row ~ bg Primary $ "Top Bar"
119110
row ~ grow $ do
120111
col ~ bg Secondary $ "Left Sidebar"
@@ -137,7 +128,7 @@ tooltips = do
137128
viewItemRow item = do
138129
col ~ stack . showTooltips . hover (color red) . pointer $ do
139130
el ~ border 1 . bg White $ text item
140-
el ~ cls "tooltip" . popup (TR 10 10) . zIndex 1 . hidden $ do
131+
el ~ cls "tooltip" . popup (TR 10 10) . zIndex 1 . visibility Hidden $ do
141132
col ~ border 2 . gap 5 . bg White . pad 5 $ do
142133
el ~ bold $ "ITEM DETAILS"
143134
el $ text item
@@ -147,13 +138,13 @@ tooltips = do
147138
css
148139
"tooltips"
149140
".tooltips:hover > .tooltip"
150-
(declarations visible)
141+
(declarations $ visibility Visible)
151142

152143
red = HexColor "#F00"
153144

154145

155146
stacks :: Html ()
156-
stacks = col ~ fillViewport $ do
147+
stacks = col ~ grow $ do
157148
row ~ bg Primary . bold . pad 10 . color White $ "Stacks"
158149
col ~ pad 10 . gap 10 $ do
159150
el "Stacks put contents on top of each other"
@@ -250,9 +241,9 @@ texts = col ~ gap 10 . pad 20 $ do
250241
el ~ border 1 . pad 5 $ "eight"
251242
el ~ border 1 . pad 5 $ "nine"
252243

253-
el ~ bold $ "textWrap"
254-
el ~ border 1 . width 200 . textWrap NoWrap $ text lorem
255-
el ~ border 1 . width 200 . textWrap Wrap $ text lorem
244+
el ~ bold $ "White Space: text wrap"
245+
el ~ border 1 . width 200 . whiteSpace NoWrap . overflow Hidden $ text lorem
246+
el ~ border 1 . width 200 . whiteSpace Wrap $ text lorem
256247

257248
el ~ bold $ "css order"
258249
el ~ flexCol . flexRow $ do

package.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: atomic-css
22
version: 0.1.0
3-
synopsis: Type-safe Atomic CSS with intuitive layouts and composable css utility classes. Inspired by Tailwindcss and Elm-UI
3+
synopsis: Type-safe, composable CSS utility functions. Inspired by Tailwindcss and Elm-UI
4+
45
homepage: https://github.com/seanhess/atomic-css
56
github: seanhess/atomic-css
67
license: BSD-3-Clause
@@ -9,7 +10,7 @@ author: Sean Hess
910
maintainer: seanhess@gmail.com
1011
category: Web
1112
description:
12-
Type-safe Atomic CSS with intuitive layouts and composable css utility classes. Inspired by Tailwindcss and Elm-UI
13+
Type-safe, composable CSS utility functions. Inspired by Tailwindcss and Elm-UI
1314
.
1415
See documentation for the @Web.Atomic@ module below
1516

@@ -18,7 +19,7 @@ extra-doc-files:
1819
- CHANGELOG.md
1920

2021
extra-source-files:
21-
- embed/preflight.css
22+
- embed/reset.css
2223

2324
language: GHC2021
2425

src/Web/Atomic.hs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Maintainer: Sean Hess <seanhess@gmail.com>
66
Stability: experimental
77
Portability: portable
88
9-
Type-safe Atomic CSS with intuitive layouts and composable css utility classes. Inspired by Tailwindcss and Elm-UI
9+
Type-safe, composable CSS utility functions. Inspired by Tailwindcss and Elm-UI
1010
-}
1111
module Web.Atomic
12-
( -- * How to use this library
12+
( -- * Haskell functions instead of classes
1313
-- $use
1414
module Web.Atomic.Types
1515

@@ -24,6 +24,12 @@ module Web.Atomic
2424
, tag
2525
, none
2626
, raw
27+
, text
28+
29+
-- ** Layout
30+
, module Web.Atomic.Html.Tag
31+
32+
-- ** Rendering
2733
, renderText
2834
, renderLazyText
2935
, renderLazyByteString
@@ -33,13 +39,13 @@ import Web.Atomic.CSS
3339
import Web.Atomic.Html
3440
import Web.Atomic.Render
3541
import Web.Atomic.Types
42+
import Web.Atomic.Html.Tag
3643

3744

3845
-- TODO: update readme
39-
-- TODO: decide on a tagline / synopsis and put it everywhere
4046

4147
{- $html
42-
We also provide an Html Monad and combinator library with basic functions to generate html and add attributes with the `(@)` operator
48+
Atomic-css also provides an Html Monad and combinator library with basic functions to generate html and add attributes with the `(@)` operator
4349
-}
4450

4551

@@ -56,27 +62,28 @@ pad px = utility ("pad" -. px) ["padding" :. 'style' px]
5662
example = el ~ bold . pad 10 $ "Padded and bold"
5763
@
5864
59-
See Web.Atomic.CSS for a full list of utilities provided by this library
65+
Web.Atomic.CSS contains many useful utilities:
6066
-}
6167

6268

6369
{- $use
6470
65-
Create stylish html using composable haskell functions:
71+
Style your html with composable CSS utility functions:
6672
6773
@
68-
'el' ~ 'bold' $ "Hello World"
74+
'el' ~ 'bold' . 'pad' 8 $ "Hello World"
6975
@
7076
71-
This renders as the following HTML with embedded CSS definitions
77+
This renders as the following HTML with embedded CSS utility classes:
7278
7379
> <style type='text/css'>
7480
> .bold { font-weight:bold }
81+
> .p-8 { padding:0.500rem }
7582
> </style>
7683
>
77-
> <div class='bold'>Hello World</div>
84+
> <div class='bold p-8'>Hello World</div>
7885
79-
Instead of relying on the fickle cascade, factor and compose styles with the full power of Haskell functions!
86+
Instead of relying on the fickle cascade for code reuse, factor and compose styles with the full power of Haskell functions!
8087
8188
> header = bold
8289
> h1 = header . fontSize 32
@@ -86,8 +93,7 @@ Instead of relying on the fickle cascade, factor and compose styles with the ful
8693
> example = el ~ page $ do
8794
> el ~ h1 $ "My Page"
8895
> el ~ h2 $ "Introduction"
89-
> el "lorem ipsum yada yada yada"
90-
> ...
96+
> el "lorem ipsum..."
9197
9298
This approach is inspired by Tailwindcss' [Utility Classes](https://tailwindcss.com/docs/styling-with-utility-classes)
9399
-}

0 commit comments

Comments
 (0)