Skip to content

Commit

Permalink
fix(ui): fix types
Browse files Browse the repository at this point in the history
affects: @varlet/ui
  • Loading branch information
haoziqaq committed Oct 15, 2021
1 parent c87784d commit ead022f
Show file tree
Hide file tree
Showing 25 changed files with 124 additions and 106 deletions.
8 changes: 4 additions & 4 deletions packages/varlet-ui/src/action-sheet/ActionSheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@

<script lang="ts">
import Ripple from '../ripple'
import Popup from '../popup'
import Icon from '../icon'
import VarPopup from '../popup'
import VarIcon from '../icon'
import { defineComponent, ref, watch } from 'vue'
import { props } from './props'
import { dt } from '../utils/shared'
Expand All @@ -62,8 +62,8 @@ export default defineComponent({
name: 'VarActionSheet',
directives: { Ripple },
components: {
[Popup.name]: Popup,
[Icon.name]: Icon,
VarPopup,
VarIcon,
},
inheritAttrs: false,
props,
Expand Down
6 changes: 2 additions & 4 deletions packages/varlet-ui/src/badge/Badge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
</template>

<script lang="ts">
import VarIcon from '../icon'
import { computed, defineComponent } from 'vue'
import { props } from './props'
import Icon from '../icon'
import { toNumber } from '../utils/shared'
import type { ComputedRef } from 'vue'
export default defineComponent({
name: 'VarBadge',
components: {
[Icon.name]: Icon,
},
components: { VarIcon },
inheritAttrs: false,
props,
setup(props, { slots }) {
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/button/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@

<script lang="ts">
import Ripple from '../ripple'
import Loading from '../loading'
import VarLoading from '../loading'
import { defineComponent } from 'vue'
import { props } from './props'
export default defineComponent({
name: 'VarButton',
components: {
[Loading.name]: Loading,
VarLoading,
},
directives: { Ripple },
props,
Expand Down
6 changes: 2 additions & 4 deletions packages/varlet-ui/src/checkbox-group/CheckboxGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</template>

<script lang="ts">
import FormDetails from '../form-details'
import VarFormDetails from '../form-details'
import { defineComponent, computed, watch, nextTick } from 'vue'
import { props } from './props'
import { useValidation } from '../utils/components'
Expand All @@ -21,9 +21,7 @@ import type { CheckboxGroupProvider } from './provide'
export default defineComponent({
name: 'VarCheckboxGroup',
components: {
[FormDetails.name]: FormDetails,
},
components: { VarFormDetails },
props,
setup(props) {
const max: ComputedRef<number | string | undefined> = computed(() => props.max)
Expand Down
8 changes: 4 additions & 4 deletions packages/varlet-ui/src/checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
</template>

<script lang="ts">
import Icon from '../icon'
import VarIcon from '../icon'
import VarFormDetails from '../form-details'
import Ripple from '../ripple'
import FormDetails from '../form-details'
import { defineComponent, ref, computed, watch, nextTick } from 'vue'
import { props } from './props'
import { useValidation } from '../utils/components'
Expand All @@ -63,8 +63,8 @@ export default defineComponent({
name: 'VarCheckbox',
directives: { Ripple },
components: {
[Icon.name]: Icon,
[FormDetails.name]: FormDetails,
VarIcon,
VarFormDetails,
},
props,
setup(props) {
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/chip/Chip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
</template>

<script lang="ts">
import Icon from '../icon'
import VarIcon from '../icon'
import { defineComponent, computed } from 'vue'
import { props } from './props'
import type { ComputedRef } from 'vue'
export default defineComponent({
name: 'VarChip',
components: {
[Icon.name]: Icon,
VarIcon,
},
inheritAttrs: false,
props,
Expand Down
8 changes: 4 additions & 4 deletions packages/varlet-ui/src/counter/Counter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
</template>

<script lang="ts">
import Icon from '../icon'
import VarIcon from '../icon'
import VarFormDetails from '../form-details'
import Ripple from '../ripple'
import FormDetails from '../form-details'
import { defineComponent, ref, watch, computed, nextTick } from 'vue'
import { Decimal } from 'decimal.js'
import { props } from './props'
Expand All @@ -79,8 +79,8 @@ const DELAY = 600
export default defineComponent({
name: 'VarCounter',
components: {
[Icon.name]: Icon,
[FormDetails.name]: FormDetails,
VarIcon,
VarFormDetails,
},
directives: { Ripple },
inheritAttrs: false,
Expand Down
8 changes: 4 additions & 4 deletions packages/varlet-ui/src/dialog/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
</template>

<script lang="ts">
import Popup from '../popup'
import Button from '../button'
import VarPopup from '../popup'
import VarButton from '../button'
import { props } from './props'
import { defineComponent, ref, watch } from 'vue'
import { dt } from '../utils/shared'
Expand All @@ -65,8 +65,8 @@ import type { Ref } from 'vue'
export default defineComponent({
name: 'VarDialog',
components: {
[Popup.name]: Popup,
[Button.name]: Button,
VarPopup,
VarButton,
},
inheritAttrs: false,
props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ exports[`test form with select 1`] = `
<div class=\\"var-select__select var-select--disabled\\" style=\\"text-align: left;\\">
<div>
<div class=\\"var-select__chips\\">
<transition-stub><span class=\\"var-chip var--box var-chip--normal var--inline-flex var-chip--null var-chip--round var-select__chip\\" var-select-cover=\\"\\"><span class=\\"var-chip--text-normal\\">选项1</span><span class=\\"var-chip--close\\"><i class=\\"var-icon var-icon--set var-icon-close-circle\\" style=\\"transition: all 0ms;\\"></i></span></span></transition-stub>
<transition-stub><span class=\\"var-chip var--box var-chip--small var--inline-flex var-chip--default var-chip--round var-select__chip\\" var-select-cover=\\"\\"><span class=\\"var-chip--text-small\\">选项1</span><span class=\\"var-chip--close\\"><i class=\\"var-icon var-icon--set var-icon-close-circle\\" style=\\"transition: all 0ms;\\"></i></span></span></transition-stub>
</div>
</div><i class=\\"var-icon var-icon--set var-icon-menu-down var-select__arrow\\" style=\\"transition: all 300ms;\\" var-select-cover=\\"\\"></i>
</div><label class=\\"var-select__placeholder var-select--placeholder-hint\\"></label>
Expand Down Expand Up @@ -350,7 +350,7 @@ exports[`test form with select 2`] = `
<div class=\\"var-select__select\\" style=\\"text-align: left;\\">
<div>
<div class=\\"var-select__chips\\">
<transition-stub><span class=\\"var-chip var--box var-chip--normal var--inline-flex var-chip--null var-chip--round var-select__chip\\" var-select-cover=\\"\\"><span class=\\"var-chip--text-normal\\">选项1</span><span class=\\"var-chip--close\\"><i class=\\"var-icon var-icon--set var-icon-close-circle\\" style=\\"transition: all 0ms;\\"></i></span></span></transition-stub>
<transition-stub><span class=\\"var-chip var--box var-chip--small var--inline-flex var-chip--default var-chip--round var-select__chip\\" var-select-cover=\\"\\"><span class=\\"var-chip--text-small\\">选项1</span><span class=\\"var-chip--close\\"><i class=\\"var-icon var-icon--set var-icon-close-circle\\" style=\\"transition: all 0ms;\\"></i></span></span></transition-stub>
</div>
</div><i class=\\"var-icon var-icon--set var-icon-menu-down var-select__arrow\\" style=\\"transition: all 300ms;\\" var-select-cover=\\"\\"></i>
</div><label class=\\"var-select__placeholder var-select--placeholder-hint\\"></label>
Expand Down Expand Up @@ -380,7 +380,7 @@ exports[`test form with select 3`] = `
<div class=\\"var-select__select var-select--error\\" style=\\"text-align: left;\\">
<div>
<div class=\\"var-select__chips\\">
<transition-stub><span class=\\"var-chip var--box var-chip--normal var--inline-flex var-chip--danger var-chip--round var-select__chip\\" var-select-cover=\\"\\"><span class=\\"var-chip--text-normal\\">选项1</span><span class=\\"var-chip--close\\"><i class=\\"var-icon var-icon--set var-icon-close-circle\\" style=\\"transition: all 0ms;\\"></i></span></span></transition-stub>
<transition-stub><span class=\\"var-chip var--box var-chip--small var--inline-flex var-chip--danger var-chip--round var-select__chip\\" var-select-cover=\\"\\"><span class=\\"var-chip--text-small\\">选项1</span><span class=\\"var-chip--close\\"><i class=\\"var-icon var-icon--set var-icon-close-circle\\" style=\\"transition: all 0ms;\\"></i></span></span></transition-stub>
</div>
</div><i class=\\"var-icon var-icon--set var-icon-menu-down var-select__arrow\\" style=\\"transition: all 300ms;\\" var-select-cover=\\"\\"></i>
</div><label class=\\"var-select__placeholder var-select--placeholder-hint\\"></label>
Expand Down
16 changes: 8 additions & 8 deletions packages/varlet-ui/src/image-preview/ImagePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
</template>

<script lang="ts">
import Swipe from '../swipe'
import SwipeItem from '../swipe-item'
import Icon from '../icon'
import Popup from '../popup'
import VarSwipe from '../swipe'
import VarSwipeItem from '../swipe-item'
import VarIcon from '../icon'
import VarPopup from '../popup'
import { defineComponent, ref, computed, watch } from 'vue'
import { props } from './props'
import { toNumber } from '../utils/shared'
Expand All @@ -92,10 +92,10 @@ const ANIMATION_DURATION = 200
export default defineComponent({
name: 'VarImagePreview',
components: {
[Swipe.name]: Swipe,
[SwipeItem.name]: SwipeItem,
[Popup.name]: Popup,
[Icon.name]: Icon,
VarSwipe,
VarSwipeItem,
VarPopup,
VarIcon,
},
inheritAttrs: false,
props,
Expand Down
8 changes: 4 additions & 4 deletions packages/varlet-ui/src/input/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
</template>

<script lang="ts">
import FormDetails from '../form-details'
import Icon from '../icon'
import VarFormDetails from '../form-details'
import VarIcon from '../icon'
import { defineComponent, getCurrentInstance, ref, computed, nextTick } from 'vue'
import { props } from './props'
import { isEmpty, isNumber, toNumber } from '../utils/shared'
Expand All @@ -108,8 +108,8 @@ import type { InputProvider } from './provide'
export default defineComponent({
name: 'VarInput',
components: {
[Icon.name]: Icon,
[FormDetails.name]: FormDetails,
VarIcon,
VarFormDetails,
},
props,
setup(props) {
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/input/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export const props = {
type: Array as PropType<Array<(v: string | number) => any>>,
},
onFocus: {
type: Function as PropType<(e: Event) => void>,
type: Function as PropType<(e: FocusEvent) => void>,
},
onBlur: {
type: Function as PropType<(e: Event) => void>,
type: Function as PropType<(e: FocusEvent) => void>,
},
onClick: {
type: Function as PropType<(e: Event) => void>,
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/list/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</template>

<script lang="ts">
import VarLoading from '../loading'
import Ripple from '../ripple'
import Loading from '../loading'
import { defineComponent, onMounted, onUnmounted, ref, nextTick } from 'vue'
import { getParentScroller, isHidden, toPxNum } from '../utils/elements'
import { props } from './props'
Expand All @@ -37,7 +37,7 @@ export default defineComponent({
name: 'VarList',
directives: { Ripple },
components: {
[Loading.name]: Loading,
VarLoading,
},
props,
setup(props) {
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/option/Option.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</template>

<script lang="ts">
import Checkbox from '../checkbox'
import VarCheckbox from '../checkbox'
import Ripple from '../ripple'
import { defineComponent, computed, ref, watch } from 'vue'
import { useSelect } from './provide'
Expand All @@ -46,7 +46,7 @@ export default defineComponent({
name: 'VarOption',
directives: { Ripple },
components: {
[Checkbox.name]: Checkbox,
VarCheckbox,
},
props,
setup(props) {
Expand Down
31 changes: 23 additions & 8 deletions packages/varlet-ui/src/picker/Picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
closeOnClickOverlay,
teleport,
show,
'onUpdate:show': (value) => $props['onUpdate:show']?.(value),
'onUpdate:show': handlePopupUpdateShow,
position: 'bottom',
class: 'var-picker__popup',
}
Expand Down Expand Up @@ -53,14 +53,14 @@
<div
class="var-picker__column"
v-for="c in scrollColumns"
:key="c"
:key="c.id"
@touchstart="handleTouchstart($event, c)"
@touchmove.prevent="handleTouchmove($event, c)"
@touchend="handleTouchend($event, c)"
>
<div
class="var-picker__scroller"
:ref="(el) => (c.scrollEl = el)"
:ref="(el) => getScrollEl(el, c)"
:style="{
transform: `translateY(${c.translate}px)`,
transitionDuration: `${c.duration}ms`,
Expand Down Expand Up @@ -92,18 +92,19 @@
</template>

<script lang="ts">
import Button from '../button'
import Popup from '../popup'
import VarButton from '../button'
import VarPopup from '../popup'
import { defineComponent, watch, ref, computed, Transition, toRaw } from 'vue'
import { props } from './props'
import { isArray, dt } from '../utils/shared'
import { toPxNum, getTranslate } from '../utils/elements'
import { pack } from '../locale'
import type { Ref, ComputedRef } from 'vue'
import type { Ref, ComputedRef, ComponentPublicInstance } from 'vue'
import type { CascadeColumn, NormalColumn } from './props'
import type { Texts } from './index'
export interface ScrollColumn {
id: number
touching: boolean
index: number
prevY: number | undefined
Expand All @@ -120,11 +121,13 @@ export interface ScrollColumn {
const MOMENTUM_RECORD_TIME = 300
const MOMENTUM_ALLOW_DISTANCE = 15
let sid = 0
export default defineComponent({
name: 'VarPicker',
components: {
[Button.name]: Button,
[Popup.name]: Popup,
VarButton,
VarPopup,
},
inheritAttrs: false,
props,
Expand All @@ -138,6 +141,14 @@ export default defineComponent({
const columnHeight: ComputedRef<number> = computed(() => optionCount.value * optionHeight.value)
let prevIndexes: number[] = []
const getScrollEl = (el: Element | ComponentPublicInstance | null, scrollColumn: ScrollColumn) => {
scrollColumn.scrollEl = el as HTMLElement
}
const handlePopupUpdateShow = (value: boolean) => {
props['onUpdate:show']?.(value)
}
const limitTranslate = (scrollColumn: ScrollColumn) => {
const START_LIMIT = optionHeight.value + center.value
const END_LIMIT = center.value - scrollColumn.column.texts.length * optionHeight.value
Expand Down Expand Up @@ -240,6 +251,7 @@ export default defineComponent({
return normalColumns.map((column: NormalColumn | any[]) => {
const normalColumn = (isArray(column) ? { texts: column } : column) as NormalColumn
const scrollColumn: ScrollColumn = {
id: sid++,
prevY: undefined,
momentumPrevY: undefined,
touching: false,
Expand Down Expand Up @@ -267,6 +279,7 @@ export default defineComponent({
const createChildren = (scrollColumns: ScrollColumn[], children: CascadeColumn[]) => {
if (isArray(children) && children.length) {
const scrollColumn: ScrollColumn = {
id: sid++,
prevY: undefined,
momentumPrevY: undefined,
touching: false,
Expand Down Expand Up @@ -370,6 +383,8 @@ export default defineComponent({
columnHeight,
center,
Transition,
getScrollEl,
handlePopupUpdateShow,
handleTouchstart,
handleTouchmove,
handleTouchend,
Expand Down
Loading

0 comments on commit ead022f

Please sign in to comment.