Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sidebar): finish support icon #1520

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"subpackages": [
{
"root": "pages/side-bar/",
"pages": ["side-bar", "base/index", "switch/index", "custom/index"]
"pages": ["side-bar", "base/index", "switch/index", "custom/index", "with-icon/index"]
},
{
"root": "pages/action-sheet/",
Expand Down
4 changes: 4 additions & 0 deletions src/side-bar-item/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const props: TdSideBarItemProps = {
type: Boolean,
value: false,
},
/* 图标,传对象则透传至 Icon */
icon: {
type: null,
},
/** 展示的标签 */
label: {
type: String,
Expand Down
3 changes: 2 additions & 1 deletion src/side-bar-item/side-bar-item.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"component": true,
"usingComponents": {
"t-badge": "../badge/badge"
"t-badge": "../badge/badge",
"t-icon": "../icon/icon"
}
}
9 changes: 9 additions & 0 deletions src/side-bar-item/side-bar-item.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
@side-bar-disabled-color: var(--td-side-bar-disabled-color, @font-gray-4);
@side-bar-active-color: var(--td-side-bar-active-color, @primary-color);
@side-bar-border-radius: var(--td-side-bar-border-radius, 18rpx);
@side-bar-icon-size: var(--td-side-bar-icon-size, 40rpx);

.@{prefix}-side-bar-item {
display: flex;
align-items: center;
justify-content: center;
position: relative;
padding: 32rpx;
font-size: @side-bar-font-size;
Expand All @@ -26,6 +30,11 @@
color: @side-bar-active-color;
}

&__icon {
font-size: @side-bar-icon-size;
margin-right: 4rpx;
}

&__prefix,
&__suffix {
z-index: 1;
Expand Down
6 changes: 5 additions & 1 deletion src/side-bar-item/side-bar-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export default class SideBarItem extends SuperComponent {
},
};

observers = {};
observers = {
icon(v) {
this.setData({ _icon: typeof v === 'string' ? { name: v } : v });
},
};

data = {
classPrefix: name,
Expand Down
2 changes: 2 additions & 0 deletions src/side-bar-item/side-bar-item.wxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<import src="../common/template/badge" />
<import src="../common/template/icon" />
<wxs src="../common/utils.wxs" module="_" />

<view
Expand All @@ -13,6 +14,7 @@
<view class="{{classPrefix}}__prefix"></view>
<view class="{{classPrefix}}__suffix"></view>
</block>
<template wx:if="{{_icon}}" is="icon" data="{{ class: classPrefix + '__icon', ..._icon }}" />
<block wx:if="{{badgeProps}}">
<template is="badge" data="{{ ...badgeProps, content: label }}" />
</block>
Expand Down
6 changes: 6 additions & 0 deletions src/side-bar-item/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export interface TdSideBarItemProps {
type: BooleanConstructor;
value?: boolean;
};
/**
* 图标,传对象则透传至 Icon
*/
icon?: {
type: null;
};
/**
* 展示的标签
* @default ''
Expand Down
1 change: 1 addition & 0 deletions src/side-bar/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ name | type | default | description | required
-- | -- | -- | -- | --
badge-props | Object | - | \- | N
disabled | Boolean | false | \- | N
icon | String / Object | - | `1.0.0-rc.1` | N
label | String | - | \- | N
value | String / Number | - | \- | N
9 changes: 9 additions & 0 deletions src/side-bar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ isComponent: true

{{ switch }}

### 带图标侧边导航

{{ with-icon }}

### 自定义样式

{{ custom }}

## API
### SideBar Props

Expand All @@ -56,5 +64,6 @@ click | `(value: number \| string, label: string)` | 点击选项时触发
-- | -- | -- | -- | --
badge-props | Object | - | 透传至 Badge 组件 | N
disabled | Boolean | false | 是否禁用 | N
icon | String / Object | - | `1.0.0-rc.1`。图标,传对象则透传至 Icon | N
label | String | - | 展示的标签 | N
value | String / Number | - | 当前选项的值 | N
Loading