Skip to content

Commit 9dacac7

Browse files
Update for Halogen 5 (#39)
* Remove QueryF from Select in preparation for v5 changes, as there is no longer the ability to leverage a query within ComponentHTML. Add the npm-check-updates package to dev dependencies. * switch to variants * Complete switch to Halogen 5 * switch examples to v5 * switch to extensible state, no comonad * now that state can be embedded, take as an argument * cleanup * switch to handling messages, which addresses lingering concerns with extensibility in the components * uncomment * cleanup * add default.nix file containing mkdocs * update dependencies * fix infinite recursion (compiler bug?) * eta-expand instead of removing helper * remove unused css * Add type synonyms for simple cases * rename RunQuery to AsAction * allow external initialization, merge state fields * simplify examples * Simplify a little more * formatting * add finalizer to default spec * extensible actions * update item counts on attempted highlight * cleanup * polish up CSS for examples to test behavior * switch to void
1 parent c646a55 commit 9dacac7

File tree

18 files changed

+893
-941
lines changed

18 files changed

+893
-941
lines changed

.circleci/config.yml

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,6 @@ jobs:
4848
paths:
4949
- js
5050

51-
css:
52-
<<: *defaults
53-
steps:
54-
- checkout
55-
56-
- run:
57-
name: Fetch and persist CSS
58-
command: |
59-
yarn fetch-css && yarn move-css
60-
61-
- persist_to_workspace:
62-
root: docs
63-
paths:
64-
- css
65-
6651
site:
6752
working_directory: ~/select
6853
docker:
@@ -139,16 +124,6 @@ workflows:
139124
ignore: gh-pages
140125

141126
# On master branch, rebuild docs
142-
- css:
143-
filters:
144-
branches:
145-
only:
146-
- master
147-
- docs
148-
149-
requires:
150-
- test
151-
152127
- site:
153128
filters:
154129
branches:
@@ -168,4 +143,4 @@ workflows:
168143

169144
requires:
170145
- site
171-
- css
146+

bower.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
"generated-docs"
3232
],
3333
"dependencies": {
34-
"purescript-halogen": "^4.0.0",
35-
"purescript-halogen-renderless": "^0.0.3"
34+
"purescript-halogen": "^5.0.0-rc.3",
35+
"purescript-record": "^2.0.0"
3636
},
3737
"devDependencies": {
38-
"purescript-debug": "^4.0.0"
38+
"purescript-debug": "^4.0.0",
39+
"purescript-affjax": "^9.0.0",
40+
"purescript-argonaut": "^6.0.0"
3941
}
4042
}

