@wzyjs/uis 0.3.28 → 0.3.29

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/uis",
3
- "version": "0.3.28",
3
+ "version": "0.3.29",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "sideEffects": false,
@@ -39,7 +39,6 @@
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@wzyjs/hooks": "^0.2.37",
42
- "@wzyjs/types": "^0.2.37",
43
42
  "@wzyjs/utils": "^0.2.37",
44
43
  "antd": "^6.0.0"
45
44
  },
@@ -47,7 +46,7 @@
47
46
  "@types/js-beautify": "^1.14.3",
48
47
  "@types/react-grid-layout": "1.3.5"
49
48
  },
50
- "gitHead": "cfb708a071a9f7f0e2c819760c95427d7196623b",
49
+ "gitHead": "a78702bb9367a10779eaa376ed70834d8b42b5a8",
51
50
  "publishConfig": {
52
51
  "access": "public"
53
52
  }
@@ -0,0 +1,131 @@
1
+ 'use client'
2
+
3
+ import React, { useState, useRef, useEffect, forwardRef, CSSProperties } from 'react'
4
+ import { Card, Button, CardProps } from 'antd'
5
+ import { DownOutlined, UpOutlined } from '@ant-design/icons'
6
+
7
+ export interface FoldCardProps extends CardProps {
8
+ max?: number; // 默认折叠高度,可根据需要调整
9
+ buttonStyle?: CSSProperties;
10
+ defaultCollapsed?: boolean;
11
+ showButtonOnHover?: boolean;
12
+ }
13
+
14
+ export const FoldCard = forwardRef((props: FoldCardProps, ref: any) => {
15
+ const {
16
+ max,
17
+ buttonStyle,
18
+ defaultCollapsed = true,
19
+ showButtonOnHover = true,
20
+ children,
21
+ style,
22
+ onMouseEnter,
23
+ onMouseLeave,
24
+ ...rest
25
+ } = props
26
+
27
+ const maxHeight = max ?? 300
28
+
29
+ const [collapsed, setCollapsed] = useState(defaultCollapsed)
30
+ const [hovered, setHovered] = useState(false)
31
+ const [isOverflow, setIsOverflow] = useState(false)
32
+ const contentRef = useRef<HTMLDivElement>(null)
33
+
34
+ const measureOverflow = () => {
35
+ const contentEl = contentRef.current
36
+ if (!contentEl) {
37
+ return
38
+ }
39
+
40
+ setIsOverflow(contentEl.scrollHeight > maxHeight)
41
+ }
42
+
43
+ const toggleCollapse = (ev: React.MouseEvent<HTMLElement>) => {
44
+ ev.stopPropagation()
45
+ setCollapsed(value => !value)
46
+ }
47
+
48
+ useEffect(() => {
49
+ measureOverflow()
50
+
51
+ const contentEl = contentRef.current
52
+ if (!contentEl || typeof ResizeObserver === 'undefined') {
53
+ return
54
+ }
55
+
56
+ const observer = new ResizeObserver(measureOverflow)
57
+ observer.observe(contentEl)
58
+ return () => observer.disconnect()
59
+ }, [children, maxHeight])
60
+
61
+ const contentStyle: CSSProperties = {
62
+ maxHeight: collapsed ? maxHeight : undefined,
63
+ transition: 'max-height 0.3s ease',
64
+ overflow: collapsed ? 'hidden' : 'visible',
65
+ }
66
+
67
+ const hoverButtonContainerStyle: CSSProperties = {
68
+ position: 'absolute',
69
+ bottom: hovered ? 10 : -40,
70
+ left: '50%',
71
+ transform: 'translateX(-50%)',
72
+ transition: 'bottom 0.3s ease, opacity 0.3s ease',
73
+ display: 'flex',
74
+ justifyContent: 'center',
75
+ width: '100%',
76
+ pointerEvents: 'none',
77
+ opacity: hovered && isOverflow ? 1 : 0,
78
+ }
79
+
80
+ const inlineButtonContainerStyle: CSSProperties = {
81
+ textAlign: 'center',
82
+ marginTop: 8,
83
+ }
84
+
85
+ const finalButtonStyle: CSSProperties = {
86
+ pointerEvents: 'auto',
87
+ border: 'none',
88
+ boxShadow: showButtonOnHover ? '0 2px 8px rgba(0, 0, 0, 0.15)' : undefined,
89
+ ...buttonStyle,
90
+ }
91
+
92
+ const button = (
93
+ <Button
94
+ size='small'
95
+ icon={collapsed ? <DownOutlined /> : <UpOutlined />}
96
+ onClick={toggleCollapse}
97
+ style={finalButtonStyle}
98
+ />
99
+ )
100
+
101
+ return (
102
+ <Card
103
+ ref={ref}
104
+ style={{ position: 'relative', overflow: 'hidden', ...style }}
105
+ onMouseEnter={(ev) => {
106
+ setHovered(true)
107
+ onMouseEnter?.(ev)
108
+ }}
109
+ onMouseLeave={(ev) => {
110
+ setHovered(false)
111
+ onMouseLeave?.(ev)
112
+ }}
113
+ {...rest}
114
+ >
115
+ <div style={contentStyle} ref={contentRef}>
116
+ {children}
117
+ </div>
118
+ {isOverflow && (
119
+ showButtonOnHover ? (
120
+ <div style={hoverButtonContainerStyle}>
121
+ {button}
122
+ </div>
123
+ ) : (
124
+ <div style={inlineButtonContainerStyle}>
125
+ {button}
126
+ </div>
127
+ )
128
+ )}
129
+ </Card>
130
+ )
131
+ })
@@ -4,7 +4,7 @@ import React from 'react'
4
4
  import { InputNumber, InputNumberProps, Space } from 'antd'
