ranui 0.1.0-alpha
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/.vitepress/config.ts +26 -0
- package/.vitepress/theme/index.ts +9 -0
- package/assets/image/failImage.ts +4 -0
- package/assets/svgs/check-circle.svg +4 -0
- package/assets/svgs/close-circle.svg +4 -0
- package/assets/svgs/eye-close.svg +4 -0
- package/assets/svgs/eye.svg +4 -0
- package/assets/svgs/info-circle.svg +5 -0
- package/assets/svgs/lock.svg +4 -0
- package/assets/svgs/unlock.svg +4 -0
- package/assets/svgs/user.svg +3 -0
- package/components/button/index.less +95 -0
- package/components/button/index.ts +64 -0
- package/components/form/index.less +0 -0
- package/components/form/index.ts +36 -0
- package/components/image/index.less +0 -0
- package/components/image/index.ts +62 -0
- package/components/input/index.less +114 -0
- package/components/input/index.ts +367 -0
- package/components/modal/index.less +0 -0
- package/components/modal/index.ts +118 -0
- package/components/tabPane/index.less +0 -0
- package/components/tabPane/index.ts +71 -0
- package/components/tabs/index.less +47 -0
- package/components/tabs/index.ts +207 -0
- package/dist/assets/image/failImage.d.ts +2 -0
- package/dist/components/button/index.d.ts +2 -0
- package/dist/components/image/index.d.ts +2 -0
- package/dist/components/input/index.d.ts +2 -0
- package/dist/components/modal/index.d.ts +2 -0
- package/dist/components/tabPane/index.d.ts +2 -0
- package/dist/components/tabs/index.d.ts +2 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +677 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +2 -0
- package/dist/index.umd.cjs.map +1 -0
- package/dist/style.css +1 -0
- package/dist/typings.d.ts +4 -0
- package/dist/utils/index.d.ts +7 -0
- package/docs/button/index.md +25 -0
- package/docs/image/index.md +9 -0
- package/docs/input/index.md +146 -0
- package/docs/tabs/index.md +121 -0
- package/index.html +67 -0
- package/index.md +1 -0
- package/index.ts +6 -0
- package/package.json +33 -0
- package/plugins/auto-import-file.ts +59 -0
- package/plugins/load-style.ts +31 -0
- package/tsconfig.json +31 -0
- package/typings.d.ts +4 -0
- package/utils/index.ts +12 -0
- package/vite.config.ts +58 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { isDisabled } from '@/utils/index'
|
|
2
|
+
class Tabs extends HTMLElement {
|
|
3
|
+
static get observedAttributes() {
|
|
4
|
+
return ["active", 'forceRender'];
|
|
5
|
+
}
|
|
6
|
+
_container: HTMLDivElement;
|
|
7
|
+
_header: HTMLDivElement;
|
|
8
|
+
_nav: HTMLDivElement;
|
|
9
|
+
_line: HTMLDivElement;
|
|
10
|
+
_content: HTMLDivElement;
|
|
11
|
+
_wrap: HTMLDivElement;
|
|
12
|
+
_slot: HTMLSlotElement;
|
|
13
|
+
tabHeaderKeyMapIndex: Record<string, number>;
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
/**
|
|
17
|
+
* <div class="tab">
|
|
18
|
+
* <div class="tab-header">
|
|
19
|
+
* <div class="tab-header_nav">...</div>
|
|
20
|
+
* <div class="tab-header_line"></div>
|
|
21
|
+
* </div>
|
|
22
|
+
* <div class="tab-content">
|
|
23
|
+
* <div class="tab-content_wrap">
|
|
24
|
+
* <slot></slot>
|
|
25
|
+
* </div>
|
|
26
|
+
* </div>
|
|
27
|
+
* </div>
|
|
28
|
+
*/
|
|
29
|
+
this._container = document.createElement("div");
|
|
30
|
+
this._container.setAttribute("class", "tab");
|
|
31
|
+
this._header = document.createElement("div");
|
|
32
|
+
this._header.setAttribute("class", "tab-header");
|
|
33
|
+
this._nav = document.createElement("div");
|
|
34
|
+
this._nav.setAttribute("class", "tab-header_nav");
|
|
35
|
+
this._line = document.createElement("div");
|
|
36
|
+
this._line.setAttribute("class", "tab-header_line");
|
|
37
|
+
this._content = document.createElement("div");
|
|
38
|
+
this._content.setAttribute("class", "tab-content");
|
|
39
|
+
this._wrap = document.createElement("div");
|
|
40
|
+
this._wrap.setAttribute("class", "tab-content_wrap");
|
|
41
|
+
this._slot = document.createElement("slot");
|
|
42
|
+
this._wrap.appendChild(this._slot);
|
|
43
|
+
this._content.appendChild(this._wrap);
|
|
44
|
+
this._header.appendChild(this._nav);
|
|
45
|
+
this._header.appendChild(this._line);
|
|
46
|
+
this._container.appendChild(this._header);
|
|
47
|
+
this._container.appendChild(this._content);
|
|
48
|
+
|
|
49
|
+
this.tabHeaderKeyMapIndex = {}
|
|
50
|
+
|
|
51
|
+
const shadowRoot = this.attachShadow({ mode: "closed" });
|
|
52
|
+
shadowRoot.appendChild(this._container);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get align() {
|
|
56
|
+
return this.getAttribute("align") || "start";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
set align(value) {
|
|
60
|
+
this.setAttribute("align", value);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get type() {
|
|
64
|
+
return this.getAttribute("type") || "flat";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get active() {
|
|
68
|
+
return this.getAttribute("active");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
set active(value) {
|
|
72
|
+
if (value) {
|
|
73
|
+
this.setAttribute("active", value);
|
|
74
|
+
this.setTabLine(value)
|
|
75
|
+
this.setTabContent(value)
|
|
76
|
+
} else {
|
|
77
|
+
this.removeAttribute("active");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
set type(value) {
|
|
82
|
+
this.setAttribute("type", value);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @description: 构建tabPane组件key值和index的映射,同时判断一个tabs下的tabPane key值不能重复
|
|
86
|
+
* @param {string} key
|
|
87
|
+
* @param {number} index
|
|
88
|
+
*/
|
|
89
|
+
initTabHeaderKeyMapIndex = (key: string, index: number) => {
|
|
90
|
+
const value = this.tabHeaderKeyMapIndex[key]
|
|
91
|
+
if (value) {
|
|
92
|
+
throw new Error('tab 组件的 key 值存在重复, 或者某个 tab 组件缺少 key 属性')
|
|
93
|
+
} else {
|
|
94
|
+
this.tabHeaderKeyMapIndex[key] = index
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @description: 根据传入的tabPane生成tabs的头部
|
|
99
|
+
* @param {Element} tabPane
|
|
100
|
+
* @param {number} index
|
|
101
|
+
* @return {Element}
|
|
102
|
+
*/
|
|
103
|
+
createTabHeader(tabPane: Element, index: number) {
|
|
104
|
+
const label = tabPane.getAttribute("label") || '';
|
|
105
|
+
const key = tabPane.getAttribute('key') || `${index}`
|
|
106
|
+
const type = tabPane.getAttribute('type') || 'text'
|
|
107
|
+
this.initTabHeaderKeyMapIndex(key, index)
|
|
108
|
+
const tabHeader = document.createElement('r-button')
|
|
109
|
+
tabHeader.setAttribute('class', 'tab-header_nav__item')
|
|
110
|
+
tabHeader.setAttribute('type', type)
|
|
111
|
+
isDisabled(tabPane) && tabHeader.setAttribute('disabled', '')
|
|
112
|
+
tabHeader.setAttribute('ran-key', key)
|
|
113
|
+
tabHeader.innerHTML = label
|
|
114
|
+
return tabHeader
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @description: 通过key值设置tabLine的位置
|
|
118
|
+
* @param {string} key
|
|
119
|
+
*/
|
|
120
|
+
setTabLine = (key: string) => {
|
|
121
|
+
if (key) {
|
|
122
|
+
const index = this.tabHeaderKeyMapIndex[key]
|
|
123
|
+
this._line.style.setProperty('transform', `translateX(${100 * index}%)`)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* @description: 通过传入的key值设置tabContent
|
|
128
|
+
*/
|
|
129
|
+
setTabContent = (key: string) => {
|
|
130
|
+
if (key) {
|
|
131
|
+
const index = this.tabHeaderKeyMapIndex[key]
|
|
132
|
+
this._wrap.style.setProperty('transform', `translateX(${index * -100}%)`)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @description: 根据点击设置tabLine的位置
|
|
137
|
+
* @param {Event} e
|
|
138
|
+
* @param {number} index
|
|
139
|
+
* @param {number} width
|
|
140
|
+
*/
|
|
141
|
+
clickTabHead = (e: Event) => {
|
|
142
|
+
const tabHeader = e.target as Element
|
|
143
|
+
const key = tabHeader.getAttribute('ran-key')
|
|
144
|
+
const disabled = isDisabled(tabHeader)
|
|
145
|
+
if (!disabled && key) {
|
|
146
|
+
this.setAttribute('active', key)
|
|
147
|
+
this.setTabLine(key)
|
|
148
|
+
this.setTabContent(key)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @description: 初始化tabs的active属性和tabLine,tabContent
|
|
153
|
+
*/
|
|
154
|
+
initActive = () => {
|
|
155
|
+
const tabHeaderList = [...this._nav.children]
|
|
156
|
+
const initTabHeader = tabHeaderList.filter(item => !isDisabled(item)).shift()
|
|
157
|
+
if (!initTabHeader) return
|
|
158
|
+
const index = tabHeaderList.findIndex(item => item === initTabHeader)
|
|
159
|
+
const key = initTabHeader?.getAttribute('ran-key') || `${index}`
|
|
160
|
+
if (this.active === null && key !== null) {
|
|
161
|
+
this.setAttribute('active', `${key}`)
|
|
162
|
+
const { width = 0 } = initTabHeader.getBoundingClientRect()
|
|
163
|
+
this._line.style.setProperty("width", `${width}px`);
|
|
164
|
+
this.setTabLine(key)
|
|
165
|
+
this.setTabContent(key)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @description: 监听slot组件的添加/删除/替换操作,进行tabs初始化
|
|
170
|
+
* @return {*}
|
|
171
|
+
*/
|
|
172
|
+
listenSlotChange = () => {
|
|
173
|
+
const slots = this._slot.assignedElements();
|
|
174
|
+
slots.forEach((item, index) => {
|
|
175
|
+
const tabPane = this.createTabHeader(item, index)
|
|
176
|
+
this._nav.appendChild(tabPane)
|
|
177
|
+
tabPane.addEventListener('click', this.clickTabHead)
|
|
178
|
+
});
|
|
179
|
+
this.initActive()
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
connectedCallback() {
|
|
183
|
+
this._slot.addEventListener("slotchange", this.listenSlotChange);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
disconnectCallback() {
|
|
187
|
+
this._slot.removeEventListener("slotchange", this.listenSlotChange);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
|
191
|
+
if (oldValue !== newValue) {
|
|
192
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
193
|
+
detail: {
|
|
194
|
+
active: this.active,
|
|
195
|
+
}
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function CustomElement() {
|
|
202
|
+
if (!customElements.get("r-tabs")) {
|
|
203
|
+
customElements.define("r-tabs", Tabs);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export default CustomElement();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const failImage = "\n data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAADDCAYAAADQvc6UAAABRWlDQ1BJQ0MgUHJvZmlsZQAAKJFjYGASSSwoyGFhYGDIzSspCnJ3UoiIjFJgf8LAwSDCIMogwMCcmFxc4BgQ4ANUwgCjUcG3awyMIPqyLsis7PPOq3QdDFcvjV3jOD1boQVTPQrgSkktTgbSf4A4LbmgqISBgTEFyFYuLykAsTuAbJEioKOA7DkgdjqEvQHEToKwj4DVhAQ5A9k3gGyB5IxEoBmML4BsnSQk8XQkNtReEOBxcfXxUQg1Mjc0dyHgXNJBSWpFCYh2zi+oLMpMzyhRcASGUqqCZ16yno6CkYGRAQMDKMwhqj/fAIcloxgHQqxAjIHBEugw5sUIsSQpBobtQPdLciLEVJYzMPBHMDBsayhILEqEO4DxG0txmrERhM29nYGBddr//5/DGRjYNRkY/l7////39v///y4Dmn+LgeHANwDrkl1AuO+pmgAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAA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CRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiEC/wGgKKC4YMA4TAAAAABJRU5ErkJggg==\n";
|
|
2
|
+
export default failImage;
|
package/dist/index.d.ts
ADDED
|
File without changes
|