|
| 1 | +# vue-blob-select |
| 2 | + |
| 3 | +vue-blob-select is a fork of [blob-select](https://github.com/Blobfolio/blob-select), reimagined as a [Vue.js](https://vuejs.org/) component. |
| 4 | + |
| 5 | +Both plugins provide an easy way to style pesky `<select>` elements, emphasizing markup simplicity and performance. Both plugins, also, integrate perfectly well with Vue. (Though obviously, this one *only* works with Vue.) |
| 6 | + |
| 7 | +So why the fork? |
| 8 | + |
| 9 | +Because the original [blob-select](https://github.com/Blobfolio/blob-select) is dependency-free, it contains a lot of code that is redundant when a framework like Vue is also present. Cutting those bits out reduces the size of the Javascript by over 50%. |
| 10 | + |
| 11 | +Hooking into the complex DOM capabilities of Vue also provide some runtime performance gains, particularly as applied to change detection and repainting. |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +##### Table of Contents |
| 16 | + |
| 17 | +1. [Features](#features) |
| 18 | +2. [Requirements](#requirements) |
| 19 | +3. [Use](#use) |
| 20 | + * [Installation](#installation) |
| 21 | + * [Configuration](#configuration) |
| 22 | +4. [Styling](#styling) |
| 23 | +5. [License](#license) |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +## Features |
| 30 | + |
| 31 | +vue-blob-select has all the same features as [blob-select](https://github.com/Blobfolio/blob-select#features). For more details, check out that README. |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +## Requirements |
| 38 | + |
| 39 | +vue-blob-select is a Vue component, and as such requires [Vue.js](https://vuejs.org/). But other than that, there are no special dependencies. |
| 40 | + |
| 41 | +It is compatible with all major modern web browsers, and ~~the browser that just won't die~~ IE 11. |
| 42 | + |
| 43 | +This plugin does make use of some ES6 markup like `let` and `const`. If your project needs to support *old* browsers, you will need to first transpile `vue-blobselect.min.js` to ES5 with a tool like [Babel](https://babeljs.io/), then serve that copy to visitors. |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +## Use |
| 50 | + |
| 51 | + |
| 52 | +### Installation |
| 53 | + |
| 54 | +Grab a copy of `dist/vue-blobselect.min.js` and throw it onto the page: |
| 55 | + |
| 56 | +```html |
| 57 | +<script src="/path/to/vue.min.js"></script> |
| 58 | +<script src="/path/to/vue-blobselect.min.js"></script> |
| 59 | +<script src="/path/to/your-vue-project.min.js"></script> |
| 60 | +``` |
| 61 | + |
| 62 | +If a global `window.Vue` exists, the component should self-register. Otherwise you can register it like any other component via something like: |
| 63 | + |
| 64 | +```javascript |
| 65 | +import blobSelect from './vue-blobselect.min.js'; |
| 66 | +Vue.component(blobSelect); |
| 67 | +``` |
| 68 | + |
| 69 | +The `dist/` folder also includes an example stylesheet and icon for the search bar to help get you started. Of course, you can also write styles from scratch; the generated markup is pretty straight-forward. :) |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +### Configuration |
| 75 | + |
| 76 | +While the features and eventual markup of this fork maintain full parity with [blob-select](https://github.com/Blobfolio/blob-select), the configuration for this plugin is handled in a more Vue-appropriate way. |
| 77 | + |
| 78 | +```html |
| 79 | +<blob-select v-model="some.model" :any-props="some.value"…></blob-select> |
| 80 | +``` |
| 81 | + |
| 82 | +In case it wasn't obvious, the component has bi-directional `model` support, so you can bind the `<select>` value to any Vue data you want. To treat values numerically, use `v-model.number="foo"` in combination with `value-type='number'`. Otherwise it's strings all the way down. |
| 83 | + |
| 84 | +The following properties can be set on the component. To set them dynamically (to e.g. Vue data), prefix the field with a `:`, otherwise if passing a literal, just throw it in as any old attribute. |
| 85 | + |
| 86 | +Any attributes not mentioned below will be copied to the `.blobselect` container. You can set classes in this way; they'll just be merged with the plugin's. |
| 87 | + |
| 88 | +| Type | Key | Description | Default | |
| 89 | +| ---- | --- | ----------- | ------- | |
| 90 | +| *string* | **id** | An ID to apply to the true `<select>` field. | `"blobselect"` | |
| 91 | +| *string* | **name** | A name to apply to the true `<select>` field. | `"blobselect"` | |
| 92 | +| *array* | **items** | These are your `<option>`s. See below for more information. | `[]` | |
| 93 | +| *bool* | **disabled** | Disable the entire field. | `FALSE` | |
| 94 | +| *bool* | **multiple** | Mimic `[multiple]` behaviors. | `FALSE` | |
| 95 | +| *bool* | **placeholder** | Enable a placeholder-like null `<option>`. | `FALSE` | |
| 96 | +| *bool* | **required** | Mark the field required. | `FALSE` | |
| 97 | +| *bool* | **search** | Enable the search/filter bar. | `FALSE` | |
| 98 | +| *string* | **sort** | Sort items either `"ASC"` or `"DESC"`. | `""` (no sorting) | |
| 99 | +| *string* | **field-placeholder** | When **placeholder** is `TRUE` and no value is selected, this text will appear in the main field. | `"---"` | |
| 100 | +| *string* | **label-placeholder** | When **placeholder** is `TRUE`, a null `<option>` with this text will be added to the menu. | `"---"` | |
| 101 | +| *string* | **label-type** | If **sort** is enabled, you can set this to `"number"` to treat labels as numbers when sorting. | `"string"` | |
| 102 | +| *string* | **value-type** | Set this to `"number"` to treat values as numbers rathre than strings. If binding a model, also be sure to use the `.number` modifier. | `"string"` | |
| 103 | + |
| 104 | +#### Items |
| 105 | + |
| 106 | +Items (i.e. `<option>`s) should be passed as an `Array` via the `:items="[…]"` attribute on the component. |
| 107 | + |
| 108 | +Each item — an element of the items array — can be either a simple, flat value like `"foo"`, or an object specifying that item's properties. |
| 109 | + |
| 110 | +For flat items, the value and label will be the same, e.g. `<option value="foo">foo</option>`. |
| 111 | + |
| 112 | +The following settings can be specified for any item defined as an object: |
| 113 | + |
| 114 | +| Type | Key | Description | Default | |
| 115 | +| ---- | --- | ----------- | ------- | |
| 116 | +| *string* | **group** | A group label to mimic `<optgroup>` suborganization. | `""` | |
| 117 | +| *mixed* | **label** | The item label. The data type should match the main **label-type** property. | `""` or `0` | |
| 118 | +| *mixed* | **value** | The item value. The data type should match the main **value-type** property. | `""` or `0` | |
| 119 | +| *bool* | **disabled** | Mark the item disabled. If the component itself is disabled, this setting has no effect. | `FALSE` | |
| 120 | + |
| 121 | +To see an example, check out `src/demo.html`. |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +## Styling |
| 128 | + |
| 129 | +The markup resulting from vue-blob-select is identical to that generated by the original [blob-select](https://github.com/Blobfolio/blob-select#styling). For more details, check out that README. |
| 130 | + |
| 131 | +Otherwise the SCSS source folder includes example styles to get you started. |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | +## License |
| 138 | + |
| 139 | +Copyright © 2018 [Blobfolio, LLC](https://blobfolio.com) <hello@blobfolio.com> |
| 140 | + |
| 141 | +This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2. |
| 142 | + |
| 143 | + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
| 144 | + Version 2, December 2004 |
| 145 | + |
| 146 | + Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> |
| 147 | + |
| 148 | + Everyone is permitted to copy and distribute verbatim or modified |
| 149 | + copies of this license document, and changing it is allowed as long |
| 150 | + as the name is changed. |
| 151 | + |
| 152 | + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
| 153 | + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
| 154 | + |
| 155 | + 0. You just DO WHAT THE FUCK YOU WANT TO. |
| 156 | + |
| 157 | +### Donations |
| 158 | + |
| 159 | +<table> |
| 160 | + <tbody> |
| 161 | + <tr> |
| 162 | + <td width="200"><img src="https://blobfolio.com/wp-content/themes/b3/svg/btc-github.svg" width="200" height="200" alt="Bitcoin QR" /></td> |
| 163 | + <td width="450">If you have found this work useful and would like to contribute financially, Bitcoin tips are always welcome!<br /><br /><strong>1Af56Nxauv8M1ChyQxtBe1yvdp2jtaB1GF</strong></td> |
| 164 | + </tr> |
| 165 | + </tbody> |
| 166 | +</table> |
0 commit comments