Skip to content

Commit 173a6f7

Browse files
committed
feat: forms@3
1 parent e655043 commit 173a6f7

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

src/content/docs/reference/forms/components.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: HTML like form for Astro
44
---
55

66
## Form Input
7-
### Input
7+
### BInput
88

99
The basic component for most of the form filed.
1010

@@ -20,12 +20,16 @@ It includes the following attributes:
2020
- **required** - a value must be send
2121
- **readonly** - make the value unchangeable
2222
- **value** - default value, mainly use for the `readonly` attribute
23+
- **as** - change the base element (default `input`, can be a React component)
24+
- **props** - props for the `as` element
2325

2426
```astro
25-
<Input type="date" name="meetingDate" min="2023-2-2" max"2023-4-2" required/>
27+
28+
```astro
29+
<BInput type="date" name="meetingDate" min="2023-2-2" max"2023-4-2" required/>
2630
```
2731

28-
### Textarea
32+
### BTextarea
2933

3034
Simple to input, but only for text
3135

@@ -36,37 +40,41 @@ It includes the following attributes:
3640
- **pattern** - regex pattern for text
3741
- **required** - a value must be send
3842
- **readonly** - make the value unchangeable
43+
- **as** - change the base element (default `textarea`, can be a React component)
44+
- **props** - props for the `as` element
3945

4046
```astro
41-
<Textarea name="moreInfo" maxlength={400} required/>
47+
<BTextarea name="moreInfo" maxlength={400} required/>
4248
```
4349

44-
### Select
50+
### BSelect
4551

4652
The select component is use to make the user choose value / values
4753

4854
- **type** - `text` / `date` / `number` - for parsing purposes
4955
- **multiple** - to select more then one value
5056
- **required** - something must be selected (default `true`)
57+
- **as** - change the base element (default `select`, can be a React component)
58+
- **props** - props for the `as` element
5159

52-
#### Option
60+
#### BOption
5361

5462
The select option
5563

5664
- **value** - value to send to the server
5765
- **disabled** - you can not select this option
5866

5967
```astro
60-
<Select name="favoriteFood" required={false}>
61-
<Option disabled selected>Idk</Option> <--! The default, but not selectable-->
62-
<Option>Pizaa</Option>
63-
<Option>Salad</Option>
64-
<Option>Lasagna</Option>
65-
</Select>
68+
<BSelect name="favoriteFood" required={false}>
69+
<BOption disabled selected>Idk</BOption> <--! The default, but not selectable-->
70+
<BOption>Pizaa</BOption>
71+
<BOption>Salad</BOption>
72+
<BOption>Lasagna</BOption>
73+
</BSelect>
6674
```
6775

6876
## Form controls
69-
`Button` is the general form control. You can also use it without `BindForm` component
77+
`BButton` is the general form control. You can also use it without `BindForm` component
7078
Attributes:
7179
- **onClick** - function to execute when the button clicked
7280
- **connectId** - (optional) name for the button action (auto-generate by default)
@@ -78,7 +86,7 @@ function sayHi(){
7886
console.log('Hi');
7987
}
8088
---
81-
<Button onClick={sayHi}>Say Hi</Button>
89+
<BButton onClick={sayHi}>Say Hi</BButton>
8290
8391
```
8492
### Note
@@ -95,7 +103,7 @@ Attributes:
95103

96104
```astro
97105
<FormErrors title="From Errors"/>
98-
<Input type='int' min="1" name='number' errorMessage="Number is smaller then 1"/>
106+
<BInput type='int' min="1" name='number' errorMessage="Number is smaller then 1"/>
99107
```
100108

101109
This will output the following:

src/content/docs/reference/forms/data-binding.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Behinds the seen, the form is <ins>validate</ins> and <ins>parsed</ins> accordin
1111

1212
```astro
1313
---
14-
import { Bind } from "@astro-utils/forms";
15-
import { BindForm, Button, Input } from "@astro-utils/forms/forms.js";
14+
import { Bind, BindForm, BButton, BInput } from "@astro-utils/forms/forms.js";
1615
import Layout from "../layouts/Layout.astro";
1716
1817
const form = Bind();
@@ -27,12 +26,12 @@ function formSubmit(){
2726
{showSubmitText}
2827
2928
<h4>What you name*</h4>
30-
<Input type={'text'} name="name" maxlength={20} required/>
29+
<BInput type={'text'} name="name" maxlength={20} required/>
3130
3231
<h4>Enter age*</h4>
33-
<Input type={'int'} name="age" required/>
32+
<BInput type={'int'} name="age" required/>
3433
35-
<Button onClick={formSubmit} whenFormOK>Submit</Button>
34+
<BButton onClick={formSubmit} whenFormOK>Submit</BButton>
3635
</BindForm>
3736
</Layout>
3837
```
@@ -64,9 +63,9 @@ function userNameOK(value: string){
6463
<FormErrors title="Errors"/>
6564
6665
<h4>What you name*</h4>
67-
<Input type={'text'} name="name" validate={userNameOK} maxlength={20} required/>
66+
<BInput type={'text'} name="name" validate={userNameOK} maxlength={20} required/>
6867
69-
<Button onClick={formSubmit} whenFormOK>Submit</Button>
68+
<BButton onClick={formSubmit} whenFormOK>Submit</BButton>
7069
</BindForm>
7170
</Layout>
7271
```
@@ -95,12 +94,12 @@ function formSubmit(){
9594
{showSubmitText}
9695
9796
<h4>What you name</h4>
98-
<Input type={'text'} name="name"/>
97+
<BInput type={'text'} name="name"/>
9998
10099
<h4>Enter age*</h4>
101-
<Input type={'int'} name="age" min={10} required/>
100+
<BInput type={'int'} name="age" min={10} required/>
102101
103-
<Button onClick={formSubmit} whenFormOK>Submit</Button>
102+
<BButton onClick={formSubmit} whenFormOK>Submit</BButton>
104103
</BindForm>
105104
</Layout>
106105
```

src/content/docs/reference/forms/session.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Use can get the session with the activation of web forms
1313

1414
```astro
1515
---
16-
import { Button } from "@astro-utils/forms/forms.js";
16+
import { BButton } from "@astro-utils/forms/forms.js";
1717
const { session } = Astro.locals;
1818
1919
function increase() {
@@ -22,7 +22,7 @@ function increase() {
2222
}
2323
---
2424
25-
<Button onClick={increase}>++</Button>
25+
<BButton onClick={increase}>++</BButton>
2626
<p>Current counter: {amSession.counter}</p>
2727
```
2828

0 commit comments

Comments
 (0)