Skip to content

Commit 046d450

Browse files
committed
Bugfix: Github issues are fixed
1 parent 0bc729c commit 046d450

File tree

10 files changed

+103
-77
lines changed

10 files changed

+103
-77
lines changed

components/ui/datetime-picker.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const DatetimeGrid = forwardRef<
6666
return (
6767
<div
6868
className={cn(
69-
'flex items-center w-fit p-1 border-2',
69+
'flex items-center w-fit p-1 border',
7070
className,
7171
'border-input rounded-md gap-1 selection:bg-transparent selection:text-foreground',
7272
)}
@@ -81,7 +81,7 @@ const DatetimeGrid = forwardRef<
8181
<React.Fragment key={unit}>
8282
<Input
8383
className={cn(timePickerInputBase, 'min-w-8', {
84-
'min-w-12': unit === 'years',
84+
'min-w-10': unit === 'years',
8585
'bg-foreground/15': unit === 'am/pm',
8686
})}
8787
{...timescape.getInputProps(unit)}

public/sitemap-0.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
3-
<url><loc>https://www.shadcn-form.com/templates</loc><lastmod>2024-11-07T21:13:34.890Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
4-
<url><loc>https://www.shadcn-form.com/components</loc><lastmod>2024-11-07T21:13:34.890Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
5-
<url><loc>https://www.shadcn-form.com/test</loc><lastmod>2024-11-07T21:13:34.890Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
6-
<url><loc>https://www.shadcn-form.com/readme</loc><lastmod>2024-11-07T21:13:34.890Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
7-
<url><loc>https://www.shadcn-form.com</loc><lastmod>2024-11-07T21:13:34.890Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
8-
<url><loc>https://www.shadcn-form.com/playground</loc><lastmod>2024-11-07T21:13:34.890Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
3+
<url><loc>https://www.shadcn-form.com/components</loc><lastmod>2024-11-10T13:41:06.034Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
4+
<url><loc>https://www.shadcn-form.com/readme</loc><lastmod>2024-11-10T13:41:06.034Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
5+
<url><loc>https://www.shadcn-form.com/test</loc><lastmod>2024-11-10T13:41:06.034Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
6+
<url><loc>https://www.shadcn-form.com/templates</loc><lastmod>2024-11-10T13:41:06.034Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
7+
<url><loc>https://www.shadcn-form.com</loc><lastmod>2024-11-10T13:41:06.034Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
8+
<url><loc>https://www.shadcn-form.com/playground</loc><lastmod>2024-11-10T13:41:06.034Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
99
</urlset>

screens/edit-field-dialog/index.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ export const EditFieldDialog: React.FC<EditFieldDialogProps> = ({
8888
}
8989
/>
9090
</div>
91+
<div>
92+
<Label htmlFor="className">className</Label>
93+
<Input
94+
id="className"
95+
value={editedField.className}
96+
onChange={(e) =>
97+
setEditedField({ ...editedField, className: e.target.value })
98+
}
99+
/>
100+
</div>
91101
<div>
92102
<Label htmlFor="label">Name</Label>
93103
<Input

screens/field-item.tsx

+37-53
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useMotionValue, motion, Reorder } from 'framer-motion'
1+
import { useEffect, useState } from 'react'
2+
import { motion, Reorder } from 'framer-motion'
23

34
import { cn } from '@/lib/utils'
45
import { FormFieldType } from '@/types'
56
import { defaultFieldConfig, fieldTypes } from '@/constants'
6-
import { Input } from '@/components/ui/input'
77
import { Button } from '@/components/ui/button'
88
import {
99
DropdownMenu,
@@ -15,7 +15,7 @@ import {
1515
} from '@/components/ui/dropdown-menu'
1616
import If from '@/components/ui/if'
1717

18-
import { LuGrip, LuColumns, LuPencil, LuTrash2 } from 'react-icons/lu'
18+
import { LuColumns, LuPencil, LuTrash2 } from 'react-icons/lu'
1919

2020
export type FormFieldOrGroup = FormFieldType | FormFieldType[]
2121

@@ -43,6 +43,9 @@ export const FieldItem = ({
4343
subIndex === (formFields[index] as FormFieldType[]).length - 1
4444

4545
const path = subIndex !== undefined ? [index, subIndex] : [index]
46+
const [columnCount, setColumnCount] = useState(() =>
47+
Array.isArray(formFields[index]) ? formFields[index].length : 1,
48+
)
4649

4750
const addNewColumn = (variant: string, index: number) => {
4851
const newFieldName = `name_${Math.random().toString().slice(-10)}`
@@ -103,38 +106,43 @@ export const FieldItem = ({
103106
}
104107

105108
const removeColumn = () => {
106-
// Extracting the exact row and subIndex from path
107109
const rowIndex = path[0]
108110
const subIndex = path.length > 1 ? path[1] : null
109111

110112
setFormFields((prevFields) => {
111-
const newFields = [...prevFields] // Create a shallow copy of formFields
113+
const newFields = [...prevFields]
112114

113115
if (Array.isArray(newFields[rowIndex])) {
114-
// If it's an array (a row with multiple fields)
115-
const row = [...(newFields[rowIndex] as FormFieldType[])] // Shallow copy of the row
116+
const row = [...(newFields[rowIndex] as FormFieldType[])]
116117

117118
if (subIndex !== null && subIndex >= 0 && subIndex < row.length) {
118-
// Only remove the specific field at subIndex
119119
row.splice(subIndex, 1)
120120

121-
// Update the row after removal
122121
if (row.length > 0) {
123-
newFields[rowIndex] = row // Replace the row with the updated row
122+
newFields[rowIndex] = row
123+
// Update column count immediately after removal
124+
setColumnCount(row.length)
124125
} else {
125-
// If the row becomes empty, remove the entire row
126126
newFields.splice(rowIndex, 1)
127+
setColumnCount(1)
127128
}
128129
}
129130
} else {
130-
// If it's a single field, simply remove it
131131
newFields.splice(rowIndex, 1)
132+
setColumnCount(1)
132133
}
133134

134-
return newFields // Update formFields state
135+
return newFields
135136
})
136137
}
137138

139+
useEffect(() => {
140+
const newColumnCount = Array.isArray(formFields[index])
141+
? formFields[index].length
142+
: 1
143+
setColumnCount(newColumnCount)
144+
}, [formFields, index])
145+
138146
return (
139147
<Reorder.Item
140148
value={field}
@@ -148,60 +156,33 @@ export const FieldItem = ({
148156
exit={{ opacity: 0, y: 20, transition: { duration: 0.3 } }}
149157
whileDrag={{ backgroundColor: '#9ca3af', borderRadius: '12px' }}
150158
className={cn('w-full', {
151-
'col-span-12':
152-
Array.isArray(formFields[index]) && formFields[index].length === 1,
153-
'col-span-6':
154-
Array.isArray(formFields[index]) && formFields[index].length === 2,
155-
'col-span-4':
156-
Array.isArray(formFields[index]) && formFields[index].length === 3,
159+
'col-span-12': columnCount === 1,
160+
'col-span-6': columnCount === 2,
161+
'col-span-4': columnCount === 3,
157162
})}
163+
key={`${field.name}-${columnCount}`}
158164
>
159-
<motion.div layout="position" className="flex items-center gap-3">
165+
{/* Rest of your component JSX */}
166+
<motion.div
167+
layout="position"
168+
className="flex items-center gap-3"
169+
key={`${field.name}-${columnCount}`}
170+
>
160171
<div className="flex items-center gap-1 border rounded-xl px-3 py-1.5 w-full">
161172
<If
162173
condition={Array.isArray(formFields[index])}
163174
render={() => <LuColumns className="cursor-grab w-4 h-4" />}
164175
/>
165176
<div className="flex items-center w-full">
166-
<div className="w-full text-sm">
167-
{field.variant}
168-
{/* <Input
169-
value={field.label}
170-
onChange={(e) =>
171-
updateFormField(path, { label: e.target.value })
172-
}
173-
placeholder="Enter label"
174-
/> */}
175-
</div>
177+
<div className="w-full text-sm">{field.variant}</div>
176178
<Button
177179
variant="ghost"
178180
size="icon"
179181
onClick={() => openEditDialog(field)}
180182
>
181183
<LuPencil />
182184
</Button>
183-
<Button
184-
variant="ghost"
185-
size="icon"
186-
onClick={removeColumn}
187-
// onClick={() => {
188-
// setFormFields((prevFields) => {
189-
// const newFields = [...prevFields]
190-
// if (Array.isArray(newFields[index])) {
191-
// // If it's an array, remove the specific subfield
192-
// ;(newFields[index] as FormFieldType[]).splice(subIndex!, 1)
193-
// // If the array becomes empty, remove it entirely
194-
// if ((newFields[index] as FormFieldType[]).length === 0) {
195-
// newFields.splice(index, 1)
196-
// }
197-
// } else {
198-
// // If it's a single field, remove it
199-
// newFields.splice(index, 1)
200-
// }
201-
// return newFields
202-
// })
203-
// }}
204-
>
185+
<Button variant="ghost" size="icon" onClick={removeColumn}>
205186
<LuTrash2 />
206187
</Button>
207188
</div>
@@ -225,7 +206,10 @@ export const FieldItem = ({
225206
{fieldTypes.map((fieldType) => (
226207
<DropdownMenuItem
227208
key={fieldType.name}
228-
onClick={() => addNewColumn(fieldType.name, index)}
209+
onClick={() => {
210+
addNewColumn(fieldType.name, index)
211+
setColumnCount((prev) => prev + 1)
212+
}}
229213
>
230214
{fieldType.name}
231215
</DropdownMenuItem>

screens/field-selector/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const FieldSelector: React.FC<FieldSelectorProps> = ({
1313
addFormField,
1414
}) => {
1515
return (
16-
<div className="flex md:flex-col items-start flex-wrap md:flex-nowrap gap-3">
16+
<div className="flex md:flex-col items-start flex-wrap md:flex-nowrap gap-3 h-[70vh] overflow-y-auto">
1717
{fieldTypes.map((variant) => (
1818
<div className="flex items-center gap-1" key={variant.name}>
1919
<Button

screens/form-builder/index.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ export default function FormBuilder() {
5050
type: '',
5151
value: '',
5252
variant,
53-
// min: 1,
54-
// max: 100,
55-
// step: 5,
5653
}
5754
setFormFields([...formFields, newField])
5855
}

screens/form-preview/index.tsx

+16-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ export type FormPreviewProps = {
2929
const renderFormFields = (fields: FormFieldOrGroup[], form: any) => {
3030
return fields.map((fieldOrGroup, index) => {
3131
if (Array.isArray(fieldOrGroup)) {
32-
const colSpan = fieldOrGroup.length === 2 ? 6 : 4
32+
// Calculate column span based on number of fields in the group
33+
const getColSpan = (totalFields: number) => {
34+
switch (totalFields) {
35+
case 2:
36+
return 6 // Two columns
37+
case 3:
38+
return 4 // Three columns
39+
default:
40+
return 12 // Single column or fallback
41+
}
42+
}
43+
3344
return (
3445
<div key={index} className="grid grid-cols-12 gap-4">
3546
{fieldOrGroup.map((field, subIndex) => (
@@ -38,7 +49,9 @@ const renderFormFields = (fields: FormFieldOrGroup[], form: any) => {
3849
control={form.control}
3950
name={field.name}
4051
render={({ field: formField }) => (
41-
<FormItem className={`col-span-${colSpan}`}>
52+
<FormItem
53+
className={`col-span-${getColSpan(fieldOrGroup.length)}`}
54+
>
4255
<FormControl>
4356
{React.cloneElement(
4457
renderFormField(field, form) as React.ReactElement,
@@ -60,7 +73,7 @@ const renderFormFields = (fields: FormFieldOrGroup[], form: any) => {
6073
control={form.control}
6174
name={fieldOrGroup.name}
6275
render={({ field: formField }) => (
63-
<FormItem>
76+
<FormItem className="col-span-12">
6477
<FormControl>
6578
{React.cloneElement(
6679
renderFormField(fieldOrGroup, form) as React.ReactElement,

screens/generate-code-parts/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const generateZodSchema = (
5252
})
5353
break
5454
case 'Smart Datetime Input':
55-
fieldSchema = z.coerce.date()
55+
fieldSchema = z.date()
5656
break
5757
case 'Number':
5858
fieldSchema = z.coerce.number()

screens/render-form-field/index.tsx

+29-8
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ export const renderFormField = (field: FormFieldType, form: any) => {
133133
switch (field.variant) {
134134
case 'Checkbox':
135135
return (
136-
<FormItem className="flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4">
136+
<FormItem
137+
className={cn(
138+
'flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4',
139+
field.className,
140+
)}
141+
>
137142
<FormControl>
138143
<Checkbox
139144
checked={checked} // Ensure this is handled as boolean
@@ -235,10 +240,13 @@ export const renderFormField = (field: FormFieldType, form: any) => {
235240
<Calendar
236241
mode="single"
237242
selected={date}
238-
onSelect={setDate}
239-
disabled={(date) =>
240-
date > new Date() || date < new Date('1900-01-01')
241-
}
243+
onSelect={(newDate) => {
244+
setDate(newDate)
245+
form.setValue(field.name, newDate, {
246+
shouldValidate: true,
247+
shouldDirty: true,
248+
})
249+
}}
242250
initialFocus
243251
/>
244252
</PopoverContent>
@@ -256,7 +264,14 @@ export const renderFormField = (field: FormFieldType, form: any) => {
256264
<DatetimePicker
257265
{...field}
258266
value={datetime}
259-
onChange={setDatetime}
267+
// onChange={setDatetime}
268+
onChange={(newDate) => {
269+
setDatetime(newDate)
270+
form.setValue(field.name, newDate, {
271+
shouldValidate: true,
272+
shouldDirty: true,
273+
})
274+
}}
260275
format={[
261276
['months', 'days', 'years'],
262277
['hours', 'minutes', 'am/pm'],
@@ -461,10 +476,16 @@ export const renderFormField = (field: FormFieldType, form: any) => {
461476
<FormLabel>{field.label}</FormLabel>
462477
<FormControl>
463478
<SmartDatetimeInput
464-
locale={field.locale}
479+
locale={field.locale as any}
465480
hour12={field.hour12}
466481
value={smartDatetime}
467-
onValueChange={(newDate) => setSmartDatetime(newDate)}
482+
onValueChange={(newDate) => {
483+
setSmartDatetime(newDate)
484+
form.setValue(field.name, newDate, {
485+
shouldValidate: true,
486+
shouldDirty: true,
487+
})
488+
}}
468489
placeholder="e.g. tomorrow at 3pm"
469490
/>
470491
</FormControl>

types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type FormFieldType = {
2525
step?: number
2626
locale?: keyof typeof Locales
2727
hour12?: boolean
28+
className?: string
2829
}
2930

3031
export type FieldType = { name: string; isNew: boolean; index?: number }

0 commit comments

Comments
 (0)