Skip to content

Commit df583af

Browse files
author
Christopher A. Flores
committed
chore: update GitHub Actions checkout action to v4 and enhance form validation rules in documentation
1 parent 2845a4e commit df583af

3 files changed

Lines changed: 246 additions & 27 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727

2828
steps:
29-
- uses: actions/checkout@v3
29+
- uses: actions/checkout@v4
3030
- uses: pnpm/action-setup@v2
3131
with:
3232
version: 8

src/.vitepress/theme/components/form.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ const form = useForm({
2424
type: FieldType.text,
2525
label: 'First name',
2626
placeholder: 'John',
27+
rules: (value) => !!value || 'First name is required',
2728
},
2829
lastName: {
2930
type: FieldType.text,
3031
label: 'Last name',
3132
placeholder: 'Doe',
33+
rules: (value) => !!value || 'Last name is required',
3234
},
3335
},
3436
settings: {
35-
url: 'endpoint/'
37+
url: 'users/',
3638
},
3739
})
3840

src/guide/get-started.md

Lines changed: 242 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
# Introduction
2-
FancyCRUD is a powerful library designed to facilitate the creation of forms and tables; handling the CRUD (Create, Read, Update, and Delete) process.
32

4-
# Why?
5-
When we are in the process to create a website, we'll be in the case to create one or more forms. And it's very likely that we have worked on any form before, so we go to our last project, copy and paste parts of the older code, make some changes and voilà... right?.
3+
**FancyCRUD** is a powerful library designed to facilitate the creation of forms and tables, handling the complete CRUD (Create, Read, Update, and Delete) process with minimal boilerplate code.
64

7-
Well... sometimes it could be just as ease like that, but in other cases we need to add more fields, then we need extra HTML, Javascript code, validations, handle the field values, send data into the requests, handle responses, display notifications and so on. At the end, our code becomes messy and repetitive. For those cases we create `FancyCRUD`.
5+
## Why FancyCRUD?
6+
7+
When building web applications, forms are inevitable. Often, we find ourselves copying code from previous projects, making adjustments, and hoping it works. While this might seem simple at first, things get complicated quickly.
8+
9+
As requirements grow, you need:
10+
- More fields and complex layouts
11+
- Validation rules and error handling
12+
- State management for field values
13+
- HTTP requests with proper error handling
14+
- Response interceptors and notifications
15+
- Consistent UI across different forms
16+
- Table views with pagination and filtering
17+
18+
Before you know it, your code becomes messy, repetitive, and hard to maintain. **FancyCRUD** solves these problems by providing a declarative, configuration-based approach to building forms and tables.
19+
20+
## Key Features
21+
22+
- 🎯 **Declarative Configuration**: Define forms and tables using simple configuration objects
23+
- 🔄 **Command Pattern**: Built on a powerful command bus pattern for extensibility
24+
- 🎨 **Framework Agnostic**: Works with multiple UI frameworks through wrappers
25+
-**Built-in Validation**: Support for custom validation rules with error handling
26+
- 🌐 **HTTP Integration**: Automatic API calls with request/response handling
27+
- 📊 **Tables & Pagination**: Complete table functionality with sorting, filtering, and pagination
28+
- 🔔 **Notifications**: Automatic success/error notifications
29+
- 🎭 **Type Safe**: Full TypeScript support
830

931
## Installation
10-
We don't want limitations with the use of UI Frameworks. We known there are many alternatives and all of them are really powerful and unique. We're planning to handle them by using wrappers. Right now, you can use a wrapper for:
32+
33+
FancyCRUD is designed to work with multiple UI frameworks through wrappers. This means you're not locked into a specific component library. Currently supported frameworks:
1134

1235
<!--@include: @/add-ons/wrappers.md -->
1336

14-
:::tip INFO
15-
We're working to bring more and more wrappers 😃.
37+
:::tip
38+
We're actively working on supporting more UI frameworks. Contributions are welcome!
1639
:::
1740

18-
The next command will install `FancyCRUD` and `wrapper-vuetify`
41+
### Install FancyCRUD with your preferred UI framework
42+
43+
Choose your UI framework and install FancyCRUD with the corresponding wrapper:
44+
45+
#### Vuetify
1946

2047
::: code-group
2148
```bash [NPM]
@@ -29,41 +56,136 @@ yarn add @fancy-crud/vue @fancy-crud/wrapper-vuetify
2956
```
3057
:::
3158

