Skip to content

Commit

Permalink
Add shadcn/ui post
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Oct 24, 2024
1 parent 8207230 commit 581d996
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 67 deletions.
149 changes: 82 additions & 67 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@ export default defineConfig({
['link', {rel: 'icon', href: '/favicon.ico', sizes: "32x32"}],
['link', {rel: 'icon', href: '/icon.svg', type: 'image/svg+xml'}],

['meta', { name: 'twitter:card', content: 'summary_large_image' }],
['meta', { name: 'twitter:site', content: site }],
['meta', { name: 'twitter:description', value: description }],
['meta', { name: 'twitter:image', content: image }],
['meta', {name: 'twitter:card', content: 'summary_large_image'}],
['meta', {name: 'twitter:site', content: site}],
['meta', {name: 'twitter:description', value: description}],
['meta', {name: 'twitter:image', content: image}],

['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:locale', content: 'en_US' }],
['meta', { property: 'og:site', content: site }],
['meta', { property: 'og:site_name', content: title }],
['meta', { property: 'og:image', content: image }],
['meta', { property: 'og:description', content: description }],
['meta', {property: 'og:type', content: 'website'}],
['meta', {property: 'og:locale', content: 'en_US'}],
['meta', {property: 'og:site', content: site}],
['meta', {property: 'og:site_name', content: title}],
['meta', {property: 'og:image', content: image}],
['meta', {property: 'og:description', content: description}],
],

themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
{text: 'Home', link: '/'},
{text: 'Guide', link: '/guide'},
{text: 'Cookbook', link: '/cookbook/integrating-shadcn-ui'},
{
text: 'Links', items: [
{text: 'Official Inertia.js docs', link: 'https://inertiajs.com'},
Expand All @@ -55,63 +56,77 @@ export default defineConfig({

logo: '/logo.svg',

sidebar: [
{
items: [
{text: 'Introduction', link: '/guide'},
{text: 'Demo app', link: '/guide/demo-application'},
],
},
{
text: 'Installation',
items: [
{text: 'Server-side', link: '/guide/server-side-setup'},
{text: 'Client-side', link: '/guide/client-side-setup'},
]
},
{
text: 'Core concepts',
items: [
{text: 'Who is it for', link: '/guide/who-is-it-for'},
{text: 'How it works', link: '/guide/how-it-works'},
{text: 'The protocol', link: '/guide/the-protocol'},
]
},
{
text: 'The basics',
items: [
{text: 'Pages', link: '/guide/pages'},
{text: 'Responses', link: '/guide/responses'},
{text: 'Redirects', link: '/guide/redirects'},
{text: 'Routing', link: '/guide/routing'},
{text: 'Title & meta', link: '/guide/title-and-meta'},
{text: 'Links', link: '/guide/links'},
{text: 'Manual visits', link: '/guide/manual-visits'},
{text: 'Forms', link: '/guide/forms'},
{text: 'File uploads', link: '/guide/file-uploads'},
{text: 'Validation', link: '/guide/validation'},
{text: 'Shared data', link: '/guide/shared-data'},
]
},
{
text: 'Advanced',
items: [
{text: 'Events', link: '/guide/events'},
{text: 'Testing', link: '/guide/testing'},
{text: 'Partial reloads', link: '/guide/partial-reloads'},
{text: 'Scroll management', link: '/guide/scroll-management'},
{text: 'Authentication', link: '/guide/authentication'},
{text: 'Authorization', link: '/guide/authorization'},
{text: 'CSRF protection', link: '/guide/csrf-protection'},
{text: 'Error handling', link: '/guide/error-handling'},
{text: 'Asset versioning', link: '/guide/asset-versioning'},
{text: 'Progress indicators', link: '/guide/progress-indicators'},
{text: 'Remembering state', link: '/guide/remembering-state'},
{text: 'Code splitting', link: '/guide/code-splitting'},
{text: 'Server-side rendering', link: '/guide/server-side-rendering'},
]
}
],
sidebar: {
'/guide': [
{
items: [
{text: 'Introduction', link: '/guide'},
{text: 'Demo app', link: '/guide/demo-application'},
],
},
{
text: 'Installation',
items: [
{text: 'Server-side', link: '/guide/server-side-setup'},
{text: 'Client-side', link: '/guide/client-side-setup'},
]
},
{
text: 'Core concepts',
items: [
{text: 'Who is it for', link: '/guide/who-is-it-for'},
{text: 'How it works', link: '/guide/how-it-works'},
{text: 'The protocol', link: '/guide/the-protocol'},
]
},
{
text: 'The basics',
items: [
{text: 'Pages', link: '/guide/pages'},
{text: 'Responses', link: '/guide/responses'},
{text: 'Redirects', link: '/guide/redirects'},
{text: 'Routing', link: '/guide/routing'},
{text: 'Title & meta', link: '/guide/title-and-meta'},
{text: 'Links', link: '/guide/links'},
{text: 'Manual visits', link: '/guide/manual-visits'},
{text: 'Forms', link: '/guide/forms'},
{text: 'File uploads', link: '/guide/file-uploads'},
{text: 'Validation', link: '/guide/validation'},
{text: 'Shared data', link: '/guide/shared-data'},
]
},
{
text: 'Advanced',
items: [
{text: 'Events', link: '/guide/events'},
{text: 'Testing', link: '/guide/testing'},
{text: 'Partial reloads', link: '/guide/partial-reloads'},
{text: 'Scroll management', link: '/guide/scroll-management'},
{text: 'Authentication', link: '/guide/authentication'},
{text: 'Authorization', link: '/guide/authorization'},
{text: 'CSRF protection', link: '/guide/csrf-protection'},
{text: 'Error handling', link: '/guide/error-handling'},
{text: 'Asset versioning', link: '/guide/asset-versioning'},
{text: 'Progress indicators', link: '/guide/progress-indicators'},
{text: 'Remembering state', link: '/guide/remembering-state'},
{text: 'Code splitting', link: '/guide/code-splitting'},
{text: 'Server-side rendering', link: '/guide/server-side-rendering'},
]
}
],
'/cookbook': [
{
items: [
{
text: 'Integrations',
items: [
{text: 'shadcn/ui', link: '/cookbook/integrating-shadcn-ui'},
]
},
],
},
],
},

search: {
provider: 'algolia',
Expand Down
12 changes: 12 additions & 0 deletions docs/.vitepress/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,15 @@
border-top-left-radius: 0 !important;
border-top-right-radius: 0 !important;
}

.plugin-tabs--content:has(> p:first-child) {
border-left: 2px solid var(--vp-c-divider) !important;
border-right: 2px solid var(--vp-c-divider) !important;
border-bottom: 2px solid var(--vp-c-divider) !important;
padding: 8px !important;
}

.plugin-tabs--content:has(> p:first-child) p {
margin-top: 16px !important;
padding-left: 16px;
}
136 changes: 136 additions & 0 deletions docs/cookbook/integrating-shadcn-ui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Integrating `shadcn/ui`

This guide demonstrates how to integrate [shadcn/ui](https://ui.shadcn.com) - a collection of reusable React components - with your Inertia Rails application.

## Getting Started in 5 Minutes

If you're starting fresh, create a new Rails application with Inertia (or skip this step if you already have one):

:::tabs key:languages

== TypeScript

```bash
rails new -JA shadcn-inertia-rails
cd shadcn-inertia-rails
bundle add inertia_rails-contrib

rails generate inertia:install --framework=react --typescript --install-vite --install-tailwind --no-interactive
Installing Inertia's Rails adapter
...
```
== JavaScript
```bash
rails new -JA shadcn-inertia-rails
cd shadcn-inertia-rails
bundle add inertia_rails-contrib
rails generate inertia:install --framework=react --install-vite --install-tailwind --no-interactive
Installing Inertia's Rails adapter
...
```

:::

> [!NOTE]
> You can also run `rails generate inertia:install` to run the installer interactively.
> Need more details on the initial setup? Check out our [server-side setup guide](/guide/server-side-setup.md).
## Setting Up Path Aliases

Let's configure our project to work seamlessly with `shadcn/ui`. Choose your path based on whether you're using TypeScript or JavaScript.


:::tabs key:languages

== TypeScript

You'll need to configure two files. First, update your `tsconfig.app.json`:

```json5
{
"compilerOptions": {
// ...
"baseUrl": ".",
"paths": {
"@/*": [
"./app/frontend/*"
]
}
},
// ...
}
```

Then, set up your `tsconfig.json` to match `shadcn/ui`'s requirements (note the `baseUrl` and `paths` properties are different from the `tsconfig.app.json`):

```json5
{
//...
"compilerOptions": {
/* Required for shadcn-ui/ui */
"baseUrl": "./app/frontend",
"paths": {
"@/*": [
"./*"
]
}
}
}
```

== JavaScript

Using JavaScript? It's even simpler! Just create a `jsconfig.json`:

```json
{
"compilerOptions": {
"baseUrl": "./app/frontend",
"paths": {
"@/*": ["./*"]
}
}
}
```

:::

## Initializing `shadcn/ui`

Now you can initialize `shadcn/ui` with a single command:

```bash
npx shadcn@latest init

✔ Preflight checks.
✔ Verifying framework. Found Vite.
✔ Validating Tailwind CSS.
✔ Validating import alias.
✔ Which style would you like to use? › New York
✔ Which color would you like to use as the base color? › Neutral
✔ Would you like to use CSS variables for theming? … no / yes
✔ Writing components.json.
✔ Checking registry.
✔ Updating tailwind.config.js
✔ Updating app/frontend/entrypoints/application.css
✔ Installing dependencies.
✔ Created 1 file:
- app/frontend/lib/utils.js

Success! Project initialization completed.
You may now add components.
```

You're all set! Want to try it out? Add your first component:

```shell
npx shadcn@latest add button
```

Now you can import and use your new button component from `@/components/ui/button`. Happy coding!

> [!NOTE]
> Check out the [`shadcn/ui` components gallery](https://ui.shadcn.com/docs/components/accordion) to explore all the beautiful components at your disposal.

0 comments on commit 581d996

Please sign in to comment.