From a820f06d61e7100402b95fad5d2ed1c012cbae80 Mon Sep 17 00:00:00 2001 From: Jeff Sagal Date: Wed, 11 Mar 2020 09:16:07 -0700 Subject: [PATCH] docs: overhaul slot docs (#1099) * docs: sort slots alphabetically --- docs/.vuepress/components/SlotFooter.vue | 7 + docs/.vuepress/components/SlotHeader.vue | 7 + docs/.vuepress/components/SlotListFooter.vue | 7 + docs/.vuepress/components/SlotListHeader.vue | 7 + docs/.vuepress/components/SlotNoOptions.vue | 7 + .../components/SlotOpenIndicator.vue | 7 + docs/.vuepress/components/SlotOption.vue | 24 ++ docs/.vuepress/components/SlotSearch.vue | 12 + .../components/SlotSelectedOption.vue | 26 ++ .../SlotSelectedOptionContainer.vue | 23 ++ docs/.vuepress/components/SlotSpinner.vue | 9 + docs/api/slots.md | 271 +++++++++--------- 12 files changed, 275 insertions(+), 132 deletions(-) create mode 100644 docs/.vuepress/components/SlotFooter.vue create mode 100644 docs/.vuepress/components/SlotHeader.vue create mode 100644 docs/.vuepress/components/SlotListFooter.vue create mode 100644 docs/.vuepress/components/SlotListHeader.vue create mode 100644 docs/.vuepress/components/SlotNoOptions.vue create mode 100644 docs/.vuepress/components/SlotOpenIndicator.vue create mode 100644 docs/.vuepress/components/SlotOption.vue create mode 100644 docs/.vuepress/components/SlotSearch.vue create mode 100644 docs/.vuepress/components/SlotSelectedOption.vue create mode 100644 docs/.vuepress/components/SlotSelectedOptionContainer.vue create mode 100644 docs/.vuepress/components/SlotSpinner.vue diff --git a/docs/.vuepress/components/SlotFooter.vue b/docs/.vuepress/components/SlotFooter.vue new file mode 100644 index 0000000..2d95fdc --- /dev/null +++ b/docs/.vuepress/components/SlotFooter.vue @@ -0,0 +1,7 @@ + diff --git a/docs/.vuepress/components/SlotHeader.vue b/docs/.vuepress/components/SlotHeader.vue new file mode 100644 index 0000000..4c1525a --- /dev/null +++ b/docs/.vuepress/components/SlotHeader.vue @@ -0,0 +1,7 @@ + diff --git a/docs/.vuepress/components/SlotListFooter.vue b/docs/.vuepress/components/SlotListFooter.vue new file mode 100644 index 0000000..9ba155b --- /dev/null +++ b/docs/.vuepress/components/SlotListFooter.vue @@ -0,0 +1,7 @@ + diff --git a/docs/.vuepress/components/SlotListHeader.vue b/docs/.vuepress/components/SlotListHeader.vue new file mode 100644 index 0000000..bfb24d3 --- /dev/null +++ b/docs/.vuepress/components/SlotListHeader.vue @@ -0,0 +1,7 @@ + diff --git a/docs/.vuepress/components/SlotNoOptions.vue b/docs/.vuepress/components/SlotNoOptions.vue new file mode 100644 index 0000000..c8e9b5c --- /dev/null +++ b/docs/.vuepress/components/SlotNoOptions.vue @@ -0,0 +1,7 @@ + diff --git a/docs/.vuepress/components/SlotOpenIndicator.vue b/docs/.vuepress/components/SlotOpenIndicator.vue new file mode 100644 index 0000000..302d85a --- /dev/null +++ b/docs/.vuepress/components/SlotOpenIndicator.vue @@ -0,0 +1,7 @@ + diff --git a/docs/.vuepress/components/SlotOption.vue b/docs/.vuepress/components/SlotOption.vue new file mode 100644 index 0000000..e94e435 --- /dev/null +++ b/docs/.vuepress/components/SlotOption.vue @@ -0,0 +1,24 @@ + + + diff --git a/docs/.vuepress/components/SlotSearch.vue b/docs/.vuepress/components/SlotSearch.vue new file mode 100644 index 0000000..d8b611f --- /dev/null +++ b/docs/.vuepress/components/SlotSearch.vue @@ -0,0 +1,12 @@ + diff --git a/docs/.vuepress/components/SlotSelectedOption.vue b/docs/.vuepress/components/SlotSelectedOption.vue new file mode 100644 index 0000000..4db88ed --- /dev/null +++ b/docs/.vuepress/components/SlotSelectedOption.vue @@ -0,0 +1,26 @@ + + + diff --git a/docs/.vuepress/components/SlotSelectedOptionContainer.vue b/docs/.vuepress/components/SlotSelectedOptionContainer.vue new file mode 100644 index 0000000..aa0ba69 --- /dev/null +++ b/docs/.vuepress/components/SlotSelectedOptionContainer.vue @@ -0,0 +1,23 @@ + + + diff --git a/docs/.vuepress/components/SlotSpinner.vue b/docs/.vuepress/components/SlotSpinner.vue new file mode 100644 index 0000000..3e9c083 --- /dev/null +++ b/docs/.vuepress/components/SlotSpinner.vue @@ -0,0 +1,9 @@ + diff --git a/docs/api/slots.md b/docs/api/slots.md index 453a97f..6cbc817 100644 --- a/docs/api/slots.md +++ b/docs/api/slots.md @@ -3,23 +3,22 @@ Vue Select leverages scoped slots to allow for total customization of the presen Slots can be used to change the look and feel of the UI, or to simply swap out text. ::: -## Wrapper + -### `header` +
-Displayed at the top of the component, above `.vs__dropdown-toggle`. - -- `search {string}` - the current search query -- `loading {boolean}` - is the component loading -- `searching {boolean}` - is the component searching -- `filteredOptions {array}` - options filtered by the search text -- `deselect {function}` - function to deselect an option - -```html - -``` - -### `footer` +## `footer` Displayed at the bottom of the component, below `.vs__dropdown-toggle`. @@ -32,113 +31,23 @@ Otherwise content in this slot will affect it's positioning. - `filteredOptions {array}` - options filtered by the search text - `deselect {function}` - function to deselect an option -```html - -``` + +<<< @/.vuepress/components/SlotFooter.vue -## Selected Option(s) +## `header` -### `selected-option` - -#### Scope: - -- `option {Object}` - A selected option - -```html - - {{ getOptionLabel(option) }} - -``` - -### `selected-option-container` - -#### Scope: - -- `option {Object}` - A selected option -- `deselect {Function}` - Method used to deselect a given option when `multiple` is true -- `disabled {Boolean}` - Determine if the component is disabled -- `multiple {Boolean}` - If the component supports the selection of multiple values - -```html - - - - {{ getOptionLabel(option) }} - - - - -``` - -## Component Actions - -### `spinner` - -#### Scope: - -- `loading {Boolean}` - if the component is in a loading state - -```html - -
Loading...
-
-``` - -### `open-indicator` - -```js -attributes : { - 'ref': 'openIndicator', - 'role': 'presentation', - 'class': 'vs__open-indicator', -} -``` - -```vue - - - -``` - -## Dropdown - -### `list-header` - -Displayed as the first item in the dropdown. No content by default. Parent element is the `
    `, -so this slot should contain a root `
  • `. +Displayed at the top of the component, above `.vs__dropdown-toggle`. - `search {string}` - the current search query - `loading {boolean}` - is the component loading - `searching {boolean}` - is the component searching - `filteredOptions {array}` - options filtered by the search text +- `deselect {function}` - function to deselect an option -```html - -``` + +<<< @/.vuepress/components/SlotHeader.vue -### `list-footer` +## `list-footer` Displayed as the last item in the dropdown. No content by default. Parent element is the `
      `, so this slot should contain a root `
    • `. @@ -148,34 +57,132 @@ so this slot should contain a root `
    • `. - `searching {boolean}` - is the component searching - `filteredOptions {array}` - options filtered by the search text -```html - + +<<< @/.vuepress/components/SlotListFooter.vue + +## `list-header` + +Displayed as the first item in the dropdown. No content by default. Parent element is the `
        `, +so this slot should contain a root `
      • `. + +- `search {string}` - the current search query +- `loading {boolean}` - is the component loading +- `searching {boolean}` - is the component searching +- `filteredOptions {array}` - options filtered by the search text + + +<<< @/.vuepress/components/SlotListHeader.vue + +## `no-options` + +The no options slot is displayed above `list-footer` in the dropdown when +`filteredOptions.length === 0`. + +- `search {string}` - the current search query +- `loading {boolean}` - is the component loading +- `searching {boolean}` - is the component searching + + +<<< @/.vuepress/components/SlotNoOptions.vue + +## `open-indicator` + +The open indicator is the caret icon on the component used to indicate dropdown status. + +```js +attributes: { + 'ref': 'openIndicator', + 'role': 'presentation', + 'class': 'vs__open-indicator', +} ``` -### `option` + +<<< @/.vuepress/components/SlotOpenIndicator.vue + +## `option` The current option within the dropdown, contained within `
      • `. - `option {Object}` - The currently iterated option from `filteredOptions` -```html - - {{ getOptionLabel(option) }} - + +<<< @/.vuepress/components/SlotOption.vue + +## `search` + +The search input has a lot of bindings, but they're grouped into `attributes` and `events`. Most +of the time, you will just be binding those two with `v-on="events"` and `v-bind="attributes"`. + +If you want the default styling, you'll need to add `.vs__search` to the input you provide. + +```js + /** + * Attributes to be bound to a search input. + */ + attributes: { + 'disabled': this.disabled, + 'placeholder': this.searchPlaceholder, + 'tabindex': this.tabindex, + 'readonly': !this.searchable, + 'id': this.inputId, + 'aria-autocomplete': 'list', + 'aria-labelledby': `vs${this.uid}__combobox`, + 'aria-controls': `vs${this.uid}__listbox`, + 'aria-activedescendant': this.typeAheadPointer > -1 + ? `vs${this.uid}__option-${this.typeAheadPointer}` + : '', + 'ref': 'search', + 'type': 'search', + 'autocomplete': this.autocomplete, + 'value': this.search, + }, + /** + * Events that this element should handle. + */ + events: { + 'compositionstart': () => this.isComposing = true, + 'compositionend': () => this.isComposing = false, + 'keydown': this.onSearchKeyDown, + 'blur': this.onSearchBlur, + 'focus': this.onSearchFocus, + 'input': (e) => this.search = e.target.value, + } ``` -### `no-options` + +<<< @/.vuepress/components/SlotSearch.vue{5-6} -The no options slot is displayed in the dropdown when `filteredOptions.length === 0`. +## `selected-option` -- `search {String}` - the current search text -- `searching {Boolean}` - if the component has search text +The text displayed within `selected-option-container`. -```vue - - Sorry, no matching options. - -``` +This slot doesn't exist if `selected-option-container` is implemented. + +- `option {Object}` - A selected option + + +<<< @/.vuepress/components/SlotSelectedOption.vue + +## `selected-option-container` + +This is the root element where `v-for="option in selectedValue"`. Most of the time you'll want to +use `selected-option`, but this container is useful if you want to disable the deselect button, +or have fine grain control over the markup. + +- `option {Object}` - Currently iterated selected option +- `deselect {Function}` - Method used to deselect a given option when `multiple` is true +- `disabled {Boolean}` - Determine if the component is disabled +- `multiple {Boolean}` - If the component supports the selection of multiple values + + +<<< @/.vuepress/components/SlotSelectedOptionContainer.vue + +## `spinner` + +- `loading {Boolean}` - if the component is in a loading state + + +<<< @/.vuepress/components/SlotSpinner.vue + +