59+
#### Element Plus
60+
61+
::: code-group
62+
```bash [NPM]
63+
npm i @fancy-crud/vue @fancy-crud/wrapper-element-plus
64+
```
65+
```bash [PNPM]
66+
pnpm add @fancy-crud/vue @fancy-crud/wrapper-element-plus
67+
```
68+
```bash [Yarn]
69+
yarn add @fancy-crud/vue @fancy-crud/wrapper-element-plus
70+
```
71+
:::
72+
73+
#### Quasar
74+
75+
::: code-group
76+
```bash [NPM]
77+
npm i @fancy-crud/vue @fancy-crud/wrapper-quasar
78+
```
79+
```bash [PNPM]
80+
pnpm add @fancy-crud/vue @fancy-crud/wrapper-quasar
81+
```
82+
```bash [Yarn]
83+
yarn add @fancy-crud/vue @fancy-crud/wrapper-quasar
84+
```
85+
:::
86+
87+
#### Oruga UI
88+
89+
::: code-group
90+
```bash [NPM]
91+
npm i @fancy-crud/vue @fancy-crud/wrapper-oruga-ui
92+
```
93+
```bash [PNPM]
94+
pnpm add @fancy-crud/vue @fancy-crud/wrapper-oruga-ui
95+
```
96+
```bash [Yarn]
97+
yarn add @fancy-crud/vue @fancy-crud/wrapper-oruga-ui
98+
```
99+
:::
100+
32101
## Configuration
33-
Let's create `fancy-crud.config.ts` file which it's going to contain the base configuration.
102+
103+
Create a `fancy-crud.config.ts` file to configure FancyCRUD with your HTTP client and UI components.
104+
105+
Select your wrapper to see the configuration:
34106

35107
::: code-group
36-
```ts [fancy-crud.config.ts]
108+
```ts [Vuetify]
37109
import { defineConfig } from '@fancy-crud/vue'
38-
110+
import axios from 'axios'
39111
import components, { styles } from '@fancy-crud/wrapper-vuetify'
40-
import { axios } from 'axios'
41112

42113
export const fancyCrud = defineConfig({
43114
http: {
44115
request: axios,
45116
},
46-
components
117+
components,
118+
styles,
119+
})
120+
```
121+
122+
```ts [Element Plus]
123+
import { defineConfig } from '@fancy-crud/vue'
124+
import axios from 'axios'
125+
import components, { styles } from '@fancy-crud/wrapper-element-plus'
126+
127+
export const fancyCrud = defineConfig({
128+
http: {
129+
request: axios,
130+
},
131+
components,
132+
styles,
133+
})
134+
```
135+
136+
```ts [Quasar]
137+
import { defineConfig } from '@fancy-crud/vue'
138+
import axios from 'axios'
139+
import components, { styles } from '@fancy-crud/wrapper-quasar'
140+
141+
export const fancyCrud = defineConfig({
142+
http: {
143+
request: axios,
144+
},
145+
components,
146+
styles,
147+
})
148+
```
149+
150+
```ts [Oruga UI]
151+
import { defineConfig } from '@fancy-crud/vue'
152+
import axios from 'axios'
153+
import components, { styles } from '@fancy-crud/wrapper-oruga-ui'
154+
155+
export const fancyCrud = defineConfig({
156+
http: {
157+
request: axios,
158+
},
159+
components,
47160
styles,
48161
})
49162
```
50163
:::
51164

52-
Then we just need to add the configuration as a Vue Plugin in the root file (usually main.ts or main.js if you're not using typescript)
165+
The configuration includes:
166+
- **http.request**: Your HTTP client (axios, fetch, etc.)
167+
- **components**: UI components from the wrapper
168+
- **styles**: Default styling configuration for forms and tables
169+
170+
### Register FancyCRUD Plugin
171+
172+
Add the configuration as a Vue plugin in your application entry point (usually `main.ts` or `main.js`).
173+
174+
Select your framework to see the setup:
53175

54176
::: code-group
55-
```ts [main.ts]
177+
```ts [Vuetify]
56178
import { createApp } from 'vue'
57-
58-
import 'vuetify/styles'
59179
import { createVuetify } from 'vuetify'
60180
import * as components from 'vuetify/components'
61181
import * as directives from 'vuetify/directives'
62182

63-
// FancyCRUD configurations
183+
// FancyCRUD imports
64184
import { FancyCrud } from '@fancy-crud/vue'
65-
import fancyCrudConfig from './fancy-crud.config'
185+
import { fancyCrud } from './fancy-crud.config'
66186

187+
// Styles
188+
import 'vuetify/styles'
67189
import '@mdi/font/css/materialdesignicons.css'
68190
import '@fancy-crud/vue/dist/fancy-crud-vue.css'
69191
import '@fancy-crud/wrapper-vuetify/dist/fancy-crud-wrapper-vuetify.css'
@@ -77,14 +199,88 @@ const vuetify = createVuetify({
77199
directives,
78200
})
79201

80-
app.user(vuetify)
202+
app.use(vuetify)
203+
app.use(FancyCrud, fancyCrud)
204+
app.mount('#app')
205+
```
206+
207+
```ts [Element Plus]
208+
import { createApp } from 'vue'
209+
import ElementPlus from 'element-plus'
210+
211+
// FancyCRUD imports
212+
import { FancyCrud } from '@fancy-crud/vue'
213+
import { fancyCrud } from './fancy-crud.config'
214+
215+
// Styles
216+
import 'element-plus/dist/index.css'
217+
import '@fancy-crud/vue/dist/fancy-crud-vue.css'
218+
import '@fancy-crud/wrapper-element-plus/dist/fancy-crud-wrapper-element-plus.css'
219+
220+
import App from './App.vue'
221+
222+
const app = createApp(App)
223+
224+
app.use(ElementPlus)
225+
app.use(FancyCrud, fancyCrud)
226+
app.mount('#app')
227+
```
228+
229+
```ts [Quasar]
230+
import { createApp } from 'vue'
231+
import { Quasar } from 'quasar'
232+
233+
// FancyCRUD imports
234+
import { FancyCrud } from '@fancy-crud/vue'
235+
import { fancyCrud } from './fancy-crud.config'
236+
237+
// Styles
238+
import 'quasar/dist/quasar.css'
239+
import '@quasar/extras/material-icons/material-icons.css'
240+
import '@fancy-crud/vue/dist/fancy-crud-vue.css'
241+
import '@fancy-crud/wrapper-quasar/dist/fancy-crud-wrapper-quasar.css'
242+
243+
import App from './App.vue'
244+
245+
const app = createApp(App)
246+
247+
app.use(Quasar, {
248+
plugins: {},
249+
})
250+
app.use(FancyCrud, fancyCrud)
251+
app.mount('#app')
252+
```
253+
254+
```ts [Oruga UI]
255+
import { createApp } from 'vue'
256+
import Oruga from '@oruga-ui/oruga-next'
257+
258+
// FancyCRUD imports
259+
import { FancyCrud } from '@fancy-crud/vue'
260+
import { fancyCrud } from './fancy-crud.config'
261+
262+
// Styles
263+
import '@oruga-ui/oruga-next/dist/oruga.css'
264+
import '@fancy-crud/vue/dist/fancy-crud-vue.css'
265+
import '@fancy-crud/wrapper-oruga-ui/dist/fancy-crud-wrapper-oruga-ui.css'
266+
267+
import App from './App.vue'
268+
269+
const app = createApp(App)
270+
271+
app.use(Oruga)
81272
app.use(FancyCrud, fancyCrud)
82273
app.mount('#app')
83274
```
84275
:::
85276

