@qingwu-ui/select 0.9.0-beta
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 +154 -0
- package/README.md +91 -0
- package/dist/index.cjs +448 -0
- package/dist/index.d.cts +118 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +118 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +449 -0
- package/dist/index.mjs.map +1 -0
- package/dist/style.css +355 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity.
|
|
18
|
+
|
|
19
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
20
|
+
exercising permissions granted by this License.
|
|
21
|
+
|
|
22
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
23
|
+
including but not limited to software source code, documentation
|
|
24
|
+
source, and configuration files.
|
|
25
|
+
|
|
26
|
+
"Object" form shall mean any form resulting from mechanical
|
|
27
|
+
transformation or translation of a Source form, including but
|
|
28
|
+
not limited to compiled object code, generated documentation,
|
|
29
|
+
and conversions to other media types.
|
|
30
|
+
|
|
31
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
32
|
+
Object form, made available under the License, as indicated by a
|
|
33
|
+
copyright notice that is included in or attached to the work.
|
|
34
|
+
|
|
35
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
36
|
+
form, that is based on (or derived from) the Work and for which the
|
|
37
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
38
|
+
represent, as a whole, an original work of authorship.
|
|
39
|
+
|
|
40
|
+
"Contribution" shall mean any work of authorship, including
|
|
41
|
+
the original version of the Work and any modifications or additions
|
|
42
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
43
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
44
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
45
|
+
the copyright owner.
|
|
46
|
+
|
|
47
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
48
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
49
|
+
subsequently incorporated within the Work.
|
|
50
|
+
|
|
51
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
52
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
53
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
54
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
55
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
56
|
+
Work and such Derivative Works in Source or Object form.
|
|
57
|
+
|
|
58
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
59
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
60
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
61
|
+
(except as stated in this section) patent license to make, have made,
|
|
62
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
63
|
+
where such license applies only to those patent claims licensable
|
|
64
|
+
by such Contributor that are necessarily infringed by their
|
|
65
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
66
|
+
with the Work to which such Contribution(s) was submitted.
|
|
67
|
+
|
|
68
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
69
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
70
|
+
modifications, and in Source or Object form, provided that You
|
|
71
|
+
meet the following conditions:
|
|
72
|
+
|
|
73
|
+
(a) You must give any other recipients of the Work or
|
|
74
|
+
Derivative Works a copy of this License; and
|
|
75
|
+
|
|
76
|
+
(b) You must cause any modified files to carry prominent notices
|
|
77
|
+
stating that You changed the files; and
|
|
78
|
+
|
|
79
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
80
|
+
that You distribute, all copyright, patent, trademark, and
|
|
81
|
+
attribution notices from the Source form of the Work,
|
|
82
|
+
excluding those notices that do not pertain to any part of
|
|
83
|
+
the Derivative Works; and
|
|
84
|
+
|
|
85
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
86
|
+
distribution, then any Derivative Works that You distribute must
|
|
87
|
+
include a readable copy of the attribution notices contained
|
|
88
|
+
within such NOTICE file, excluding those notices that do not
|
|
89
|
+
pertain to any part of the Derivative Works, in at least one
|
|
90
|
+
of the following places: within a NOTICE text file distributed
|
|
91
|
+
as part of the Derivative Works; within the Source form or
|
|
92
|
+
documentation, if provided along with the Derivative Works; or,
|
|
93
|
+
within a display generated by the Derivative Works, if and
|
|
94
|
+
wherever such third-party notices normally appear.
|
|
95
|
+
|
|
96
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
97
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
98
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
99
|
+
this License, without any additional terms or conditions.
|
|
100
|
+
|
|
101
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
102
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
103
|
+
except as required for reasonable and customary use in describing the
|
|
104
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
105
|
+
|
|
106
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
107
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
108
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
109
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
110
|
+
implied, including, without limitation, any warranties or conditions
|
|
111
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
112
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
113
|
+
appropriateness of using or redistributing the Work and assume any
|
|
114
|
+
risks associated with Your exercise of permissions under this License.
|
|
115
|
+
|
|
116
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
117
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
118
|
+
unless required by applicable law (such as deliberate and grossly
|
|
119
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
120
|
+
liable to You for damages, including any direct, indirect, special,
|
|
121
|
+
incidental, or consequential damages of any character arising as a
|
|
122
|
+
result of this License or out of the use or inability to use the
|
|
123
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
124
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
125
|
+
other commercial damages or losses), even if such Contributor
|
|
126
|
+
has been advised of the possibility of such damages.
|
|
127
|
+
|
|
128
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
129
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
130
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
131
|
+
or other liability obligations and/or rights consistent with this
|
|
132
|
+
License. However, in accepting such obligations, You may act only
|
|
133
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
134
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
135
|
+
defend, and hold each Contributor harmless for any liability
|
|
136
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
137
|
+
of your accepting any such warranty or additional liability.
|
|
138
|
+
|
|
139
|
+
END OF TERMS AND CONDITIONS
|
|
140
|
+
|
|
141
|
+
Copyright 2026 QingWu Contributors
|
|
142
|
+
|
|
143
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
144
|
+
you may not use this file except in compliance with the License.
|
|
145
|
+
You may obtain a copy of the License at
|
|
146
|
+
|
|
147
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
148
|
+
|
|
149
|
+
Unless required by applicable law or agreed to in writing, software
|
|
150
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
152
|
+
See the License for the specific language governing permissions and
|
|
153
|
+
limitations under the License.
|
|
154
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @qingwu-ui/select
|
|
2
|
+
|
|
3
|
+
[青梧UI](https://github.com/apricotdream/qingwu-ui) 的 **下拉选择器组件** —— 框架无关,纯 DOM + CSS,零依赖。
|
|
4
|
+
|
|
5
|
+
- **手风琴错峰动画**:打开面板时选项像琴键一样逐项按下(stagger 级联 + 弹性回弹),向上展开时反向级联
|
|
6
|
+
- **选项禁用**:单个选项 `disabled` 置灰、点击无效、键盘导航自动跳过
|
|
7
|
+
- **向上/向下自适应翻转**:贴近视口底边自动向上弹,动画方向同步反转
|
|
8
|
+
- **性能保护**:选项超过 `maxStagger`(默认 12)自动降级为面板整体淡入,避免冗长开幕
|
|
9
|
+
- **键盘优先**:`↑ ↓` 导航(跳过禁用)、`Home`/`End`、`Enter` 选中、`Esc` 关闭、`Tab` 移出关闭
|
|
10
|
+
- **无障碍内建**:`role="combobox"` / `listbox` / `option` + `aria-activedescendant` 完整语义
|
|
11
|
+
- 自动尊重 `prefers-reduced-motion`
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @qingwu-ui/select
|
|
17
|
+
# or: pnpm add @qingwu-ui/select / bun add @qingwu-ui/select
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 使用
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { Select } from "@qingwu-ui/select";
|
|
24
|
+
import "@qingwu-ui/select/style.css";
|
|
25
|
+
|
|
26
|
+
const el = document.querySelector("#root");
|
|
27
|
+
const select = new Select(el, {
|
|
28
|
+
placeholder: "选择框架",
|
|
29
|
+
defaultValue: "react",
|
|
30
|
+
options: [
|
|
31
|
+
{ value: "react", label: "React", hint: "框架无关 · 原生 DOM" },
|
|
32
|
+
{ value: "vue", label: "Vue", hint: "new Select(el) 即用" },
|
|
33
|
+
{ value: "svelte", label: "Svelte" },
|
|
34
|
+
{ value: "ember", label: "Ember", disabled: true },
|
|
35
|
+
],
|
|
36
|
+
onChange: (value, option) => console.log("选中", value, option),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
select.open(); // 或 select.close() / select.toggle()
|
|
40
|
+
|
|
41
|
+
// 受控:外部同步显示值(不触发 onChange)
|
|
42
|
+
select.update({ value: "vue" });
|
|
43
|
+
|
|
44
|
+
select.destroy();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
React / Vue 集成时在 `useEffect` / `onMounted` 中实例化,卸载时调用 `destroy()`。
|
|
48
|
+
|
|
49
|
+
## 配置
|
|
50
|
+
|
|
51
|
+
| 选项 | 类型 | 默认 | 说明 |
|
|
52
|
+
| --- | --- | --- | --- |
|
|
53
|
+
| `options` | `SelectOption[]` | `[]` | 选项列表 |
|
|
54
|
+
| `value` | `string \| null` | `-` | 受控值(传入后用户选择仅回调 `onChange`,显示值由 `update({ value })` 同步) |
|
|
55
|
+
| `defaultValue` | `string \| null` | `null` | 非受控初始值 |
|
|
56
|
+
| `placeholder` | `string` | `""` | 未选中时占位文本 |
|
|
57
|
+
| `disabled` | `boolean` | `false` | 整体禁用 |
|
|
58
|
+
| `open` | `boolean` | `false` | 受控展开 |
|
|
59
|
+
| `defaultOpen` | `boolean` | `false` | 非受控初始展开 |
|
|
60
|
+
| `className` | `string` | `""` | 附加到根容器类名 |
|
|
61
|
+
| `width` | `"trigger" \| "auto"` | `"trigger"` | 面板宽度:跟随触发器 / 内容自适应 |
|
|
62
|
+
| `duration` | `number` | `380` | 单个选项错峰动画时长 ms |
|
|
63
|
+
| `stagger` | `number` | `28` | 选项错峰间隔 ms |
|
|
64
|
+
| `animate` | `boolean` | `true` | 手风琴错峰动画开关 |
|
|
65
|
+
| `maxStagger` | `number` | `12` | 超过该选项数降级为整体淡入,`0` 不降级 |
|
|
66
|
+
| `ariaLabel` | `string` | `placeholder` | 触发器无障碍标签 |
|
|
67
|
+
| `onOpenChange` | `(open) => void` | `-` | 展开状态变化回调 |
|
|
68
|
+
| `onChange` | `(value, option) => void` | `-` | 选中值变化回调(取消为 `null`) |
|
|
69
|
+
|
|
70
|
+
`SelectOption`:`{ value: string; label: string; disabled?: boolean; hint?: string; glyph?: string }`
|
|
71
|
+
|
|
72
|
+
## 实例方法
|
|
73
|
+
|
|
74
|
+
| 方法 | 说明 |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| `open()` / `close()` / `toggle()` | 展开 / 关闭 / 切换 |
|
|
77
|
+
| `update(patch)` | 外部同步值 / 选项 / 禁用 / 占位 / 展开(`value` 同步不触发 `onChange`) |
|
|
78
|
+
| `setValue(value)` | 程序化选中(等价 `update({ value })`) |
|
|
79
|
+
| `setDisabled(v)` | 动态切换整体禁用 |
|
|
80
|
+
| `destroy()` | 销毁组件,清空宿主容器并移除面板 |
|
|
81
|
+
|
|
82
|
+
## 属性
|
|
83
|
+
|
|
84
|
+
| 属性 | 说明 |
|
|
85
|
+
| --- | --- |
|
|
86
|
+
| `.value` | 当前选中值(`string \| null`) |
|
|
87
|
+
| `.expanded` | 是否展开 |
|
|
88
|
+
|
|
89
|
+
## 主题
|
|
90
|
+
|
|
91
|
+
样式由 `--qsel-*` 令牌驱动,复用宿主已定义的 `--paper / --card / --ink / --teal / --line` 等;支持 `<html data-theme="dark">` 与 `.dark` 类两种暗色约定。详情见 `style.css`。
|