Skip to content

Commit 9137dd9

Browse files
authored
Merge pull request #21 from seanhess/atomic-css
atomic-css major refactor! Please Review. Fixes #17
2 parents 8c6ad0a + 35685f6 commit 9137dd9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3338
-2884
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
dist-newstyle
22
node_modules
3+
Session.vim
34
dist
45
.DS_Store
56
tags

CHANGELOG.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,43 @@
1-
# Revision history for web-view
1+
# Revision history for atomic-css
22

3-
## 0.7.0
3+
## atomic-css 0.1.0
4+
5+
Renamed library to atomic-css with a focus on css utilities. View, Url and other Hyperbole-specific types moved to Hyperbole. Still provides an Html monad
6+
7+
Major rewrite of Library and API
8+
* New interface with operators: (@) for attributes, (~) to utilities
9+
* Defining custom CSS selectors and new utilities is more intuitive
10+
11+
## web-view 0.7.0
412

513
* stack, popup, offset, layer - more intuitive interface
614
* added Web.View.Url.renderPath
715
* Style class
816
* added code, lists
917

10-
## 0.6.0
18+
## web-view 0.6.0
1119

1220
* stack - layout children on top of each other
1321
* ChildCombinator: apply styles to direct children
1422
* `Mod` is now `Mod context`, allowing for type-safe `Mod`s
1523
* fixed: escaping in auto-generated `<style>`
1624
* Refactored: selectors and rendering
1725

18-
## 0.5.0
26+
## web-view 0.5.0
1927

2028
* Rendering improvements
2129
* extClass to add external css class
2230
* inline elements
2331
* Url: no longer lowercases automatically. Show/Read instance
24-
*
2532

26-
## 0.4.0
33+
## web-view 0.4.0
2734

2835
* Added new Mods. Length type. Improved Url type
2936

30-
## 0.3.1
37+
## web-view 0.3.1
3138

3239
* Cleanup. Refactored Mods
3340

34-
## 0.2.3 -- 2023-11-27
41+
## web-view 0.2.3 -- 2023-11-27
3542

3643
* First version. Released on an unsuspecting world.

DELETEME.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
OK, so....
3+
4+
hover needs to work with multiple classes:
5+
=> hover (bg Green <> color Red)
6+
7+
but overriding selectors needs to work in a sane way
8+
-- use a monadic bind?
9+
-- this sure looks like one!
10+
setSelector $ \this $ a |> b >> this
11+
12+
-- they don't have to be directly serializable
13+
-- they could be functions!
14+
15+
bg Green => {bg-green}
16+
hover (bg Green) => \sel -> sel ': "hover"
17+
18+
19+
-- I like the new stuff. Now you can't do setSelector (placeholder "woot")
20+
21+
22+
Ok ok ok ... so... selector...
23+
24+

README.md

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,112 @@
1-
Web View
1+
Atomic CSS
22
============
33

