@invana/forms 0.0.26 → 0.0.28
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.
- package/README.md +75 -0
- package/dist/index.cjs +82 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -1
- package/dist/index.d.ts +58 -1
- package/dist/index.js +81 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @invana/forms
|
|
2
|
+
|
|
3
|
+
Composable form building blocks for Invana products — `FormField` with an `ObjectField`, plus the
|
|
4
|
+
leaf inputs.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpm add @invana/forms
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Peer dependencies: `@invana/ui`, `@invana/styling`, `react`, `react-dom`, `react-hook-form`.
|
|
11
|
+
|
|
12
|
+
## This is not a form renderer
|
|
13
|
+
|
|
14
|
+
There is no `FormRenderer` and no `FormSchema` tree. **You own `useForm`** and you compose your own
|
|
15
|
+
chrome — Card, Tabs, Accordion, a footer, a submit button. This package supplies the fields.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
`FormField.ObjectField` is the primary building block. Fields render as `${name}.${field.name}`,
|
|
20
|
+
so several ObjectFields in one `useForm` all write into a single shared data object.
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { useForm } from 'react-hook-form';
|
|
24
|
+
import { Form, FormField } from '@invana/forms';
|
|
25
|
+
import { Button } from '@invana/ui';
|
|
26
|
+
|
|
27
|
+
export function ShapeSettings() {
|
|
28
|
+
const form = useForm({ defaultValues: { shape: { fill: '#2563eb', radius: 4, visible: true } } });
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Form {...form}>
|
|
32
|
+
<form onSubmit={form.handleSubmit(console.log)}>
|
|
33
|
+
<FormField.ObjectField
|
|
34
|
+
control={form.control}
|
|
35
|
+
name="shape"
|
|
36
|
+
labelPosition="top"
|
|
37
|
+
fields={[
|
|
38
|
+
{ name: 'fill', type: 'color', label: 'Fill' },
|
|
39
|
+
{ name: 'radius', type: 'number', label: 'Radius', min: 0, max: 32 },
|
|
40
|
+
{ name: 'visible', type: 'boolean', label: 'Visible' },
|
|
41
|
+
]}
|
|
42
|
+
rowConfig={[{ fields: ['fill', 'radius'] }]}
|
|
43
|
+
/>
|
|
44
|
+
<Button type="submit">Save</Button>
|
|
45
|
+
</form>
|
|
46
|
+
</Form>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
A field with a `group` property is auto-wrapped in an Accordion; ungrouped fields render flat.
|
|
52
|
+
`rowConfig` puts named fields side by side in one row.
|
|
53
|
+
|
|
54
|
+
## Exports
|
|
55
|
+
|
|
56
|
+
**Fields** — `FormField` (augmented with `.ObjectField`, `.Color`, `.Number`, `.Select`,
|
|
57
|
+
`.Boolean`, `.Input`, `.Icon`), and the standalone `Field`, `ObjectField`, `InputField`,
|
|
58
|
+
`PasswordField`, `TextareaField`, `SelectField`, `BooleanField`, `RadioField`,
|
|
59
|
+
`CheckboxGroupField`, `ColorField`, `NumberField`, `IconField`.
|
|
60
|
+
|
|
61
|
+
**Controls** — `ColorSwatches`, `SliderNumber`, `IconInput`, and `SettingsPanel`.
|
|
62
|
+
|
|
63
|
+
**Types** — `FieldConfig`, `RowConfig`, `GroupConfig`, `ObjectFieldProps`, `FieldType`,
|
|
64
|
+
`LabelPosition`, `FieldOrientation`, `FieldSize`, `FieldBadge`, `BooleanControl`, `ColorPreset`.
|
|
65
|
+
|
|
66
|
+
React Hook Form's `Control`, `FieldValues`, `SubmitHandler`, `UseFormReturn`, `DefaultValues` and
|
|
67
|
+
`Mode` are re-exported so consumers need not import them separately.
|
|
68
|
+
|
|
69
|
+
## Icons
|
|
70
|
+
|
|
71
|
+
Pass icons in as props. This package does not bind you to an icon set.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT © Ravi Raja Merugu
|
package/dist/index.cjs
CHANGED
|
@@ -1413,6 +1413,86 @@ function FieldError({
|
|
|
1413
1413
|
}
|
|
1414
1414
|
);
|
|
1415
1415
|
}
|
|
1416
|
+
var PARAM_SOURCES = ["literal", "argument", "binding"];
|
|
1417
|
+
var ParamRow = React2__namespace.forwardRef(
|
|
1418
|
+
({
|
|
1419
|
+
name,
|
|
1420
|
+
type,
|
|
1421
|
+
source,
|
|
1422
|
+
onSourceChange,
|
|
1423
|
+
value,
|
|
1424
|
+
onValueChange,
|
|
1425
|
+
note,
|
|
1426
|
+
invalid,
|
|
1427
|
+
disabled,
|
|
1428
|
+
className,
|
|
1429
|
+
children,
|
|
1430
|
+
...props
|
|
1431
|
+
}, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1432
|
+
"div",
|
|
1433
|
+
{
|
|
1434
|
+
ref,
|
|
1435
|
+
"data-invalid": invalid || void 0,
|
|
1436
|
+
"data-disabled": disabled || void 0,
|
|
1437
|
+
className: ui.cn("flex items-start gap-3 py-1.5", className),
|
|
1438
|
+
...props,
|
|
1439
|
+
children: [
|
|
1440
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-[118px] shrink-0 pt-1", children: [
|
|
1441
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "truncate font-mono text-meta", children: name }),
|
|
1442
|
+
type != null ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "truncate text-meta text-muted-foreground", children: type }) : null
|
|
1443
|
+
] }),
|
|
1444
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
|
|
1445
|
+
children ?? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0", children: [
|
|
1446
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1447
|
+
Select,
|
|
1448
|
+
{
|
|
1449
|
+
value: source,
|
|
1450
|
+
onValueChange: (v) => onSourceChange?.(v),
|
|
1451
|
+
disabled,
|
|
1452
|
+
children: [
|
|
1453
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1454
|
+
SelectTrigger,
|
|
1455
|
+
{
|
|
1456
|
+
triggerSize: "sm",
|
|
1457
|
+
"aria-label": `${name} source`,
|
|
1458
|
+
className: "w-auto shrink-0 rounded-r-none border-r-0 text-meta text-muted-foreground",
|
|
1459
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SelectValue, {})
|
|
1460
|
+
}
|
|
1461
|
+
),
|
|
1462
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectContent, { children: PARAM_SOURCES.map((s) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: s, children: s }, s)) })
|
|
1463
|
+
]
|
|
1464
|
+
}
|
|
1465
|
+
),
|
|
1466
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1467
|
+
Input,
|
|
1468
|
+
{
|
|
1469
|
+
inputSize: "sm",
|
|
1470
|
+
value,
|
|
1471
|
+
onChange: (e) => onValueChange?.(e.target.value),
|
|
1472
|
+
disabled,
|
|
1473
|
+
"aria-invalid": invalid || void 0,
|
|
1474
|
+
"aria-label": name,
|
|
1475
|
+
style: invalid ? { borderColor: "var(--color-destructive)" } : void 0,
|
|
1476
|
+
className: "min-w-0 flex-1 rounded-l-none font-mono"
|
|
1477
|
+
}
|
|
1478
|
+
)
|
|
1479
|
+
] }),
|
|
1480
|
+
note != null ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1481
|
+
"div",
|
|
1482
|
+
{
|
|
1483
|
+
className: ui.cn(
|
|
1484
|
+
"text-meta",
|
|
1485
|
+
invalid ? "text-destructive" : "text-muted-foreground"
|
|
1486
|
+
),
|
|
1487
|
+
children: note
|
|
1488
|
+
}
|
|
1489
|
+
) : null
|
|
1490
|
+
] })
|
|
1491
|
+
]
|
|
1492
|
+
}
|
|
1493
|
+
)
|
|
1494
|
+
);
|
|
1495
|
+
ParamRow.displayName = "ParamRow";
|
|
1416
1496
|
function InputGroup({ className, ...props }) {
|
|
1417
1497
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1418
1498
|
"div",
|
|
@@ -1589,6 +1669,8 @@ exports.InputGroupTextarea = InputGroupTextarea;
|
|
|
1589
1669
|
exports.Label = Label;
|
|
1590
1670
|
exports.NumberField = NumberField;
|
|
1591
1671
|
exports.ObjectField = ObjectField;
|
|
1672
|
+
exports.PARAM_SOURCES = PARAM_SOURCES;
|
|
1673
|
+
exports.ParamRow = ParamRow;
|
|
1592
1674
|
exports.PasswordField = PasswordField;
|
|
1593
1675
|
exports.PasswordInput = PasswordInput;
|
|
1594
1676
|
exports.RadioField = RadioField;
|