Skip to content

Commit

Permalink
Merge pull request #14 from Elliot-Alexander/run-sherif
Browse files Browse the repository at this point in the history
Update CI
  • Loading branch information
Elliot-Alexander authored Jan 13, 2024
2 parents bc9811b + 34445ee commit 86f78d6
Show file tree
Hide file tree
Showing 31 changed files with 168 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": ["playground"]
}
5 changes: 5 additions & 0 deletions .changeset/silver-beds-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vaul-vue": patch
---

Initial MVP of Vaul implementation in Vue
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
'extends': [
extends: [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-typescript',
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
node-version-file: '.nvmrc'
cache: 'pnpm'

- name: Install Dependencies
Expand All @@ -32,4 +32,4 @@ jobs:
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27 changes: 25 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ on:
branches-ignore:
- main
jobs:
sherif:
name: Monorepo Sherif
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'

- name: Run sherif
run: pnpm dlx sherif@latest

lint:
name: Lint and Format
runs-on: ubuntu-latest
Expand All @@ -17,7 +36,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
node-version-file: '.nvmrc'
cache: 'pnpm'

- name: Install dependencies
Expand All @@ -30,6 +49,7 @@ jobs:
run: pnpm run prettier:check

tests:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -41,12 +61,15 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
node-version-file: '.nvmrc'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Build package
run: pnpm run build-package

- name: Install Playwright browsers
run: pnpm dlx playwright install --with-deps

Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/pnpm-lock.yaml
/.gitignore
/.changeset/**.md
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}
}
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Vaul Vue

Vaul Vue is an unstyled drawer component for Vue that can be used as a Dialog replacement on tablet and mobile devices.
Vaul Vue is an unstyled drawer component for Vue that can be used as a Dialog replacement on tablet and mobile devices.
It uses [Radix Vue's Dialog primitive](https://www.radix-vue.com/components/dialog.html) under the hood and is a feature complete port of [Emil Kowalski's Vaul library](https://github.com/emilkowalski/vaul) (built for React).

## Installation
Expand All @@ -18,33 +18,27 @@ yarn add (not published yet sorry)
```

## Usage

```vue
<script setup lang="ts">
import {
DrawerRoot,
DrawerTrigger,
DrawerOverlay,
DrawerContent,
DrawerPortal,
} from 'vaul-vue'
import { DrawerRoot, DrawerTrigger, DrawerOverlay, DrawerContent, DrawerPortal } from 'vaul-vue'
</script>
<template>
<DrawerRoot>
<DrawerTrigger>
Open
</DrawerTrigger>
<DrawerPortal>
<DrawerOverlay />
<DrawerContent>
<p>Content</p>
</DrawerContent>
</DrawerPortal>
</DrawerRoot>
<DrawerRoot>
<DrawerTrigger> Open </DrawerTrigger>
<DrawerPortal>
<DrawerOverlay />
<DrawerContent>
<p>Content</p>
</DrawerContent>
</DrawerPortal>
</DrawerRoot>
</template>
```

## Credits

All credits go to these open-source works and resources

- Major credits go to [Emil Kowalski](https://emilkowal.ski/) for the original [Vaul library](https://github.com/emilkowalski/vaul).
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
"private": true,
"type": "module",
"scripts": {
"prettier:check": "prettier --check . --ignore-path .gitignore",
"prettier:fix": "prettier --write . --ignore-path .gitignore",
"prettier:check": "prettier --check .",
"prettier:fix": "prettier --write .",
"eslint:check": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --ignore-path .gitignore",
"eslint:fix": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"test": "pnpm -r test",
"release": "pnpm -r release"
"release": "pnpm -r release",
"build-package": "pnpm --filter vaul-vue build-only"
},
"packageManager": "[email protected]",
"devDependencies": {
"@changesets/cli": "^2.27.1",
"@rushstack/eslint-patch": "^1.3.3",
Expand Down
1 change: 1 addition & 0 deletions packages/vaul-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
Expand Down
4 changes: 1 addition & 3 deletions packages/vaul-vue/src/DrawerOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { computed } from 'vue'
import { injectDrawerRootContext } from './context'
const { overlayRef, snapPoints, isVisible, isOpen, shouldFade } = injectDrawerRootContext()
const hasSnapPoints = computed(
() => snapPoints && (snapPoints.value?.length ?? 0) > 0
)
const hasSnapPoints = computed(() => snapPoints && (snapPoints.value?.length ?? 0) > 0)
</script>

<template>
Expand Down
6 changes: 3 additions & 3 deletions packages/vaul-vue/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const TRANSITIONS = {
DURATION: 0.5,
EASE: [0.32, 0.72, 0, 1],
};
EASE: [0.32, 0.72, 0, 1]
}

export const VELOCITY_THRESHOLD = 0.4;
export const VELOCITY_THRESHOLD = 0.4
1 change: 1 addition & 0 deletions packages/vaul-vue/src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export function useDrawer(): DrawerRootContext {
onSnapPointChange
})

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { restorePositionSetting } = usePositionFixed({
isOpen,
modal: true,
Expand Down
54 changes: 27 additions & 27 deletions packages/vaul-vue/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
interface Style {
[key: string]: string;
[key: string]: string
}

const cache = new WeakMap();
const cache = new WeakMap()

export function isInView(el: HTMLElement): boolean {
const rect = el.getBoundingClientRect();
const rect = el.getBoundingClientRect()

if (!window.visualViewport) return false;
if (!window.visualViewport) return false

return (
rect.top >= 0 &&
rect.left >= 0 &&
// Need + 40 for safari detection
rect.bottom <= window.visualViewport.height - 40 &&
rect.right <= window.visualViewport.width
);
)
}

export function set(el?: Element | HTMLElement | null, styles?: Style, ignoreCache = false) {
if (!el || !(el instanceof HTMLElement) || !styles) return;
let originalStyles: Style = {};
if (!el || !(el instanceof HTMLElement) || !styles) return
const originalStyles: Style = {}

Object.entries(styles).forEach(([key, value]: [string, string]) => {
if (key.startsWith('--')) {
el.style.setProperty(key, value);
return;
el.style.setProperty(key, value)
return
}

originalStyles[key] = (el.style as any)[key];
(el.style as any)[key] = value;
});
originalStyles[key] = (el.style as any)[key]
;(el.style as any)[key] = value
})

if (ignoreCache) return;
if (ignoreCache) return

cache.set(el, originalStyles);
cache.set(el, originalStyles)
}

export function reset(el: Element | HTMLElement | null, prop?: string) {
if (!el || !(el instanceof HTMLElement)) return;
let originalStyles = cache.get(el);
if (!el || !(el instanceof HTMLElement)) return
const originalStyles = cache.get(el)

if (!originalStyles) {
return;
return
}

if (prop) {
(el.style as any)[prop] = originalStyles[prop];
;(el.style as any)[prop] = originalStyles[prop]
} else {
Object.entries(originalStyles).forEach(([key, value]) => {
(el.style as any)[key] = value;
});
;(el.style as any)[key] = value
})
}
}

export function getTranslateY(element: HTMLElement): number | null {
const style = window.getComputedStyle(element);
const style = window.getComputedStyle(element)
const transform =
// @ts-ignore
style.transform || style.webkitTransform || style.mozTransform;
let mat = transform.match(/^matrix3d\((.+)\)$/);
if (mat) return parseFloat(mat[1].split(', ')[13]);
mat = transform.match(/^matrix\((.+)\)$/);
return mat ? parseFloat(mat[1].split(', ')[5]) : null;
style.transform || style.webkitTransform || style.mozTransform
let mat = transform.match(/^matrix3d\((.+)\)$/)
if (mat) return parseFloat(mat[1].split(', ')[13])
mat = transform.match(/^matrix\((.+)\)$/)
return mat ? parseFloat(mat[1].split(', ')[5]) : null
}

export function dampenValue(v: number) {
return 8 * (Math.log(v + 1) - 2);
return 8 * (Math.log(v + 1) - 2)
}
14 changes: 8 additions & 6 deletions packages/vaul-vue/src/scroll/platformTests.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
function testPlatform(re: RegExp): boolean | undefined {
return typeof window !== 'undefined' && window.navigator != null ? re.test(window.navigator.platform) : undefined;
return typeof window !== 'undefined' && window.navigator != null
? re.test(window.navigator.platform)
: undefined
}

function isMac(): boolean | undefined {
return testPlatform(/^Mac/);
return testPlatform(/^Mac/)
}

function isIPhone(): boolean | undefined {
return testPlatform(/^iPhone/);
return testPlatform(/^iPhone/)
}

export function isSafari(): boolean | undefined {
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
}

function isIPad(): boolean | undefined {
return (
testPlatform(/^iPad/) ||
// iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
(isMac() && navigator.maxTouchPoints > 1)
);
)
}

export function isIOS(): boolean | undefined {
return isIPhone() || isIPad();
return isIPhone() || isIPad()
}
2 changes: 1 addition & 1 deletion packages/vaul-vue/src/scroll/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function addEvent<K extends keyof GlobalEventHandlersEventMap>(
}

// Sets a CSS property on an element, and returns a function to revert it to the previous value.
export function setStyle<T>(
export function setStyle(
element: HTMLElement,
style: keyof Omit<CSSStyleDeclaration, 'length' | 'parentRule' | number | typeof Symbol.iterator>,
value: string
Expand Down
4 changes: 2 additions & 2 deletions packages/vaul-vue/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface SnapPoint {
fraction: number;
height: number;
fraction: number
height: number
}
Loading

0 comments on commit 86f78d6

Please sign in to comment.