4-
[![Hackage](https://img.shields.io/hackage/v/web-view.svg)][hackage]
4+
[![Hackage](https://img.shields.io/hackage/v/atomic-css.svg)][hackage]
5+
6+
Type-safe, composable CSS utility functions. Inspired by Tailwindcss and Elm-UI
57

6-
Type-safe HTML and CSS with intuitive layout and composable styles. Inspired by Tailwindcss and Elm-UI
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

76-
If you want to get a feel for web-view without cloning the project run `nix run github:seanhess/web-view` to run the example webserver locally
88+
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
7789

7890
Import Flake
7991
------------
8092

81-
You can import this flake's overlay to add `web-view` to `overriddenHaskellPackages` and which provides a ghc966 and ghc982 package set that satisfy `web-view`'s dependencies.
93+
You can import this flake's overlay to add `atomic-css` to `overriddenHaskellPackages` and which provides a ghc966 and ghc982 package set that satisfy `atomic-css`'s dependencies.
8294

8395
```nix
8496
{
8597
inputs = {
8698
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
87-
web-view.url = "github:seanhess/web-view"; # or "path:/path/to/cloned/web-view";
99+
atomic-css.url = "github:seanhess/atomic-css"; # or "path:/path/to/cloned/atomic-css";
88100
flake-utils.url = "github:numtide/flake-utils";
89101
};
90102
91-
outputs = { self, nixpkgs, web-view, flake-utils, ... }:
103+
outputs = { self, nixpkgs, atomic-css, flake-utils, ... }:
92104
flake-utils.lib.eachDefaultSystem (
93105
system:
94106
let
95107
pkgs = import nixpkgs {
96108
inherit system;
97-
overlays = [ web-view.overlays.default ];
109+
overlays = [ atomic-css.overlays.default ];
98110
};
99111
haskellPackagesOverride = pkgs.overriddenHaskellPackages.ghc966.override (old: {
100112
overrides = pkgs.lib.composeExtensions (old.overrides or (_: _: { })) (hfinal: hprev: {
@@ -104,7 +116,7 @@ You can import this flake's overlay to add `web-view` to `overriddenHaskellPacka
104116
in
105117
{
106118
devShells.default = haskellPackagesOverride.shellFor {
107-
packages = p: [ p.web-view ];
119+
packages = p: [ p.atomic-css ];
108120
};
109121
}
110122
);
@@ -116,16 +128,16 @@ Local Development
116128

117129
### Recommended ghcid command
118130

119-
If you want to work on both the web-view library and example code, this `ghcid` command will run and reload the examples server as you change any non-testing code.
131+
If you want to work on both the atomic-css library and example code, this `ghcid` command will run and reload the examples server as you change any non-testing code.
120132

121133
```
122-
ghcid --command="cabal repl exe:example lib:web-view" --run=Main.main --warnings --reload=./embed/preflight.css
134+
ghcid --command="cabal repl exe:example lib:atomic-css" --run=Main.main --warnings --reload=./embed/preflight.css
123135
```
124136

125137
If you want to work on the test suite, this will run the tests each time any library code is changed.
126138

127139
```
128-
ghcid --command="cabal repl test lib:web-view" --run=Main.main --warnings --reload=./embed/preflight.css
140+
ghcid --command="cabal repl test lib:atomic-css" --run=Main.main --warnings --reload=./embed/preflight.css
129141
```
130142

131143
### Nix
@@ -136,7 +148,7 @@ ghcid --command="cabal repl test lib:web-view" --run=Main.main --warnings --relo
136148
- `nix run .#ghc966-example` to start the example project with GHC 9.6.6
137149
- `nix develop` or `nix develop .#ghc982-shell` to get a shell with all dependencies installed for GHC 9.8.2.
138150
- `nix develop .#ghc966-shell` to get a shell with all dependencies installed for GHC 9.6.6.
139-
- `nix build`, `nix build .#ghc982-web-view` and `nix build .#ghc966-web-view` builds the library with the `overriddenHaskellPackages`
151+
- `nix build`, `nix build .#ghc982-atomic-css` and `nix build .#ghc966-atomic-css` builds the library with the `overriddenHaskellPackages`
140152
- If you want to import this flake, use the overlay
141153
- `nix flake update nixpkgs` will update the Haskell package sets and development tools
142154

@@ -165,15 +177,15 @@ Learn More
165177
----------
166178

167179
View Documentation on [Hackage][hackage]
168-
* https://hackage.haskell.org/package/web-view
180+
* https://hackage.haskell.org/package/atomic-css
169181

170182
View on Github
171-
* https://github.com/seanhess/web-view
183+
* https://github.com/seanhess/atomic-css
172184

173-
View [Examples](https://github.com/seanhess/web-view/blob/latest/example/app/Main.hs)
185+
View [Examples](https://github.com/seanhess/atomic-css/blob/latest/example/app/Main.hs)
174186

175187

176-
[hackage]: https://hackage.haskell.org/package/web-view
188+
[hackage]: https://hackage.haskell.org/package/atomic-css
177189

178190

179191
Contributors

0 commit comments

Comments
 (0)