Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
steadymoka committed Jul 2, 2021
0 parents commit de0cc2a
Show file tree
Hide file tree
Showing 23 changed files with 11,743 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
plugins: ['prettier'],
overrides: [
{
files: ['**/*.ts', '**/*.vue'],
parser: 'vue-eslint-parser',
extends: ['plugin:vue/essential', 'stable', 'stable/typescript'],
parserOptions: {
extraFileExtensions: ['.vue'],
parser: '@typescript-eslint/parser',
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
},
{
files: ['**/*.js'],
extends: ['stable'],
},
],
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules

/lib
/example-dist
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "semi": false, "singleQuote": true }
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/node_modules": true
},
"editor.formatOnSave": true
}
96 changes: 96 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Vue Refreshable Scroll View

<p>
<a href="https://npmcharts.com/compare/vue-refreshable-scroll-view?minimal=true"><img alt="Downloads" src="https://img.shields.io/npm/dt/vue-refreshable-scroll-view.svg?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/vue-refreshable-scroll-view"><img alt="Version" src="https://img.shields.io/npm/v/vue-refreshable-scroll-view.svg?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/vue-refreshable-scroll-view"><img alt="License" src="https://img.shields.io/npm/l/vue-refreshable-scroll-view.svg?style=flat-square" /></a>
<img alt="VueJS 3.x" src="https://img.shields.io/badge/vue.js-3.x-brightgreen.svg?style=flat-square" />
<img alt="Language Typescript" src="https://img.shields.io/badge/language-Typescript-007acc.svg?style=flat-square" />
</p>

iOS Style Vue component (for Vue 3.0) that you can pull to refresh.

[See Example](https://) ([sources](./example))

## Installation

```bash
npm i vue-refreshable-scroll-view
```

## Usage

```js
import { createApp } from 'vue'
import RefreshableScrollView from 'vue-refreshable-scroll-view'

const app = createApp(/* */)

app.use(RefreshableScrollView) // export default is plugin
```

**Local Registration**

[Vue3 Local Registration Guide](https://v3.vuejs.org/guide/component-registration.html#local-registration)

```vue
<template>
<div class="h-screen overflow-y-hidden">
<RefreshableScrollView
class="h-full overflow-y-auto"
:on-refresh="onRefersh"
>
<template #loading="{ state, progress }">
<div>
{{ state }}
</div>
</template>
<div>
<template v-for="(item, index) in items" :key="index">
<div>
{{ item }}
</div>
</template>
</div>
</RefreshableScrollView>
</div>
</template>
<script>
import { RefreshableScrollView } from 'vue-refreshable-scroll-view'
export default {
components: {
RefreshableScrollView,
},
methods: {
async onRefersh() {
await work()
},
},
}
</script>
```

## Options

### Props

| Name | Type | Default | Example |
| ----------------- | :--------- | ------- | ---------------- |
| distanceToRefresh | `number` | `42` | |
| damping | `number` | `224` | |
| scale | `number` | `0.6` | between 0 ~ 1 |
| onRefresh | `function` | `null` | `async function` |

### Events

| Name | Type |
| ------------ | :------ |
| scroll:event | `event` |

### Slots

| Name | Prop | Default |
| ------- | :------------------------------------ | ------------- |
| default | `{ }` | |
| loading | `{ state: string, progress: number }` | `{{ state }}` |
5 changes: 5 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: [
'@commitlint/config-conventional',
],
}
4 changes: 4 additions & 0 deletions entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import RefreshableScrollView from './src'

export * from './src'
export default RefreshableScrollView
41 changes: 41 additions & 0 deletions example/Example.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template>
<div class="flex flex-col h-screen">
<h2 class="m-4 text-4xl font-bold">Refreshable ScrollView</h2>
<h4 class="mx-4 mb-2 text-lg text-gray-400">
iOS Style Vue component that you can pull to refresh.
</h4>
<RefreshableScrollView
class="flex-grow overflow-y-auto"
:on-refresh="onRefersh"
>
<template #loading="{ state, progress }">
<div class="grid w-full h-full text-gray-500 place-items-center">
{{ state }}
</div>
</template>
<div class="px-2">
<template v-for="(item, index) in items" :key="index">
<div class="py-2">
{{ item }}
</div>
</template>
</div>
</RefreshableScrollView>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
data() {
return {
items: [...Array(51).keys()],
}
},
methods: {
async onRefersh() {
await new Promise((res) => setTimeout(res, 2000))
},
},
})
</script>
12 changes: 12 additions & 0 deletions example/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import './example.css'

import { createApp } from 'vue'
import RefreshableScrollView from 'refreshable-scroll-view'

import Example from './Example.vue'

const app = createApp(Example)

app.use(RefreshableScrollView)

app.mount('#app')
3 changes: 3 additions & 0 deletions example/example.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
16 changes: 16 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<title>Vue Refreshable Scroll View Sample</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/entry.ts"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions example/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'refreshable-scroll-view': resolve(__dirname, '../src'),
},
},
build: {
outDir: resolve(__dirname, '../example-dist'),
},
})
Loading

0 comments on commit de0cc2a

Please sign in to comment.