ThemeColorPicker.vue 1.9 KB
Newer Older
V
vben 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<template>
  <div :class="prefixCls">
    <template v-for="color in colorList || []" :key="color">
      <span
        @click="handleClick(color)"
        :class="[
          `${prefixCls}__item`,
          {
            [`${prefixCls}__item--active`]: def === color,
          },
        ]"
        :style="{ background: color }"
      >
        <CheckOutlined />
      </span>
    </template>
  </div>
</template>
<script lang="ts">
  import { defineComponent, PropType } from 'vue';
  import { CheckOutlined } from '@ant-design/icons-vue';

  import { useDesign } from '/@/hooks/web/useDesign';

  import { baseHandler } from '../handler';
  import { HandlerEnum } from '../enum';

  export default defineComponent({
V
Vben 已提交
29
    name: 'ThemeColorPicker',
V
vben 已提交
30 31 32 33
    components: { CheckOutlined },
    props: {
      colorList: {
        type: Array as PropType<string[]>,
34
        default: () => [],
V
vben 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
      },
      event: {
        type: Number as PropType<HandlerEnum>,
      },
      def: {
        type: String,
      },
    },
    setup(props) {
      const { prefixCls } = useDesign('setting-theme-picker');

      function handleClick(color: string) {
        props.event && baseHandler(props.event, color);
      }
      return {
        prefixCls,
        handleClick,
      };
    },
  });
</script>
<style lang="less">
  @prefix-cls: ~'@{namespace}-setting-theme-picker';

  .@{prefix-cls} {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
V
vben 已提交
63
    margin: 16px 0;
V
vben 已提交
64 65 66 67 68 69

    &__item {
      width: 20px;
      height: 20px;
      border: 1px solid #ddd;
      border-radius: 2px;
V
vben 已提交
70
      cursor: pointer;
V
vben 已提交
71 72 73 74 75 76 77 78 79 80 81 82

      svg {
        display: none;
      }

      &--active {
        border: 1px solid lighten(@primary-color, 10%);

        svg {
          display: inline-block;
          margin: 0 0 3px 3px;
          fill: @white !important;
V
vben 已提交
83
          font-size: 12px;
V
vben 已提交
84 85 86 87 88
        }
      }
    }
  }
</style>