shadcn-ui 0.0.3 → 0.0.5
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 +4 -4
- data/Procfile.dev +0 -1
- data/README.md +13 -314
- data/app/assets/stylesheets/shadcn.css +8 -0
- data/app/controllers/components_controller.rb +1 -0
- data/app/controllers/documentation_controller.rb +0 -1
- data/app/controllers/users_controller.rb +19 -0
- data/app/form_builders/shadcn_form_builder.rb +43 -0
- data/app/helpers/components/alert_dialog_helper.rb +19 -3
- data/app/helpers/components/forms_helper.rb +13 -0
- data/app/helpers/components/input_helper.rb +15 -5
- data/app/helpers/components/slider_helper.rb +1 -1
- data/app/helpers/components/toast_helper.rb +4 -1
- data/app/helpers/components_helper.rb +4 -0
- data/app/helpers/examples_helper.rb +6 -1
- data/app/javascript/controllers/highlight_controller.js +0 -1
- data/app/javascript/controllers/ui/dialog_controller.js +1 -1
- data/app/javascript/controllers/ui/dropdown_controller.js +1 -1
- data/app/javascript/controllers/ui/hover-card_controller.js +2 -3
- data/app/javascript/controllers/ui/popover_controller.js +7 -3
- data/app/javascript/controllers/ui/sheet_controller.js +1 -1
- data/app/javascript/controllers/ui/toast_controller.js +50 -23
- data/app/javascript/controllers/ui/transition_controller.js +1 -1
- data/app/models/user.rb +9 -0
- data/app/views/application/index.html.erb +625 -17
- data/app/views/components/ui/_alert_dialog.html.erb +10 -6
- data/app/views/components/ui/_card.html.erb +7 -1
- data/app/views/components/ui/_dialog.html.erb +0 -26
- data/app/views/components/ui/_filter.html.erb +3 -2
- data/app/views/components/ui/_input.html.erb +3 -0
- data/app/views/components/ui/_label.html.erb +1 -1
- data/app/views/components/ui/_toast.html.erb +8 -4
- data/app/views/documentation/generators.html.md +20 -0
- data/app/views/documentation/helpers.html.md +54 -0
- data/app/views/documentation/installation.html.md +1 -1
- data/app/views/documentation/javascript.html.md +8 -0
- data/app/views/examples/components/accordion.html.erb +5 -7
- data/app/views/examples/components/alert-dialog/_usage.html.erb +24 -0
- data/app/views/examples/components/alert-dialog/code/_preview.erb +22 -0
- data/app/views/examples/components/alert-dialog/code/_usage.erb +13 -0
- data/app/views/examples/components/alert-dialog.html.erb +14 -11
- data/app/views/examples/components/alert.html.erb +9 -10
- data/app/views/examples/components/badge.html.erb +3 -15
- data/app/views/examples/components/button.html.erb +3 -25
- data/app/views/examples/components/card/code/{preview.erb → _preview.erb} +1 -1
- data/app/views/examples/components/card/code/_usage.erb +3 -0
- data/app/views/examples/components/card.html.erb +5 -9
- data/app/views/examples/components/checkbox/code/_preview.erb +2 -0
- data/app/views/examples/components/checkbox.html.erb +3 -3
- data/app/views/examples/components/collapsible.html.erb +3 -11
- data/app/views/examples/components/dialog.html.erb +5 -14
- data/app/views/examples/components/dropdown-menu/_usage.html.erb +19 -0
- data/app/views/examples/components/dropdown-menu/code/_preview.erb +19 -0
- data/app/views/examples/components/dropdown-menu/code/_usage.erb +13 -0
- data/app/views/examples/components/dropdown-menu.html.erb +29 -15
- data/app/views/examples/components/filter/_usage.html.erb +14 -0
- data/app/views/examples/components/filter/code/_icon.html.erb +7 -0
- data/app/views/examples/components/filter/code/_preview.erb +3 -0
- data/app/views/examples/components/filter/code/_usage.erb +5 -0
- data/app/views/examples/components/filter.html.erb +27 -7
- data/app/views/examples/components/forms/_usage.html.erb +28 -0
- data/app/views/examples/components/forms/code/_preview.erb +13 -0
- data/app/views/examples/components/forms/code/_usage.erb +6 -0
- data/app/views/examples/components/forms.html.erb +23 -0
- data/app/views/examples/components/hover-card/_usage.html.erb +15 -0
- data/app/views/examples/components/hover-card/code/_preview.erb +13 -0
- data/app/views/examples/components/hover-card/code/_usage.erb +6 -0
- data/app/views/examples/components/hover-card.html.erb +12 -14
- data/app/views/examples/components/input/_usage.html.erb +10 -0
- data/app/views/examples/components/input/code/_borderless.erb +3 -0
- data/app/views/examples/components/input/code/_preview.erb +1 -0
- data/app/views/examples/components/input/code/_usage.erb +1 -0
- data/app/views/examples/components/input.html.erb +17 -3
- data/app/views/examples/components/label/_usage.html.erb +9 -0
- data/app/views/examples/components/label/code/_preview.erb +5 -0
- data/app/views/examples/components/label/code/_usage.erb +1 -0
- data/app/views/examples/components/label.html.erb +14 -5
- data/app/views/examples/components/popover/_usage.html.erb +12 -0
- data/app/views/examples/components/popover/code/_form.erb +23 -0
- data/app/views/examples/components/popover/code/_preview.erb +13 -0
- data/app/views/examples/components/popover/code/_usage.erb +7 -0
- data/app/views/examples/components/popover.html.erb +28 -24
- data/app/views/examples/components/progress/_usage.erb +9 -0
- data/app/views/examples/components/progress/code/_preview.erb +1 -0
- data/app/views/examples/components/progress/code/_usage.erb +1 -0
- data/app/views/examples/components/progress.html.erb +12 -2
- data/app/views/examples/components/separator/_usage.html.erb +10 -0
- data/app/views/examples/components/separator/code/_fancy.erb +21 -0
- data/app/views/examples/components/separator/code/_preview.erb +1 -0
- data/app/views/examples/components/separator/code/_usage.erb +1 -0
- data/app/views/examples/components/separator.html.erb +26 -19
- data/app/views/examples/components/sheet/_usage.html.erb +38 -0
- data/app/views/examples/components/sheet/code/_mobile_menu.erb +17 -0
- data/app/views/examples/components/sheet/code/_preview.erb +22 -0
- data/app/views/examples/components/sheet/code/_usage.erb +7 -0
- data/app/views/examples/components/sheet.html.erb +17 -10
- data/app/views/examples/components/skeleton/_usage.html.erb +9 -0
- data/app/views/examples/components/skeleton/code/_preview.erb +1 -0
- data/app/views/examples/components/skeleton/code/_usage.erb +1 -0
- data/app/views/examples/components/skeleton.html.erb +16 -2
- data/app/views/examples/components/slider/_usage.html.erb +11 -0
- data/app/views/examples/components/slider/code/_preview.erb +3 -0
- data/app/views/examples/components/slider/code/_usage.erb +1 -0
- data/app/views/examples/components/slider.html.erb +16 -2
- data/app/views/examples/components/textarea/_usage.html.erb +9 -0
- data/app/views/examples/components/textarea/code/_preview.erb +1 -0
- data/app/views/examples/components/textarea/code/_usage.erb +1 -0
- data/app/views/examples/components/textarea.html.erb +16 -2
- data/app/views/examples/components/toast/_usage.html.erb +11 -0
- data/app/views/examples/components/toast/code/_destructive.erb +6 -0
- data/app/views/examples/components/toast/code/_preview.erb +4 -0
- data/app/views/examples/components/toast/code/_usage.erb +2 -0
- data/app/views/examples/components/toast.html.erb +28 -5
- data/app/views/examples/components/toggle/_usage.html.erb +10 -0
- data/app/views/examples/components/toggle/code/_preview.erb +1 -0
- data/app/views/examples/components/toggle/code/_usage.erb +1 -0
- data/app/views/examples/components/toggle.html.erb +16 -2
- data/app/views/examples/components/tooltip/_usage.html.erb +11 -0
- data/app/views/examples/components/tooltip/code/_preview.erb +12 -0
- data/app/views/examples/components/tooltip/code/_usage.erb +7 -0
- data/app/views/examples/components/tooltip.html.erb +16 -13
- data/app/views/layouts/shared/_components.html.erb +35 -33
- data/config/environments/production.rb +4 -4
- data/config/routes.rb +3 -0
- data/lib/components.json +13 -1
- data/lib/generators/shadcn-ui_generator.rb +1 -1
- data/lib/shadcn-ui/version.rb +1 -1
- metadata +84 -20
- data/app/views/examples/components/card/code/usage.erb +0 -3
- data/app/views/examples/components/checkbox/code/preview.erb +0 -2
- /data/app/views/examples/components/accordion/code/{preview.erb → _preview.erb} +0 -0
- /data/app/views/examples/components/accordion/code/{usage.erb → _usage.erb} +0 -0
- /data/app/views/examples/components/alert/code/{preview.erb → _preview.erb} +0 -0
- /data/app/views/examples/components/alert/code/{usage.erb → _usage.erb} +0 -0
- /data/app/views/examples/components/badge/code/{preview.erb → _preview.erb} +0 -0
- /data/app/views/examples/components/badge/code/{usage.erb → _usage.erb} +0 -0
- /data/app/views/examples/components/button/code/{preview.erb → _preview.erb} +0 -0
- /data/app/views/examples/components/button/code/{usage.erb → _usage.erb} +0 -0
- /data/app/views/examples/components/checkbox/code/{usage.erb → _usage.erb} +0 -0
- /data/app/views/examples/components/collapsible/code/{preview.erb → _preview.erb} +0 -0
- /data/app/views/examples/components/collapsible/code/{usage.erb → _usage.erb} +0 -0
- /data/app/views/examples/components/dialog/code/{form.erb → _form.erb} +0 -0
- /data/app/views/examples/components/dialog/code/{notifications.erb → _notifications.erb} +0 -0
- /data/app/views/examples/components/dialog/code/{preview.erb → _preview.erb} +0 -0
- /data/app/views/examples/components/dialog/code/{usage.erb → _usage.erb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc5e15a7e38cfc62b7c6baeabfd28b0d1b1869d9c1af906cee95a6c1d6dafb0e
|
4
|
+
data.tar.gz: 4ace082612e01960d714dc068e734a67d57cac288f77bb13eed827d22591e87e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f604552bb826fd72f8974ce1a5fec84c93ece1957df5b8831287abb7f2ffb5520068a713bd6f8fd9d9b4804ab6cce50648adc32778282472f991a328f2da6b0b
|
7
|
+
data.tar.gz: 5bc64754ad18e8d2d70641934bfc8db0bea5855b3921b43a9626214122da0dfb12b9e925c904ae3525bbf7f7c44c50b696701b90f6c2bf3db239e0ae051c9232
|
data/Procfile.dev
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,11 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/shadcn-ui)
|
4
4
|
|
5
|
-
|
6
|
-
Source. **Use this to build your own component library**.
|
5
|
+
[Shadcn on Rails](https://shadcn.rails-components.com) provides customizable components that you can
|
6
|
+
copy and paste into your apps. Free. Open Source. **Use this to build your own component library**.
|
7
|
+
|
8
|
+
**If you're using this, [please let me know](https://twitter.com/aviflombaum) so I keep developing
|
9
|
+
it.**
|
7
10
|
|
8
11
|
## About
|
9
12
|
|
@@ -21,321 +24,17 @@ Use this as a reference to build your own component libraries.
|
|
21
24
|
|
22
25
|

|
23
26
|
|
24
|
-
##
|
25
|
-
|
26
|
-
Prior to the initial gem release, you can use this as an alpha by cloning this repository and
|
27
|
-
starting up the app as you would a standard rails app.
|
28
|
-
|
29
|
-
```
|
30
|
-
git clone https://github.com/aviflombaum/shadcn-rails.git
|
31
|
-
cd shadcn-rails
|
32
|
-
bundle install
|
33
|
-
./bin/dev
|
34
|
-
```
|
35
|
-
|
36
|
-
There are very few dependencies and no database so it should just boot up. Visit
|
37
|
-
http://localhost:3000 to see the demo app which is also the documentation. You'll be able to browse
|
38
|
-
the components at http://localhost:3000/components.
|
39
|
-
|
40
|
-
If there's a component you want to try in your app, you will be copying the code from this app to
|
41
|
-
yours. There's a few other steps you'll need.
|
42
|
-
|
43
|
-
## Installing a Component
|
44
|
-
|
45
|
-
### Add Tailwind CSS
|
46
|
-
|
47
|
-
Components are styled using Tailwind CSS. You need to install Tailwind CSS in your project.
|
48
|
-
|
49
|
-
[Follow the Tailwind CSS installation instructions to get started.](https://tailwindcss.com/docs/installation)
|
50
|
-
|
51
|
-
### Add dependencies
|
52
|
-
|
53
|
-
If you haven't already, install Tailwind into your rails application by adding `tailwindcss-rails`
|
54
|
-
to your `Gemfile` and install tailwind into your app:
|
55
|
-
|
56
|
-
```sh
|
57
|
-
./bin/bundle add tailwindcss-rails
|
58
|
-
./bin/rails tailwindcss:install
|
59
|
-
```
|
60
|
-
|
61
|
-
Then install ./bin/rails tailwindcss:install
|
62
|
-
|
63
|
-
### Configure tailwind.config.js
|
64
|
-
|
65
|
-
Here's what my `tailwind.config.js` file looks like:
|
66
|
-
|
67
|
-
```js title="tailwind.config.js"
|
68
|
-
const defaultTheme = require("tailwindcss/defaultTheme");
|
69
|
-
|
70
|
-
module.exports = {
|
71
|
-
darkMode: ["class"],
|
72
|
-
content: [
|
73
|
-
"./public/*.html",
|
74
|
-
"./app/helpers/**/*.rb",
|
75
|
-
"./app/javascript/**/*.js",
|
76
|
-
"./app/views/**/*.{erb,haml,html,slim}",
|
77
|
-
],
|
78
|
-
theme: {
|
79
|
-
container: {
|
80
|
-
center: true,
|
81
|
-
padding: "2rem",
|
82
|
-
screens: {
|
83
|
-
"2xl": "1400px",
|
84
|
-
},
|
85
|
-
},
|
86
|
-
extend: {
|
87
|
-
colors: {
|
88
|
-
border: "hsl(var(--border))",
|
89
|
-
input: "hsl(var(--input))",
|
90
|
-
ring: "hsl(var(--ring))",
|
91
|
-
background: "hsl(var(--background))",
|
92
|
-
foreground: "hsl(var(--foreground))",
|
93
|
-
primary: {
|
94
|
-
DEFAULT: "hsl(var(--primary))",
|
95
|
-
foreground: "hsl(var(--primary-foreground))",
|
96
|
-
},
|
97
|
-
secondary: {
|
98
|
-
DEFAULT: "hsl(var(--secondary))",
|
99
|
-
foreground: "hsl(var(--secondary-foreground))",
|
100
|
-
},
|
101
|
-
destructive: {
|
102
|
-
DEFAULT: "hsl(var(--destructive))",
|
103
|
-
foreground: "hsl(var(--destructive-foreground))",
|
104
|
-
},
|
105
|
-
muted: {
|
106
|
-
DEFAULT: "hsl(var(--muted))",
|
107
|
-
foreground: "hsl(var(--muted-foreground))",
|
108
|
-
},
|
109
|
-
accent: {
|
110
|
-
DEFAULT: "hsl(var(--accent))",
|
111
|
-
foreground: "hsl(var(--accent-foreground))",
|
112
|
-
},
|
113
|
-
popover: {
|
114
|
-
DEFAULT: "hsl(var(--popover))",
|
115
|
-
foreground: "hsl(var(--popover-foreground))",
|
116
|
-
},
|
117
|
-
card: {
|
118
|
-
DEFAULT: "hsl(var(--card))",
|
119
|
-
foreground: "hsl(var(--card-foreground))",
|
120
|
-
},
|
121
|
-
},
|
122
|
-
borderRadius: {
|
123
|
-
lg: `var(--radius)`,
|
124
|
-
md: `calc(var(--radius) - 2px)`,
|
125
|
-
sm: "calc(var(--radius) - 4px)",
|
126
|
-
},
|
127
|
-
fontFamily: {
|
128
|
-
sans: ["var(--font-sans)", ...defaultTheme.fontFamily.sans],
|
129
|
-
},
|
130
|
-
keyframes: {
|
131
|
-
"accordion-down": {
|
132
|
-
from: { height: 0 },
|
133
|
-
to: { height: "var(--radix-accordion-content-height)" },
|
134
|
-
},
|
135
|
-
"accordion-up": {
|
136
|
-
from: { height: "var(--radix-accordion-content-height)" },
|
137
|
-
to: { height: 0 },
|
138
|
-
},
|
139
|
-
},
|
140
|
-
animation: {
|
141
|
-
"accordion-down": "accordion-down 0.2s ease-out",
|
142
|
-
"accordion-up": "accordion-up 0.2s ease-out",
|
143
|
-
},
|
144
|
-
},
|
145
|
-
},
|
146
|
-
plugins: [
|
147
|
-
require("@tailwindcss/forms"),
|
148
|
-
require("@tailwindcss/aspect-ratio"),
|
149
|
-
require("@tailwindcss/typography"),
|
150
|
-
require("@tailwindcss/container-queries"),
|
151
|
-
require("tailwindcss-animate"),
|
152
|
-
],
|
153
|
-
};
|
154
|
-
```
|
155
|
-
|
156
|
-
### Configure styles
|
157
|
-
|
158
|
-
Add the following to your app/assets/stylesheets/application.tailwind.css file.
|
159
|
-
|
160
|
-
```css title="application.tailwind.css"
|
161
|
-
@tailwind base;
|
162
|
-
@tailwind components;
|
163
|
-
@tailwind utilities;
|
164
|
-
|
165
|
-
@layer base {
|
166
|
-
:root {
|
167
|
-
--background: 0 0% 100%;
|
168
|
-
--foreground: 222.2 47.4% 11.2%;
|
169
|
-
|
170
|
-
--muted: 210 40% 96.1%;
|
171
|
-
--muted-foreground: 215.4 16.3% 46.9%;
|
172
|
-
|
173
|
-
--popover: 0 0% 100%;
|
174
|
-
--popover-foreground: 222.2 47.4% 11.2%;
|
175
|
-
|
176
|
-
--border: 214.3 31.8% 91.4%;
|
177
|
-
--input: 214.3 31.8% 91.4%;
|
178
|
-
|
179
|
-
--card: 0 0% 100%;
|
180
|
-
--card-foreground: 222.2 47.4% 11.2%;
|
181
|
-
|
182
|
-
--primary: 222.2 47.4% 11.2%;
|
183
|
-
--primary-foreground: 210 40% 98%;
|
184
|
-
|
185
|
-
--secondary: 210 40% 96.1%;
|
186
|
-
--secondary-foreground: 222.2 47.4% 11.2%;
|
187
|
-
|
188
|
-
--accent: 210 40% 96.1%;
|
189
|
-
--accent-foreground: 222.2 47.4% 11.2%;
|
190
|
-
|
191
|
-
--destructive: 0 100% 50%;
|
192
|
-
--destructive-foreground: 210 40% 98%;
|
193
|
-
|
194
|
-
--ring: 215 20.2% 65.1%;
|
195
|
-
|
196
|
-
--radius: 0.5rem;
|
197
|
-
}
|
198
|
-
|
199
|
-
.dark {
|
200
|
-
--background: 224 71% 4%;
|
201
|
-
--foreground: 213 31% 91%;
|
202
|
-
|
203
|
-
--muted: 223 47% 11%;
|
204
|
-
--muted-foreground: 215.4 16.3% 56.9%;
|
205
|
-
|
206
|
-
--accent: 216 34% 17%;
|
207
|
-
--accent-foreground: 210 40% 98%;
|
208
|
-
|
209
|
-
--popover: 224 71% 4%;
|
210
|
-
--popover-foreground: 215 20.2% 65.1%;
|
211
|
-
|
212
|
-
--border: 216 34% 17%;
|
213
|
-
--input: 216 34% 17%;
|
214
|
-
|
215
|
-
--card: 224 71% 4%;
|
216
|
-
--card-foreground: 213 31% 91%;
|
217
|
-
|
218
|
-
--primary: 210 40% 98%;
|
219
|
-
--primary-foreground: 222.2 47.4% 1.2%;
|
220
|
-
|
221
|
-
--secondary: 222.2 47.4% 11.2%;
|
222
|
-
--secondary-foreground: 210 40% 98%;
|
223
|
-
|
224
|
-
--destructive: 0 63% 31%;
|
225
|
-
--destructive-foreground: 210 40% 98%;
|
226
|
-
|
227
|
-
--ring: 216 34% 17%;
|
228
|
-
|
229
|
-
--radius: 0.5rem;
|
230
|
-
}
|
231
|
-
}
|
232
|
-
|
233
|
-
@layer base {
|
234
|
-
* {
|
235
|
-
@apply border-border;
|
236
|
-
}
|
237
|
-
body {
|
238
|
-
@apply bg-background text-foreground;
|
239
|
-
font-feature-settings:
|
240
|
-
"rlig" 1,
|
241
|
-
"calt" 1;
|
242
|
-
}
|
243
|
-
}
|
244
|
-
```
|
245
|
-
|
246
|
-
### Copy a a component's files to your application
|
247
|
-
|
248
|
-
For example, if you want to use the Accordion component, you would copy the following files to your
|
249
|
-
application:
|
250
|
-
|
251
|
-
- `app/javascript/controllers/components/ui/accordion_controller.js` The Stimulus controller for any
|
252
|
-
component that requires javascript.
|
253
|
-
- `app/helpers/components/accordion_helper.rb` The helper for the component that allows for easy
|
254
|
-
rendering within views.
|
255
|
-
- `app/views/components/ui/_accordion.html.erb` The html for the component.
|
256
|
-
|
257
|
-
Once those are copied in your application you can render an accordion with:
|
258
|
-
|
259
|
-
```erb
|
260
|
-
<%= render_accordion title: "Did you know?", description: "You can wrap shadcn helpers in any
|
261
|
-
component library you want!" %>
|
262
|
-
<%= render_accordion title: "Use the generators.", description: "Add components with #{code("rails g shadcn_ui add accordion")}".html_safe %>
|
263
|
-
```
|
264
|
-
|
265
|
-
See the component's demo page in `app/views/examples/components/accordion.html.erb` for more
|
266
|
-
examples.
|
267
|
-
|
268
|
-
This will be similar for each component.
|
269
|
-
|
270
|
-
## Documentation
|
271
|
-
|
272
|
-
Visit https://avi.nyc/shadcn-on-rails to view the documentation.
|
273
|
-
|
274
|
-
## Contributing
|
275
|
-
|
276
|
-
I am desperately seeking contributors to this project as it is in the very early stages.
|
277
|
-
|
278
|
-
### Contributing with Issues
|
279
|
-
|
280
|
-
I am looking for people to start documenting issues in the project. The issues I'm interested in
|
281
|
-
are:
|
282
|
-
|
283
|
-
1. What components are missing? Just start listing out the components that have yet to be
|
284
|
-
implemented, better yet, open a PR with a branch for that issue and we can all start adding to
|
285
|
-
it.
|
286
|
-
2. What components are not accessible? I am not an accessibility expert, so I need help with this.
|
287
|
-
If you see something that is not accessible, please open an issue and let me know. This might
|
288
|
-
mean the aria labels are hardcoded and not customizable or that the labels are simply missing.
|
289
|
-
3. What components are not customizable? I am trying to make all components as customizable as
|
290
|
-
possible. If you see something that is not customizable, please open an issue and let me know.
|
291
|
-
All the attributes of a component, like aria labels or classes or id or name, etc, should be
|
292
|
-
customizeable by passing attributes into their helper functions that are passed down to the
|
293
|
-
component's partial to be rendered.
|
294
|
-
4. Suggestions for the API of the components. I am trying to make the API as simple as possible. If
|
295
|
-
you have any suggestions for how to make the API simpler, please open an issue and let me know. I
|
296
|
-
am open to any and all suggestions.
|
297
|
-
|
298
|
-
These are 3 main areas that would make the project easier for people to contribute to. They all make
|
299
|
-
for great opportunities for someone new to open source to both file the issue and even begin to
|
300
|
-
slowly implement them.
|
301
|
-
|
302
|
-
### Setup
|
303
|
-
|
304
|
-
1. Fork and clone the repo.
|
305
|
-
2. Run `bundle install` to install dependencies, there aren't many as this is currently a standard
|
306
|
-
Rails applications.
|
307
|
-
3. `/bin/dev` to start the application.
|
308
|
-
|
309
|
-
### App Structure
|
310
|
-
|
311
|
-
For now this is a standard Rails 7 application using propshaft and **importmaps**. This will soon be
|
312
|
-
extracted into a gem that provides the components to be installed (copied) into the including
|
313
|
-
application.
|
314
|
-
|
315
|
-
### Components
|
316
|
-
|
317
|
-
The goal of this project is to provide a set of components that can be copied into your application.
|
318
|
-
The components are built using [TailwindCSS](https://tailwindcss.com/) and
|
319
|
-
[Stimulus](https://stimulus.hotwire.dev/). Each component follows the same structure:
|
27
|
+
## Installation
|
320
28
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
2. There is a component helper named after the component that is responsible for rendering the
|
325
|
-
component and taking in arguments to customize the component located in `app/helpers/components`.
|
326
|
-
Ex `app/helpers/components/button.rb` provides the `render_button` helper that accepts arguments
|
327
|
-
such as `variant` which describes the kind of button and passes the classes for that `variant` to
|
328
|
-
the partial.
|
329
|
-
3. When needed there is a stimulus controller for the component that provides the javascript
|
330
|
-
required to make the component interactive. Ex. `app/javascript/controllers/toast_controller.js`
|
331
|
-
provides the javascript for the toast component to display it and then hide it after a certain
|
332
|
-
amount of time.
|
29
|
+
Refer to
|
30
|
+
[Installation](https://github.com/aviflombaum/shadcn-rails/blob/main/app/views/documentation/installation.html.md)
|
31
|
+
or the [Installation](https://shadcn.rails-components.com/docs/installation) page on the demo site.
|
333
32
|
|
334
|
-
|
335
|
-
`app/views/examples/components`. This is used to create the documentation site that this application
|
336
|
-
provides with examples of teh components rendered.
|
33
|
+
## Development
|
337
34
|
|
338
|
-
|
35
|
+
Clone the repo and run `bin/setup` to install dependencies. Then, run `bin/dev` to start the
|
36
|
+
tailwind watcher and then run `rails s`. I have to run the server and tailwind separately to keep
|
37
|
+
debuggers working.
|
339
38
|
|
340
39
|
## [shadcn-ui](https://ui.shadcn.com)
|
341
40
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
layout "component"
|
3
|
+
|
4
|
+
def create
|
5
|
+
params[:component] = "forms"
|
6
|
+
@user = User.new(user_params)
|
7
|
+
if @user.valid?
|
8
|
+
# Toast message
|
9
|
+
else
|
10
|
+
render "examples/components/forms", status: 422
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def user_params
|
17
|
+
params.require(:user).permit(:email, :password)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class ShadcnFormBuilder < ActionView::Helpers::FormBuilder
|
2
|
+
def label(method, options = {})
|
3
|
+
error_class = @object.errors[method].any? ? "error" : ""
|
4
|
+
options[:class] = @template.tw("#{options[:class]} #{error_class}")
|
5
|
+
@template.render_label(name: "#{object_name}[#{method}]", label: method.capitalize, **options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def text_field(method, options = {})
|
9
|
+
options[:class] << " error" if @object.errors[method].any?
|
10
|
+
@template.render_input(
|
11
|
+
name: "#{object_name}[#{method}]",
|
12
|
+
id: "#{object_name}_#{method}",
|
13
|
+
value: @object.send(method),
|
14
|
+
type: "text", **options
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def password_field(method, options = {})
|
19
|
+
error_class = @object.errors[method].any? ? "error" : ""
|
20
|
+
options[:class] = @template.tw("#{options[:class]} #{error_class}")
|
21
|
+
@template.render_input(
|
22
|
+
name: "#{object_name}[#{method}]",
|
23
|
+
id: "#{object_name}_#{method}",
|
24
|
+
value: @object.send(method),
|
25
|
+
type: "password", **options
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def email_field(method, options = {})
|
30
|
+
error_class = @object.errors[method].any? ? "error" : ""
|
31
|
+
options[:class] = @template.tw("#{options[:class]} #{error_class}")
|
32
|
+
@template.render_input(
|
33
|
+
name: "#{object_name}[#{method}]",
|
34
|
+
id: "#{object_name}_#{method}",
|
35
|
+
value: @object.send(method),
|
36
|
+
type: "email", **options
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def submit(value = nil, options = {})
|
41
|
+
@template.render_button(value, **options)
|
42
|
+
end
|
43
|
+
end
|
@@ -1,6 +1,22 @@
|
|
1
1
|
module Components::AlertDialogHelper
|
2
|
-
def render_alert_dialog(
|
3
|
-
|
4
|
-
render "components/ui/alert_dialog",
|
2
|
+
def render_alert_dialog(**options, &block)
|
3
|
+
content = capture(&block) if block
|
4
|
+
render "components/ui/alert_dialog", content: content, **options
|
5
|
+
end
|
6
|
+
|
7
|
+
def alert_dialog_trigger(&block)
|
8
|
+
content_for :alert_dialog_trigger, capture(&block), flush: true
|
9
|
+
end
|
10
|
+
|
11
|
+
def alert_dialog_content(&block)
|
12
|
+
content_for :alert_dialog_content, capture(&block), flush: true
|
13
|
+
end
|
14
|
+
|
15
|
+
def alert_dialog_continue(&block)
|
16
|
+
content_for :alert_dialog_continue, capture(&block), flush: true
|
17
|
+
end
|
18
|
+
|
19
|
+
def alert_dialog_cancel(&block)
|
20
|
+
content_for :alert_dialog_cancel, capture(&block), flush: true
|
5
21
|
end
|
6
22
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Components::FormsHelper
|
2
|
+
def render_form_with(**opts)
|
3
|
+
form_with(**opts.merge(builder: ShadcnFormBuilder)) do |form|
|
4
|
+
yield form
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def render_form_for(obj, **opts)
|
9
|
+
form_for(obj, **opts.merge(builder: ShadcnFormBuilder), html: opts) do |form|
|
10
|
+
yield form
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,14 +1,24 @@
|
|
1
1
|
module Components::InputHelper
|
2
2
|
def render_input(name:, label: false, id: nil, type: :text, value: nil, **options)
|
3
|
-
options[:class] = "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50 #{options[:class]} "
|
4
|
-
options[:class] << case options[:
|
3
|
+
options[:class] = "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm transition-colors ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50 #{options[:class]} "
|
4
|
+
options[:class] << case options[:variant]
|
5
5
|
when :borderless
|
6
6
|
" border-0 focus-visible:outline-none focus-visible:shadow-none focus-visible:ring-transparent"
|
7
7
|
else
|
8
|
-
" focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:border-muted"
|
8
|
+
"shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:border-muted"
|
9
9
|
end
|
10
|
-
options
|
11
|
-
|
10
|
+
options[:class] = tw(options[:class])
|
11
|
+
|
12
|
+
options.reverse_merge!(
|
13
|
+
label: (options[:lable] || false),
|
14
|
+
required: (options[:required] || false),
|
15
|
+
disabled: (options[:disabled] || false),
|
16
|
+
readonly: (options[:readonly] || false),
|
17
|
+
placeholder: (options[:placeholder] || ""),
|
18
|
+
autocomplete: (options[:autocomplete] || ""),
|
19
|
+
autocapitalize: (options[:autocapitalize] || nil),
|
20
|
+
autocorrect: (options[:autocorrect] || nil)
|
21
|
+
)
|
12
22
|
render partial: "components/ui/input", locals: {
|
13
23
|
type:,
|
14
24
|
label:,
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module Components::ToastHelper
|
2
|
-
def render_toast(header: nil, description: nil, action: nil, class: nil, data:
|
2
|
+
def render_toast(header: nil, description: nil, action: nil, class: nil, data: {}, variant: :default, **options, &block)
|
3
|
+
options[:class] ||= ""
|
4
|
+
options[:class] << " destructive group border-destructive bg-destructive text-destructive-foreground " if variant == :destructive
|
5
|
+
|
3
6
|
render "components/ui/toast", header:, description:, action:, class:, data:, options: options
|
4
7
|
end
|
5
8
|
end
|
@@ -1,4 +1,8 @@
|
|
1
1
|
module ComponentsHelper
|
2
|
+
def tw(classes)
|
3
|
+
TailwindMerge::Merger.new.merge(classes)
|
4
|
+
end
|
5
|
+
|
2
6
|
PRIMARY_CLASSES = " bg-primary text-primary-foreground hover:bg-primary/80 "
|
3
7
|
SECONDARY_CLASSES = " bg-secondary text-secondary-foreground hover:bg-secondary/80 "
|
4
8
|
OUTLINE_CLASSES = " border border-input bg-background hover:bg-accent hover:text-accent-foreground "
|
@@ -15,10 +15,15 @@ module ExamplesHelper
|
|
15
15
|
render "examples/components/#{name}/usage"
|
16
16
|
end
|
17
17
|
|
18
|
+
def render_code_preview(name)
|
19
|
+
render "examples/components/#{name}/code/preview"
|
20
|
+
end
|
21
|
+
|
18
22
|
def code_partial(name, language)
|
23
|
+
component, partial = name.split("/")
|
19
24
|
content_tag :pre, class: "code-sample py-4 px-4", data: {controller: "highlight"} do
|
20
25
|
content_tag :code, class: "language-#{language}" do
|
21
|
-
html_escape(File.read(Rails.root.join("app", "views", "examples", "components", "#{
|
26
|
+
html_escape(File.read(Rails.root.join("app", "views", "examples", "components", "#{component}/code/_#{partial}.erb")))
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Inspired by https://github.com/kanety/stimulus-dialog
|
2
2
|
import { Controller } from "@hotwired/stimulus";
|
3
|
-
import "
|
3
|
+
import "https://ga.jspm.io/npm:@kanety/stimulus-static-actions@1.0.1/dist/index.modern.js";
|
4
4
|
|
5
5
|
export default class UIDialog extends Controller {
|
6
6
|
static targets = ["dialog", "modal", "focus", "drag", "backdrop", "closeButton"];
|
@@ -1,5 +1,5 @@
|
|
1
1
|
// Inspired By: https://github.com/stimulus-components/stimulus-dropdown/blob/master/src/index.ts
|
2
2
|
import UIPopover from "controllers/ui/popover_controller";
|
3
|
-
import { useTransition } from "stimulus-use";
|
3
|
+
import { useTransition } from "https://ga.jspm.io/npm:stimulus-use@0.51.3/dist/index.js";
|
4
4
|
|
5
5
|
export default class extends UIPopover {}
|
@@ -1,9 +1,8 @@
|
|
1
1
|
// Inspired by: https://github.com/excid3/tailwindcss-stimulus-components/blob/master/src/popover.js
|
2
2
|
|
3
3
|
import { Controller } from "@hotwired/stimulus";
|
4
|
-
import { createPopper } from "
|
5
|
-
import { useDebounce } from "stimulus-use";
|
6
|
-
import { useHover } from "stimulus-use";
|
4
|
+
import { createPopper } from "https://ga.jspm.io/npm:@popperjs/core@2.11.8/lib/index.js";
|
5
|
+
import { useDebounce, useHover } from "https://ga.jspm.io/npm:stimulus-use@0.51.3/dist/index.js";
|
7
6
|
|
8
7
|
export default class UIHoverCardController extends Controller {
|
9
8
|
static debounces = ["mouseEnter", "mouseLeave"];
|
@@ -1,7 +1,8 @@
|
|
1
1
|
// Inspired by: https://github.com/excid3/tailwindcss-stimulus-components/blob/master/src/popover.js
|
2
2
|
|
3
3
|
import { Controller } from "@hotwired/stimulus";
|
4
|
-
import { createPopper } from "
|
4
|
+
import { createPopper } from "https://ga.jspm.io/npm:@popperjs/core@2.11.8/lib/index.js";
|
5
|
+
import { useClickOutside } from "https://ga.jspm.io/npm:stimulus-use@0.51.3/dist/index.js";
|
5
6
|
|
6
7
|
export default class UIPopover extends Controller {
|
7
8
|
static values = {
|
@@ -9,9 +10,8 @@ export default class UIPopover extends Controller {
|
|
9
10
|
};
|
10
11
|
static targets = ["content", "wrapper", "trigger"];
|
11
12
|
|
12
|
-
// Sets the popover offset using Stimulus data map objects.
|
13
|
-
|
14
13
|
connect() {
|
14
|
+
useClickOutside(this);
|
15
15
|
this.popperInstance = createPopper(this.triggerTarget, this.contentTarget, {
|
16
16
|
placement: this.contentTarget.dataset.side || "bottom",
|
17
17
|
modifiers: [
|
@@ -37,6 +37,10 @@ export default class UIPopover extends Controller {
|
|
37
37
|
this.contentTarget.dataset.state = "closed";
|
38
38
|
}
|
39
39
|
|
40
|
+
clickOutside(event) {
|
41
|
+
this.hide();
|
42
|
+
}
|
43
|
+
|
40
44
|
// Toggle the popover on demand
|
41
45
|
toggle(event) {
|
42
46
|
this.popperInstance.update();
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import UIDialog from "controllers/ui/dialog_controller";
|
2
|
-
import "
|
2
|
+
import "https://ga.jspm.io/npm:@kanety/stimulus-static-actions@1.0.1/dist/index.modern.js";
|
3
3
|
|
4
4
|
export default class extends UIDialog {
|
5
5
|
// Handles a button triggering the sheet in a different
|