Skip to content

Commit

Permalink
feat(indexes): add css variable
Browse files Browse the repository at this point in the history
  • Loading branch information
anlyyao committed Jul 25, 2022
1 parent df8026d commit 222d816
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
12 changes: 12 additions & 0 deletions src/indexes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ isComponent: true
"t-indexes": "tdesign-miniprogram/indexes/indexes"
}
```
### 主题定制
CSS 变量名|说明
--|--
--td-indexes-title-color | 索引标题颜色;
--td-indexes-title-bg-color | 索引标题背景颜色;
--td-indexes-children-text-color | 索引内容文本颜色;
--td-indexes-children-bg-color | 索引内容背景颜色;
--td-indexes-index-text-color | 索引文本颜色;
--td-indexes-index-text-active-color | 索引文本激活态颜色;
--td-indexes-index-bg-color | 索引背景颜色;
--td-indexes-tips-text-color | 索引提示信息颜色;
--td-indexes-tips-bg-color | 索引提示信息颜色;

## 代码演示

Expand Down
36 changes: 27 additions & 9 deletions src/indexes/indexes.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '../common/style/index.less';

@font-size: 32rpx;
@color: #000;

Expand All @@ -9,21 +11,36 @@

@primary-color: #0071ce;

@background-color: #f8f8f8;
@front-background-color: white;

@active-color: #0052d9;
@active-font-size: 32rpx;
@active-line-height: 56rpx;

.t-indexes {
background-color: @background-color;
page {
--td-indexes-title-color: @text-level-3-color;
--td-indexes-title-bg-color: @bg-color-fade;
--td-indexes-children-text-color: @color;
--td-indexes-children-bg-color: @front-background-color;
--td-indexes-index-text-color: @hint-color;
--td-indexes-index-text-active-color: @active-color;
--td-indexes-index-bg-color: @front-background-color;
--td-indexes-tips-text-color: @front-background-color;
--td-indexes-tips-bg-color: @active-color;
}

.@{prefix}-indexes {
position: relative;

&__title {
color: var(--td-indexes-title-color);
background-color: var(--td-indexes-title-bg-color);
}

&__row {
font-size: @font-size;
color: @color;
background-color: @front-background-color;
color: var(--td-indexes-children-text-color);
background-color: var(--td-indexes-children-bg-color);
height: @cell-height;
display: flex;
align-items: center;
Expand All @@ -40,7 +57,8 @@
right: 0;
width: 100rpx;
font-size: 24rpx;
color: @hint-color;
color: var(--td-indexes-index-text-color);
background-color: var(--td-indexes-index-bg-color);
font-size: @hint-font-size;
line-height: @hint-line-height;
text-align: center;
Expand All @@ -63,7 +81,7 @@
position: relative;

&.is-actived {
color: @active-color;
color: var(--td-indexes-index-text-active-color);
font-size: @active-font-size;
line-height: @active-line-height;
}
Expand All @@ -77,8 +95,8 @@
vertical-align: middle;
font-size: 40rpx;
font-weight: 700;
color: white;
background-color: @active-color;
color: var(--td-indexes-tips-text-color);
background-color: var(--td-indexes-tips-bg-color);
border-radius: 40rpx 40rpx 0;
position: absolute;
top: 0;
Expand Down
3 changes: 2 additions & 1 deletion src/indexes/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const topOffset = 40; // 滑动选中高亮的顶部偏移(px)

@wxComponent()
export default class IndexBar extends SuperComponent {
externalClasses = ['t-class', 't-class-index'];
externalClasses = [`${prefix}-class`, `${prefix}-class-index`];

properties = props;

Expand All @@ -30,6 +30,7 @@ export default class IndexBar extends SuperComponent {
};

data = {
prefix,
classPrefix,
clientHeight: 0,
groups: [],
Expand Down
11 changes: 4 additions & 7 deletions src/indexes/indexes.wxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<view class="{{classPrefix}} t-class">
<view class="{{classPrefix}} {{prefix}}-class">
<scroll-view
class="{{classPrefix}}__content"
scroll-y
Expand All @@ -8,7 +8,7 @@
bindscroll="onListScroll"
>
<t-cell-group
t-class="{{classPrefix}}__group"
t-class-title="{{classPrefix}}__title"
class="{{classPrefix}}__group"
wx:for="{{ groups }}"
wx:key="index"
Expand All @@ -29,7 +29,7 @@
></t-cell>
</t-cell-group>
</scroll-view>
<view class="{{classPrefix}}__index t-class-index">
<view class="{{classPrefix}}__index {{prefix}}-class-index">
<view
class="{{classPrefix}}__bar"
id="id-{{classPrefix}}__bar"
Expand All @@ -46,10 +46,7 @@
data-group="{{ group }}"
>
{{ group.index }}
<view
class="{{classPrefix}}__tips"
wx:if="{{ showScrollTip && currentGroup.index === group.index }}"
>
<view class="{{classPrefix}}__tips" wx:if="{{ showScrollTip && currentGroup.index === group.index }}">
<view class="{{classPrefix}}__tips-text">{{ currentGroup.index }}</view>
</view>
</view>
Expand Down

0 comments on commit 222d816

Please sign in to comment.