project init & fix ui

This commit is contained in:
2023-01-06 14:24:11 +08:00
parent abc4f65a8e
commit ac9b479805
866 changed files with 39916 additions and 53 deletions

View File

@@ -0,0 +1,35 @@
:: BASE_DOC ::
## API
### Collapse Props
name | type | default | description | required
-- | -- | -- | -- | --
custom-style `v0.25.0` | String | - | \- | N
default-expand-all | Boolean | false | \- | N
disabled | Boolean | - | \- | N
expand-icon | Boolean / Slot | true | \- | N
expand-mutex | Boolean | false | \- | N
theme | String | default | optionsdefault/card | N
value | Array | [] | Typescript`CollapseValue` `type CollapseValue = Array<string \| number>`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/collapse/type.ts) | N
default-value | Array | undefined | uncontrolled property。Typescript`CollapseValue` `type CollapseValue = Array<string \| number>`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/collapse/type.ts) | N
### Collapse Events
name | params | description
-- | -- | --
change | `(value: CollapseValue)` | \-
### CollapsePanel Props
name | type | default | description | required
-- | -- | -- | -- | --
content | String / Slot | - | \- | N
custom-style `v0.25.0` | String | - | \- | N
disabled | Boolean | undefined | \- | N
expand-icon | Boolean / Slot | undefined | \- | N
external-classes | Array | - | `['t-class', 't-class-header', 't-class-content']` | N
header | String / Slot | - | \- | N
header-right-content | String / Slot | - | \- | N
value | String / Number | - | \- | N

View File

@@ -0,0 +1,82 @@
---
title: Collapse 折叠面板
description: 用于对复杂区域进行分组和隐藏 常用于订单信息展示等
spline: data
isComponent: true
---
<span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20lines-100%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20functions-100%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20statements-99%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20branches-87%25-blue" /></span>
<div style="background: #ecf2fe; display: flex; align-items: center; line-height: 20px; padding: 14px 24px; border-radius: 3px; color: #555a65">
<svg fill="none" viewBox="0 0 16 16" width="16px" height="16px" style="margin-right: 5px">
<path fill="#0052d9" d="M8 15A7 7 0 108 1a7 7 0 000 14zM7.4 4h1.2v1.2H7.4V4zm.1 2.5h1V12h-1V6.5z" fillOpacity="0.9"></path>
</svg>
该组件于 0.7.3 版本上线,请留意版本。
</div>
## 引入
全局引入,在 miniprogram 根目录下的`app.json`中配置,局部引入,在需要引入的页面或组件的`index.json`中配置。
```json
"usingComponents": {
"t-collapse": "tdesign-miniprogram/collapse/collapse",
"t-collapse-panel": "tdesign-miniprogram/collapse/collapse-panel"
}
```
## 代码演示
### 类型
基础折叠面板
{{ base }}
带操作说明
{{ action }}
手风琴模式
{{ accordion }}
### 样式
卡片折叠面板
{{ theme }}
## API
### Collapse Props
名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
default-expand-all | Boolean | false | 默认是否展开全部 | N
disabled | Boolean | - | 是否禁用面板展开/收起操作 | N
expand-icon | Boolean / Slot | true | 展开图标。值为 undefined 或 false 则不显示展开图标;值为 true 显示默认图标;值类型为函数,则表示完全自定义展开图标 | N
expand-mutex | Boolean | false | 每个面板互斥展开,每次只展开一个面板 | N
style | String | - | 自定义组件样式 | N
theme | String | default | 折叠面板风格。可选项card | N
value | Array | [] | 展开的面板集合。TS 类型:`CollapseValue` `type CollapseValue = Array<string \| number>`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/collapse/type.ts) | N
default-value | Array | undefined | 展开的面板集合。非受控属性。TS 类型:`CollapseValue` `type CollapseValue = Array<string \| number>`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/collapse/type.ts) | N
### Collapse Events
名称 | 参数 | 描述
-- | -- | --
change | `(value: CollapseValue)` | 切换面板时触发,返回变化的值
### CollapsePanel Props
名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
content | String / Slot | - | 折叠面板内容 | N
disabled | Boolean | undefined | 禁止当前面板展开,优先级大于 Collapse 的同名属性 | N
expand-icon | Boolean / Slot | undefined | 当前折叠面板展开图标,优先级大于 Collapse 的同名属性 | N
external-classes | Array | - | 组件类名,用于组件外层元素、标题、内容。`['t-class', 't-class-header', 't-class-content']` | N
header | String / Slot | - | 面板头内容 | N
header-right-content | String / Slot | - | 面板头的右侧区域,一般用于呈现面板操作 | N
style | String | - | 自定义组件样式 | N
value | String / Number | - | 当前面板唯一标识,如果值为空则取当前面下标兜底作为唯一标识 | N

