Skip to content

Commit 6c372df

Browse files
committed
Cleanups for 0.1.0 release
1 parent 28a3351 commit 6c372df

5 files changed

Lines changed: 209 additions & 82 deletions

File tree

README.md

Lines changed: 171 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,216 @@
11
# Sodium
22

3-
A wrapper around [soda-ash](https://github.com/gadfly361/soda-ash)
4-
and [semantic-ui-react](https://github.com/Semantic-Org/Semantic-UI-React) that is
5-
friendlier to re-frame. And the name? Simple, Sodium is highly reactive, and starts
6-
with an "S", like Soda-ash and Semantic-UI.
3+
## Introduction
74

8-
Sodium is still an early work in progress. I am using it to help me with other projects.
9-
It will only grow as it helps me (or other contributers) accomplish what they need. If
10-
you need features now, PRs are welcome.
5+
Sodium is a wrapper around [soda-ash](https://github.com/gadfly361/soda-ash) which, in
6+
turn is a ClojureScript wrapper
7+
around [semantic-ui-react](https://github.com/Semantic-Org/Semantic-UI-React). Sodium
8+
adds two sets of features into the mix, both aimed at making it easier to include
9+
Semantic UI in re-frame projects:
1110

12-
Sodium offers the following:
11+
1. Utility functions to get values in and out of components.
12+
2. Validity-checking aids to help avoid typos.
1313

14-
## Cleaner inter-op between Semantic-UI and [re-frame](https://github.com/Day8/re-frame)
14+
### Why "Sodium"?
1515

16-
`sodium.core/>event` and `sodium.core/>atom` - Create `:on-*` handlers to pass a value
17-
to a re-frame event or react atom.
16+
The element sodium is highly reactive. It also starts with an "S", like Soda-ash and
17+
Semantic-UI. In addition, the chemical symbol for sodium is "NA", nicely similar to the
18+
"SA" abbreviation used for the Soda-ash namespace. And, hey, I like puns.
1819

19-
`sodium.core/<atom` - Get a value from a react atom.
20+
### State of this project
2021

21-
`sodium.core/defcontrol` and `sodium.core/def-simple-control` Define a control;
22-
typically a thin wrapper around the Soda-ash control, to give parameter checking,
23-
etc. (see below). Soon, Sodium will contain definitions wrapping all the Soda-ash
24-
(Semantic-UI) controls, but we are not there yet.
22+
Sodium is still an early work in progress. I am using it to help me with other projects
23+
and have only addded functionality that I need and can test. Sodium will only grow as
24+
it helps me (or other contributers) accomplish what they need. If you need features now,
25+
PRs are welcome.
26+
27+
### Background
28+
29+
I have used [re-com](https://github.com/Day8/re-com) for a while in my
30+
[re-frame](https://github.com/Day8/re-frame) projects. Re-com is a wonderful, reliable,
31+
easy to use, and opinionated library of UI components. In many ways, it was
32+
perfect. But, as the authors warn, it is designed for desktop applications. When I tried
33+
using it for mobile and portable pages, I kept running into little annoyances.
34+
35+
I recently discovered Semantic UI and its Soda-ash wrapper. I switched to it, and my
36+
pages became much more usable on mobile devices. But, I miss the slick features and
37+
re-frame integration of re-com. Sodium is an attempt to bridge this gap.
38+
39+
40+
## Setup
2541

42+
[![Clojars Project](https://img.shields.io/clojars/v/com.degel/sodium.svg)](https://clojars.org/com.degel/sodium)
43+
44+
Sodium is a wrapper around Soda-ash, Semantic UI React, and Semantic UI. Setup requires
45+
a couple of steps:
2646

27-
## Clojure-friendly naming conventions
47+
- Your project.clj should include a dependency on Sodium: `[com.degel/sodium "0.1.0"]`
48+
- It will probably (see below) also need a dependency on Soda-ash (currently `[soda-ash
49+
"0.3.0"]`, but see the [Soda-ash README](https://github.com/gadfly361/soda-ash) for
50+
any recent changes).
51+
- You will also need to include the Semantic UI stylesheet in your _index.html_:
52+
`<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.10/semantic.min.css">`
53+
- Finally, you will need to require Sodium, and maybe also Soda-ash, in your namespace:
54+
- `[sodium.core :as na]` - Most of Sodium's functionality
55+
- `[sodium.utils :refer [<sub >evt]]` - Useful utilities
56+
- `[sodium.chars :as chars]` - Minor Unicocde support
57+
- `[soda-ash.core :as sa]` - Soda-ash functions
2858

29-
Controls and parameters in kebab-case (`:on-change`) rather than JavaScript-friendly
30-
camel-case (`onChange`).
3159

32-
## Parameter type-checking
60+
If you want to contribute to this project, you will want to test your changes. You can
61+
extend the (very minimal) tests inside Sodium, but you will probably need to really test
62+
by using Sodium in a ClojureScript project. The easiest way to do this, while you are
63+
changing Sodium, is by using Leiningen's
64+
[checkout directory](https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#checkout-dependencies)
65+
feature by sym-linking directly to your copy of Sodium.
3366

34-
For now, just starting to check if parameters are valid. This is a bit of a mixed
35-
blessing, because I've not yet found a definitive list of all the valid parameters. So,
36-
this may be overly restrictive.
67+
## Using Sodium
3768

38-
I will, soon, add an option to partially disable checking. But, NYI. For now, you can
39-
call the Soda-ash function directly. `>event` and friends will work just fine.
69+
Sodium is a library, with a grab-bag of functions to enhance the usability of Semantic
70+
UI from your re-frame projects. You can use it in several ways:
4071

41-
## A few helpful utility functions
72+
### Data-in and -out
73+
74+
Sodium offers the following:
4275

43-
### In `sodium.utils`
76+
- `na/>event` and `na/>atom` - Create `:on-*` handlers to pass a value
77+
to a re-frame event or react atom.
78+
- `sodium.core/<atom` - Get a value from a react atom.
79+
80+
#### Typical usage
81+
82+
````
83+
(defn login-panel []
84+
(let [email (reagent/atom "")
85+
password (reagent/atom "")]
86+
(fn []
87+
[na/form {}
88+
[na/form-input {:label "Email"
89+
:type "email"
90+
:on-change (na/>atom email)}]
91+
[na/form-input {:label "Password"
92+
:type "password"
93+
:on-change (na/>atom password)}]
94+
[na/form-button {:content "Login"
95+
:on-click (na/>event [:login @email @password])}]])))
96+
````
97+
98+
These functions work equally with with Sodium components and bare Soda-ash ones. I
99+
recommend using Sodium components where available. But, see below, you will still often
100+
need to use Soda-ash components.
101+
102+
### Helper functions
103+
104+
These are some some of the functions that I've needed often in re-frame projects. I
105+
expect this will grow rapidly with time. PRs are welcome here, though I'm likely to be
106+
opinionated about what I accept.
107+
108+
#### In `sodium.utils`
44109
- `validate` - Wrapper for Clojure specs checking in pre-conditions.
45110
- "Camelize" functions - Convert Clojure-style names to JavaScript style
46111

47-
### In `sodium.re-utils`
112+
#### In `sodium.re-utils`
48113
- `<sub` and `>evt` - Re-frame wrappers, taken from <https://lambdaisland.com/blog/11-02-2017-re-frame-form-1-subscriptions>
49114

50-
### In `sodium.chars`
115+
#### In `sodium.chars`
51116

52117
Definitions for a few common Unicode characters.
53118

54119

55-
## Useful links (for now)
120+
### Semantic enhancements
56121

57-
- https://react.semantic-ui.com/introduction
58-
- https://github.com/Semantic-Org/Semantic-UI-React
122+
HTML controls offer a lot of freedom, and sometimes too many choices. Our front-end code
123+
can be much more readable if we define controls with relatively constrained and
124+
consistent behavior. But, there is an art to doing this right; constrain a control too
125+
much, and it is perfect for one project, but too limited to be useful in other
126+
projects. Semantic UI helps a lot, but still offers too many choices for a consistent,
127+
simple, web page.
59128

129+
I am trying, slowly, to create a set of components that meet my needs yet are general
130+
purpose. Most of them are still in my other projects, mostly not public, that use
131+
Sodium. But, I intend to migrate them into Sodium as I gain comfort.
60132

133+
One component is already here:
61134

62-
## Usage
135+
- `form-button` - HTML forms are, by default, very tied to the old-school HTML notions
136+
of page submission. This does not play well with the re-frame philosophy that a form
137+
handler should simply trigger a re-frame event. When I naively use the Soda-ash
138+
sa/FormButton component at first, I was hit with unexpected extra connections to my
139+
server, trying to submit the form. The fix for this, once I realized the problem, was
140+
simple: the component needs to explicitly speicify a type of "button." The
141+
`na/form-button` component handles this automatically.
63142

64-
[![Clojars Project](https://img.shields.io/clojars/v/com.degel/sodium.svg)](https://clojars.org/com.degel/sodium)
143+
### Type-checked wrappers
65144

66-
You will need to include a dependency `[com.degel/sodium "0.1.0-SNAPSHOT"]` and `require`
67-
- `[sodium.core :as na]` - Most of Sodium's functionality
68-
- `[sodium.chars :as chars]` - Minor Unicocde support
69-
- `[sodium.utils :refer [<sub >evt]]` - Useful utilities
145+
This is the most experimental part of Sodium and, sadly, still mostly incomplete.
70146

147+
So far, it includes the following components, each a very thin wrapper around the
148+
corresponding Soda-ash / Semantic UI one:
71149

72-
### Running
150+
- `na/checkbox`: `sa/Checkbox`
151+
- `na/container`: `sa/Container`
152+
- `na/dropdown`: `sa/Dropdown`
153+
- `na/form`: `sa/Form`
154+
- `na/form-input`: `sa/FormInput`
155+
- `na/form-group`: `sa/FormGroup`
156+
- `na/grid`: `sa/Grid`
157+
- `na/header`: `sa/Header`
158+
- `na/input`: `sa/Input`
159+
- `na/menu`: `sa/Menu`
160+
- `na/menu-item`: `sa/MenuItem`
161+
- `na/rail`: `sa/Rail`
162+
- `na/text-area`: `sa/TextArea`
73163

74-
At this stage, I expect that most users of Sodium will be myself or contributers. If
75-
you will be changing Sodium, it is easier to run this library from within the project
76-
using it.
77164

78-
Sym-link to Sodium from the checkouts directory of your project. (See the
79-
[Leiningen notes](https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#checkout-dependencies)
80-
for a discussion of this feature). If you are me, a working example is at
81-
~/Documents/git/projects/receipts/client/checkouts.
165+
These wrappers improve the components in two ways (both admittedly arguable):
166+
- The names are in Clojure-friendly kebab-case, rather than camelCase.
167+
- The valid parameters are listed in the arglist. Parameters you supply are
168+
checked for validity, catching typos and undefind parameters.
82169

170+
These improvements have some drawbacks, which make Sodium still less usable that
171+
Soda-ash in many circumstances. For that reason, I deliberately designed the Sodium
172+
functions to work with both Sodium and Soda-ash components.
83173

174+
Some current limitations:
175+
176+
- I've only defined some components so far; only about a dozen of the 140+ exported by Soda-ash.
177+
- I've tried to list all the valid parameters for each component. I built these lists
178+
mostly from the Semantic UI React [documentation](https://react.semantic-ui.com/), but
179+
discovered them to be incomplete. I've added missing parameters as I discovered them,
180+
but have surely missed some. [PRs *very* eagerly welcome here].
181+
- The params map is mandatory in Sodium components. It is not valid, e.g., to say
182+
`[na/form [na/...]]`. Instead, you have to explicitly specify even an empty map:
183+
`[na/form {} [na/...]]`
184+
185+
186+
### Internals
187+
188+
`sodium.core/defcomponent` and `sodium.core/def-simple-component` Define a component;
189+
typically a thin wrapper around the Soda-ash component, to give parameter checking,
190+
etc. (see below). Soon, Sodium will contain definitions wrapping all the Soda-ash
191+
(Semantic-UI) components, but we are not there yet.
84192

85-
You will also need to follow the instruction in
86-
the [soda-ash README](https://github.com/gadfly361/soda-ash), particularly to include
87-
the stylesheet and dependency.
88193

89194
### Testing
90195

91-
`lein doo phantom test auto` will run the few unit tests I've written so far.
196+
`lein doo phantom test auto` will run the few unit tests I've written so far. More are
197+
needed. PRs especially welcome here.
92198

93-
## License
199+
## Useful references
94200

95-
Licensed under the Eclipse Public License.
201+
- https://semantic-ui.com/
202+
- https://react.semantic-ui.com/introduction
203+
- https://github.com/Semantic-Org/Semantic-UI-React
204+
- https://github.com/gadfly361/soda-ashsoda
205+
206+
207+
## Questions
208+
209+
I can usually be found on the [Clojurians Slack](https://clojurians.net) #reagent or
210+
#re-frame slack channels. My handle is @deg. Email is also fine.
211+
212+
## License
96213

97214
Copyright © 2017, David Goldfarb <deg@degel.com>
215+
216+
Licensed under the Eclipse Public License.

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(defproject
2-
com.degel/sodium "0.1.0-SNAPSHOT"
2+
com.degel/sodium "0.1.0"
33
:description "A wrapper around soda-ash and semantic-ui-react"
44
:url "https://github.com/deg/sodium"
55
:license {:name "Eclipse Public License"

src/sodium/core.cljs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
(ns sodium.core
55
(:require-macros
6-
[sodium.macros :refer [defcontrol def-simple-control]])
6+
[sodium.macros :refer [defcomponent def-simple-component]])
77
(:require
88
[clojure.spec.alpha :as s]
99
[soda-ash.core :as sa]
@@ -68,7 +68,7 @@
6868

6969
(defn <atom
7070
"Get a value from an atom. Suitable to use, e.g., as the :value or
71-
:default-value parameter to a control.
71+
:default-value parameter to a component.
7272
Atom is the atom to be dereferenced. It will be translated by access-fn.
7373
If null, default will be supplied instead."
7474
([atom]
@@ -79,28 +79,28 @@
7979
(or (access-fn @atom) default)))
8080

8181

82-
;;; Controls that we supply so far. More coming soon.
82+
;;; Components that we supply so far. More coming soon.
8383
;;; The final argument here is a descriptor the acceptable parameters.
8484
;;; For more details about this, see keys.clj and macros.clj
85-
(def-simple-control checkbox sa/Checkbox [:basic :checkbox])
86-
(def-simple-control container sa/Container [:basic :container])
87-
(def-simple-control dropdown sa/Dropdown [:basic :dropdown])
88-
(def-simple-control form sa/Form [:basic :form])
89-
(def-simple-control form-input sa/FormInput [:basic :form-field :input :input-html])
90-
(def-simple-control form-group sa/FormGroup [:basic :form-group])
91-
(def-simple-control grid sa/Grid [:basic :grid])
92-
(def-simple-control header sa/Header [:basic :header])
93-
(def-simple-control input sa/Input [:basic :form-field :input :input-html])
94-
(def-simple-control menu sa/Menu [:basic :menu])
95-
(def-simple-control menu-item sa/MenuItem [:basic :menu-item])
96-
(def-simple-control rail sa/Rail [:basic :rail])
97-
(def-simple-control text-area sa/TextArea [:basic :form-field :input :input-html :text-area])
85+
(def-simple-component checkbox sa/Checkbox [:basic :checkbox])
86+
(def-simple-component container sa/Container [:basic :container])
87+
(def-simple-component dropdown sa/Dropdown [:basic :dropdown])
88+
(def-simple-component form sa/Form [:basic :form])
89+
(def-simple-component form-input sa/FormInput [:basic :form-field :input :input-html])
90+
(def-simple-component form-group sa/FormGroup [:basic :form-group])
91+
(def-simple-component grid sa/Grid [:basic :grid])
92+
(def-simple-component header sa/Header [:basic :header])
93+
(def-simple-component input sa/Input [:basic :form-field :input :input-html])
94+
(def-simple-component menu sa/Menu [:basic :menu])
95+
(def-simple-component menu-item sa/MenuItem [:basic :menu-item])
96+
(def-simple-component rail sa/Rail [:basic :rail])
97+
(def-simple-component text-area sa/TextArea [:basic :form-field :input :input-html :text-area])
9898

99-
;;; This is (at least for now) how we define controls that don't fit
100-
;;; into the def-simple-control cookie-cutter regime.
99+
;;; This is (at least for now) how we define components that don't fit
100+
;;; into the def-simple-component cookie-cutter regime.
101101
;;; Actually, all that's really non-standard here is the supplying
102102
;;; of "button" as the default type.
103-
(defcontrol form-button [params]
103+
(defcomponent form-button [params]
104104
{::key-sets [:basic :form-field :button]
105105
::keys [data-tooltip]
106106
:pre [(utils/validate (s/nilable ifn?) on-click)

src/sodium/keys.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33

44
(ns sodium.keys)
55

6+
;;; [TODO] Fill in more keys
7+
;;; For mapping of HTML attributes to elements, see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
8+
;;; For list of all HTML tags, see http://www.fillster.com/htmlcodes/htmltags.html
9+
;;; also, https://developer.mozilla.org/en/docs/Web/HTML/Element
10+
;;; and https://www.w3schools.com/TAGs/default.asp
11+
;;; See also http://learnsemantic.com/
12+
13+
14+
615

716
(def ui-key-set-map (atom {}))
817

0 commit comments

Comments
 (0)