gi-component 0.0.37 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  type AllKeys<T> = T extends any ? keyof T : never;
2
2
  type UnionType<T, K extends PropertyKey> = T extends any ? K extends keyof T ? T[K] : never : never;
3
3
  export type MergeMultiple<T extends any[]> = {
4
- [K in AllKeys<T[number]>]: UnionType<T[number], K>;
4
+ [K in AllKeys<T[number]>]?: UnionType<T[number], K>;
5
5
  };
6
6
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gi-component",
3
3
  "type": "module",
4
- "version": "0.0.37",
4
+ "version": "0.0.38",
5
5
  "description": "Vue3中基于Element Plus二次封装基础组件库",
6
6
  "author": "lin",
7
7
  "license": "MIT",
@@ -1,60 +1,60 @@
1
- <template>
2
- <ElButton :class="b('button')" v-bind="bindProps" @click="(e: MouseEvent) => emit('click', e)">
3
- <slot>{{ btnText }}</slot>
4
- </ElButton>
5
- </template>
6
-
7
- <script setup lang="ts">
8
- import type { ButtonProps as ElButtonProps } from 'element-plus'
9
- import type { ButtonProps } from './type.ts'
10
- import {
11
- Delete,
12
- Download,
13
- Edit,
14
- Plus,
15
- Printer,
16
- Search,
17
- Upload
18
- } from '@element-plus/icons-vue'
19
- import { ElButton } from 'element-plus'
20
- import { computed, useAttrs } from 'vue'
21
- import { useBemClass } from '../../../hooks'
22
-
23
- const props = withDefaults(defineProps<ButtonProps>(), {
24
- type: ''
25
- })
26
-
27
- const emit = defineEmits<{
28
- (e: 'click', event: MouseEvent): void
29
- }>()
30
-
31
- const attrs = useAttrs()
32
-
33
- const { b } = useBemClass()
34
-
35
- const obj: Record<string, { btnProps: Partial<ButtonProps>, btnText: string }>
36
- = {
37
- add: { btnProps: { icon: Plus, type: 'primary' }, btnText: '新增' },
38
- edit: { btnProps: { icon: Edit, type: 'primary' }, btnText: '编辑' },
39
- delete: { btnProps: { icon: Delete, type: 'danger' }, btnText: '删除' },
40
- search: { btnProps: { icon: Search, type: 'primary' }, btnText: '搜索' },
41
- reset: { btnProps: { type: undefined }, btnText: '重置' },
42
- upload: { btnProps: { icon: Upload }, btnText: '上传' },
43
- download: {
44
- btnProps: { icon: Download },
45
- btnText: '下载'
46
- },
47
- print: { btnProps: { icon: Printer }, btnText: '打印' }
48
- }
49
-
50
- const bindProps = computed(() => {
51
- const btnProps = obj?.[props.type]?.btnProps || { type: props.type }
52
- return { ...attrs, ...props, ...btnProps } as Omit<ElButtonProps, 'type'>
53
- })
54
-
55
- const btnText = computed(() => {
56
- return obj[props.type].btnText
57
- })
58
- </script>
59
-
60
- <style lang="scss" scoped></style>
1
+ <template>
2
+ <ElButton :class="b('button')" v-bind="bindProps" @click="(e: MouseEvent) => emit('click', e)">
3
+ <slot>{{ btnText }}</slot>
4
+ </ElButton>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import type { ButtonProps as ElButtonProps } from 'element-plus'
9
+ import type { ButtonProps } from './type.ts'
10
+ import {
11
+ Delete,
12
+ Download,
13
+ Edit,
14
+ Plus,
15
+ Printer,
16
+ Search,
17
+ Upload
18
+ } from '@element-plus/icons-vue'
19
+ import { ElButton } from 'element-plus'
20
+ import { computed, useAttrs } from 'vue'
21
+ import { useBemClass } from '../../../hooks'
22
+
23
+ const props = withDefaults(defineProps<ButtonProps>(), {
24
+ type: ''
25
+ })
26
+
27
+ const emit = defineEmits<{
28
+ (e: 'click', event: MouseEvent): void
29
+ }>()
30
+
31
+ const attrs = useAttrs()
32
+
33
+ const { b } = useBemClass()
34
+
35
+ const obj: Record<string, { btnProps: Partial<ButtonProps>, btnText: string }>
36
+ = {
37
+ add: { btnProps: { icon: Plus, type: 'primary' }, btnText: '新增' },
38
+ edit: { btnProps: { icon: Edit, type: 'primary' }, btnText: '编辑' },
39
+ delete: { btnProps: { icon: Delete, type: 'danger' }, btnText: '删除' },
40
+ search: { btnProps: { icon: Search, type: 'primary' }, btnText: '搜索' },
41
+ reset: { btnProps: { type: undefined }, btnText: '重置' },
42
+ upload: { btnProps: { icon: Upload }, btnText: '上传' },
43
+ download: {
44
+ btnProps: { icon: Download },
45
+ btnText: '下载'
46
+ },
47
+ print: { btnProps: { icon: Printer }, btnText: '打印' }
48
+ }
49
+
50
+ const bindProps = computed(() => {
51
+ const btnProps = obj?.[props.type]?.btnProps || { type: props.type }
52
+ return { ...attrs, ...props, ...btnProps } as Omit<ElButtonProps, 'type'>
53
+ })
54
+
55
+ const btnText = computed(() => {
56
+ return obj[props.type].btnText
57
+ })
58
+ </script>
59
+
60
+ <style lang="scss" scoped></style>
@@ -0,0 +1,5 @@
1
+ import Flex from './src/flex.vue'
2
+
3
+ export type FlexInstance = InstanceType<typeof Flex>
4
+ export * from './src/type'
5
+ export default Flex
@@ -0,0 +1,72 @@
1
+ <template>
2
+ <div :class="classNames" :style="style">
3
+ <slot />
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import type { CSSProperties } from 'vue'
9
+ import type { FlexProps } from './type'
10
+ import { computed } from 'vue'
11
+ import { useBemClass } from '../../../hooks'
12
+
13
+ const props = withDefaults(defineProps<FlexProps>(), {
14
+ vertical: false,
15
+ wrap: false,
16
+ justify: 'normal',
17
+ align: 'normal',
18
+ flex: 'normal'
19
+ })
20
+
21
+ const { b } = useBemClass()
22
+
23
+ const classNames = computed(() => [b('flex')])
24
+
25
+ const gapMap: Record<string, string> = {
26
+ small: '8px',
27
+ middle: '16px',
28
+ large: '24px'
29
+ }
30
+
31
+ const resolvedGap = computed(() => {
32
+ if (props.gap === undefined || props.gap === null || props.gap === '')
33
+ return undefined
34
+ if (typeof props.gap === 'number')
35
+ return `${props.gap}px`
36
+ if (gapMap[props.gap])
37
+ return gapMap[props.gap]
38
+ return String(props.gap)
39
+ })
40
+
41
+ const resolvedWrap = computed(() => {
42
+ if (typeof props.wrap === 'boolean')
43
+ return props.wrap ? 'wrap' : 'nowrap'
44
+ // 模板中写 wrap 无值时 Vue 传空字符串,视为开启换行
45
+ if (props.wrap === '')
46
+ return 'wrap'
47
+ return props.wrap
48
+ })
49
+
50
+ const style = computed<CSSProperties>(() => {
51
+ const obj: CSSProperties = {
52
+ display: 'flex',
53
+ flexDirection: props.vertical ? 'column' : 'row',
54
+ flexWrap: resolvedWrap.value,
55
+ justifyContent: props.justify,
56
+ alignItems: props.align
57
+ }
58
+ if (props.flex !== 'normal') {
59
+ obj.flex = props.flex
60
+ }
61
+ if (resolvedGap.value) {
62
+ obj.gap = resolvedGap.value
63
+ }
64
+ return obj
65
+ })
66
+ </script>
67
+
68
+ <style scoped lang="scss">
69
+ :deep(.el-button+.el-button) {
70
+ margin-left: 0;
71
+ }
72
+ </style>
@@ -0,0 +1,14 @@
1
+ export interface FlexProps {
2
+ /** Flex 主轴的方向是否垂直,使用 flex-direction: column */
3
+ vertical?: boolean
4
+ /** 设置元素单行显示还是多行显示,参考 flex-wrap;支持布尔值,true 为 wrap,false 为 nowrap */
5
+ wrap?: 'nowrap' | 'wrap' | 'wrap-reverse' | boolean | ''
6
+ /** 设置元素在主轴方向上的对齐方式,参考 justify-content */
7
+ justify?: 'normal' | 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly'
8
+ /** 设置元素在交叉轴方向上的对齐方式,参考 align-items */
9
+ align?: 'normal' | 'flex-start' | 'flex-end' | 'center' | 'stretch' | 'baseline'
10
+ /** flex CSS 简写属性 */
11
+ flex?: string
12
+ /** 设置网格之间的间隙,可选预设 small / middle / large 或 string / number */
13
+ gap?: 'small' | 'middle' | 'large' | string | number
14
+ }
@@ -15,6 +15,7 @@ declare module 'vue' {
15
15
  GiDot: typeof import('./components/dot/src/dot.vue')['default']
16
16
  GiDrawer: typeof import('./components/drawer/src/drawer.vue')['default']
17
17
  GiEditTable: typeof import('./components/edit-table/src/edit-table.vue')['default']
18
+ GiFlex: typeof import('./components/flex/src/flex.vue')['default']
18
19
  GiForm: typeof import('./components/form/src/form.vue')['default']
19
20
  GiGrid: typeof import('./components/grid/src/grid.vue')['default']
20
21
  GiGridItem: typeof import('./components/grid/src/grid-item.vue')['default']
package/packages/index.ts CHANGED
@@ -6,6 +6,7 @@ import DialogComponent, { Dialog as DialogFunction } from './components/dialog'
6
6
  import Dot from './components/dot'
7
7
  import Drawer from './components/drawer'
8
8
  import EditTable from './components/edit-table'
9
+ import Flex from './components/flex'
9
10
  import Form from './components/form'
10
11
  import GridItem from './components/grid/src/grid-item.vue'
11
12
  import Grid from './components/grid/src/grid.vue'
@@ -37,6 +38,7 @@ const components = {
37
38
  Tabs,
38
39
  InputGroup,
39
40
  InputSearch,
41
+ Flex,
40
42
  Grid,
41
43
  GridItem,
42
44
  Form,
@@ -55,6 +57,7 @@ export const GiDot: typeof Dot = Dot
55
57
  export const GiTabs: typeof Tabs = Tabs
56
58
  export const GiInputGroup: typeof InputGroup = InputGroup
57
59
  export const GiInputSearch: typeof InputSearch = InputSearch
60
+ export const GiFlex: typeof Flex = Flex
58
61
  export const GiGrid: typeof Grid = Grid
59
62
  export const GiGridItem: typeof GridItem = GridItem
60
63
  export const GiForm: typeof Form = Form