Browse Source

style: popup

suzigang 4 years ago
parent
commit
b2d3b75dfe

+ 9 - 20
src/packages/checkbox/index.vue

@@ -1,6 +1,6 @@
 <template>
   <view>
-    <label :class="['nut-checkbox', 'nut-checkbox-size-' + currentSize]">
+    <view :class="['nut-checkbox', 'nut-checkbox-size-' + currentSize]">
       <input
         type="checkbox"
         :name="name"
@@ -10,13 +10,13 @@
         :value="submittedValue"
         @change="changeEvt"
       />
-      <span class="nut-checkbox-label" v-if="label">
+      <view class="nut-checkbox-label" v-if="label">
         {{ label }}
-      </span>
-      <span class="nut-checkbox-label" v-else>
+      </view>
+      <view class="nut-checkbox-label" v-else>
         <slot></slot>
-      </span>
-    </label>
+      </view>
+    </view>
   </view>
 </template>
 <script lang="ts">
@@ -57,7 +57,7 @@ export default create({
     },
     submittedValue: {
       type: String,
-      default: 'on' // HTML default
+      default: 'on'
     },
     checked: {
       type: Boolean,
@@ -75,8 +75,8 @@ export default create({
   setup(props, { emit }) {
     const parentGroup = inject('checkboxgroup', {
       parentNode: false,
-      changeVal: val => {
-        console.log();
+      changeVal: (val: number) => {
+        console.log(1);
       }
     });
     const parentProps = getCurrentInstance()?.parent?.props;
@@ -93,21 +93,10 @@ export default create({
         return isCheckedVal;
       }
     });
-    // const isCheckedVal = props.modelValue == props.trueValue || props.checked;
-    // const isChecked = ref(isCheckedVal);
     const isObject = obj => {
       return obj !== null && typeof obj === 'object';
     };
 
-    // const looseEqual = (a, b) => {
-    //   return (
-    //     a == b ||
-    //     (isObject(a) && isObject(b)
-    //       ? JSON.stringify(a) === JSON.stringify(b)
-    //       : false)
-    //   );
-    // };
-
     const isDisabled = computed(() => {
       if (parentGroup && parentGroup.parentNode) {
         return parentProps?.disabled;

+ 2 - 21
src/packages/popup/demo.vue

@@ -7,7 +7,7 @@
       @click="state.showBasic = true"
     ></nut-cell>
     <nut-popup
-      popClass="popclass"
+      pop-class="popclass"
       :style="{ padding: '30px 50px' }"
       v-model:show="state.showBasic"
       >正文</nut-popup
@@ -99,22 +99,6 @@
       :style="{ height: '30%' }"
       v-model:show="state.showRound"
     ></nut-popup>
-    <!-- <h2>组合弹框</h2> -->
-    <!-- <nut-cell title="组合弹框" is-link @click="state.showCombination = true"></nut-cell>
-    <nut-popup
-      id="combination"
-      :style="{ padding: '30px 50px' }"
-      v-model:show="state.showCombination"
-      >正文</nut-popup
-    >
-    <nut-popup
-      id="combination"
-      position="bottom"
-      closeable
-      round
-      :style="{ height: '30%' }"
-      v-model:show="state.showCombination"
-    ></nut-popup> -->
     <h2>指定挂载节点</h2>
     <nut-cell
       title="指定挂载节点"
@@ -154,7 +138,4 @@ export default createDemo({
 });
 </script>
 
-<style lang="scss" scoped>
-.nut-temp {
-}
-</style>
+<style lang="scss" scoped></style>

+ 18 - 18
src/packages/popup/doc.md

@@ -92,33 +92,33 @@ app.use(Popup);
 
 | 参数                   | 说明                                                        | 类型           | 默认值      |
 | ---------------------- | ----------------------------------------------------------- | -------------- | ----------- |
-| show                   | 当前组件是否显示                                            | Boolean        | false       |
-| z-index                | 遮罩层级                                                    | String、Number | 2000        |
-| duration               | 动画时长,单位秒                                            | String、Number | 0.3         |
+| show                   | 当前组件是否显示                                            | Boolean        | `false`       |
+| z-index                | 遮罩层级                                                    | String、Number | `2000`        |
+| duration               | 动画时长,单位秒                                            | String、Number | `0.3`         |
 | overlay-class          | 自定义遮罩类名                                              | String         | -           |
 | overlay-style          | 自定义遮罩样式                                              | CSSProperties  | -           |
-| lock-scroll            | 背景是否锁定                                                | Boolean        | false       |
-| overlay                | 是否显示遮罩                                                | Boolean        | true        |
-| close-on-click-overlay | 是否点击遮罩关闭                                            | Boolean        | true        |
-| position               | 弹出位置(top,bottom,left,right,center)                    | String         | "center"    |
+| lock-scroll            | 背景是否锁定                                                | Boolean        | `false`       |
+| overlay                | 是否显示遮罩                                                | Boolean        | `true`        |
+| close-on-click-overlay | 是否点击遮罩关闭                                            | Boolean        | `true`        |
+| position               | 弹出位置(top,bottom,left,right,center)                    | String         | `"center"`    |
 | transition             | 动画名                                                      | String         | -           |
 | style                  | 自定义弹框样式                                              | CSSProperties  | -           |
 | pop-class               | 自定义弹框类名                    | String         | -    |
-| closeable              | 是否显示关闭按钮                                            | Boolean        | true        |
-| close-icon-position    | 关闭按钮位置(top-left,top-right,bottom-left,bottom-right) | String         | "top-right" |
-| close-icon             | 自定义 Icon                                                 | String         | "close"     |
-| destroy-on-close       | 组件销毁后是否关闭                                          | Boolean        | true        |
-| round                  | 是否显示圆角                                                | Boolean        | false       |
-| teleport               | 指定挂载节点                                                | String         | "body"      |
+| closeable              | 是否显示关闭按钮                                            | Boolean        | `true`        |
+| close-icon-position    | 关闭按钮位置(top-left,top-right,bottom-left,bottom-right) | String         | `"top-right"` |
+| close-icon             | 自定义 Icon                                                 | String         | `"close"`     |
+| destroy-on-close       | 组件销毁后是否关闭                                          | Boolean        | `true`        |
+| round                  | 是否显示圆角                                                | Boolean        | `false`       |
+| teleport               | 指定挂载节点                                                | String         | `"body"`      |
 
 ### Events
 
 | 事件名           | 说明                   | 回调参数     |
 | ---------------- | ---------------------- | ------------ |
-| click            | 点击弹框时触发         | event: Event |
-| click-close-icon | 点击关闭图标时触发     | event: Event |
+| click            | 点击弹框时触发         | `event: Event` |
+| click-close-icon | 点击关闭图标时触发     | `event: Event` |
 | open             | 打开弹框时触发         | -            |
 | close            | 关闭弹框时触发         | -            |
-| opend            | 遮罩打开动画结束时触发 | event: Event |
-| closed           | 遮罩关闭动画结束时触发 | event: Event |
-| click-overlay    | 点击遮罩触发           | event: Event |
+| opend            | 遮罩打开动画结束时触发 | `event: Event` |
+| closed           | 遮罩关闭动画结束时触发 | `event: Event` |
+| click-overlay    | 点击遮罩触发           | `event: Event` |

+ 1 - 1
src/packages/popup/index.scss

@@ -75,7 +75,7 @@
   position: fixed;
   max-height: 100%;
   overflow-y: auto;
-  background-color: #fff;
+  background-color: $white;
   transition: transform 0.3s;
   -webkit-overflow-scrolling: touch;
 }

+ 31 - 36
src/packages/popup/index.vue

@@ -1,20 +1,20 @@
 <template>
   <Teleport :to="teleport">
     <nut-overlay
-      :show="show"
+      :show="show && overlay"
       :class="overlayClass"
       :style="overlayStyle"
-      :zIndex="state.zIndex"
+      :z-index="zIndex"
       :duration="duration"
       @click="onClickOverlay"
     />
     <Transition
-      :name="state.transitionName"
+      :name="transitionName"
       @after-enter="onOpened"
       @after-leave="onClosed"
     >
       <view v-show="show" :class="classes" :style="popStyle" @click="onClick">
-        <slot v-if="state.showSlot"></slot>
+        <slot v-if="showSlot"></slot>
         <nut-icon
           v-if="closeable"
           @click="onClickCloseIcon"
@@ -39,7 +39,8 @@ import {
   computed,
   reactive,
   PropType,
-  CSSProperties
+  CSSProperties,
+  toRefs
 } from 'vue';
 import { useLockScroll } from './use-lock-scroll';
 import { overlayProps } from './../overlay/index.vue';
@@ -47,17 +48,9 @@ import overlay from '@/packages/overlay/index.vue';
 import { createComponent } from '@/utils/create';
 const { componentName, create } = createComponent('popup');
 
-// let _global = {
-//   zIndex: 2000,
-//   overLayCount: 0
-// };
-
 let _zIndex = 2000;
 
 const popupProps = {
-  id: {
-    type: [String, Number]
-  },
   position: {
     type: String,
     default: 'center'
@@ -99,6 +92,11 @@ const popupProps = {
     default: 'body'
   },
 
+  overlay: {
+    type: Boolean,
+    default: true
+  },
+
   round: {
     type: Boolean,
     default: false
@@ -122,15 +120,13 @@ export default create({
   ],
 
   setup(props, { emit }) {
-    // if (props.id) console.log(props.id);
-    let opened;
-    let keepAlive;
-    // let ocount = 1;
     const state = reactive({
       zIndex: 0,
       showSlot: true,
       transitionName: `popup-fade-${props.position}`,
-      overLayCount: 1
+      overLayCount: 1,
+      keepAlive: false,
+      opened: false
     });
 
     const [lockScroll, unlockScroll] = useLockScroll(() => props.lockScroll);
@@ -154,11 +150,11 @@ export default create({
     });
 
     const open = () => {
-      if (!opened) {
+      if (!state.opened) {
         if (props.zIndex !== undefined) {
           _zIndex = Number(props.zIndex);
         }
-        opened = true;
+        state.opened = true;
         lockScroll();
         state.zIndex = ++_zIndex;
 
@@ -169,8 +165,8 @@ export default create({
     };
 
     const close = () => {
-      if (opened) {
-        opened = false;
+      if (state.opened) {
+        state.opened = false;
         unlockScroll();
         emit('update:show', false);
         if (props.destroyOnClose) {
@@ -181,32 +177,31 @@ export default create({
       }
     };
 
-    const onClick = e => {
+    const onClick = (e: Event) => {
       emit('click', e);
     };
 
-    const onClickCloseIcon = e => {
+    const onClickCloseIcon = (e: Event) => {
       emit('click-close-icon', e);
       close();
     };
 
-    const onClickOverlay = e => {
+    const onClickOverlay = (e: Event) => {
       if (props.closeOnClickOverlay) {
         emit('click-overlay', e);
         close();
       }
     };
 
-    const onOpened = e => {
+    const onOpened = (e: Event) => {
       emit('opend', e);
     };
 
-    const onClosed = e => {
+    const onClosed = (e: Event) => {
       emit('closed', e);
     };
 
     onMounted(() => {
-      // console.log(props.id);
       props.transition
         ? (state.transitionName = props.transition)
         : (state.transitionName = `popup-slide-${props.position}`);
@@ -219,22 +214,22 @@ export default create({
     });
 
     onBeforeMount(() => {
-      if (opened) {
+      if (state.opened) {
         unlockScroll();
       }
     });
 
     onActivated(() => {
-      if (keepAlive) {
+      if (state.keepAlive) {
         emit('update:show', true);
-        keepAlive = false;
+        state.keepAlive = false;
       }
     });
 
     onDeactivated(() => {
       if (props.show) {
         close();
-        keepAlive = true;
+        state.keepAlive = true;
       }
     });
 
@@ -261,14 +256,14 @@ export default create({
     );
 
     return {
+      ...toRefs(state),
+      popStyle,
+      classes,
       onClick,
       onClickCloseIcon,
       onClickOverlay,
       onOpened,
-      onClosed,
-      state,
-      popStyle,
-      classes
+      onClosed
     };
   }
 });