View File

@@ -0,0 +1,3 @@
import { TdCollapsePanelProps } from './type';
declare const props: TdCollapsePanelProps;
export default props;

View File

@@ -0,0 +1,30 @@
const props = {
content: {
type: String,
},
customStyle: {
type: String,
value: '',
},
disabled: {
type: Boolean,
value: null,
},
expandIcon: {
type: Boolean,
value: true,
},
externalClasses: {
type: Array,
},
header: {
type: String,
},
headerRightContent: {
type: String,
},
value: {
type: null,
},
};
export default props;

View File

@@ -0,0 +1,29 @@
import { SuperComponent, RelationsOptions } from '../common/src/index';
import type { TdCollapsePanelProps } from './type';
export interface CollapsePanelProps extends TdCollapsePanelProps {
}
export default class CollapsePanel extends SuperComponent {
externalClasses: string[];
options: {
multipleSlots: boolean;
};
relations: RelationsOptions;
properties: TdCollapsePanelProps;
data: {
prefix: string;
contentHeight: number;
expanded: boolean;
classPrefix: string;
classBasePrefix: string;
ultimateExpandIcon: boolean;
ultimateDisabled: boolean;
};
methods: {
set(data: Record<string, object | any>): Promise<unknown>;
updateExpanded(activeValues: any): Promise<void>;
getRect(selector: string): Promise<WechatMiniprogram.BoundingClientRectCallbackResult>;
updateStyle(expanded: boolean): any;
onClick(): void;
onTransitionEnd(): void;
};
}

View File

@@ -0,0 +1,116 @@
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { SuperComponent, wxComponent } from '../common/src/index';
import config from '../common/config';
import props from './collapse-panel-props';
const { prefix } = config;
const name = `${prefix}-collapse-panel`;
const nextTick = () => new Promise((resolve) => setTimeout(resolve, 20));
let CollapsePanel = class CollapsePanel extends SuperComponent {
constructor() {
super(...arguments);
this.externalClasses = [`${prefix}-class`, `${prefix}-class-content`, `${prefix}-class-header`];
this.options = {
multipleSlots: true,
};
this.relations = {
'./collapse': {
type: 'ancestor',
linked(target) {
this.parent = target;
const { value, defaultExpandAll, expandMutex, expandIcon, disabled } = target.properties;
const activeValues = defaultExpandAll && !expandMutex ? [this.properties.value] : value;
this.setData({
ultimateExpandIcon: expandIcon || this.properties.expandIcon,
ultimateDisabled: this.properties.disabled == null ? disabled : this.properties.disabled,
});
this.updateExpanded(activeValues);
},
},
};
this.properties = props;
this.data = {
prefix,
contentHeight: 0,
expanded: false,
classPrefix: name,
classBasePrefix: prefix,
ultimateExpandIcon: false,
ultimateDisabled: false,
};
this.methods = {
set(data) {
this.setData(data);
return new Promise((resolve) => wx.nextTick(resolve));
},
updateExpanded(activeValues) {
if (!this.parent) {
return Promise.resolve()
.then(nextTick)
.then(() => {
const data = { transition: true };
if (this.data.expanded) {
data.contentHeight = 'auto';
}
this.setData(data);
});
}
const { value } = this.properties;
const expanded = activeValues.includes(value);
if (expanded === this.properties.expanded)
return;
this.setData({ expanded });
this.updateStyle(expanded);
},
getRect(selector) {
return new Promise((resolve) => {
wx.createSelectorQuery()
.in(this)
.select(selector)
.boundingClientRect((rect) => {
if (rect) {
resolve(rect);
}
})
.exec();
});
},
updateStyle(expanded) {
return this.getRect(`.${name}__content`)
.then((rect) => rect.height)
.then((height) => {
if (expanded) {
return this.set({
contentHeight: height ? `${height}px` : 'auto',
});
}
return this.set({ contentHeight: `${height}px` })
.then(nextTick)
.then(() => this.set({ contentHeight: 0 }));
});
},
onClick() {
const { ultimateDisabled } = this.data;
const { value } = this.properties;
if (ultimateDisabled)
return;
this.parent.switch(value);
},
onTransitionEnd() {
if (this.data.expanded) {
this.setData({
contentHeight: 'auto',
});
}
},
};
}
};
CollapsePanel = __decorate([
wxComponent()
], CollapsePanel);
export default CollapsePanel;

