whose-components 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +231 -0
- data/Rakefile +8 -0
- data/app/assets/fonts/whose_components/OFL.txt +93 -0
- data/app/assets/fonts/whose_components/leaguespartan-bold.woff2 +0 -0
- data/app/assets/tailwind/whose_components/engine.css +139 -0
- data/app/components/whose/badge_component/badge_component.html.haml +1 -0
- data/app/components/whose/badge_component.rb +23 -0
- data/app/components/whose/button_component/button_component.html.haml +6 -0
- data/app/components/whose/button_component.rb +40 -0
- data/app/components/whose/card_component/card_component.html.haml +6 -0
- data/app/components/whose/card_component.rb +24 -0
- data/app/components/whose/dialog.rb +21 -0
- data/app/components/whose/dialog_header_component/dialog_header_component.en.yml +2 -0
- data/app/components/whose/dialog_header_component/dialog_header_component.html.haml +3 -0
- data/app/components/whose/dialog_header_component.rb +8 -0
- data/app/components/whose/flash_component/flash_component.en.yml +2 -0
- data/app/components/whose/flash_component/flash_component.html.haml +14 -0
- data/app/components/whose/flash_component.rb +35 -0
- data/app/components/whose/form/field_component/field_component.html.haml +16 -0
- data/app/components/whose/form/field_component.rb +90 -0
- data/app/components/whose/link_component/link_component.html.haml +1 -0
- data/app/components/whose/link_component.rb +22 -0
- data/app/components/whose/list_component/list_component.html.haml +3 -0
- data/app/components/whose/list_component.rb +15 -0
- data/app/components/whose/list_row_component/list_row_component.html.haml +12 -0
- data/app/components/whose/list_row_component.rb +19 -0
- data/app/components/whose/modal_component/modal_component.html.haml +10 -0
- data/app/components/whose/modal_component.rb +12 -0
- data/app/components/whose/nav/item_component/item_component.html.haml +5 -0
- data/app/components/whose/nav/item_component.rb +21 -0
- data/app/components/whose/nav_component/nav_component.en.yml +4 -0
- data/app/components/whose/nav_component/nav_component.html.haml +22 -0
- data/app/components/whose/nav_component.rb +55 -0
- data/app/components/whose/offcanvas_component/offcanvas_component.html.haml +8 -0
- data/app/components/whose/offcanvas_component.rb +21 -0
- data/app/components/whose/page_header_component/page_header_component.html.haml +7 -0
- data/app/components/whose/page_header_component.rb +17 -0
- data/app/components/whose/pagination_component/pagination_component.html.haml +2 -0
- data/app/components/whose/pagination_component.rb +12 -0
- data/app/components/whose/tooltip_component/tooltip_component.html.haml +3 -0
- data/app/components/whose/tooltip_component.rb +26 -0
- data/app/controllers/concerns/whose/authentication.rb +77 -0
- data/app/controllers/whose/confirmations_controller.rb +29 -0
- data/app/controllers/whose/passwords_controller.rb +38 -0
- data/app/controllers/whose/registrations_controller.rb +29 -0
- data/app/controllers/whose/sessions_controller.rb +31 -0
- data/app/helpers/whose/component_helper.rb +18 -0
- data/app/helpers/whose/form_helper.rb +16 -0
- data/app/javascript/whose/controllers/whose_dialog_controller.js +3 -0
- data/app/javascript/whose/controllers/whose_notification_controller.js +8 -0
- data/app/javascript/whose/controllers/whose_password_visibility_controller.js +3 -0
- data/app/jobs/.keep +0 -0
- data/app/mailers/whose/auth_mailer.rb +17 -0
- data/app/models/concerns/whose/authenticatable.rb +31 -0
- data/app/models/whose/current.rb +6 -0
- data/app/models/whose/session.rb +7 -0
- data/app/views/whose/auth_mailer/account_exists.html.haml +6 -0
- data/app/views/whose/auth_mailer/account_exists.text.haml +9 -0
- data/app/views/whose/auth_mailer/confirmation.html.haml +3 -0
- data/app/views/whose/auth_mailer/confirmation.text.haml +5 -0
- data/app/views/whose/auth_mailer/password_reset.html.haml +3 -0
- data/app/views/whose/auth_mailer/password_reset.text.haml +5 -0
- data/app/views/whose/confirmations/new.html.haml +11 -0
- data/app/views/whose/confirmations/show.html.haml +6 -0
- data/app/views/whose/passwords/edit.html.haml +11 -0
- data/app/views/whose/passwords/new.html.haml +11 -0
- data/app/views/whose/registrations/new.html.haml +16 -0
- data/app/views/whose/sessions/new.html.haml +15 -0
- data/config/importmap.rb +7 -0
- data/config/locales/whose/auth.en.yml +71 -0
- data/config/locales/whose/errors.en.yml +17 -0
- data/config/locales/whose/form.en.yml +5 -0
- data/config/locales/whose/nav.en.yml +4 -0
- data/lib/generators/whose/components/install/install_generator.rb +56 -0
- data/lib/generators/whose/components/install/templates/application.html.haml +24 -0
- data/lib/generators/whose/components/install/templates/create_users.rb.tt +17 -0
- data/lib/generators/whose/components/install/templates/create_whose_sessions.rb.tt +13 -0
- data/lib/generators/whose/components/install/templates/user.rb.tt +7 -0
- data/lib/generators/whose/components/install/templates/users.rb.tt +15 -0
- data/lib/generators/whose/components/views/USAGE +12 -0
- data/lib/generators/whose/components/views/views_generator.rb +19 -0
- data/lib/templates/app/.claude/skills/asd-ste100/LICENSE +21 -0
- data/lib/templates/app/.claude/skills/asd-ste100/README.md +102 -0
- data/lib/templates/app/.claude/skills/asd-ste100/SKILL.md +139 -0
- data/lib/templates/app/.claude/skills/asd-ste100/examples/before-after.md +92 -0
- data/lib/templates/app/.claude/skills/asd-ste100/examples/linter-edge-cases.md +14 -0
- data/lib/templates/app/.claude/skills/asd-ste100/references/writing-rules.md +59 -0
- data/lib/templates/app/.claude/skills/asd-ste100/scripts/ste-lint.py +486 -0
- data/lib/templates/app/CLAUDE.md.tt +181 -0
- data/lib/templates/whose_app_template.rb +144 -0
- data/lib/whose/components/engine.rb +33 -0
- data/lib/whose/components/form_builder.rb +158 -0
- data/lib/whose/components/routes.rb +16 -0
- data/lib/whose/components/version.rb +7 -0
- data/lib/whose/components.rb +16 -0
- data/lib/whose/merge_classes.rb +17 -0
- data/vendor/javascript/@stimulus-components--dialog.js +4 -0
- data/vendor/javascript/@stimulus-components--notification.js +4 -0
- data/vendor/javascript/@stimulus-components--password-visibility.js +4 -0
- data/vendor/javascript/LICENSES +30 -0
- data/vendor/javascript/stimulus-use.js +4 -0
- metadata +272 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1cbe1ab5584a6efbb51e2bd757c68ad1b0b6485e1bea820c93f03ae993a88e06
|
|
4
|
+
data.tar.gz: 34dbddb5a5c354f064ff9e337948530df8150eac4c0961553425f2efab10235b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e6243a377da18bdb8fcbf4a0c00bc4bca18e8101689e1e0f30003e1d05aa990dcbe5e6becb4eec291316f8b902d3ca99ad4931fae5f5b701ef6cfe48a2d21bfe
|
|
7
|
+
data.tar.gz: 5031b6f01f4302121cf5ae6249871bb9ad7ddb3a3d7c383ec135f1cdf7bec55a375f506dc134146e59d0cc121241aaf27d0c800157274c2f7ee77869e3f59236
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright WeiHsi Hu
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# Whose::Components
|
|
2
|
+
A Rails engine with Tailwind UI components, a light and dark theme, and email-and-password auth that the gem holds. It also has a `rails new` template that sets up a new app with all of these.
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
Make a new app with the app template:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
rails new myapp -d postgresql --css tailwind -m https://raw.githubusercontent.com/waywho/whose-components/v0.1.0/lib/templates/whose_app_template.rb
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
With all the flags of the template, for an app with sign-in and a home page:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
rails new myapp -d postgresql --css tailwind --auth --root pages#home \
|
|
15
|
+
-m https://raw.githubusercontent.com/waywho/whose-components/v0.1.0/lib/templates/whose_app_template.rb
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Short command with ~/.railsrc
|
|
19
|
+
`rails new` reads default flags from `~/.railsrc`. To put the database, the CSS and the template URL there, run this once from a checkout of this repo:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bin/install-railsrc
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then make a new app with only the flags of the template:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
rails new myapp --auth --root pages#home
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- The URL in `~/.railsrc` names the version of your checkout. After a new release, run `git pull` and `bin/install-railsrc` again.
|
|
32
|
+
- If `~/.railsrc` has other settings, the script stops. Add `--force` to replace the file.
|
|
33
|
+
- Keep `--auth`, `--no-auth`, `--root` and `--component-gem-path` on the command line. The template does not see these flags in `~/.railsrc`.
|
|
34
|
+
- To make an app without these defaults, add `--no-rc` to `rails new`.
|
|
35
|
+
|
|
36
|
+
The URL names a ref: a tag, a branch, or `refs/tags/<tag>` or `refs/heads/<branch>`. The gem and the template files both come from that ref. A branch name that has a slash does not work.
|
|
37
|
+
|
|
38
|
+
Add `--root pages#home` to make a root page. The template writes the route, the controller, the view and a controller test. Use any `controller#action`, for example `--root landing#show`. With sign-in, the page asks a signed-out visitor to sign in.
|
|
39
|
+
|
|
40
|
+
If you pass `--skip-bundle`, the template prints the commands that you must run by hand.
|
|
41
|
+
|
|
42
|
+
The template asks if the app needs sign-in. Add `--auth` or `--no-auth` to answer without the prompt.
|
|
43
|
+
|
|
44
|
+
Add `--component-gem-path /path/to/whose-components` to install the gem from a local checkout instead of GitHub.
|
|
45
|
+
|
|
46
|
+
## Form layouts
|
|
47
|
+
`whose_form_with` takes a `layout:` option. An unknown layout raises `ArgumentError`.
|
|
48
|
+
|
|
49
|
+
- `:vertical` (default): each label sits above its input, and the fields stack.
|
|
50
|
+
- `:horizontal`: each label sits beside its input. On a phone the label moves above.
|
|
51
|
+
- `:inline`: the fields and the submit button sit side by side in one row. Labels stay above the inputs. On a phone the row becomes a stack.
|
|
52
|
+
|
|
53
|
+
```haml
|
|
54
|
+
= whose_form_with model: @search, url: search_path, layout: :inline do |f|
|
|
55
|
+
= f.text_field :query
|
|
56
|
+
= f.submit "Search"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`whose_form_with` also takes `labels: :placeholder`. Text, email, password and other typed fields and text areas then show the label as the placeholder. Only screen readers see the label. A placeholder that a field sets itself stays. Selects, file fields, checkboxes and toggles keep a visible label. The option works with all three layouts.
|
|
60
|
+
|
|
61
|
+
```haml
|
|
62
|
+
= whose_form_with model: @search, url: search_path, layout: :inline, labels: :placeholder do |f|
|
|
63
|
+
= f.text_field :query, label: "Search"
|
|
64
|
+
= f.submit "Search"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Form fields
|
|
68
|
+
The form builder wraps each field in a label, the theme classes, an optional hint and the first error message. Each field takes `label:` and `hint:`.
|
|
69
|
+
|
|
70
|
+
- Typed fields: `text_field`, `email_field`, `password_field` (with a Show/Hide button), `number_field`, `telephone_field`, `url_field`, `search_field`, `date_field`, `datetime_field`, `datetime_local_field`, `time_field`, `month_field`, `week_field`, `color_field`, `range_field`, `text_area` and `file_field`.
|
|
71
|
+
- Choices: `select` and `collection_select`. These take `label:` and `hint:` in the options hash.
|
|
72
|
+
- `checkbox` and `toggle` put the label after the input.
|
|
73
|
+
- `collection_radio_buttons` renders one group with one label, one hint and one error. A single `radio_button` gets only the radio style, with no label.
|
|
74
|
+
|
|
75
|
+
```haml
|
|
76
|
+
= whose_form_with model: @user do |f|
|
|
77
|
+
= f.collection_radio_buttons :role, [["Editor", "editor"], ["Admin", "admin"]], :last, :first, label: "Role", hint: "Admins can change settings."
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The error messages are plain English, for example "Enter a value." in place of "can't be blank". The gem sets them under `en.errors.messages` in `config/locales/whose/errors.en.yml`. To change one, set the same key in your app's locale file.
|
|
81
|
+
|
|
82
|
+
## View helpers
|
|
83
|
+
Each component has a view helper. The helper name is the component class name in snake case, without `Whose`. The helper takes the same arguments and block as the component.
|
|
84
|
+
|
|
85
|
+
- `button_component`, `link_component`, `badge_component`, `card_component`
|
|
86
|
+
- `flash_component`, `page_header_component`, `list_component`, `list_row_component`
|
|
87
|
+
- `modal_component`, `offcanvas_component`, `tooltip_component`
|
|
88
|
+
- `nav_component`, `nav_item_component`, `pagination_component`
|
|
89
|
+
|
|
90
|
+
```erb
|
|
91
|
+
<%= card_component do |card| %>
|
|
92
|
+
<% card.with_header { "Title" } %>
|
|
93
|
+
Body
|
|
94
|
+
<% end %>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`whose_form_with` wraps `form_with` and is not a component.
|
|
98
|
+
|
|
99
|
+
## Installation
|
|
100
|
+
Add the gem to your Gemfile:
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
gem "whose-components", "~> 0.3"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Then run:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
bundle install
|
|
110
|
+
bin/rails generate whose:components:install
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The install generator does these things:
|
|
114
|
+
|
|
115
|
+
- Adds `@import "../builds/tailwind/whose_components.css";` to `app/assets/tailwind/application.css`, after `@import "tailwindcss";`.
|
|
116
|
+
- Adds `eagerLoadControllersFrom("whose/controllers", application)` to `app/javascript/controllers/index.js`.
|
|
117
|
+
- Replaces `app/views/layouts/application.html.erb` with `app/views/layouts/application.html.haml`. The new layout uses the theme and renders the nav and flash components.
|
|
118
|
+
|
|
119
|
+
For email-and-password sign-in, add `--auth`:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
bin/rails generate whose:components:install --auth
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
With `--auth`, the generator also does these things:
|
|
126
|
+
|
|
127
|
+
- Creates the migrations `create_users` and `create_whose_sessions`.
|
|
128
|
+
- Creates `app/models/user.rb`, which includes `Whose::Authenticatable`, and `test/factories/users.rb`.
|
|
129
|
+
- Adds `include Whose::Authentication` to `ApplicationController`.
|
|
130
|
+
- Adds `whose_authentication` to `config/routes.rb`. It defines the routes for `session`, `registration`, `confirmations` and `passwords`.
|
|
131
|
+
- Adds a sign-out button to the nav in the layout. Only a signed-in user sees it.
|
|
132
|
+
|
|
133
|
+
## Auth views
|
|
134
|
+
To change the auth views, copy them into your app:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
bin/rails generate whose:components:views
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The generator copies the folders `sessions`, `registrations`, `confirmations`, `passwords` and `auth_mailer` from the gem to `app/views/whose/`. Your copies replace the views of the gem.
|
|
141
|
+
|
|
142
|
+
## Auth hooks
|
|
143
|
+
The install generator includes `Whose::Authentication` in `ApplicationController`. Override these private methods there to change the behaviour:
|
|
144
|
+
|
|
145
|
+
| Method | Default |
|
|
146
|
+
| --- | --- |
|
|
147
|
+
| `after_sign_in_path` | `root_path` of the app, or `"/"` if the app has no root route |
|
|
148
|
+
| `after_sign_up_path` | `new_session_path` |
|
|
149
|
+
| `after_sign_out_path` | `new_session_path` |
|
|
150
|
+
| `sign_up_params` | `params.expect(user: %i[first_name last_name email password password_confirmation])` |
|
|
151
|
+
| `after_sign_up(user)` | Does nothing. It runs after a user signs up. |
|
|
152
|
+
|
|
153
|
+
After sign-in, a user goes back to the page that they first asked for. `after_sign_in_path` applies only when there is no such page.
|
|
154
|
+
|
|
155
|
+
Every action requires sign-in by default. To make a page public, call `allow_unauthenticated_access` in the controller:
|
|
156
|
+
|
|
157
|
+
```ruby
|
|
158
|
+
class PagesController < ApplicationController
|
|
159
|
+
allow_unauthenticated_access only: :home
|
|
160
|
+
end
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The auth flow never shows whether an email address has an account. Sign-in, sign-up, confirmation resend and password reset give the same status, page and message for a known and an unknown address.
|
|
164
|
+
|
|
165
|
+
## Theme
|
|
166
|
+
The theme tokens are CSS variables with the prefix `--whose-`, defined in `:root`. Dark mode redefines the colour variables under `prefers-color-scheme: dark`. The variables are:
|
|
167
|
+
|
|
168
|
+
- Colours: `--whose-canvas`, `--whose-surface`, `--whose-subtle`, `--whose-fg`, `--whose-muted`, `--whose-border`, `--whose-accent`, `--whose-on-accent`, `--whose-accent-soft`, `--whose-accent-text`
|
|
169
|
+
- Status colours: `--whose-positive`, `--whose-negative` and `--whose-warning`, each with a `-soft` variant
|
|
170
|
+
- `--whose-radius`
|
|
171
|
+
- Fonts: `--whose-font-sans`, `--whose-font-display`
|
|
172
|
+
|
|
173
|
+
Tailwind has a utility for each token, for example `bg-surface`, `text-fg`, `border-border` and `bg-accent`.
|
|
174
|
+
|
|
175
|
+
To change a token, set it in `app/assets/tailwind/application.css`, after the import of the gem CSS:
|
|
176
|
+
|
|
177
|
+
```css
|
|
178
|
+
:root {
|
|
179
|
+
--whose-accent: var(--color-teal-600);
|
|
180
|
+
--whose-radius: 0.75rem;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Dark mode sets its own `--whose-accent`. To change the accent in dark mode too, set it again inside `@media (prefers-color-scheme: dark)`.
|
|
185
|
+
|
|
186
|
+
## Pagination
|
|
187
|
+
`pagination_component(pagy: @pagy)` renders `@pagy.series_nav`, so it needs Pagy 43. The gem does not depend on Pagy. Add `gem "pagy", "~> 43"` to your Gemfile. The component renders nothing when there is only one page.
|
|
188
|
+
|
|
189
|
+
## Development
|
|
190
|
+
The `docs/` folder holds the docs app. It shows each component in Lookbook, and the gem's tests run against it.
|
|
191
|
+
|
|
192
|
+
### What you need
|
|
193
|
+
- Ruby 3.4.7, the version that CI uses.
|
|
194
|
+
- Google Chrome, for the system tests.
|
|
195
|
+
|
|
196
|
+
### First setup
|
|
197
|
+
```bash
|
|
198
|
+
git clone git@github.com:waywho/whose-components.git
|
|
199
|
+
cd whose-components
|
|
200
|
+
bin/setup
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
`bin/setup` installs the gems, builds the Tailwind CSS, prepares the docs app database and then starts `bin/dev`. Add `--skip-server` to stop before the server starts. Add `--reset` to empty the database and load the schema again.
|
|
204
|
+
|
|
205
|
+
### Run the docs app
|
|
206
|
+
```bash
|
|
207
|
+
bin/dev
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
This starts the server and the Tailwind watcher on port 3000.
|
|
211
|
+
|
|
212
|
+
- `http://localhost:3000` is the docs home page.
|
|
213
|
+
- `http://localhost:3000/lookbook` shows each component.
|
|
214
|
+
- Mail in development opens in the browser with `letter_opener`.
|
|
215
|
+
|
|
216
|
+
Code in `lib/`, such as the form builder, does not reload. After you change it, run `bin/rails restart` from the repo root in another terminal. It restarts the running server, so you do not need to stop `bin/dev`.
|
|
217
|
+
|
|
218
|
+
### Run the tests
|
|
219
|
+
```bash
|
|
220
|
+
bin/rails test # The unit, component, controller and integration tests
|
|
221
|
+
bin/rails test test/system # The system tests, in headless Chrome
|
|
222
|
+
bin/rubocop -A # Style
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The tests read the built Tailwind CSS. `bin/setup` and `bin/dev` build it. Without `bin/dev`, run `bin/rails app:tailwindcss:build` after you change a class.
|
|
226
|
+
|
|
227
|
+
### After you pull
|
|
228
|
+
Run `bin/setup --skip-server`. It installs new gems, builds the CSS and runs new migrations.
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2020 The League Spartan Project Authors (https://github.com/theleagueof/league-spartan)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
https://openfontlicense.org
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
@source "../../../components";
|
|
2
|
+
@source "../../../views";
|
|
3
|
+
@source "../../../helpers";
|
|
4
|
+
@source "../../../../lib/whose";
|
|
5
|
+
|
|
6
|
+
@font-face {
|
|
7
|
+
font-family: "League Spartan";
|
|
8
|
+
src: url("whose_components/leaguespartan-bold.woff2") format("woff2");
|
|
9
|
+
font-weight: bold;
|
|
10
|
+
font-style: normal;
|
|
11
|
+
font-display: swap;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
:root {
|
|
15
|
+
--whose-canvas: var(--color-stone-50);
|
|
16
|
+
--whose-surface: var(--color-white);
|
|
17
|
+
--whose-subtle: var(--color-stone-100);
|
|
18
|
+
--whose-fg: var(--color-stone-900);
|
|
19
|
+
--whose-muted: var(--color-stone-500);
|
|
20
|
+
--whose-border: var(--color-stone-200);
|
|
21
|
+
--whose-accent: var(--color-indigo-600);
|
|
22
|
+
--whose-on-accent: var(--color-white);
|
|
23
|
+
--whose-accent-soft: var(--color-indigo-100);
|
|
24
|
+
--whose-accent-text: var(--color-indigo-700);
|
|
25
|
+
--whose-positive: var(--color-green-700);
|
|
26
|
+
--whose-positive-soft: var(--color-green-100);
|
|
27
|
+
--whose-negative: var(--color-red-700);
|
|
28
|
+
--whose-negative-soft: var(--color-red-100);
|
|
29
|
+
--whose-warning: var(--color-amber-700);
|
|
30
|
+
--whose-warning-soft: var(--color-amber-100);
|
|
31
|
+
--whose-backdrop: color-mix(in oklab, var(--color-black) 50%, transparent);
|
|
32
|
+
--whose-radius: 0.375rem;
|
|
33
|
+
--whose-font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
|
34
|
+
--whose-font-display: "League Spartan", var(--whose-font-sans);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@media (prefers-color-scheme: dark) {
|
|
38
|
+
:root {
|
|
39
|
+
--whose-canvas: var(--color-stone-950);
|
|
40
|
+
--whose-surface: var(--color-stone-900);
|
|
41
|
+
--whose-subtle: var(--color-stone-800);
|
|
42
|
+
--whose-fg: var(--color-stone-50);
|
|
43
|
+
--whose-muted: var(--color-stone-300);
|
|
44
|
+
--whose-border: var(--color-stone-700);
|
|
45
|
+
--whose-accent: var(--color-violet-800);
|
|
46
|
+
--whose-on-accent: var(--color-white);
|
|
47
|
+
--whose-accent-soft: var(--color-violet-950);
|
|
48
|
+
--whose-accent-text: var(--color-violet-200);
|
|
49
|
+
--whose-positive: var(--color-green-300);
|
|
50
|
+
--whose-positive-soft: var(--color-green-950);
|
|
51
|
+
--whose-negative: var(--color-red-300);
|
|
52
|
+
--whose-negative-soft: var(--color-red-950);
|
|
53
|
+
--whose-warning: var(--color-amber-300);
|
|
54
|
+
--whose-warning-soft: var(--color-amber-950);
|
|
55
|
+
--whose-backdrop: color-mix(in oklab, var(--color-black) 70%, transparent);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@theme inline {
|
|
60
|
+
--color-canvas: var(--whose-canvas);
|
|
61
|
+
--color-surface: var(--whose-surface);
|
|
62
|
+
--color-subtle: var(--whose-subtle);
|
|
63
|
+
--color-fg: var(--whose-fg);
|
|
64
|
+
--color-muted: var(--whose-muted);
|
|
65
|
+
--color-border: var(--whose-border);
|
|
66
|
+
--color-accent: var(--whose-accent);
|
|
67
|
+
--color-on-accent: var(--whose-on-accent);
|
|
68
|
+
--color-accent-soft: var(--whose-accent-soft);
|
|
69
|
+
--color-accent-text: var(--whose-accent-text);
|
|
70
|
+
--color-positive: var(--whose-positive);
|
|
71
|
+
--color-positive-soft: var(--whose-positive-soft);
|
|
72
|
+
--color-negative: var(--whose-negative);
|
|
73
|
+
--color-negative-soft: var(--whose-negative-soft);
|
|
74
|
+
--color-warning: var(--whose-warning);
|
|
75
|
+
--color-warning-soft: var(--whose-warning-soft);
|
|
76
|
+
--color-backdrop: var(--whose-backdrop);
|
|
77
|
+
--radius-box: var(--whose-radius);
|
|
78
|
+
--font-sans: var(--whose-font-sans);
|
|
79
|
+
--font-display: var(--whose-font-display);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@layer base {
|
|
83
|
+
h1, h2, h3, h4, h5, h6 {
|
|
84
|
+
font-family: var(--whose-font-display);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.field_with_errors {
|
|
88
|
+
@apply contents;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@layer components {
|
|
93
|
+
.pagy.series-nav {
|
|
94
|
+
display: inline-flex;
|
|
95
|
+
gap: 0.25rem;
|
|
96
|
+
font-family: var(--whose-font-sans);
|
|
97
|
+
font-size: 0.875rem;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.pagy.series-nav a {
|
|
101
|
+
min-width: 2.25rem;
|
|
102
|
+
padding: 0.375rem 0.75rem;
|
|
103
|
+
text-align: center;
|
|
104
|
+
color: var(--whose-fg);
|
|
105
|
+
background: var(--whose-surface);
|
|
106
|
+
border: 1px solid var(--whose-border);
|
|
107
|
+
border-radius: var(--whose-radius);
|
|
108
|
+
text-decoration: none;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.pagy.series-nav a:focus-visible {
|
|
112
|
+
outline: 2px solid var(--whose-accent);
|
|
113
|
+
outline-offset: 2px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.pagy.series-nav a[href]:hover {
|
|
117
|
+
background: var(--whose-accent-soft);
|
|
118
|
+
color: var(--whose-accent-text);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.pagy.series-nav a[aria-current="page"] {
|
|
122
|
+
background: var(--whose-accent);
|
|
123
|
+
border-color: var(--whose-accent);
|
|
124
|
+
color: var(--whose-on-accent);
|
|
125
|
+
font-weight: 600;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.pagy.series-nav a[aria-disabled="true"]:not([aria-current]) {
|
|
129
|
+
color: var(--whose-muted);
|
|
130
|
+
opacity: 0.5;
|
|
131
|
+
cursor: not-allowed;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.pagy.series-nav a[role="separator"] {
|
|
135
|
+
background: transparent;
|
|
136
|
+
border-color: transparent;
|
|
137
|
+
cursor: default;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
%span{attributes}= content
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Whose::BadgeComponent < ViewComponent::Base
|
|
4
|
+
BASE_CLASSES = "inline-flex items-center rounded-box px-2 py-0.5 font-sans text-xs font-medium"
|
|
5
|
+
VARIANT_CLASSES = {
|
|
6
|
+
neutral: "bg-canvas text-muted border border-border",
|
|
7
|
+
accent: "bg-accent-soft text-accent-text",
|
|
8
|
+
positive: "bg-positive-soft text-positive",
|
|
9
|
+
negative: "bg-negative-soft text-negative",
|
|
10
|
+
warning: "bg-warning-soft text-warning"
|
|
11
|
+
}.freeze
|
|
12
|
+
|
|
13
|
+
def initialize(variant: :neutral, **html_attributes)
|
|
14
|
+
@variant = variant.to_sym
|
|
15
|
+
raise ArgumentError, "Unknown variant: #{variant.inspect}." unless VARIANT_CLASSES.key?(@variant)
|
|
16
|
+
|
|
17
|
+
@html_attributes = html_attributes
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def attributes
|
|
21
|
+
@html_attributes.merge(class: Whose.merge_classes(BASE_CLASSES, VARIANT_CLASSES[@variant], @html_attributes[:class]))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Whose::ButtonComponent < ViewComponent::Base
|
|
4
|
+
BASE_CLASSES = "inline-flex items-center justify-center gap-2 rounded-box font-sans font-medium " \
|
|
5
|
+
"cursor-pointer focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent " \
|
|
6
|
+
"disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50"
|
|
7
|
+
VARIANT_CLASSES = {
|
|
8
|
+
primary: "bg-accent text-on-accent border border-transparent hover:opacity-90",
|
|
9
|
+
secondary: "bg-subtle text-fg border border-border hover:bg-border",
|
|
10
|
+
danger: "bg-negative text-surface border border-transparent hover:opacity-90",
|
|
11
|
+
invisible: "bg-transparent text-fg border border-transparent hover:bg-accent-soft hover:text-accent-text"
|
|
12
|
+
}.freeze
|
|
13
|
+
SIZE_CLASSES = {
|
|
14
|
+
sm: "px-3 py-1.5 text-sm",
|
|
15
|
+
md: "px-4 py-2 text-base"
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
def initialize(variant: :primary, size: :md, href: nil, type: "button", disabled: false, full: false, **html_attributes)
|
|
19
|
+
@variant = variant.to_sym
|
|
20
|
+
@size = size.to_sym
|
|
21
|
+
raise ArgumentError, "Unknown variant: #{variant.inspect}." unless VARIANT_CLASSES.key?(@variant)
|
|
22
|
+
raise ArgumentError, "Unknown size: #{size.inspect}." unless SIZE_CLASSES.key?(@size)
|
|
23
|
+
|
|
24
|
+
@href = href
|
|
25
|
+
@type = type
|
|
26
|
+
@disabled = disabled
|
|
27
|
+
@full = full
|
|
28
|
+
@html_attributes = html_attributes
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def attributes
|
|
32
|
+
@html_attributes.merge(class: Whose.merge_classes(BASE_CLASSES, VARIANT_CLASSES[@variant], SIZE_CLASSES[@size], width_class, @html_attributes[:class]))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def width_class
|
|
38
|
+
@full ? "w-full" : "w-fit"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Whose::CardComponent < ViewComponent::Base
|
|
4
|
+
renders_one :header
|
|
5
|
+
renders_one :footer
|
|
6
|
+
|
|
7
|
+
BASE_CLASSES = "rounded-box border border-border bg-surface font-sans text-fg"
|
|
8
|
+
|
|
9
|
+
def initialize(padded: true, **html_attributes)
|
|
10
|
+
@padded = padded
|
|
11
|
+
@html_attributes = html_attributes
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def attributes
|
|
15
|
+
@html_attributes.merge(
|
|
16
|
+
class: Whose.merge_classes(BASE_CLASSES, @html_attributes[:class]),
|
|
17
|
+
data: { card: true }.merge(@html_attributes[:data] || {})
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def body_classes
|
|
22
|
+
"p-4" if @padded
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whose::Dialog
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
renders_one :trigger
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def title_id
|
|
11
|
+
@title_id ||= "whose-dialog-title-#{SecureRandom.hex(4)}"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def attributes
|
|
15
|
+
@html_attributes.merge(data: { controller: "whose-dialog", action: "click->whose-dialog#backdropClose" }.merge(@html_attributes[:data] || {}))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def before_render
|
|
19
|
+
raise ArgumentError, "The trigger slot is required." unless trigger?
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
.flex.items-start.justify-between.gap-4
|
|
2
|
+
%h2.text-lg.font-semibold{ id: @title_id }= @title
|
|
3
|
+
%button.shrink-0.cursor-pointer.rounded-box.px-1.opacity-70.hover:opacity-100.focus-visible:outline-2.focus-visible:outline-offset-2.focus-visible:outline-accent{ type: "button", aria: { label: t(".close") }, data: { action: "whose-dialog#close" } } ×
|