Skip to content

Commit 70439a5

Browse files
committed
New features
1 parent caeb27b commit 70439a5

File tree

7 files changed

+123
-18
lines changed

7 files changed

+123
-18
lines changed

form-submit.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ You may also use a slot:
1313
<svg>...</svg>
1414
<span>Send now</span>
1515
</x-splade-submit>
16+
```
17+
18+
In addition to providing a custom template with a slot, you may change the styling of the default submit button with the `danger` or `secondary` attributes:
19+
20+
```blade
21+
<x-splade-submit danger label="Remove account" />
22+
23+
<x-splade-submit secondary label="Save for later" />
1624
```

splade-vs-livewire.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To summarize:
1414

1515
## Components
1616

17-
Livewire works by building **Livewire-specific** Components. It has its own syntax in Blade templates with `wire:*` attributes and directives. Splade works with Laravel's *native* [Blade Components](https://laravel.com/docs/9.x/blade) and Vue Components. Though some features of Splade require a single Middleware (like the SPA-navigation features), it doesn't need a custom compiler or engine to work.
17+
Livewire works by building **Livewire-specific** Components. It has its own syntax in Blade templates with `wire:*` attributes and directives. Splade works with Laravel's *native* [Blade Components](https://laravel.com/docs/9.x/blade) and Vue Components. Though some features of Splade require a single Middleware (like the SPA-navigation features), you don't need to create *Splade-specific* components, it's all just Blade and Vue.
1818

1919
To summarize:
2020
* Splade doesn't need the creation of *special* components as it uses native Laravel and Vue implementations to achieve reactivity.

x-data.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,23 @@ The remembered state will be lost whenever the user fully refreshes the app. You
7272
<button @click.prevent="data.accepted = true">Accept</button>
7373
</x-splade-data>
7474
```
75+
76+
## Global Store
77+
78+
Sometimes you want to use a set of reactive data through the template or layout. Instead of wrapping everything inside the data component, you may also define a store and use it at other places in your template.
79+
80+
```blade
81+
<x-splade-data store="navigation" default="{ opened: false }" />
82+
83+
<!-- other elements... -->
84+
85+
<button @click.prevent="navigation.opened = true">
86+
Open Navigation
87+
</button>
88+
89+
<nav v-show="navigation.opened">
90+
...
91+
</nav>
92+
```
93+
94+
You must pass a key to the `store` attribute and avoid generic naming. For example, don't use keys like *data*, *form*, and *toggle* as they might interfere with other scoped Vue components.

x-defer.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,28 @@ The **Defer Component** allows you to load data asynchronously. The component ex
1212

1313
## Request body
1414

15-
By default, the component performs a `GET` request with an `application/json` accept header. You may change this with the `method` and `accept-header` attributes. In case you need to post data, you may use the `request` attribute:
15+
By default, the component performs a `GET` request with an `application/json` accept header. You may change this with the `method` and `accept-header` attributes. In case you need to post data, you may use the `request` attribute. Just like the [Data component](/x-data.md), it allows you to pass a PHP value *or* a JavaScript object. The value passed to the `request` attribute will be parsed by Vue, not by PHP.
1616

1717
```blade
1818
<x-splade-defer method="POST" url="/post/increase" request="{ post_id: 1 }">
1919
...
2020
</x-splade-defer>
2121
```
2222

23+
If you want to parse the value by PHP, you may use the `:request` attribute (note the colon).
24+
25+
```blade
26+
<x-splade-defer method="POST" url="/post/increase" :request="['post_id' => 1]">
27+
```
28+
29+
You can do the same for adding headers:
30+
31+
```blade
32+
<x-splade-defer method="POST" url="/post/increase" headers="{ 'In-Background': 1 }">
33+
34+
<x-splade-defer method="POST" url="/post/increase" :headers="['In-Background' => 1]">
35+
```
36+
2337
## Poll
2438

2539
You may also use this component to poll for new data. With the `poll` attribute, you can specify the interval in milliseconds.
@@ -60,6 +74,25 @@ The component can watch a passed value for changes using the `watch-value` attri
6074

6175
If you want to watch all form data, you may pass `form.$all` to the `watch-value` attribute.
6276

77+
## Event
78+
79+
The component emits `success` and `error` events, allowing you to interact with the response data within your template. For example, you may set a form value on a successful request. Note that the `url` attribute supports *Template literals*, making it perfect for generating dynamic URLs:
80+
81+
```blade
82+
<x-splade-form>
83+
<x-splade-input name="zip" label="ZIP code" />
84+
<x-splade-input name="city" label="City" />
85+
86+
<x-splade-defer
87+
url="`https://example-city-api.com/${form.zip}/json/`"
88+
watch-value="form.zip"
89+
watch-debounce="100"
90+
manual
91+
@success="(response) => form.city = response.city"
92+
/>
93+
</x-splade-form>
94+
```
95+
6396
## Async templates and Rehydration
6497

6598
If you want to load sections of your template asynchronously, check out the [Lazy Loading](/lazy-loading.md) section. There's also a [Rehydrate Component](/x-rehydrate.md) to reload a section of your Blade template.

x-form.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ In addition, you may customize the confirmation dialog:
105105
>
106106
```
107107

