@dsh-plugin/dsh-ui-components 0.0.1 → 0.1.0-dev.43616582648
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/LICENSE +21 -21
- package/NOTICE +21 -21
- package/README.md +136 -136
- package/README.zh_CN.md +136 -136
- package/docs/tokens.md +67 -67
- package/lib/basic/form.js +49 -49
- package/lib/basic/styles.js +391 -391
- package/lib/composites/styles.js +427 -427
- package/lib/data/styles.js +257 -257
- package/lib/display/styles.js +310 -310
- package/lib/feedback/styles.js +228 -228
- package/lib/foundation/bridge.js +203 -203
- package/lib/navigation/styles.js +417 -417
- package/package.json +104 -104
- package/scripts/check-size.mjs +69 -69
- package/scripts/dump-npm-latest.mjs +59 -59
- package/scripts/gen-host-tokens.mjs +61 -61
- package/scripts/gen-icons.mjs +188 -178
- package/scripts/verify-no-literal-colors.mjs +63 -63
- package/scripts/verify-tokens.mjs +135 -135
- package/src/basic/button.tsx +76 -76
- package/src/basic/form.tsx +187 -187
- package/src/basic/icon-button.tsx +66 -66
- package/src/basic/index.ts +38 -38
- package/src/basic/input.tsx +140 -140
- package/src/basic/select.tsx +120 -120
- package/src/basic/styles.ts +412 -412
- package/src/basic/toggle.tsx +116 -116
- package/src/composites/data-view.tsx +189 -189
- package/src/composites/index.ts +11 -11
- package/src/composites/indicator.tsx +90 -90
- package/src/composites/menu-select.tsx +230 -230
- package/src/composites/panel.tsx +72 -72
- package/src/composites/settings.tsx +80 -80
- package/src/composites/styles.ts +450 -450
- package/src/data/collection.tsx +71 -71
- package/src/data/index.ts +39 -39
- package/src/data/info.tsx +89 -89
- package/src/data/picker.tsx +113 -113
- package/src/data/styles.ts +278 -278
- package/src/display/container.tsx +67 -67
- package/src/display/feedback.tsx +92 -92
- package/src/display/index.ts +44 -44
- package/src/display/label.tsx +165 -165
- package/src/display/overlay.tsx +103 -103
- package/src/display/styles.ts +332 -332
- package/src/feedback/global.tsx +110 -110
- package/src/feedback/index.ts +19 -19
- package/src/feedback/inline.tsx +50 -50
- package/src/feedback/panel.tsx +93 -93
- package/src/feedback/styles.ts +250 -250
- package/src/foundation/bridge.ts +318 -318
- package/src/foundation/icons.tsx +315 -315
- package/src/foundation/index.ts +33 -33
- package/src/foundation/palette.ts +153 -153
- package/src/foundation/provider.tsx +62 -62
- package/src/foundation/style.ts +63 -63
- package/src/foundation/tokens.ts +62 -62
- package/src/index.ts +18 -18
- package/src/navigation/hierarchy.tsx +82 -82
- package/src/navigation/index.ts +21 -21
- package/src/navigation/indicator.tsx +125 -125
- package/src/navigation/menu.tsx +94 -94
- package/src/navigation/segmented.tsx +136 -136
- package/src/navigation/styles.ts +438 -438
package/src/basic/form.tsx
CHANGED
|
@@ -1,187 +1,187 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 表单与字段容器。
|
|
3
|
-
*
|
|
4
|
-
* `Field` 是设置页最常用的组合:标签、控件、说明文字与校验消息。它自己不做
|
|
5
|
-
* 校验,只在有 `error` 时把消息以 `role="alert"` 渲染出来,并把 `id` 关联到
|
|
6
|
-
* 标签上。`Form` 直接沿用 Arco 的校验与布局能力。
|
|
7
|
-
*
|
|
8
|
-
* @module @dsh-plugin/dsh-ui-components/basic/form
|
|
9
|
-
*/
|
|
10
|
-
import * as React from 'react'
|
|
11
|
-
import { Arco } from '@dsh-plugin/dsh-loader/client'
|
|
12
|
-
import { cx, injectUiStyle } from '../foundation/style.js'
|
|
13
|
-
import { injectBasicStyles } from './styles.js'
|
|
14
|
-
|
|
15
|
-
/** 字段容器的样式表,单独一张,避免与控件表混在一起。 */
|
|
16
|
-
const FIELD_CSS = `
|
|
17
|
-
.dsh-field {
|
|
18
|
-
display: flex;
|
|
19
|
-
flex-direction: column;
|
|
20
|
-
gap: 6px;
|
|
21
|
-
min-width: 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.dsh-field__label {
|
|
25
|
-
font-size: 13px;
|
|
26
|
-
font-weight: 500;
|
|
27
|
-
line-height: 20px;
|
|
28
|
-
color: var(--dsw-alias-label-secondary);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.dsh-field__required {
|
|
32
|
-
margin-left: 2px;
|
|
33
|
-
color: var(--dsw-alias-state-error-primary);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.dsh-field__desc {
|
|
37
|
-
font-size: 12px;
|
|
38
|
-
line-height: 18px;
|
|
39
|
-
color: var(--dsw-alias-label-tertiary);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.dsh-field__error {
|
|
43
|
-
font-size: 12px;
|
|
44
|
-
line-height: 18px;
|
|
45
|
-
color: var(--dsw-alias-state-error-primary);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.dsh-field--inline {
|
|
49
|
-
flex-direction: row;
|
|
50
|
-
align-items: center;
|
|
51
|
-
justify-content: space-between;
|
|
52
|
-
gap: 16px;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.dsh-field__text {
|
|
56
|
-
display: flex;
|
|
57
|
-
flex-direction: column;
|
|
58
|
-
gap: 2px;
|
|
59
|
-
min-width: 0;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
.dsh-field--inline .dsh-field__text {
|
|
63
|
-
flex: 1 1 auto;
|
|
64
|
-
}
|
|
65
|
-
`
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 注入字段样式。
|
|
69
|
-
*
|
|
70
|
-
* @returns 释放函数。
|
|
71
|
-
*/
|
|
72
|
-
function injectFieldStyles(): void {
|
|
73
|
-
injectUiStyle('basic/field.css', FIELD_CSS)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** {@link Field} 的 props。 */
|
|
77
|
-
export interface FieldProps {
|
|
78
|
-
/** 字段标签。 */
|
|
79
|
-
label?: React.ReactNode
|
|
80
|
-
/** 控件下方或右侧的说明文字。 */
|
|
81
|
-
description?: React.ReactNode
|
|
82
|
-
/** 校验失败消息。存在时以 `role="alert"` 渲染。 */
|
|
83
|
-
error?: React.ReactNode
|
|
84
|
-
/** 与控件 `id` 关联的标签 `htmlFor`。 */
|
|
85
|
-
htmlFor?: string
|
|
86
|
-
/** 标记为必填,仅在标签后显示星号。 */
|
|
87
|
-
required?: boolean
|
|
88
|
-
/**
|
|
89
|
-
* 布局。`stack` 让标签在上、控件在下;`inline` 让文字在左、控件在右,
|
|
90
|
-
* 适合开关与短选择器。
|
|
91
|
-
*/
|
|
92
|
-
layout?: 'stack' | 'inline'
|
|
93
|
-
/** 控件。 */
|
|
94
|
-
children?: React.ReactNode
|
|
95
|
-
/** 追加类名。 */
|
|
96
|
-
className?: string
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* 标签、控件与说明文字组成的标准字段。
|
|
101
|
-
*
|
|
102
|
-
* @param props - 见 {@link FieldProps}。
|
|
103
|
-
* @returns 字段容器元素。
|
|
104
|
-
*/
|
|
105
|
-
export function Field({
|
|
106
|
-
label,
|
|
107
|
-
description,
|
|
108
|
-
error,
|
|
109
|
-
htmlFor,
|
|
110
|
-
required,
|
|
111
|
-
layout = 'stack',
|
|
112
|
-
children,
|
|
113
|
-
className,
|
|
114
|
-
}: FieldProps): React.ReactElement {
|
|
115
|
-
injectFieldStyles()
|
|
116
|
-
const hasError = error !== undefined && error !== null && error !== false
|
|
117
|
-
const text =
|
|
118
|
-
label === undefined && description === undefined
|
|
119
|
-
? null
|
|
120
|
-
: (
|
|
121
|
-
<div className="dsh-field__text">
|
|
122
|
-
{label === undefined
|
|
123
|
-
? null
|
|
124
|
-
: (
|
|
125
|
-
<label className="dsh-field__label" htmlFor={htmlFor}>
|
|
126
|
-
{label}
|
|
127
|
-
{required === true ? <span className="dsh-field__required">*</span> : null}
|
|
128
|
-
</label>
|
|
129
|
-
)}
|
|
130
|
-
{description === undefined ? null : <span className="dsh-field__desc">{description}</span>}
|
|
131
|
-
</div>
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
if (layout === 'inline') {
|
|
135
|
-
return (
|
|
136
|
-
<div className={cx('dsh-field', 'dsh-field--inline', className)}>
|
|
137
|
-
{text}
|
|
138
|
-
{children}
|
|
139
|
-
{hasError ? (
|
|
140
|
-
<span className="dsh-field__error" role="alert">
|
|
141
|
-
{error}
|
|
142
|
-
</span>
|
|
143
|
-
) : null}
|
|
144
|
-
</div>
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return (
|
|
149
|
-
<div className={cx('dsh-field', className)}>
|
|
150
|
-
{text}
|
|
151
|
-
{children}
|
|
152
|
-
{hasError ? (
|
|
153
|
-
<span className="dsh-field__error" role="alert">
|
|
154
|
-
{error}
|
|
155
|
-
</span>
|
|
156
|
-
) : null}
|
|
157
|
-
</div>
|
|
158
|
-
)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/** {@link Form} 的 props,与 Arco 的 `Form` 一致。 */
|
|
162
|
-
export type FormProps = React.ComponentPropsWithoutRef<typeof Arco.Form>
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* 表单容器,提供 Arco 的校验、布局与提交语义。
|
|
166
|
-
*
|
|
167
|
-
* @param props - 见 {@link FormProps}。
|
|
168
|
-
* @returns 表单元素。
|
|
169
|
-
*/
|
|
170
|
-
export function Form(props: FormProps): React.ReactElement {
|
|
171
|
-
injectBasicStyles()
|
|
172
|
-
return <Arco.Form {...props} />
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** {@link FormItem} 的 props。 */
|
|
176
|
-
export type FormItemProps = React.ComponentPropsWithoutRef<typeof Arco.Form.Item>
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* 表单中的一项,带标签与校验消息。
|
|
180
|
-
*
|
|
181
|
-
* @param props - 见 {@link FormItemProps}。
|
|
182
|
-
* @returns 表单项元素。
|
|
183
|
-
*/
|
|
184
|
-
export function FormItem(props: FormItemProps): React.ReactElement {
|
|
185
|
-
injectBasicStyles()
|
|
186
|
-
return <Arco.Form.Item {...props} />
|
|
187
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 表单与字段容器。
|
|
3
|
+
*
|
|
4
|
+
* `Field` 是设置页最常用的组合:标签、控件、说明文字与校验消息。它自己不做
|
|
5
|
+
* 校验,只在有 `error` 时把消息以 `role="alert"` 渲染出来,并把 `id` 关联到
|
|
6
|
+
* 标签上。`Form` 直接沿用 Arco 的校验与布局能力。
|
|
7
|
+
*
|
|
8
|
+
* @module @dsh-plugin/dsh-ui-components/basic/form
|
|
9
|
+
*/
|
|
10
|
+
import * as React from 'react'
|
|
11
|
+
import { Arco } from '@dsh-plugin/dsh-loader/client'
|
|
12
|
+
import { cx, injectUiStyle } from '../foundation/style.js'
|
|
13
|
+
import { injectBasicStyles } from './styles.js'
|
|
14
|
+
|
|
15
|
+
/** 字段容器的样式表,单独一张,避免与控件表混在一起。 */
|
|
16
|
+
const FIELD_CSS = `
|
|
17
|
+
.dsh-field {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
gap: 6px;
|
|
21
|
+
min-width: 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.dsh-field__label {
|
|
25
|
+
font-size: 13px;
|
|
26
|
+
font-weight: 500;
|
|
27
|
+
line-height: 20px;
|
|
28
|
+
color: var(--dsw-alias-label-secondary);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.dsh-field__required {
|
|
32
|
+
margin-left: 2px;
|
|
33
|
+
color: var(--dsw-alias-state-error-primary);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.dsh-field__desc {
|
|
37
|
+
font-size: 12px;
|
|
38
|
+
line-height: 18px;
|
|
39
|
+
color: var(--dsw-alias-label-tertiary);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.dsh-field__error {
|
|
43
|
+
font-size: 12px;
|
|
44
|
+
line-height: 18px;
|
|
45
|
+
color: var(--dsw-alias-state-error-primary);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.dsh-field--inline {
|
|
49
|
+
flex-direction: row;
|
|
50
|
+
align-items: center;
|
|
51
|
+
justify-content: space-between;
|
|
52
|
+
gap: 16px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.dsh-field__text {
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-direction: column;
|
|
58
|
+
gap: 2px;
|
|
59
|
+
min-width: 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.dsh-field--inline .dsh-field__text {
|
|
63
|
+
flex: 1 1 auto;
|
|
64
|
+
}
|
|
65
|
+
`
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 注入字段样式。
|
|
69
|
+
*
|
|
70
|
+
* @returns 释放函数。
|
|
71
|
+
*/
|
|
72
|
+
function injectFieldStyles(): void {
|
|
73
|
+
injectUiStyle('basic/field.css', FIELD_CSS)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** {@link Field} 的 props。 */
|
|
77
|
+
export interface FieldProps {
|
|
78
|
+
/** 字段标签。 */
|
|
79
|
+
label?: React.ReactNode
|
|
80
|
+
/** 控件下方或右侧的说明文字。 */
|
|
81
|
+
description?: React.ReactNode
|
|
82
|
+
/** 校验失败消息。存在时以 `role="alert"` 渲染。 */
|
|
83
|
+
error?: React.ReactNode
|
|
84
|
+
/** 与控件 `id` 关联的标签 `htmlFor`。 */
|
|
85
|
+
htmlFor?: string
|
|
86
|
+
/** 标记为必填,仅在标签后显示星号。 */
|
|
87
|
+
required?: boolean
|
|
88
|
+
/**
|
|
89
|
+
* 布局。`stack` 让标签在上、控件在下;`inline` 让文字在左、控件在右,
|
|
90
|
+
* 适合开关与短选择器。
|
|
91
|
+
*/
|
|
92
|
+
layout?: 'stack' | 'inline'
|
|
93
|
+
/** 控件。 */
|
|
94
|
+
children?: React.ReactNode
|
|
95
|
+
/** 追加类名。 */
|
|
96
|
+
className?: string
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 标签、控件与说明文字组成的标准字段。
|
|
101
|
+
*
|
|
102
|
+
* @param props - 见 {@link FieldProps}。
|
|
103
|
+
* @returns 字段容器元素。
|
|
104
|
+
*/
|
|
105
|
+
export function Field({
|
|
106
|
+
label,
|
|
107
|
+
description,
|
|
108
|
+
error,
|
|
109
|
+
htmlFor,
|
|
110
|
+
required,
|
|
111
|
+
layout = 'stack',
|
|
112
|
+
children,
|
|
113
|
+
className,
|
|
114
|
+
}: FieldProps): React.ReactElement {
|
|
115
|
+
injectFieldStyles()
|
|
116
|
+
const hasError = error !== undefined && error !== null && error !== false
|
|
117
|
+
const text =
|
|
118
|
+
label === undefined && description === undefined
|
|
119
|
+
? null
|
|
120
|
+
: (
|
|
121
|
+
<div className="dsh-field__text">
|
|
122
|
+
{label === undefined
|
|
123
|
+
? null
|
|
124
|
+
: (
|
|
125
|
+
<label className="dsh-field__label" htmlFor={htmlFor}>
|
|
126
|
+
{label}
|
|
127
|
+
{required === true ? <span className="dsh-field__required">*</span> : null}
|
|
128
|
+
</label>
|
|
129
|
+
)}
|
|
130
|
+
{description === undefined ? null : <span className="dsh-field__desc">{description}</span>}
|
|
131
|
+
</div>
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
if (layout === 'inline') {
|
|
135
|
+
return (
|
|
136
|
+
<div className={cx('dsh-field', 'dsh-field--inline', className)}>
|
|
137
|
+
{text}
|
|
138
|
+
{children}
|
|
139
|
+
{hasError ? (
|
|
140
|
+
<span className="dsh-field__error" role="alert">
|
|
141
|
+
{error}
|
|
142
|
+
</span>
|
|
143
|
+
) : null}
|
|
144
|
+
</div>
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<div className={cx('dsh-field', className)}>
|
|
150
|
+
{text}
|
|
151
|
+
{children}
|
|
152
|
+
{hasError ? (
|
|
153
|
+
<span className="dsh-field__error" role="alert">
|
|
154
|
+
{error}
|
|
155
|
+
</span>
|
|
156
|
+
) : null}
|
|
157
|
+
</div>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** {@link Form} 的 props,与 Arco 的 `Form` 一致。 */
|
|
162
|
+
export type FormProps = React.ComponentPropsWithoutRef<typeof Arco.Form>
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 表单容器,提供 Arco 的校验、布局与提交语义。
|
|
166
|
+
*
|
|
167
|
+
* @param props - 见 {@link FormProps}。
|
|
168
|
+
* @returns 表单元素。
|
|
169
|
+
*/
|
|
170
|
+
export function Form(props: FormProps): React.ReactElement {
|
|
171
|
+
injectBasicStyles()
|
|
172
|
+
return <Arco.Form {...props} />
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** {@link FormItem} 的 props。 */
|
|
176
|
+
export type FormItemProps = React.ComponentPropsWithoutRef<typeof Arco.Form.Item>
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 表单中的一项,带标签与校验消息。
|
|
180
|
+
*
|
|
181
|
+
* @param props - 见 {@link FormItemProps}。
|
|
182
|
+
* @returns 表单项元素。
|
|
183
|
+
*/
|
|
184
|
+
export function FormItem(props: FormItemProps): React.ReactElement {
|
|
185
|
+
injectBasicStyles()
|
|
186
|
+
return <Arco.Form.Item {...props} />
|
|
187
|
+
}
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 图标按钮。
|
|
3
|
-
*
|
|
4
|
-
* 只有图标的按钮必须带可访问名称,因此 `label` 是必填项,它同时成为
|
|
5
|
-
* `aria-label` 与 `title`。
|
|
6
|
-
*
|
|
7
|
-
* @module @dsh-plugin/dsh-ui-components/basic/icon-button
|
|
8
|
-
*/
|
|
9
|
-
import * as React from 'react'
|
|
10
|
-
import { Arco } from '@dsh-plugin/dsh-loader/client'
|
|
11
|
-
import { injectBasicStyles } from './styles.js'
|
|
12
|
-
import { type ButtonProps, type ButtonSize, type ButtonVariant } from './button.js'
|
|
13
|
-
|
|
14
|
-
/** {@link IconButton} 的 props。 */
|
|
15
|
-
export type IconButtonProps = Omit<ButtonProps, 'children' | 'icon' | 'shape'> & {
|
|
16
|
-
/** 按钮图标,通常是 `<Icon ... />` 或从逐图标子路径引入的组件。 */
|
|
17
|
-
icon: React.ReactNode
|
|
18
|
-
/** 可访问名称,作为 `aria-label` 与 `title`。 */
|
|
19
|
-
label: string
|
|
20
|
-
/** 形状,默认 `square`。 */
|
|
21
|
-
shape?: 'square' | 'circle'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** DSH 尺寸到 Arco 尺寸的映射。 */
|
|
25
|
-
const ARCO_SIZE: Record<ButtonSize, 'default' | 'small' | 'large'> = {
|
|
26
|
-
md: 'default',
|
|
27
|
-
sm: 'small',
|
|
28
|
-
lg: 'large',
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Arco 的 `type` 取值。 */
|
|
32
|
-
const ARCO_TYPE: Record<ButtonVariant, 'primary' | 'secondary' | 'outline' | 'text'> = {
|
|
33
|
-
primary: 'primary',
|
|
34
|
-
secondary: 'secondary',
|
|
35
|
-
outline: 'outline',
|
|
36
|
-
text: 'text',
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 只显示图标的方形或圆形按钮。
|
|
41
|
-
*
|
|
42
|
-
* @param props - 见 {@link IconButtonProps}。
|
|
43
|
-
* @param ref - 指向原生 `button` 元素。
|
|
44
|
-
* @returns 图标按钮元素。
|
|
45
|
-
*/
|
|
46
|
-
export const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(
|
|
47
|
-
{ icon, label, shape = 'square', variant = 'text', size = 'md', danger, htmlType, ...rest },
|
|
48
|
-
ref,
|
|
49
|
-
) {
|
|
50
|
-
injectBasicStyles()
|
|
51
|
-
return (
|
|
52
|
-
<Arco.Button
|
|
53
|
-
{...rest}
|
|
54
|
-
ref={ref}
|
|
55
|
-
type={ARCO_TYPE[variant]}
|
|
56
|
-
size={ARCO_SIZE[size]}
|
|
57
|
-
shape={shape}
|
|
58
|
-
status={danger === true ? 'danger' : undefined}
|
|
59
|
-
htmlType={htmlType ?? 'button'}
|
|
60
|
-
aria-label={label}
|
|
61
|
-
title={rest.title ?? label}
|
|
62
|
-
>
|
|
63
|
-
{icon}
|
|
64
|
-
</Arco.Button>
|
|
65
|
-
)
|
|
66
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* 图标按钮。
|
|
3
|
+
*
|
|
4
|
+
* 只有图标的按钮必须带可访问名称,因此 `label` 是必填项,它同时成为
|
|
5
|
+
* `aria-label` 与 `title`。
|
|
6
|
+
*
|
|
7
|
+
* @module @dsh-plugin/dsh-ui-components/basic/icon-button
|
|
8
|
+
*/
|
|
9
|
+
import * as React from 'react'
|
|
10
|
+
import { Arco } from '@dsh-plugin/dsh-loader/client'
|
|
11
|
+
import { injectBasicStyles } from './styles.js'
|
|
12
|
+
import { type ButtonProps, type ButtonSize, type ButtonVariant } from './button.js'
|
|
13
|
+
|
|
14
|
+
/** {@link IconButton} 的 props。 */
|
|
15
|
+
export type IconButtonProps = Omit<ButtonProps, 'children' | 'icon' | 'shape'> & {
|
|
16
|
+
/** 按钮图标,通常是 `<Icon ... />` 或从逐图标子路径引入的组件。 */
|
|
17
|
+
icon: React.ReactNode
|
|
18
|
+
/** 可访问名称,作为 `aria-label` 与 `title`。 */
|
|
19
|
+
label: string
|
|
20
|
+
/** 形状,默认 `square`。 */
|
|
21
|
+
shape?: 'square' | 'circle'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** DSH 尺寸到 Arco 尺寸的映射。 */
|
|
25
|
+
const ARCO_SIZE: Record<ButtonSize, 'default' | 'small' | 'large'> = {
|
|
26
|
+
md: 'default',
|
|
27
|
+
sm: 'small',
|
|
28
|
+
lg: 'large',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Arco 的 `type` 取值。 */
|
|
32
|
+
const ARCO_TYPE: Record<ButtonVariant, 'primary' | 'secondary' | 'outline' | 'text'> = {
|
|
33
|
+
primary: 'primary',
|
|
34
|
+
secondary: 'secondary',
|
|
35
|
+
outline: 'outline',
|
|
36
|
+
text: 'text',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 只显示图标的方形或圆形按钮。
|
|
41
|
+
*
|
|
42
|
+
* @param props - 见 {@link IconButtonProps}。
|
|
43
|
+
* @param ref - 指向原生 `button` 元素。
|
|
44
|
+
* @returns 图标按钮元素。
|
|
45
|
+
*/
|
|
46
|
+
export const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(
|
|
47
|
+
{ icon, label, shape = 'square', variant = 'text', size = 'md', danger, htmlType, ...rest },
|
|
48
|
+
ref,
|
|
49
|
+
) {
|
|
50
|
+
injectBasicStyles()
|
|
51
|
+
return (
|
|
52
|
+
<Arco.Button
|
|
53
|
+
{...rest}
|
|
54
|
+
ref={ref}
|
|
55
|
+
type={ARCO_TYPE[variant]}
|
|
56
|
+
size={ARCO_SIZE[size]}
|
|
57
|
+
shape={shape}
|
|
58
|
+
status={danger === true ? 'danger' : undefined}
|
|
59
|
+
htmlType={htmlType ?? 'button'}
|
|
60
|
+
aria-label={label}
|
|
61
|
+
title={rest.title ?? label}
|
|
62
|
+
>
|
|
63
|
+
{icon}
|
|
64
|
+
</Arco.Button>
|
|
65
|
+
)
|
|
66
|
+
})
|
package/src/basic/index.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 基础控件出口。
|
|
3
|
-
*
|
|
4
|
-
* @module @dsh-plugin/dsh-ui-components/basic
|
|
5
|
-
*/
|
|
6
|
-
export { Button, type ButtonProps, type ButtonSize, type ButtonVariant } from './button.js'
|
|
7
|
-
export { IconButton, type IconButtonProps } from './icon-button.js'
|
|
8
|
-
export {
|
|
9
|
-
Input,
|
|
10
|
-
InputNumber,
|
|
11
|
-
Textarea,
|
|
12
|
-
type FieldSize,
|
|
13
|
-
type InputNumberProps,
|
|
14
|
-
type InputNumberRef,
|
|
15
|
-
type InputProps,
|
|
16
|
-
type InputRef,
|
|
17
|
-
type TextareaProps,
|
|
18
|
-
type TextareaRef,
|
|
19
|
-
} from './input.js'
|
|
20
|
-
export { AutoComplete, Select, type AutoCompleteProps, type SelectOption, type SelectProps } from './select.js'
|
|
21
|
-
export {
|
|
22
|
-
Checkbox,
|
|
23
|
-
CheckboxGroup,
|
|
24
|
-
Radio,
|
|
25
|
-
RadioGroup,
|
|
26
|
-
Rate,
|
|
27
|
-
Slider,
|
|
28
|
-
Switch,
|
|
29
|
-
type CheckboxGroupProps,
|
|
30
|
-
type CheckboxProps,
|
|
31
|
-
type RadioGroupProps,
|
|
32
|
-
type RadioProps,
|
|
33
|
-
type RateProps,
|
|
34
|
-
type SliderProps,
|
|
35
|
-
type SwitchProps,
|
|
36
|
-
} from './toggle.js'
|
|
37
|
-
export { Field, Form, FormItem, type FieldProps, type FormItemProps, type FormProps } from './form.js'
|
|
38
|
-
export { BASIC_CSS, injectBasicStyles } from './styles.js'
|
|
1
|
+
/**
|
|
2
|
+
* 基础控件出口。
|
|
3
|
+
*
|
|
4
|
+
* @module @dsh-plugin/dsh-ui-components/basic
|
|
5
|
+
*/
|
|
6
|
+
export { Button, type ButtonProps, type ButtonSize, type ButtonVariant } from './button.js'
|
|
7
|
+
export { IconButton, type IconButtonProps } from './icon-button.js'
|
|
8
|
+
export {
|
|
9
|
+
Input,
|
|
10
|
+
InputNumber,
|
|
11
|
+
Textarea,
|
|
12
|
+
type FieldSize,
|
|
13
|
+
type InputNumberProps,
|
|
14
|
+
type InputNumberRef,
|
|
15
|
+
type InputProps,
|
|
16
|
+
type InputRef,
|
|
17
|
+
type TextareaProps,
|
|
18
|
+
type TextareaRef,
|
|
19
|
+
} from './input.js'
|
|
20
|
+
export { AutoComplete, Select, type AutoCompleteProps, type SelectOption, type SelectProps } from './select.js'
|
|
21
|
+
export {
|
|
22
|
+
Checkbox,
|
|
23
|
+
CheckboxGroup,
|
|
24
|
+
Radio,
|
|
25
|
+
RadioGroup,
|
|
26
|
+
Rate,
|
|
27
|
+
Slider,
|
|
28
|
+
Switch,
|
|
29
|
+
type CheckboxGroupProps,
|
|
30
|
+
type CheckboxProps,
|
|
31
|
+
type RadioGroupProps,
|
|
32
|
+
type RadioProps,
|
|
33
|
+
type RateProps,
|
|
34
|
+
type SliderProps,
|
|
35
|
+
type SwitchProps,
|
|
36
|
+
} from './toggle.js'
|
|
37
|
+
export { Field, Form, FormItem, type FieldProps, type FormItemProps, type FormProps } from './form.js'
|
|
38
|
+
export { BASIC_CSS, injectBasicStyles } from './styles.js'
|