https://github.com/vinayakkulkarni/v-image
:camera: Tiny little component for input type=file (css free! style it as you want!)
https://github.com/vinayakkulkarni/v-image
image-component vue vuejs vuejs2
Last synced: 3 months ago
JSON representation
:camera: Tiny little component for input type=file (css free! style it as you want!)
- Host: GitHub
- URL: https://github.com/vinayakkulkarni/v-image
- Owner: vinayakkulkarni
- License: mit
- Created: 2017-09-21T10:13:33.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2025-07-01T19:19:17.000Z (12 months ago)
- Last Synced: 2025-07-02T00:10:02.219Z (12 months ago)
- Topics: image-component, vue, vuejs, vuejs2
- Language: Vue
- Homepage: https://v-image.netlify.app/
- Size: 8.34 MB
- Stars: 40
- Watchers: 2
- Forks: 4
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-vue-zh - V-εΎε
- awesome-vue - v-image β 12
- awesome-vue - v-image
- fucking-awesome-vue - v-image
- awesome-vue - v-image
- awesome-vue - v-image
- awesome-vue - v-image - Tiny little component for input type=file (css free! style it as you want!) ` π 2 months ago` (UI Components [π](#readme))
README
# [v-image](https://vinayakkulkarni.github.io/v-image/) π·
[](https://github.com/vinayakkulkarni/v-offline/actions/workflows/ci.yml)
[](https://github.com/vinayakkulkarni/v-offline/actions/workflows/codeql.yml)
[](https://github.com/vinayakkulkarni/v-offline/actions/workflows/shipjs-trigger.yml)
[](https://github.com/vinayakkulkarni/v-image/releases)
[](https://www.npmjs.com/package/v-image)
[](http://npm-stat.com/charts.html?package=v-image)
[](https://npm-stat.com/charts.html?package=v-image)
[](https://bundlephobia.com/package/v-image@latest)
[](https://github.com/vinayakkulkarni/v-image/blob/master/package.json)
[](https://deepscan.io/dashboard#view=project&tid=9055&pid=11604&bid=426884)
[](https://snyk.io/test/github/vinayakkulkarni/v-image)
[](https://github.com/vinayakkulkarni/v-image/blob/master/LICENSE)
[](https://github.com/vinayakkulkarni/v-image/graphs/contributors)
[](https://eslint.org/)
[](https://prettier.io/)
[](https://vitejs.dev/)
[](https://vuejs.org/)
[](https://www.typescriptlang.org/)
β οΈ Docs are for Vue 3, for Vue 2 docs, check [this tree](https://github.com/vinayakkulkarni/v-image/tree/v2.6.1#readme)
## Demo
[](https://stackblitz.com/edit/v-image?file=src/App.vue)
## Features
- πͺ Built with [TypeScript](https://www.typescriptlang.org/)
- π Built with [Vue 3](https://vuejs.org/)
- β‘ Zero dependencies.
## Table of Contents
- [v-image π·](#v-image-)
- [Demo](#demo)
- [Features](#features)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Build Setup](#build-setup)
- [Usage](#usage)
- [Example](#example)
- [API](#api)
- [Props](#props)
- [Events](#events)
- [Contributing](#contributing)
- [Author](#author)
### Installation
```bash
npm i v-image
```
### Build Setup
```bash
# install dependencies
$ npm install
# package lib
$ npm run build
```
### Usage
Global component:
```js
// main.ts
import { VImage } from 'v-image';
import { createApp } from 'vue';
const app = createApp({});
app.component('VImage', VImage);
```
Or use locally
```js
// component.vue
import { VImage } from 'v-image';
export default defineComponent({
components: {
VImage,
},
})
```
For Nuxt 3, create a file in `plugins/v-image.ts`
```js
import { VImage } from 'v-image';
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.component('VImage', VImage);
});
```
then import the file in `nuxt.config.{j|t}s`:
```js
export default {
// ...
plugins: [
// ...
{ src: '~/plugins/v-image', mode: 'client' },
// ...
],
// ...
};
```
### Example
```html
```
```js
import { defineComponent, ref } from 'vue';
import type { Ref } from 'vue';
import { VImage } from 'v-image';
export default defineComponent({
components: { VImage },
setup() {
const image: Ref<null | string> = ref(null);
const placeholder = ref({
image: 'https://picsum.photos/1000/1000',
alt: 'Placeholder Image',
imgClass: 'block rounded object-contain min-h-0 w-72',
btnClass:
'cursor-pointer inline-flex items-center justify-center mt-4 rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 w-72',
wrapper: 'p-4 max-w-xs w-full border border-gray-400 border-dotted',
});
const form = ref({
name: 'myImage',
label: 'Select Image',
accept: 'image/jpg',
});
const uploaded = ref({
wrapper: 'p-4 max-w-xs w-full border border-gray-400 border-dotted',
alt: 'User uploaded dope image',
imgClass: 'block rounded object-contain min-h-0 w-72',
btnClass:
'cursor-pointer inline-flex items-center justify-center mt-4 rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 w-72',
removeBtnText: 'Remove image',
});
const onImageLoad = (img: string) => {
image.value = img;
};
const onImageRemove = (deleted: boolean) => {
if (deleted) {
image.value = null;
}
};
return {
placeholder,
form,
uploaded,
onImageLoad,
onImageRemove,
};
},
});
```
### API
#### Props
| Name | Type | Required? | Default | Description |
| ------------------------ | ------ | --------- | ------------------------------- | -------------------------------------------------- |
| `wrapper` | String | No | '' | The wrapper classes for the top level `
` |
| `placeholder` | Object | No | - | The placeholder image & input related code |
| `placeholder.wrapper` | String | No | '' | Any wrapper classes for the placeholder `` |
| `placeholder.image` | String | No | 'https://picsum.photos/200x200' | The placeholder image |
| `placeholder.alt` | String | No | 'Placeholder Image' | The placeholder image alt attribute |
| `placeholder.imgClass` | String | No | '' | Any placeholder image classes |
| `placeholder.btnClass` | String | No | '' | `Select Image` button classes |
| `form` | Object | No | - | The placeholder input form |
| `form.name` | String | No | 'v-image' | Enable the label to interact with the `` |
| `form.label` | String | No | 'Select Image' | The label/button text |
| `form.accept` | String | No | 'image/\*' | Abilty to accept file types |
| `uploaded` | Object | No | - | The user uploaded image related `Object` |
| `uploaded.wrapper` | String | No | '' | Any wrapper classes for the uploaded image `` |
| `uploaded.alt` | String | No | 'Very Interesting Image' | The actual uploaded image alt attribute |
| `uploaded.imgClass` | String | No | '' | Uploaded image classes |
| `uploaded.btnClass` | String | No | '' | `Remove Image` button classes |
| `uploaded.removeBtnText` | String | No | 'Remove Image' | `Remove Image` button text |
#### Events
| Name | Returns | Description |
| ---------------- | ------- | ---------------------------------- |
| `@image-loaded` | String | Sends the image in `base64` format |
| `@image-removed` | Boolean | Emits `true` if image is removed |
## Contributing
1. Fork it ([https://github.com/vinayakkulkarni/v-image/fork](https://github.com/vinayakkulkarni/v-image/fork))
2. Create your feature branch (`git checkout -b feat/new-feature`)
3. Commit your changes (`git commit -Sam 'feat: add feature'`)
4. Push to the branch (`git push origin feat/new-feature`)
5. Create a new [Pull Request](https://github.com/vinayakkulkarni/v-image/compare)
_Note_:
1. Please contribute using [GitHub Flow](https://web.archive.org/web/20191104103724/https://guides.github.com/introduction/flow/)
2. Commits & PRs will be allowed only if the commit messages & PR titles follow the [conventional commit standard](https://www.conventionalcommits.org/), _read more about it [here](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum)_
3. PS. Ensure your commits are signed. _[Read why](https://withblue.ink/2020/05/17/how-and-why-to-sign-git-commits.html)_
## Author
**v-image** Β© [Vinayak](https://github.com/vinayakkulkarni), Released under the [MIT](./LICENSE) License.
Authored and maintained by Vinayak Kulkarni with help from contributors ([list](https://github.com/vinayakkulkarni/v-image/contributors)).
> [vinayakkulkarni.dev](https://vinayakkulkarni.dev) Β· GitHub [@vinayakkulkarni](https://github.com/vinayakkulkarni) Β· Twitter [@\_vinayak_k](https://twitter.com/_vinayak_k)