108+
Instead of the `confirm` attribute, you may also use the `confirm-danger` attribute to render a red confirmation button.
109+
108110
### Password Confirmation
109111

110112
It's even possible to require the user to confirm their password within the confirmation dialog. First, you must register a supporting route using the `spladePasswordConfirmation()` method on the `Route` facade. As of version 1.2.2, the automatic installer does this for you. If you need to register the route manually, make sure it uses the `web` Middleware, for example, in `web.php`:
@@ -125,6 +127,12 @@ Only when the password is correct it submits the form. Splade will add the enter
125127
<x-splade-form confirm require-password="password_confirmation">
126128
```
127129

130+
To prevent users from re-entering their password over and over, you may use the `require-password-once` attribute. Once the user has successfully entered their password, it won't be asked again until the number of seconds (defined with the `auth.password_timeout` config key) has elapsed:
131+
132+
```blade
133+
<x-splade-form confirm require-password-once>
134+
```
135+
128136
## File uploads
129137

130138
You may use the input event to bind the selected file to your form data:
@@ -139,6 +147,23 @@ You may use the input event to bind the selected file to your form data:
139147

140148
The dedicated [File Component](/form-file.md) provides a cleaner solution, and has support for selecting multiple files as well as displaying the filename of the selected file.
141149

150+
151+
## State
152+
153+
There are several props that you can use to show the state of the form:
154+
155+
```blade
156+
<x-splade-form>
157+
<p v-if="form.processing">Submitting the data...</p>
158+
</x-splade-form>
159+
160+
<x-splade-form stay>
161+
<p v-if="form.wasSuccessful">Successfully submitted!</p>
162+
163+
<p v-if="form.recentlySuccessful">Flash message to show success!</p>
164+
</x-splade-form>
165+
```
166+
142167
## Submit on change
143168

144169
Sometimes you want to submit the form whenever a value changes, for example, on a settings page that you want to save immediately. For this, you may use the `submit-on-change` attribute.
@@ -157,6 +182,26 @@ In addition, you may optionally specify one or more values (with an `array` or `
157182
<x-splade-form :submit-on-change="['name', 'email']">
158183
```
159184

185+
While this is great for elements like checkboxes, radios, and selects, it might lead to a bad user experience when applied to text inputs, as the form disables user input on submission. To overcome this, you may use the `background` attribute. This prevents to form from disabling user input and leaves the state properties (`processing`, `wasSuccessful`, and `recentlySuccessful`) untouched. In addition, to prevent the form from submitting on every keystroke, you may use the `debounce` attribute to set a debounce time in milliseconds:
186+
187+
```blade
188+
<x-splade-form submit-on-change background debounce="500">
189+
<input v-model="form.message" />
190+
</x-splade-form>
191+
```
192+
193+
If you still want to indicate whether the form is processing, you may use the `processingInBackground` property:
194+
195+
```blade
196+
<x-splade-form submit-on-change background debounce="500">
197+
<input v-model="form.message" />
198+
199+
<p v-if="form.processingInBackground">Saving message in background...</p>
200+
201+
<button type="submit">Send message</button>
202+
</x-splade-form>
203+
```
204+
160205
## Reset and restore form
161206

162207
You may use the `form.reset` method to clear all form data.
@@ -203,21 +248,6 @@ You may choose to reset or restore the form data automatically. You can do this
203248
<x-splade-form stay restore-on-success>
204249
```
205250

206-
## State
207-
208-
There are several props that you can use to show the state of the form:
209-
210-
```blade
211-
<x-splade-form>
212-
<p v-if="form.processing">Submitting the data...</p>
213-
</x-splade-form>
214-
215-
<x-splade-form stay>
216-
<p v-if="form.wasSuccessful">Successfully submitted!</p>
217-
218-
<p v-if="form.recentlySuccessful">Flash message to show success!</p>
219-
</x-splade-form>
220-
```
221251

222252
## Form API
223253

x-link.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ In addition, you may customize the confirmation dialog:
2727
</Link>
2828
```
2929

30+
Instead of the `confirm` attribute, you may also use the `confirm-danger` attribute to render a red confirmation button.
31+
3032
## Redirecting To External Domains
3133

3234
When the URL is outside your application pointing to an external domain, you'd typically use a regular `<a>` element. Still, you may use the `away` attribute on the `Link` component. This can be useful when you have wrapped the component into another component and don't want to change the tag dynamically.

x-modal.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ By default, the modal is vertically centered. However, you may customize this wi
6868
<x-splade-modal position="top">
6969
```
7070

71+
The slideover opens on the right side by default, but you may change that as well with the `position` attribute:
72+
73+
```blade
74+
<x-splade-modal position="left">
75+
```
76+
7177
## Close Button
7278

7379
The modal and slideover have a *close button*, which you can disable with the `close-button` attribute.
@@ -115,4 +121,10 @@ To use a slideover, you must put the attribute on the `x-splade-component` inste
115121
<x-splade-modal name="refund-info" slideover max-width="lg">
116122
<p>...</p>
117123
</x-splade-modal>
118-
```
124+
```
125+
126+
Additionally, it's possible to immediately show the modal on page load with the `opened` attribute:
127+
128+
<x-splade-modal opened>
129+
<pre>secret-token</pre>
130+
</x-splade-modal>

0 commit comments

Comments
 (0)