Skip to content

Commit 1f3dc54

Browse files
committed
docs(ui): suggestion + progress screen
1 parent 9b068b1 commit 1f3dc54

File tree

1 file changed

+91
-6
lines changed

1 file changed

+91
-6
lines changed

docs/dev-guide/ui-api.md

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,16 +1039,23 @@ There are some builtin icons:
10391039
- `'done'`
10401040
- `'error'`
10411041

1042-
## Other plugins
1042+
## Progress screen
10431043

1044-
### hasPlugin
1044+
You can display a progress screen with some text and a progress bar:
10451045

1046-
Returns `true` if the project uses the plugin.
1046+
```js
1047+
api.setProgress({
1048+
status: 'Upgrading...',
1049+
error: null,
1050+
info: 'Step 2 of 4',
1051+
progress: 0.4 // from 0 to 1, -1 means hidden progress bar
1052+
})
1053+
```
1054+
1055+
Remove the progress screen:
10471056

10481057
```js
1049-
api.hasPlugin('eslint')
1050-
api.hasPlugin('apollo')
1051-
api.hasPlugin('vue-cli-plugin-apollo')
1058+
api.removeProgress()
10521059
```
10531060

10541061
## Hooks
@@ -1135,6 +1142,84 @@ api.onViewOpen(({ view, cwd }) => {
11351142
})
11361143
```
11371144

1145+
## Suggestions
1146+
1147+
Suggestions are buttons meant to propose an action to the user. They are displayed in the top bar. For example, we can have a button that suggest installing vue-router if the package isn't detected in the app.
1148+
1149+
```js
1150+
api.addSuggestion({
1151+
id: 'my-suggestion',
1152+
type: 'action', // Required (more types in the future)
1153+
label: 'Add vue-router',
1154+
// This will be displayed in a details modal
1155+
message: 'A longer message for the modal',
1156+
link: 'http://link-to-docs-in-the-modal',
1157+
// Function called when suggestion is activated by user
1158+
async handler () {
1159+
// ...
1160+
return {
1161+
// By default removes the button
1162+
keep: false
1163+
}
1164+
}
1165+
})
1166+
```
1167+
1168+
Then you can remove the suggestion:
1169+
1170+
```js
1171+
api.removeSuggestion('my-suggestion')
1172+
```
1173+
1174+
Typically, you will use hooks to display the suggestion in the right context:
1175+
1176+
```js
1177+
const ROUTER = 'vue-router-add'
1178+
1179+
api.onViewOpen(({ view }) => {
1180+
if (view.id === 'vue-project-plugins') {
1181+
if (!api.hasPlugin('vue-router')) {
1182+
api.addSuggestion({
1183+
id: ROUTER,
1184+
type: 'action',
1185+
label: 'cli-service.suggestions.vue-router-add.label',
1186+
message: 'cli-service.suggestions.vue-router-add.message',
1187+
link: 'https://router.vuejs.org/',
1188+
async handler () {
1189+
await install(api, 'vue-router')
1190+
}
1191+
})
1192+
}
1193+
} else {
1194+
api.removeSuggestion(ROUTER)
1195+
}
1196+
})
1197+
```
1198+
1199+
In this example we only display the vue-router suggestion in the plugins view and if the project doesn't have vue-router installed already.
1200+
1201+
Note: `addSuggestion` and `removeSuggestion` can be namespaced with `api.namespace()`.
1202+
1203+
## Other methods
1204+
1205+
### hasPlugin
1206+
1207+
Returns `true` if the project uses the plugin.
1208+
1209+
```js
1210+
api.hasPlugin('eslint')
1211+
api.hasPlugin('apollo')
1212+
api.hasPlugin('vue-cli-plugin-apollo')
1213+
```
1214+
1215+
### getCwd
1216+
1217+
Retrieve the current working directory.
1218+
1219+
```js
1220+
api.getCwd()
1221+
```
1222+
11381223
## Public static files
11391224

11401225
You may need to expose some static files over the cli-ui builtin HTTP server (typically if you want to specify an icon to a custom view).

0 commit comments

Comments
 (0)