5
5
  import { _ } from '@wzyjs/utils/web'
6
6
 
7
- export interface RangeProps extends Omit<InputNumberProps, 'value' | 'onChange'> {
7
+ export interface RangeInputProps extends Omit<InputNumberProps, 'value' | 'onChange'> {
8
8
  value?: number[];
9
9
  min?: number;
10
10
  max?: number;
@@ -12,7 +12,7 @@ export interface RangeProps extends Omit<InputNumberProps, 'value' | 'onChange'>
12
12
  }
13
13
 
14
14
  // 最小值 最大值 的输入框
15
- export const Range = (props: RangeProps) => {
15
+ export const RangeInput = (props: RangeInputProps) => {
16
16
  const { value = [], min, max, onChange } = props
17
17
 
18
18
  const onNumberChange = (index: 0 | 1, v: number | null) => {
@@ -0,0 +1,26 @@
1
+ 'use client'
2
+
3
+ import React from 'react'
4
+ import { Space } from 'antd'
5
+ import { ConfirmButton, ConfirmButtonProps } from './ConfirmButton'
6
+
7
+ export interface ButtonGroupProps {
8
+ list?: (ConfirmButtonProps & { visible?: boolean, title?: string })[]
9
+ }
10
+
11
+ // 1. 按钮组
12
+ export const ButtonGroup = (props: ButtonGroupProps) => {
13
+ const { list = [] } = props
14
+
15
+ if (!list?.length) {
16
+ return null
17
+ }
18
+
19
+ return (
20
+ <Space.Compact>
21
+ {list.filter(item => item.visible).map((item, index) => (
22
+ <ConfirmButton key={index} {...item}>{item.title}</ConfirmButton>
23
+ ))}
24
+ </Space.Compact>
25
+ )
26
+ }
@@ -4,12 +4,12 @@ import React from 'react'
4
4
  import { _ } from '@wzyjs/utils/web'
5
5
  import { Button, Popconfirm, PopconfirmProps, ButtonProps } from 'antd'
6
6
 
7
- export interface ConfirmProps extends PopconfirmProps {
7
+ export interface ConfirmButtonProps extends PopconfirmProps {
8
8
  btnProps?: ButtonProps
9
9
  }
10
10
 
11
11
  // 1. 给按钮增加了确认功能
12
- export const Confirm = (props: ConfirmProps) => {
12
+ export const ConfirmButton = (props: ConfirmButtonProps) => {
13
13
  const { children, btnProps } = props
14
14
 
15
15
  return (
@@ -8,12 +8,12 @@ import { CheckOutlined } from '@ant-design/icons'
8
8
  import { copy, readClipboard } from '@wzyjs/utils/web'
9
9
  import { useControllableValue } from '@wzyjs/hooks/web'
10
10
 
11
- export interface CopyProps extends ButtonProps {
11
+ export interface CopyButtonProps extends ButtonProps {
12
12
  value?: string,
13
13
  canPaste?: boolean,
14
14
  }
15
15
 
16
- export const Copy = (props: CopyProps) => {
16
+ export const CopyButton = (props: CopyButtonProps) => {
17
17
  const [icon, setIcon] = useState<ReactNode>(null)
18
18
  const { message } = App.useApp()
19
19
 
@@ -4,12 +4,12 @@ import React, { useState } from 'react'
4
4
  import { _ } from '@wzyjs/utils/web'
5
5
  import { Button, Drawer as AntdDrawer, DrawerProps as AntdDrawerProps, ButtonProps } from 'antd'
6
6
 
7
- export interface DrawerProps extends AntdDrawerProps {
7
+ export interface DrawerButtonProps extends AntdDrawerProps {
8
8
  btnProps?: ButtonProps
9
9
  defaultOpen?: boolean
10
10
  }
11
11
 
12
- export const Drawer = (props: DrawerProps) => {
12
+ export const DrawerButton = (props: DrawerButtonProps) => {
13
13
  const { children, defaultOpen, btnProps } = props
14
14
  const [open, setOpen] = useState<boolean>(defaultOpen ?? false)
15
15
 
@@ -0,0 +1,4 @@
1
+ export * from './ButtonGroup'
2
+ export * from './ConfirmButton'
3
+ export * from './CopyButton'
4
+ export * from './DrawerButton'
@@ -1,11 +1,5 @@
1
- export * from './Alert'
2
- export * from './Button'
3
- export * from './Card'
4
- export * from './Collapse'
5
- export * from './Image'
6
- export * from './Input'
7
- export * from './Radio'
8
- export * from './Space'
1
+ export * from './buttons'
2
+ export * from './FoldCard'
3
+ export * from './RangeInput'
9
4
  export * from './Tabs'
10
5
  export * from './Typography'
11
- export * from './Popconfirm'
@@ -1,6 +1,8 @@
1
1
  import React from 'react'
2
2
  import { AutoComplete, Button, Space } from 'antd'
3
3
 
4
+ import type { Option } from './types'
5
+
4
6
  interface DynamicSelectProps {
5
7
  value?: string[]
6
8
  onChange?: (value: string[]) => void
@@ -0,0 +1,8 @@
1
+ export type OptionValue = string | number | boolean
2
+
3
+ export interface Option<V extends OptionValue = OptionValue> {
4
+ label: string
5
+ value: V
6
+ children?: Option<V>[]
7
+ extra?: Record<string, any>
8
+ }
@@ -1,3 +1,5 @@
1
+ import type { Option } from './types'
2
+
1
3
  export const transformOptions = (data: string[][]): Option[] => {
2
4
  const result: Option[] = []
3
5
 
@@ -6,7 +6,6 @@ export * from './Com2Canvas'
6
6
  export * from './Video'
7
7
  export * from './MultiImageDisplay'
8
8
  export * from './DownloadLink'
9
- export * from './Fold'
10
9
  export * from './DragSort'
11
10
  export * from './DateSwitcher'
12
11
  export * from './GroupLayout'
@@ -1,24 +0,0 @@
1
- 'use client'
2
-
3
- import React, { ReactNode } from 'react'
4
- import { Alert, AlertProps, Space } from 'antd'
5
-
6
- export interface AlertProProps extends AlertProps {
7
- children?: ReactNode,
8
- }
9
-
10
- // 1. 支持 children 作为 description 显示
11
- export const AlertPro = (props: AlertProProps) => {
12
- const { children, description = children } = props
13
-
14
- return (
15
- <Alert
16
- {...props}
17
- description={(
18
- <Space style={{ width: '100%' }} orientation='vertical'>
19
- {description}
20
- </Space>
21
- )}
22
- />
23
- )
24
- }
@@ -1,26 +0,0 @@
1
- 'use client'
2
-
3
- import React from 'react'
4
- import { Button } from 'antd'
5
- import { Confirm, ConfirmProps } from './Confirm'
6
-
7
- export interface GroupProps {
8
- list?: (ConfirmProps & { visible?: boolean, title?: string })[]
9
- }
10
-
11
- // 1. 按钮组
12
- export const Group = (props: GroupProps) => {
13
- const { list = [] } = props
14
-
15
- if (!list?.length) {
16
- return null
17
- }
18
-
19
- return (
20
- <Button.Group>
21
- {list.filter(item => item.visible).map((item, index) => (
22
- <Confirm key={index} {...item}>{item.title}</Confirm>
23
- ))}
24
- </Button.Group>
25
- )
26
- }
@@ -1,11 +0,0 @@
1
- import { Group } from './components/Group'
2
- import { Confirm } from './components/Confirm'
3
- import { Copy } from './components/Copy'
4
- import { Drawer } from './components/Drawer'
5
-
6
- export const ButtonPro = {
7
- Group,
8
- Confirm,
9
- Copy,
10
- Drawer,
11
- }
@@ -1,92 +0,0 @@
1
- 'use client'
2
-
3
- import React, { useState, useRef, useEffect, forwardRef } from 'react'
4
- import { Card, Button, CardProps } from 'antd'
5
- import { DownOutlined, UpOutlined } from '@ant-design/icons'
6
-
7
- interface CardProProps extends CardProps {
8
- collapsedHeight?: number; // 默认折叠高度,可根据需要调整
9
- }
10
-
11
- export const CardPro = forwardRef((props: CardProProps, ref: any) => {
12
- const { collapsedHeight = 300, children, ...rest } = props
13
-
14
- const [collapsed, setCollapsed] = useState(true)
15
- const [hovered, setHovered] = useState(false)
16
- const [isOverflow, setIsOverflow] = useState(false)
17
- const contentRef = useRef<HTMLSpanElement>(null)
18
-
19
- const toggleCollapse = (ev: any) => {
20
- ev.stopPropagation()
21
- setCollapsed(!collapsed)
22
- }
23
-
24
- useEffect(() => {
25
- const contentEl = contentRef.current
26
- if (contentEl) {
27
- // 获取内容的实际高度
28
- const actualHeight = contentEl.scrollHeight
29
- if (actualHeight > collapsedHeight) {
30
- setIsOverflow(true)
31
- } else {
32
- setIsOverflow(false)
33
- }
34
- }
35
- }, [children, collapsedHeight])
36
-
37
- const cardStyle: React.CSSProperties = {
38
- position: 'relative',
39
- overflow: 'hidden',
40
- }
41
-
42
- const contentStyle: React.CSSProperties = {
43
- maxHeight: collapsed ? `${collapsedHeight}px` : 'none',
44
- overflowY: collapsed ? 'auto' : 'visible',
45
- transition: 'max-height 0.3s ease',
46
- display: 'block',
47
- textOverflow: 'ellipsis',
48
- overflow: 'hidden',
49
- }
50
-
51
- const buttonContainerStyle: React.CSSProperties = {
52
- position: 'absolute',
53
- bottom: hovered ? '10px' : '-40px', // 增加隐藏时的负值,确保按钮完全隐藏
54
- left: '50%',
55
- transform: 'translateX(-50%)',
56
- transition: 'bottom 0.3s ease, opacity 0.3s ease',
57
- display: 'flex',
58
- justifyContent: 'center',
59
- width: '100%',
60
- pointerEvents: 'none', // 默认情况下,禁止点击
61
- opacity: hovered && isOverflow ? 1 : 0, // 控制按钮的透明度
62
- }
63
-
64
- const buttonStyle: React.CSSProperties = {
65
- pointerEvents: 'auto', // 允许按钮在悬停时可点击
66
- border: 'none',
67
- boxShadow: '0 2px 8px rgba(0, 0, 0, 0.15)',
68
- }
69
-
70
- return (
71
- <Card
72
- ref={ref}
73
- style={cardStyle}
74
- onMouseEnter={() => setHovered(true)}
75
- onMouseLeave={() => setHovered(false)}
76
- {...rest}
77
- >
78
- <span style={contentStyle} ref={contentRef}>
79
- {children}
80
- </span>
81
- {isOverflow && (
82
- <div style={buttonContainerStyle}>
83
- <Button
84
- icon={collapsed ? <DownOutlined /> : <UpOutlined />}
85
- onClick={toggleCollapse}
86
- style={buttonStyle}
87
- />
88
- </div>
89
- )}
90
- </Card>
91
- )
92
- })
@@ -1,30 +0,0 @@
1
- 'use client'
2
-
3
- import React from 'react'
4
- import { Collapse, CollapsePanelProps, Space } from 'antd'
5
-
6
- export interface CollapseItemProps extends Omit<CollapsePanelProps, 'key'> {
7
- step?: boolean; // 为true自动给标题添加 `第{index}步:`
8
- index?: number; // step为true时才需要
9
- space?: boolean; // 子元素是否有间距
10
- }
11
-
12
- export const Item = (props: CollapseItemProps) => {
13
- const { step = true, header, index, space } = props
14
-
15
- return (
16
- <Collapse.Panel
17
- key={String(header)}
18
- {...props}
19
- header={step ? `第${index}步: ${header}` : header}
20
- >
21
- {space ? (
22
- <Space orientation='vertical' size='small' style={{ width: '100%' }}>
23
- {props.children}
24
- </Space>
25
- ) : (
26
- props.children
27
- )}
28
- </Collapse.Panel>
29
- )
30
- }
@@ -1,27 +0,0 @@
1
- 'use client'
2
-
3
- import React from 'react'
4
- import { Collapse, CollapseProps } from 'antd'
5
- import { Item, CollapseItemProps } from './components/Item'
6
-
7
- export interface CollapseProProps extends CollapseProps {
8
- list?: CollapseItemProps[],
9
- step?: boolean; // 为true自动给标题添加 `第{index}步:`
10
- space?: boolean; // 子元素是否有间距
11
- }
12
-
13
- export const CollapsePro = (props: CollapseProProps) => {
14
- const { list = [], step = false, space = true, accordion = true } = props
15
-
16
- if (!props.children && list.length) {
17
- props.children = list.map((item, index) => (
18
- <Item key={index} step={step} space={space} index={index + 1} {...item} />
19
- ))
20
- }
21
-
22
- return (
23
- <Collapse accordion={accordion} {...props} />
24
- )
25
- }
26
-
27
- CollapsePro.Pane = Item
@@ -1,17 +0,0 @@
1
- 'use client'
2
-
3
- import React from 'react'
4
- import { Image, ImageProps } from 'antd'
5
-
6
- export type ImageProProps = ImageProps
7
-
8
- export const ImagePro = (props: ImageProProps) => {
9
- const { preview = false } = props
10
-
11
- return (
12
- <Image
13
- {...props}
14
- preview={preview}
15
- />
16
- )
17
- }
@@ -1,61 +0,0 @@
1
- 'use client'
2
-
3
- import React, { useState, useEffect, useMemo } from 'react'
4
- import { Input, InputProps } from 'antd'
5
- import { getStrLength } from '@wzyjs/utils/web'
6
- import { Range } from './components/Range'
7
-
8
- export interface InputProProps extends Omit<InputProps, 'onChange'> {
9
- maxLengthChinese?: boolean; // 限制长度:中文算2个字符
10
- onChange?: (value: string) => void
11
- }
12
-
13
- // 1. 增加对中文字符串的长度限制 (Input的maxLength会认为汉字为1个长度)
14
- export const InputPro = (props: InputProProps) => {
15
- const {
16
- value: _value,
17
- onChange: _onChange,
18
- addonAfter: _addonAfter,
19
- maxLength,
20
- maxLengthChinese,
21
- ...rest
22
- } = props
23
-
24
- const [value, setValue] = useState<string>('')
25
-
26
- const addonAfter = useMemo(() => {
27
- if (!maxLengthChinese) {
28
- return _addonAfter
29
- }
30
-
31
- return (
32
- <>
33
- {_addonAfter}
34
- {maxLength ? `${getStrLength(value)} / ${maxLength}` : null}
35
- </>
36
- )
37
- }, [_addonAfter, value, maxLength])
38
-
39
- useEffect(() => {
40
- _onChange?.(value)
41
- }, [value])
42
-
43
- const onChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
44
- if (maxLengthChinese && maxLength && getStrLength(ev.target.value) > maxLength) {
45
- return
46
- }
47
- setValue(ev.target.value)
48
- }
49
-
50
- return (
51
- <Input
52
- value={value}
53
- onChange={onChange}
54
- addonAfter={addonAfter}
55
- maxLength={maxLength}
56
- {...rest}
57
- />
58
- )
59
- }
60
-
61
- InputPro.Range = Range
@@ -1,16 +0,0 @@
1
- 'use client'
2
-
3
- import React from 'react'
4
- import { Popconfirm, PopconfirmProps } from 'antd'
5
-
6
- export type PopconfirmProProps = PopconfirmProps
7
-
8
- export const PopconfirmPro = (props: PopconfirmProProps) => {
9
- return (
10
- <Popconfirm
11
- okText="确定"
12
- cancelText="取消"
13
- {...props}
14
- />
15
- )
16
- }
@@ -1,30 +0,0 @@
1
- 'use client'
2
-
3
- import React from 'react'
4
- import { Checkbox, CheckboxProps, CheckboxOptionType } from 'antd'
5
-
6
- export interface CancelProps {
7
- value: CheckboxProps['value'];
8
- options: CheckboxOptionType[];
9
- onChange?: CheckboxProps['onChange'];
10
- }
11
-
12
- // 给Radio组件增加取消选择的功能,是用Checkbox组件实现的
13
- export const Cancel = (props: CancelProps) => {
14
- const { value, options, onChange } = props
15
-
16
- const evs = {
17
- onChange: (checkedValue: CheckboxProps['value'][]) => {
18
- onChange?.(checkedValue.find(i => i !== value) || '')
19
- },
20
- }
21
-
22
- return (
23
- <Checkbox.Group
24
- value={[value]}
25
- prefixCls='ant-radio'
26
- options={options}
27
- onChange={evs.onChange}
28
- />
29
- )
30
- }
@@ -1,7 +0,0 @@
1
- 'use client'
2
-
3
- import { Cancel } from './components/Cancel'
4
-
5
- export const RadioPro = {
6
- Cancel,
7
- }
@@ -1,15 +0,0 @@
1
- 'use client'
2
-
3
- import React from 'react'
4
- import { Space, SpaceProps } from 'antd'
5
-
6
- export type SpaceProProps = SpaceProps
7
-
8
- export const SpacePro = (props: SpaceProProps) => {
9
- return (
10
- <Space
11
- style={{ width: '100%' }}
12
- {...props}
13
- />
14
- )
15
- }
@@ -1,52 +0,0 @@
1
- 'use client'
2
-
3
- import React, { useState } from 'react'
4
- import { Button } from 'antd'
5
- import { DownOutlined, UpOutlined } from '@ant-design/icons'
6
-
7
- interface FoldProps {
8
- max: number
9
- children?: React.ReactNode
10
- btnStyle?: React.CSSProperties
11
- }
12
-
13
- export const Fold = (props: FoldProps) => {
14
- const { max, children, btnStyle = {} } = props
15
-
16
- const [collapsed, setCollapsed] = useState<boolean | undefined>(undefined)
17
-
18
- const divRef = React.useRef<HTMLDivElement>(null)
19
-
20
- React.useEffect(() => {
21
- if (divRef.current) {
22
- const { clientHeight } = divRef.current
23
- if (clientHeight > max) {
24
- setCollapsed(true)
25
- }
26
- }
27
- }, [divRef.current])
28
-
29
- return (
30
- <div ref={divRef} style={{ overflow: 'hidden' }}>
31
- <div style={{ maxHeight: collapsed ? max : undefined }}>
32
- {children}
33
- </div>
34
-
35
- <div style={{ textAlign: 'center', ...btnStyle }}>
36
- {collapsed === undefined ? null : collapsed ? (
37
- <Button
38
- size='small'
39
- icon={<DownOutlined />}
40
- onClick={() => setCollapsed(false)}
41
- />
42
- ) : (
43
- <Button
44
- size='small'
45
- icon={<UpOutlined />}
46
- onClick={() => setCollapsed(true)}
47
- />
48
- )}
49
- </div>
50
- </div>
51
- )
52
- }