View File

@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"t-cell": "../cell/cell"
}
}

View File

@@ -0,0 +1,42 @@
<wxs src="../common/utils.wxs" module="utils" />
<view style="{{ customStyle }}" class="{{classPrefix}} {{prefix}}-class">
<view
class="{{classPrefix}}__title"
aria-role="button"
aria-expanded="{{expanded}}"
aria-disabled="{{ultimateDisabled}}"
bind:tap="onClick"
>
<t-cell
title="{{header}}"
note="{{headerRightContent}}"
bordered
right-icon="{{ ultimateExpandIcon ? (expanded ? 'chevron-up' : 'chevron-down') : '' }}"
t-class="{{classPrefix}}__header {{prefix}}-class-header"
t-class-title="class-title {{ultimateDisabled ? 'class-title--disabled' : ''}}"
t-class-note="class-note {{ultimateDisabled ? 'class-note--disabled' : ''}}"
t-class-right-icon="class-right-icon {{ultimateDisabled ? 'class-right-icon--disabled' : ''}}"
t-class-hover="class-header-hover"
>
<slot name="header" slot="title" />
<slot name="header-right-content" slot="note" />
<slot name="expand-icon" slot="right-icon" />
</t-cell>
</view>
<view
class="{{classPrefix}}__wrapper"
style="height: {{contentHeight}};"
aria-hidden="{{expanded ? '' : true}}"
bind:transitionend="onTransitionEnd"
>
<view
class="{{classPrefix}}__content {{classPrefix}}__content--{{expanded ? 'active' : ''}} {{prefix}}-class-content"
>
{{content}}
<slot />
<slot name="content" />
</view>
</view>
</view>
<!-- parentDisabled -->

View File

