-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mr.Mao
committed
May 25, 2023
1 parent
74e4e38
commit 2f33d5c
Showing
8 changed files
with
174 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# @hairy/vue-components | ||
|
||
## 0.1.0 | ||
|
||
### Minor Changes | ||
|
||
- chore: publish vue-components@0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './src/CollapseTransition' | ||
export * from './src/Field' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@hairy/vue-components", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"main": "index.ts", | ||
"publishConfig": { | ||
"main": "index.cjs.js", | ||
"types": "./index.d.ts", | ||
"module": "./index.esm.js", | ||
"unpkg": "./index.iife.min.js", | ||
"jsdelivr": "./index.iife.min.js", | ||
"exports": { | ||
".": { | ||
"import": "./index.esm.js", | ||
"require": "./index.cjs.js" | ||
}, | ||
"./*": "./*" | ||
}, | ||
"linkDirectory": false | ||
}, | ||
"scripts": { | ||
"build": "ptsup index.ts --dts --meta" | ||
}, | ||
"dependencies": { | ||
"css-render": "^0.15.12", | ||
"vue-demi": "^0.14.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* eslint-disable @typescript-eslint/no-use-before-define */ | ||
import type { DefineComponent, TransitionProps } from 'vue-demi' | ||
import { Transition, defineComponent, h } from 'vue-demi' | ||
import CssRender from 'css-render' | ||
|
||
const { c } = CssRender() | ||
|
||
export const CollapseTransition: DefineComponent = defineComponent({ | ||
name: 'CollapseTransition', | ||
setup(_, { slots }) { | ||
const on = { | ||
onBeforeEnter(el: HTMLDivElement) { | ||
el.classList.add('collapse-transition') | ||
if (!el.dataset) | ||
(el.dataset as any) = {} | ||
|
||
el.dataset.oldPaddingTop = el.style.paddingTop | ||
el.dataset.oldPaddingBottom = el.style.paddingBottom | ||
|
||
el.style.height = '0' | ||
el.style.paddingTop = '0' | ||
el.style.paddingBottom = '0' | ||
}, | ||
onEnter(el: HTMLDivElement) { | ||
el.dataset.oldOverflow = el.style.overflow | ||
if (el.scrollHeight !== 0) { | ||
el.style.height = `${el.scrollHeight}px` | ||
el.style.paddingTop = el.dataset.oldPaddingTop || '0' | ||
el.style.paddingBottom = el.dataset.oldPaddingBottom || '0' | ||
} | ||
else { | ||
el.style.height = '' | ||
el.style.paddingTop = el.dataset.oldPaddingTop || '0' | ||
el.style.paddingBottom = el.dataset.oldPaddingBottom || '0' | ||
} | ||
|
||
el.style.overflow = 'hidden' | ||
}, | ||
onAfterEnter(el: HTMLDivElement) { | ||
// for safari: remove class then reset height is necessary | ||
el.classList.remove('collapse-transition') | ||
el.style.height = '' | ||
el.style.overflow = el.dataset.oldOverflow || '0' | ||
}, | ||
|
||
onBeforeLeave(el: HTMLDivElement) { | ||
if (!el.dataset) | ||
(el.dataset as any) = {} | ||
el.dataset.oldPaddingTop = el.style.paddingTop | ||
el.dataset.oldPaddingBottom = el.style.paddingBottom | ||
el.dataset.oldOverflow = el.style.overflow | ||
|
||
el.style.height = `${el.scrollHeight}px` | ||
el.style.overflow = 'hidden' | ||
}, | ||
|
||
onLeave(el: HTMLDivElement) { | ||
if (el.scrollHeight !== 0) { | ||
// for safari: add class after set height, or it will jump to zero height suddenly, weired | ||
el.classList.add('collapse-transition') | ||
// fix #968 collapse animation failure. | ||
// in vue3.0.4, transitionProperty is set 'none' to avoid 'v-leave-from' issue | ||
el.style.transitionProperty = 'height' | ||
el.style.height = '0' | ||
el.style.paddingTop = '0' | ||
el.style.paddingBottom = '0' | ||
} | ||
}, | ||
|
||
onAfterLeave(el: HTMLDivElement) { | ||
el.classList.remove('collapse-transition') | ||
el.style.height = '' | ||
el.style.overflow = el.dataset.oldOverflow || '0' | ||
el.style.paddingTop = el.dataset.oldPaddingTop || '0' | ||
el.style.paddingBottom = el.dataset.oldPaddingBottom || '0' | ||
}, | ||
} | ||
style.mount() | ||
return () => h(Transition, on as unknown as TransitionProps, slots) | ||
}, | ||
}) | ||
|
||
const style = c('.collapse-transition', { | ||
transition: '0.2s height ease-in-out, 0.2s padding-top ease-in-out,0.2s padding-bottom ease-in-out', | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Component, PropType, VNode } from 'vue-demi' | ||
import { defineComponent, h } from 'vue-demi' | ||
|
||
export const Field = defineComponent({ | ||
name: 'Field', | ||
props: { | ||
is: { | ||
type: [String, Number, Object] as PropType<string | number | VNode | Component>, | ||
default: '', | ||
}, | ||
}, | ||
setup(props) { | ||
return () => { | ||
if (typeof props.is === 'string' || typeof props.is === 'number') | ||
return props.is | ||
return props.is ? h(props.is) : null | ||
} | ||
}, | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.