86-
## Usage example
87-
The next code creates a simple form with two fields, first name and last name.
277+
:::warning Important
278+
Make sure to register FancyCRUD **after** your UI framework (Vuetify, Quasar, Element Plus, Oruga, etc.)
279+
:::
280+
281+
## Your First Form
282+
283+
Let's create a simple user registration form with first name and last name fields:
88284

89285
```vue
90286
<template>
@@ -100,22 +296,43 @@ const form = useForm({
100296
type: FieldType.text,
101297
label: 'First name',
102298
placeholder: 'John',
299+
rules: (value) => !!value || 'First name is required',
103300
},
104301
lastName: {
105302
type: FieldType.text,
106303
label: 'Last name',
107304
placeholder: 'Doe',
305+
rules: (value) => !!value || 'Last name is required',
108306
},
109307
},
110308
settings: {
111-
url: 'endpoint/'
309+
url: 'users/',
112310
},
113311
})
114312
</script>
115313
```
116314

117-
## Demo
118-
Then if you click on "Create new", it will trigger a `POST` request to send the payload below.
315+
That's it! With this simple configuration, FancyCRUD will:
316+
317+
1. ✅ Render the form fields with labels and placeholders
318+
2. ✅ Validate inputs using the rules you defined
319+
3. ✅ Display validation errors when fields are invalid
320+
4. ✅ Handle form submission
321+
5. ✅ Send a POST request to `users/` when creating
322+
6. ✅ Send a PUT/PATCH request when updating
323+
7. ✅ Show success/error notifications automatically
324+
8. ✅ Manage loading states during API calls
325+
326+
## Interactive Demo
327+
328+
Try it out below! When you submit the form, it will trigger a `POST` request with the following payload:
329+
330+
```json
331+
{
332+
"firstName": "John",
333+
"lastName": "Doe"
334+
}
335+
```
119336

120337
<FormExample />
121338
<script setup>

0 commit comments

Comments
 (0)