Skip to content

Commit 49095ff

Browse files
committed
feat: add new primer-miso-ui library and demo app
This is just a stub library for now, just to get the machinery working. The demo app is intended to be a sort of Storybook replacement for previewing Primer UI components, though it will likely never be as full-featured as Storybook. Signed-off-by: Drew Hess <[email protected]>
1 parent 170e9a1 commit 49095ff

File tree

16 files changed

+943
-0
lines changed

16 files changed

+943
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ $(package-targets):
1616
$(MAKE) -C primer $@
1717
$(MAKE) -C primer-api $@
1818
$(MAKE) -C primer-miso $@
19+
$(MAKE) -C primer-miso-ui $@
1920
$(MAKE) -C primer-benchmark $@
2021

2122
develop-frontend:
2223
$(MAKE) -C primer-miso develop-frontend
2324

25+
develop-ui-demo:
26+
$(MAKE) -C primer-miso-ui develop-ui-demo
27+
2428
clean:
2529
cabal clean
2630

Makefile.wasm32

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,18 @@ frontend-prod:
2828
serve-frontend:
2929
$(MAKE) -C primer-miso serve-frontend
3030

31+
ui-demo:
32+
$(MAKE) -C primer-miso-ui ui-demo
33+
34+
ui-demo-prod:
35+
$(MAKE) -C primer-miso-ui ui-demo-prod
36+
37+
serve-ui-demo:
38+
$(MAKE) -C primer-miso-ui serve-ui-demo
39+
3140
clean:
3241
$(CABAL) clean
3342
$(MAKE) -C primer-miso clean
43+
$(MAKE) -C primer-miso-ui clean
3444

3545
.PHONY: build $(test-targets) update clean

cabal.project

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ if arch(wasm32)
77
primer
88
primer-api
99
primer-miso
10+
primer-miso-ui
1011
else
1112
packages:
1213
primer
1314
primer-api
1415
primer-miso
16+
primer-miso-ui
1517
primer-benchmark
1618

1719
if arch(wasm32)

licenses/basecoatcss.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Ronan Berder
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

primer-miso-ui/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
ghc_wasm_jsffi.js

primer-miso-ui/COPYING

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

primer-miso-ui/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# NOTE:
2+
#
3+
# This Makefile assumes you're using the `nix develop` shell.
4+
5+
include ../makefiles/common.mk
6+
7+
# TODO The last line here shouldn't be necessary.
8+
# For some reason, GHCID is failing to discover the right paths to watch.
9+
develop-ui-demo:
10+
ghcid \
11+
-c "cabal repl --enable-multi-repl exe:primer-miso-ui-demo lib:primer-miso-ui" \
12+
-W -T Main.main \
13+
--reload exe --reload src --ignore-loaded

primer-miso-ui/Makefile.wasm32

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# NOTE:
2+
#
3+
# This Makefile assumes you're using the `nix develop .#wasm` shell.
4+
5+
CABAL = wasm32-wasi-cabal
6+
7+
build:
8+
$(CABAL) build
9+
10+
ui-demo: build
11+
./build-demo.sh
12+
13+
ui-demo-prod: build
14+
./build-demo.sh -Oz
15+
16+
serve-ui-demo: ui-demo
17+
simple-http-server -i -p 8001 -- dist
18+
19+
clean:
20+
$(CABAL) clean
21+
rm -rf dist
22+
23+
.PHONY: build clean

primer-miso-ui/build-demo.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if [ $# -eq 0 ]; then
6+
echo "Building for dev"
7+
dev_mode=true
8+
else
9+
echo "Building for prod"
10+
dev_mode=false
11+
fi
12+
13+
rm -rf dist
14+
mkdir dist
15+
16+
hs_wasm_path=$(wasm32-wasi-cabal list-bin -v0 exe:primer-miso-ui-demo)
17+
18+
ghc_wasm_jsffi="dist/ghc_wasm_jsffi.js"
19+
20+
"$(wasm32-wasi-ghc --print-libdir)"/post-link.mjs \
21+
--input "$hs_wasm_path" --output "$ghc_wasm_jsffi"
22+
23+
if ! [ -f "$ghc_wasm_jsffi" ] ; then
24+
echo "post-link.mjs didn't produce a $ghc_wasm_jsffi file. Make sure you're in the Nix Wasm shell."
25+
exit 1
26+
fi
27+
28+
if $dev_mode; then
29+
cp "$hs_wasm_path" dist/bin.wasm
30+
else
31+
wizer --allow-wasi --wasm-bulk-memory true --init-func _initialize -o dist/bin.wasm "$hs_wasm_path"
32+
wasm-opt ${1+"$@"} dist/bin.wasm -o dist/bin.wasm
33+
wasm-tools strip -o dist/bin.wasm dist/bin.wasm
34+
brotli --rm --best dist/bin.wasm -o dist/bin.wasm.br
35+
mv dist/bin.wasm.br dist/bin.wasm
36+
fi
37+
38+
cp static/*.html dist/
39+
cp static/*.js dist
40+
cp -r static/deps dist/

primer-miso-ui/exe/Main.hs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{-# LANGUAGE CPP #-}
2+
3+
module Main where
4+
5+
import Foreword
6+
7+
import Miso (App, component, noop, run, startComponent)
8+
import Miso.Html qualified as H
9+
import Miso.Html.Property qualified as P
10+
11+
#ifdef WASM
12+
foreign export javascript "hs_start" main :: IO ()
13+
main :: IO ()
14+
main = run $ startComponent app
15+
#else
16+
import qualified Miso as M
17+
18+
main :: IO ()
19+
main = run $ startComponent app
20+
{ M.styles =
21+
[ M.Href "https://cdn.jsdelivr.net/npm/[email protected]/dist/basecoat.cdn.min.css"
22+
]
23+
, M.scripts =
24+
[ M.Src "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/all.min.js"
25+
, M.Src "https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"
26+
]
27+
}
28+
#endif
29+
30+
data Model
31+
= Model
32+
deriving stock (Eq)
33+
34+
emptyModel :: Model
35+
emptyModel = Model
36+
37+
app :: App Model ()
38+
app = component emptyModel noop $ \_ ->
39+
H.div_
40+
[]
41+
[ H.button_
42+
[ P.className "btn"
43+
]
44+
[ "UI button"
45+
]
46+
]

0 commit comments

Comments
 (0)