Skip to content

Commit 0398191

Browse files
committed
doc: facade component doc overhaul
1 parent c9d2b3e commit 0398191

File tree

11 files changed

+180
-128
lines changed

11 files changed

+180
-128
lines changed

docs/components/content/IntercomDemo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const isLoaded = ref(false)
44

55
<template>
66
<div style="padding: 40px; position: relative;">
7-
<ScriptIntercom @ready="isLoaded = true" app-id="akg5rmxb" api-base="https://api-iam.intercom.io" alignment="left" :horizontal-padding="0" class="intercom">
7+
<ScriptIntercom app-id="akg5rmxb" api-base="https://api-iam.intercom.io" alignment="left" :horizontal-padding="0" class="intercom" @ready="isLoaded = true">
88
<div style="display: flex; align-items: center; justify-content: center; width: 48px; height: 48px;">
99
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill="white" viewBox="0 0 28 32"><path d="M28 32s-4.714-1.855-8.527-3.34H3.437C1.54 28.66 0 27.026 0 25.013V3.644C0 1.633 1.54 0 3.437 0h21.125c1.898 0 3.437 1.632 3.437 3.645v18.404H28V32zm-4.139-11.982a.88.88 0 00-1.292-.105c-.03.026-3.015 2.681-8.57 2.681-5.486 0-8.517-2.636-8.571-2.684a.88.88 0 00-1.29.107 1.01 1.01 0 00-.219.708.992.992 0 00.318.664c.142.128 3.537 3.15 9.762 3.15 6.226 0 9.621-3.022 9.763-3.15a.992.992 0 00.317-.664 1.01 1.01 0 00-.218-.707z" /></svg>
1010
</div>
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
title: Facade Components
3+
description: Facade Components are fake UI elements that get replaced once a third-party script loads.
4+
---
5+
6+
Nuxt Scripts provides several Facade Components that you can use to speed up your app's performance.
7+
8+
Using them has trade-offs, but they can aid in improving the performance experience of your app.
9+
10+
## What are Facade Components?
11+
12+
To render complex components using third-party scripts such as a Video embed, payment modal, or chat widget, we need many resources.
13+
Loading these while Nuxt is starting will slow down your app's performance.
14+
15+
However, if we delay loading the script until Nuxt is finished, we end up with harmful content layout shifts (CLS) and visual noise,
16+
leading to a poor user experience.
17+
18+
Facade Components aim to solve this by rendering a "fake" UI element that gets replaced once the third-party script loads.
19+
20+
By hooking into appropriate DOM events and providing user feedback, we can use these fake elements while still providing a great user experience.
21+
22+
## What are the trade-offs in using Facade Components?
23+
24+
While the performance benefit is quite clear, there can be trade-off on user experience.
25+
26+
- **Flash of mismatched content**: The fake UI element may not look like the final UI element, leading to a flash of mis-matched content. Only minimal
27+
styling is provided by Nuxt Scripts, you may need to tweak it to match your app's design.
28+
- **Interactivity can break**: Interactivity of the elements requires the script to load, if it doesn't load then you need to provide a fallback.
29+
- **Accessibility Concerns**: We need to provide clear a11y feedback to the user when the script is loading or fails to load.
30+
31+
## Nuxt Scripts Facade Components
32+
33+
All Facade Components are headless components that wrap the relevant `useScript<provider>` composable. Minimal styling is
34+
provided within the docs to give you a starting point.
35+
36+
## Best Practices in using Facade Components
37+
38+
### Provide an error fallback
39+
40+
If the script fails to load, provide a fallback that informs the user of the failure and provides an alternative way to access the content.
41+
42+
```vue
43+
<ScriptYouTubePlayer>
44+
<template #error>
45+
<UAlert color="red" title="YouTube player failed to load" description="Please refresh the page to try again." />
46+
</template>
47+
</ScriptYouTubePlayer>
48+
```
49+
50+
### Provide a loading state with accessible feedback
51+
52+
When the script is loading, provide a loading state that informs the user that the content is loading.
53+
54+
The `ScriptLoadingIndicator` component is provided by Nuxt Scripts to help with this and provides a11y feedback.
55+
56+
```vue
57+
<ScriptYouTubePlayer>
58+
<template #loading>
59+
<ScriptLoadingIndicator />
60+
</template>
61+
</ScriptYouTubePlayer>
62+
```
63+
64+
### Choose the triggering event wisely
65+
66+
The Facade Components are pre-configured for the best general performance, but you can customize the triggering event to better match your app's needs.
67+
68+
The best triggers are one that require explicit user interaction such as a click. Loading on hover may cause user experience issues
69+
with subsequent events being lost such as clicks.
70+
71+
## Facade Components API
72+
73+
All Facade Components share a similar API.
74+
75+
### Props
76+
77+
- `trigger` - The event that triggers the script to load. See [Element Event Triggers](/docs/guides/script-triggers#element-event-triggers) for more information.
78+
79+
### Slots
80+
81+
The component provides minimal UI by default, only enough to be functional and accessible. There are a number of slots for you to customize the components however you need.
82+
83+
- `default` - Content to always display with the component.
84+
85+
```vue
86+
<template>
87+
<ScriptYouTubePlayer>
88+
<div class="bg-blue-500 text-white p-5">
89+
Youtube!
90+
</div>
91+
</ScriptYouTubePlayer>
92+
</template>
93+
```
94+
95+
- `loading` - The content to display only while the script is loading.
96+
97+
```vue
98+
<template>
99+
<ScriptYouTubePlayer>
100+
<template #loading>
101+
<ScriptLoadingIndicator />
102+
</template>
103+
</ScriptYouTubePlayer>
104+
</template>
105+
```
106+
107+
- `awaitingLoad` - The content to display only while the script is waiting to load.
108+
109+
```vue
110+
<template>
111+
<ScriptYouTubePlayer>
112+
<template #awaitingLoad>
113+
<div class="bg-blue-500 text-white p-5">
114+
Click to play!
115+
</div>
116+
</template>
117+
</ScriptYouTubePlayer>
118+
</template>
119+
```
120+
121+
- `error` - The content to display if the script fails to load.
122+
123+
```vue
124+
<template>
125+
<ScriptYouTubePlayer>
126+
<template #error>
127+
<UAlert color="red" title="YouTube player failed to load" description="Please refresh the page to try again." />
128+
</template>
129+
</ScriptYouTubePlayer>
130+
</template>
131+
```
132+
133+
### Events
134+
135+
- `ready` - Emitted when the script has loaded. Gives you access to the underlying script API.
136+
- `error` - Emitted when the script fails to load.

docs/content/scripts/ads/carbon-ads.md

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -156,50 +156,17 @@ use this example from nuxt.com.
156156
</style>
157157
```
158158

159-
### Props
160-
161-
The `ScriptCarbonAds` component accepts the following props:
162-
163-
- `serve`: The serve URL provided by Carbon Ads.
164-
- `placement`: The placement ID provided by Carbon Ads.
165-
- `trigger`: The trigger event to load the script. Default is `undefined`. See [Element Event Triggers](/docs/guides/script-triggers#element-event-triggers) for more information.
166159

167-
### Events
160+
### Component API
168161

169-
The component emits the script events.
162+
See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for full props, events, and slots.
170163

171-
```ts
172-
const emits = defineEmits<{
173-
error: [e: string | Event]
174-
load: []
175-
}>()
176-
```
177-
178-
### Slots
179-
180-
There are a number of slots mapped to the script status that you can use to customize the ad experience.
164+
Note: The Carbon Ads script _does not_ extend the `useScript` composable. Accessing the script will return the `HTMLScriptElement`.
181165

182-
- **error**:
183-
The slot is used to display content when the ad fails to load.
184-
185-
- **awaitingLoad**
186-
The slot is used to display content before the ad script is loaded.
166+
### Props
187167

188-
- **loaded**
189-
The slot is used to display content after the ad script is loaded.
168+
The `ScriptCarbonAds` component accepts the following props:
190169

191-
- **loading**
192-
The slot is used to display content while the ad script is loading.
170+
- `serve`: The serve URL provided by Carbon Ads.
171+
- `placement`: The placement ID provided by Carbon Ads.
193172

194-
```vue
195-
<template>
196-
<ScriptCarbonAds
197-
serve="..."
198-
placement="..."
199-
>
200-
<template #awaitingLoad>
201-
Loading ads...
202-
</template>
203-
</ScriptCarbonAds>
204-
</template>
205-
```

docs/content/scripts/ads/google-adsense.md

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ You can use these hooks to add a fallback when the Google Adsense script is bloc
4949
</template>
5050
```
5151

52+
53+
### Component API
54+
55+
See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for full props, events, and slots.
56+
5257
### Props
5358

5459
The `ScriptGoogleAdsense` component supports all props that Google Adsense supports on the `<ins>` tag. See the [Ad tags documentation](https://developers.google.com/adsense/platforms/transparent/ad-tags) for more information.
@@ -57,38 +62,6 @@ At a minimum you must provide the following tags:
5762
- `data-ad-client`: The Google Adsense ID.
5863
- `data-ad-slot`: The slot ID.
5964

60-
Nuxt Scripts exposes the following additional props:
61-
- `trigger`: The trigger event to load the script. Default is `undefined`. See [Element Event Triggers](/docs/guides/script-triggers#element-event-triggers) for more information.
62-
63-
### Slots
64-
65-
There are a number of slots mapped to the script status that you can use to customize the ad experience.
66-
67-
- **error**:
68-
The slot is used to display content when the ad fails to load.
69-
70-
- **awaitingLoad**
71-
The slot is used to display content before the ad script is loaded.
72-
73-
- **loaded**
74-
The slot is used to display content after the ad script is loaded.
75-
76-
- **loading**
77-
The slot is used to display content while the ad script is loading.
78-
79-
```vue
80-
<template>
81-
<ScriptGoogleAdsense
82-
serve="..."
83-
placement="..."
84-
>
85-
<template #awaitingLoad>
86-
Loading ads...
87-
</template>
88-
</ScriptGoogleAdsense>
89-
</template>
90-
```
91-
9265
## useScriptGoogleAdsense
9366

9467
The `useScriptGoogleAdsense` composable lets you have fine-grain control over the Google Adsense script.

docs/content/scripts/content/google-maps.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ or consider using the `#placeholder` slot to customize the placeholder image.
132132

133133
::
134134

135+
### Component API
136+
137+
See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for full props, events, and slots.
138+
135139
### Events
136140

137141
The `ScriptGoogleMaps` component emits a single `ready` event when the Google Maps is loaded.

docs/content/scripts/content/vimeo-player.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ or consider using the `#placeholder` slot to customize the placeholder image.
126126

127127
::
128128

129+
### Component API
130+
131+
See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for full props, events, and slots.
132+
129133
### Events
130134

131135
The `ScriptVimeoPlayer` component emits all events from the Vimeo Player SDK. Please consult the [Player Events](https://developer.vimeo.com/player/sdk/reference#about-player-events) for full documentation.

docs/content/scripts/content/youtube-player.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ or consider using the `#placeholder` slot to customize the placeholder image.
107107

108108
::
109109

110+
### Component API
111+
112+
See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for full props, events, and slots.
113+
110114
### Events
111115

112116
The `ScriptYouTubePlayer` component emits all events from the YouTube Player SDK. Please consult the [Player Events](https://developers.google.com/youtube/iframe_api_reference#Events) for full documentation.

docs/content/scripts/payments/stripe.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ You'll need to create your own [Pricing Table](https://dashboard.stripe.com/pric
4646

4747
::
4848

49+
### Component API
50+
51+
See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for full props, events, and slots.
52+
4953
### Props
5054

5155
The `ScriptStripePricingTable` component accepts the following props:
@@ -57,31 +61,6 @@ The `ScriptStripePricingTable` component accepts the following props:
5761
- `customer-email`: The email of the customer.
5862
- `customer-session-client-secret`: The client secret of the customer session.
5963

60-
### Events
61-
62-
The `ScriptStripePricingTable` component emits a single `ready` event when the pricing table is loaded.
63-
64-
```ts
65-
const emits = defineEmits<{
66-
ready: []
67-
}>()
68-
```
69-
70-
### Slots
71-
72-
The component provides minimal UI by default, only enough to be functional and accessible. There are a number of slots for you to customize the maps however you like.
73-
74-
**default**
75-
76-
The default slot is used to display content that will always be visible.
77-
78-
**awaitingLoad**
79-
80-
The slot is used to display content while the Stripe is loading.
81-
82-
**loading**
83-
84-
The slot is used to display content while the Stripe is loading.
8564

8665
## useScriptStripe
8766

docs/content/scripts/support/crisp.md

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ links:
1414

1515
[Crisp](https://crisp.chat/) is a customer messaging platform that lets you communicate with your customers through chat, email, and more.
1616

17-
Nuxt Scripts provides a [useScriptCrisp](#usescriptcrisp) composable and a headless Facade Component [useScriptCrisp](#scriptcrisp) component to interact with crisp.
17+
Nuxt Scripts provides a [useScriptCrisp](#usescriptcrisp) composable and a headless Facade Component [ScriptCrisp](#scriptcrisp) component to interact with crisp.
1818

1919
## ScriptCrisp
2020

@@ -89,6 +89,10 @@ const isLoaded = ref(false)
8989

9090
::
9191

92+
### Component API
93+
94+
See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for full props, events, and slots.
95+
9296
### Props
9397

9498
- `trigger`: The trigger event to load crisp. Default is `click`. See [Element Event Triggers](/docs/guides/script-triggers#element-event-triggers) for more information.
@@ -122,33 +126,8 @@ function onReady(crisp) {
122126
</template>
123127
```
124128

125-
### Crisp API
126-
127-
The component exposes a `crisp` instance that you can access the underlying Crisp API.
128-
129-
```vue
130-
<script setup lang="ts">
131-
const crispEl = ref()
132-
onMounted(() => {
133-
crispEl.value.crisp.do('chat:open')
134-
})
135-
</script>
136-
137-
<template>
138-
<ScriptCrisp ref="crispEl" />
139-
</template>
140-
```
141-
142129
### Slots
143130

144-
The component provides minimal UI by default, only enough to be functional and accessible. There are a number of slots for you to customize the maps however you like.
145-
146-
**default**
147-
148-
The default slot is used to display content that will always be visible.
149-
150-
Tip: It's best to leave this empty as crisp replaces this component in its own component.
151-
152131
**awaitingLoad**
153132

154133
The slot is used to display content while crisp is loading.

docs/content/scripts/support/intercom.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ const isLoaded = ref(false)
6969

7070
::
7171

72+
### Component API
73+
74+
See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for full props, events, and slots.
75+
7276
### Props
7377

7478
- `trigger`: The trigger event to load intercom. Default is `click`. See [Element Event Triggers](/docs/guides/script-triggers#element-event-triggers) for more information.

0 commit comments

Comments
 (0)