@@ -0,0 +1,142 @@
.t-float-left {
float: left;
}
.t-float-right {
float: right;
}
@keyframes tdesign-fade-out {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
.hotspot-expanded.relative {
position: relative;
}
.hotspot-expanded::after {
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
transform: scale(1.5);
}
.t-collapse-panel {
overflow: hidden;
transition: height 200ms ease-in-out;
position: relative;
background-color: #fff;
}
.t-collapse-panel::after {
content: '';
display: block;
position: absolute;
top: unset;
bottom: 0;
left: unset;
right: unset;
background-color: var(--td-collapse-border-color, var(--td-border-color, #e7e7e7));
}
.t-collapse-panel::after {
height: 1px;
left: 0;
right: 0;
transform: scaleY(0.5);
}
.t-collapse-panel--active {
height: auto;
}
.t-collapse-panel--disabled {
pointer-events: none;
}
.t-collapse-panel--disabled .t-collapse-panel__content,
.t-collapse-panel--disabled .t-collapse-panel__header {
opacity: 0.3;
}
.t-collapse-panel__header {
display: flex;
justify-content: space-between;
align-items: center;
padding-left: var(--td-collapse-horizontal-padding, 32rpx);
height: var(--td-collapse-header-height, 96rpx);
color: var(--td-collapse-header-text-color, var(--td-font-gray-1, rgba(0, 0, 0, 0.9)));
position: relative;
}
.t-collapse-panel__header::after {
content: '';
display: block;
position: absolute;
top: unset;
bottom: 0;
left: unset;
right: unset;
background-color: var(--td-collapse-border-color, var(--td-border-color, #e7e7e7));
}
.t-collapse-panel__header::after {
height: 1px;
left: 0;
right: 0;
transform: scaleY(0.5);
}
.t-collapse-panel__header:after {
left: 32rpx;
}
.t-collapse-panel__header-right {
display: inline-flex;
align-items: center;
height: 100%;
}
.t-collapse-panel__header-icon {
height: 100%;
padding-left: 8px;
width: 44px;
padding-right: 8px;
color: var(--td-collapse-icon-color, var(--td-font-gray-3, rgba(0, 0, 0, 0.4)));
}
.t-collapse-panel__extra {
font-size: var(--td-collapse-extra-font-size, var(--td-font-size-m, 32rpx));
}
.t-collapse-panel__body {
position: relative;
}
.t-collapse-panel__body::after {
content: '';
display: block;
position: absolute;
top: unset;
bottom: 0;
left: unset;
right: unset;
background-color: var(--td-collapse-border-color, var(--td-border-color, #e7e7e7));
}
.t-collapse-panel__body::after {
height: 1px;
left: 0;
right: 0;
transform: scaleY(0.5);
}
.t-collapse-panel__wrapper {
transition: height 200ms ease-in-out;
}
.t-collapse-panel__content {
color: var(--td-collapse-content-text-color, var(--td-font-gray-1, rgba(0, 0, 0, 0.9)));
font-size: var(--td-collapse-content-font-size, var(--td-font-size-base, 28rpx));
padding: var(--td-collapse-content-padding, 32rpx);
line-height: var(--td-collapse-content-line-height, 1.5);
}
.class-title {
font-size: var(--td-collapse-title-font-size, var(--td-font-size-m, 32rpx));
}
.class-title--disabled {
color: var(--td-text-disabled-color, rgba(0, 0, 0, 0.26));
}
.class-note--disabled {
color: var(--td-text-disabled-color, rgba(0, 0, 0, 0.26)) !important;
}
.class-right-icon--disabled {
color: var(--td-text-disabled-color, rgba(0, 0, 0, 0.26)) !important;
}

View File

@@ -0,0 +1,27 @@
import { SuperComponent, RelationsOptions } from '../common/src/index';
import type { CollapseValue, TdCollapseProps } from './type';
export interface CollapseProps extends TdCollapseProps {
}
export default class Collapse extends SuperComponent {
options: {
addGlobalClass: boolean;
};
externalClasses: string[];
relations: RelationsOptions;
controlledProps: {
key: string;
event: string;
}[];
properties: TdCollapseProps;
data: {
prefix: string;
classPrefix: string;
};
observers: {
'value, expandMutex '(): void;
};
methods: {
updateExpanded(): void;
switch(panelValue: CollapseValue): void;
};
}

View File

@@ -0,0 +1,70 @@
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { SuperComponent, wxComponent } from '../common/src/index';
import config from '../common/config';
import props from './props';
const { prefix } = config;
const name = `${prefix}-collapse`;
let Collapse = class Collapse extends SuperComponent {
constructor() {
super(...arguments);
this.options = {
addGlobalClass: true,
};
this.externalClasses = [`${prefix}-class`];
this.relations = {
'./collapse-panel': {
type: 'descendant',
linked() {
this.updateExpanded();
},
},
};
this.controlledProps = [
{
key: 'value',
event: 'change',
},
];
this.properties = props;
this.data = {
prefix,
classPrefix: name,
};
this.observers = {
'value, expandMutex '() {
this.updateExpanded();
},
};
this.methods = {
updateExpanded() {
const panels = this.$children;
if (panels.length === 0)
return;
panels.forEach((child) => {
child.updateExpanded(this.properties.value);
});
},
switch(panelValue) {
const { expandMutex, value: activeValues } = this.properties;
let value = [];
const hit = activeValues.indexOf(panelValue);
if (hit > -1) {
value = activeValues.filter((item) => item !== panelValue);
}
else {
value = expandMutex ? [panelValue] : activeValues.concat(panelValue);
}
this._trigger('change', { value });
},
};
}
};
Collapse = __decorate([
wxComponent()
], Collapse);
export default Collapse;

View File

@@ -0,0 +1,3 @@
{
"component": true
}

View File

@@ -0,0 +1,8 @@
<wxs src="../common/utils.wxs" module="_" />
<view
style="{{ customStyle }}"
class="{{prefix}}-class {{_.cls(classPrefix, [['hairline--top-bottom', border], theme])}}"
>
<slot />
</view>

View File

@@ -0,0 +1,32 @@
.t-float-left {
float: left;
}
.t-float-right {
float: right;
}
@keyframes tdesign-fade-out {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
.hotspot-expanded.relative {
position: relative;
}
.hotspot-expanded::after {
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
transform: scale(1.5);
}
.t-collapse--card {
margin: 0 32rpx;
border-radius: var(--td-radius-large, 18rpx);
overflow: hidden;
}

View File

@@ -0,0 +1,6 @@
export { default as Collapse } from './collapse';
export * from './type';
export * from './props';
export * from './collapse-panel-props';
export { CollapseProps } from './collapse';
export { CollapsePanelProps } from './collapse-panel';

View File

@@ -0,0 +1,4 @@
export { default as Collapse } from './collapse';
export * from './type';
export * from './props';
export * from './collapse-panel-props';

View File

@@ -0,0 +1,3 @@
import { TdCollapseProps } from './type';
declare const props: TdCollapseProps;
export default props;

View File

@@ -0,0 +1,34 @@
const props = {
customStyle: {
type: String,
value: '',
},
defaultExpandAll: {
type: Boolean,
value: false,
},
disabled: {
type: Boolean,
},
expandIcon: {
type: Boolean,
value: true,
},
expandMutex: {
type: Boolean,
value: false,
},
theme: {
type: String,
value: 'default',
},
value: {
type: Array,
value: null,
},
defaultValue: {
type: Array,
value: [],
},
};
export default props;

View File

@@ -0,0 +1,69 @@
export interface TdCollapseProps {
customStyle?: {
type: StringConstructor;
value?: string;
};
defaultExpandAll?: {
type: BooleanConstructor;
value?: boolean;
};
disabled?: {
type: BooleanConstructor;
value?: boolean;
};
expandIcon?: {
type: BooleanConstructor;
value?: boolean;
};
expandMutex?: {
type: BooleanConstructor;
value?: boolean;
};
theme?: {
type: StringConstructor;
value?: 'default' | 'card';
};
value?: {
type: ArrayConstructor;
value?: CollapseValue;
};
defaultValue?: {
type: ArrayConstructor;
value?: CollapseValue;
};
}
export interface TdCollapsePanelProps {
content?: {
type: StringConstructor;
value?: string;
};
customStyle?: {
type: StringConstructor;
value?: string;
};
disabled?: {
type: BooleanConstructor;
value?: boolean;
};
expandIcon?: {
type: BooleanConstructor;
value?: boolean;
};
externalClasses?: {
type: ArrayConstructor;
value?: ['t-class', 't-class-header', 't-class-content'];
};
header?: {
type: StringConstructor;
value?: string;
};
headerRightContent?: {
type: StringConstructor;
value?: string;
};
value?: {
type: null;
value?: string | number;
};
}
export declare type CollapseValue = Array<string | number>;

View File

@@ -0,0 +1 @@
export {};