Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
added max length to prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkingshott committed Sep 21, 2022
1 parent 3b593fb commit 5482f77
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
20 changes: 17 additions & 3 deletions docs/pages/prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ You can use the toggle at the top right of the page to switch between light and
<!-- Demo -->
<div class="bg-gray-100 dark:bg-black flex justify-center rounded-md p-6 mt-8">
<ClientOnly>
<PromptComponent :visible="show" @cancel="show = false" :lines="3" @continue="show = false"></PromptComponent>
<PromptComponent :visible="show" @cancel="show = false" :lines="3" :maxLength="15" @continue="show = false"></PromptComponent>
</ClientOnly>
<button @click="show = true"
class="bg-sky-700 text-white px-3 py-1 mt-10 mb-12 rounded-md">
Expand Down Expand Up @@ -82,6 +82,19 @@ When set to `1`, an `input` is used. When set to `2+`, a `textarea` is used.
<v-prompt :lines="6"></v-prompt>
```

### maxLength

- Type: `Number`
- Default: `null`

Set the maximum number of characters that should be allowed.

When set to `null`, no limit is enforced by the browser.

```html
<v-prompt :maxLength="30"></v-prompt>
```

### summary

- Type: `String`
Expand Down Expand Up @@ -172,14 +185,15 @@ async provideFeedback()
'In order to proceed, some input is required from you.',
'Your response',
'',
3
3,
100
);

alert(result === '' ? 'Cancel' : 'Continue');
},
```

The `prompt` method accepts five parameters, which are used to set the [title](#title), [summary](#summary), [label](#label), fallback text (if cancelled) and [lines](#lines) properties of the component.
The `prompt` method accepts six parameters, which are used to set the [title](#title), [summary](#summary), [label](#label), fallback text (if cancelled), [lines](#lines) and [maxLength](#maxlength) properties of the component.

## Custom styling

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@caneara/varnish",
"author": "Caneara",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"description": "A library of UI components built using Vue.js and TailwindCSS.",
"repository": {
Expand Down
15 changes: 9 additions & 6 deletions src/components/prompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
:label="label"
:lines="lines"
v-model="content"
icon="fas fa-signature">
:maxLength="maxLength"
icon="fas fa-signature"
@return="$emit('continue', content)">
</v-textbox>

<!-- Actions -->
Expand Down Expand Up @@ -94,11 +96,12 @@
*
*/
props : {
'label' : { type : String, default : 'Your response' },
'lines' : { type : Number, default : 1 },
'summary' : { type : String, default : 'In order to proceed, some input is required. Please enter it below, then press continue, or press cancel.' },
'title' : { type : String, default : 'Awaiting your response...' },
'visible' : { type : Boolean, default : false },
'label' : { type : String, default : 'Your response' },
'lines' : { type : Number, default : 1 },
'maxLength' : { type : Number, default : null },
'summary' : { type : String, default : 'In order to proceed, some input is required. Please enter it below, then press continue, or press cancel.' },
'title' : { type : String, default : 'Awaiting your response...' },
'visible' : { type : Boolean, default : false },
},
}
</script>
10 changes: 9 additions & 1 deletion src/components/textbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,15 @@
*/
interceptKeystroke(event)
{
if (event.key === 'Enter') this.$emit('return');
if (event.key === 'Enter' && event.shiftKey) {
return 13;
}
if (event.key === 'Enter' && ! event.shiftKey) {
event.preventDefault();
return this.$emit('return');
}
},
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/mixins/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,19 @@ export default
* Request that the user provide some feedback.
*
*/
prompt(title = null, summary = null, label = null, fallback = '', lines = 1)
prompt(title = null, summary = null, label = null, fallback = '', lines = 1, maxLength = null)
{
let dialog = this.createDialogElement();

return new Promise((resolve, reject) =>
{
dialog.container = createApp(PromptComponent, {
label : label ?? 'Your response',
lines : lines,
summary : summary ?? 'In order to proceed, some input is required. Please enter it below, then press continue, or press cancel.',
title : title ?? 'Awaiting your response...',
visible : true,
label : label ?? 'Your response',
lines : lines,
maxLength : maxLength,
summary : summary ?? 'In order to proceed, some input is required. Please enter it below, then press continue, or press cancel.',
title : title ?? 'Awaiting your response...',
visible : true,
onCancel : () => {
resolve(fallback);

Expand Down

0 comments on commit 5482f77

Please sign in to comment.