default.nix

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{ nixpkgs ? import <nixpkgs> {} }:
2+
with nixpkgs;
3+
4+
let
5+
livereload = python27Packages.buildPythonPackage {
6+
name = "livereload-2.5.1";
7+
src = fetchurl {
8+
url = https://pypi.python.org/packages/e9/2e/c4972828cf526a2e5f5571d647fb2740df68f17e8084a9a1092f4d209f4c/livereload-2.5.1.tar.gz;
9+
sha256 = "0b2yyfnpddmrwjfqsndidzchkf3l9jlgzfkwl8dplim9gq6y2ba2";
10+
};
11+
12+
propagatedBuildInputs = with python27Packages; [ six tornado ];
13+
14+
meta = {
15+
homepage = https://github.com/lepture/python-livereload;
16+
description = "Python LiveReload is an awesome tool for web developers";
17+
license = stdenv.lib.licenses.bsd3;
18+
};
19+
};
20+
21+
mkdocs = python27Packages.buildPythonApplication rec {
22+
name="mkdocs-0.17.2";
23+
src = fetchurl {
24+
url = https://pypi.python.org/packages/27/0a/bb42cda3b298ffb4b30375b7538a4d57803ff8be418ee3e00460188c4332/mkdocs-0.17.2.tar.gz;
25+
sha256 = "18d3m9iws5shlbg0yj5xwiy68bliiz70v32y5pa8wi274c36nssa";
26+
};
27+
28+
propagatedBuildInputs = with python27Packages;
29+
[ tornado livereload click pyyaml markdown jinja2 ];
30+
31+
meta = {
32+
homepage = http://www.mkdocs.org/;
33+
description = "MkDocs is a fast, simple and downright gorgeous static site generator that’s geared towards building project documentation. Documentation source files are written in Markdown, and configured with a single YAML configuration file.";
34+
license = stdenv.lib.licenses.bsd3;
35+
};
36+
};
37+
38+
pymdown-extensions = python27Packages.buildPythonPackage {
39+
name = "pymdown-extensions-4.8";
40+
src = fetchurl {
41+
url = https://pypi.python.org/packages/f5/9f/74d8a85458e831f3b161956b30bc60d31c6a507ed72ac4f4cb2ca08d8042/pymdown-extensions-4.8.tar.gz;
42+
sha256 = "1zvi8d44v758vbhi9fl5x5gqs098ajamilfz53jzid0v0fad88nj";
43+
};
44+
45+
propagatedBuildInputs = with python27Packages; [ markdown ];
46+
doCheck = false;
47+
48+
meta = {
49+
homepage = https://github.com/facelessuser/pymdown-extensions;
50+
description = "Extension pack for Python Markdown.";
51+
license = stdenv.lib.licenses.mit;
52+
};
53+
};
54+
55+
mkdocs-material = python27Packages.buildPythonPackage {
56+
name = "mkdocs-material-2.6.0";
57+
src = fetchurl {
58+
url = https://pypi.python.org/packages/e3/85/f42493d453d9b6f51912b818134a4a555c597807ba96b40eae12017ede35/mkdocs-material-2.6.0.tar.gz;
59+
sha256 = "1xq5nkj0g6gg4lm8nhcwc30g9drq1i4p4pky8s5c0rfa1s9s7sla";
60+
};
61+
62+
propagatedBuildInputs = with python27Packages; [ pymdown-extensions pygments mkdocs ];
63+
64+
meta = {
65+
homepage = https://squidfunk.github.io/mkdocs-material/;
66+
description = "A Material Design theme for MkDocs";
67+
license = stdenv.lib.licenses.mit;
68+
};
69+
};
70+
71+
markdown-fenced-code-tabs = python27Packages.buildPythonPackage {
72+
name = "markdown-fenced-code-tabs-0.2.0";
73+
src = fetchurl {
74+
url = https://pypi.python.org/packages/21/7a/0cee39060c5173cbd80930b720fb18f5cb788477c03214ccdef44ec91d85/markdown-fenced-code-tabs-0.2.0.tar.gz;
75+
sha256 = "05k5v9wlxgghw2k18savznxc1xgg60gqz60mka4gnp8nsxpz99zs";
76+
};
77+
78+
propagatedBuildInputs = with python27Packages; [ markdown ];
79+
80+
meta = {
81+
homepage = https://github.com/yacir/markdown-fenced-code-tabs;
82+
description = "Generates Bootstrap HTML Tabs for Consecutive Fenced Code Blocks";
83+
license = stdenv.lib.licenses.mit;
84+
};
85+
};
86+
87+
in
88+
nixpkgs.stdenv.mkDerivation {
89+
name = "env";
90+
buildInputs = [
91+
mkdocs
92+
mkdocs-material
93+
nixpkgs.nodejs
94+
nixpkgs.yarn
95+
nixpkgs.stack
96+
];
97+
}

docs/examples.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ You can play around with a few example components here. However, for a much rich
1111

1212
Dropdowns are a common button-driven input type, especially for navigation. But most custom dropdowns sacrifice usability: unlike browser default dropdowns, you can't type on most custom dropdowns, nor are many built with accessibility in mind. With `Select` you can easily create rich, usable dropdowns with little code.
1313

14-
<div data-component="dropdown" class="ocelot-scoped"></div>
14+
<div data-component="dropdown"></div>
1515

16-
Curious how to build a dropdown with `Select`? Check out [the dropdown tutorial](https://citizennet.github.io/tutorials/build-a-dropdown).
16+
Curious how to build a dropdown with `Select`? Check out [the dropdown tutorial](https://citizennet.github.io/tutorials/dropdown).
1717

1818
### Typeahead / Autocomplete
1919

@@ -23,6 +23,6 @@ Building typeaheads with `Select` is only a little more complex than building dr
2323

2424
The typeahead below is quite simple; to see examples of more sophisticated typeaheads -- including ones that fetch and display data asynchronously -- check out the [Ocelot component library](https://citizennet.github.io/purescript-ocelot/#typeaheads).
2525

26-
<div data-component="typeahead" class="ocelot-scoped"></div>
26+
<div data-component="typeahead"></div>
2727

28-
Curious how to build a typeahead with `Select`? Check out [the typeahead tutorial](https://citizennet.github.io/tutorials/build-a-typehead).
28+
Curious how to build a typeahead with `Select`? Check out [the typeahead tutorial](https://citizennet.github.io/tutorials/typeahead).

examples/Components/CSS.purs

Lines changed: 0 additions & 88 deletions
This file was deleted.

examples/Components/Dropdown.purs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
module Components.Dropdown where
2+
3+
import Prelude
4+
5+
import Data.Const (Const)
6+
import Effect.Aff (Aff)
7+
import Data.Array ((!!), mapWithIndex, length)
8+
import Data.Maybe (Maybe(..), fromMaybe)
9+
import Data.Monoid (guard)
10+
import Halogen as H
11+
import Halogen.HTML as HH
12+
import Internal.CSS (class_, classes_, whenElem)
13+
import Select as S
14+
import Select.Setters as SS
15+
16+
type Slot =
17+
H.Slot S.Query' Message
18+
19+
type State =
20+
( items :: Array String
21+
, selection :: Maybe String
22+
, buttonLabel :: String
23+
)
24+
25+
data Message
26+
= SelectionChanged (Maybe String) (Maybe String)
27+
28+
-- it is unnecessary to export your own input type, but doing so helps if you
29+
-- would like to set some sensible defaults behind the scenes.
30+
type Input =
31+
{ items :: Array String
32+
, buttonLabel :: String
33+
}
34+
35+
input :: Input -> S.Input State
36+
input { items, buttonLabel } =
37+
{ inputType: S.Toggle
38+
, search: Nothing
39+
, debounceTime: Nothing
40+
, getItemCount: length <<< _.items
41+
, items
42+
, buttonLabel
43+
, selection: Nothing
44+
}
45+
46+
spec :: S.Spec State (Const Void) Void () Message Aff
47+
spec = S.defaultSpec { render = render, handleMessage = handleMessage }
48+
where
49+
handleMessage = case _ of
50+
S.Selected ix -> do
51+
st <- H.get
52+
let selection = st.items !! ix
53+
H.modify_ _ { selection = selection, visibility = S.Off }
54+
H.raise $ SelectionChanged st.selection selection
55+
_ -> pure unit
56+
57+
render st =
58+
HH.div
59+
[ class_ "Dropdown" ]
60+
[ renderToggle, renderContainer ]
61+
where
62+
renderToggle =
63+
HH.button
64+
( SS.setToggleProps st [ class_ "Dropdown__toggle" ] )
65+
[ HH.text (fromMaybe st.buttonLabel st.selection) ]
66+
67+
renderContainer = whenElem (st.visibility == S.On) \_ ->
68+
HH.div
69+
( SS.setContainerProps [ class_ "Dropdown__container" ] )
70+
( renderItem `mapWithIndex` st.items )
71+
where
72+
renderItem index item =
73+
HH.div
74+
( SS.setItemProps index
75+
[ classes_
76+
[ "Dropdown__item"
77+
, "Dropdown__item--highlighted" # guard (st.highlightedIndex == Just index)
78+
]
79+
]
80+
)
81+
[ HH.text item ]
82+

0 commit comments

Comments
 (0)