Skip to content

Commit cd4e724

Browse files
authored
feat: doc-phone support href link (#411)
* feat(doc-phone): add href link * chore: update stylelint rules
1 parent 1699189 commit cd4e724

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

.stylelintrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,15 @@ module.exports = {
44
'number-leading-zero': 'never',
55
'color-function-notation': 'legacy',
66
'alpha-value-notation': 'number',
7+
// TODO 后面统一改 class 小写 且 BEM,当前按警告提示
8+
'selector-class-pattern': [
9+
'^[a-z]+([-]?[a-z0-9]+)*(__[a-z0-9]([-]?[a-z0-9]+)*)?(--[a-z0-9]([-]?[a-z0-9]+)*)?$',
10+
{
11+
resolveNestedSelectors: true,
12+
message: 'Expected class selector "%s" to be lowercase and BEM format',
13+
severity: 'warning',
14+
},
15+
],
16+
'media-feature-range-notation': 'prefix',
717
},
818
};

packages/components/src/components/td-doc-phone/index.js

+23-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import style from './style.less';
44
import qrcodeIcon from '@images/qrcode.svg?raw';
55
import mobileIcon from '@images/mobile.svg?raw';
66
import closeIcon from '@images/close.svg?raw';
7+
import jumpIcon from '@images/jump.svg?raw';
78

89
function toggleCollapsePhone(host) {
910
if (!host.shadowRoot) return;
@@ -20,6 +21,7 @@ function toggleCollapsePhone(host) {
2021
export default define({
2122
tag: 'td-doc-phone',
2223
headless: false,
24+
href: '',
2325
QRCode: () => QRCode,
2426
qrCanvas: ({ render }) => render().querySelector('#qrcode'),
2527
qrcodeUrl: {
@@ -50,30 +52,38 @@ export default define({
5052
const { scrollTop, scrollHeight, clientHeight } = document.documentElement;
5153

5254
// 当底部出现时不要超过底部区域
53-
const FOOTER_HEIGHT = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--footer-height'));
55+
const FOOTER_HEIGHT = parseFloat(
56+
getComputedStyle(document.documentElement).getPropertyValue('--footer-height'),
57+
);
5458
const PHONE_HEIGHT = parseFloat(getComputedStyle(host).getPropertyValue('--phone-body-height'));
5559
const TD_HEIGHT = 64;
5660
const maxPhonePos = scrollHeight - FOOTER_HEIGHT - PHONE_HEIGHT - TD_HEIGHT - 64; // 预留底部 64 像素间距
57-
const canViewPhoneAndFooter = clientHeight <= (FOOTER_HEIGHT + PHONE_HEIGHT + 64);
61+
const canViewPhoneAndFooter = clientHeight <= FOOTER_HEIGHT + PHONE_HEIGHT + 64;
5862

5963
if (scrollTop >= 228) {
60-
if ((scrollTop + 88) >= maxPhonePos && canViewPhoneAndFooter) {
64+
if (scrollTop + 88 >= maxPhonePos && canViewPhoneAndFooter) {
6165
Object.assign(host, {
6266
[key]: {
63-
...host.fixedStyle, position: 'absolute', top: `${maxPhonePos}px`,
67+
...host.fixedStyle,
68+
position: 'absolute',
69+
top: `${maxPhonePos}px`,
6470
},
6571
});
6672
} else {
6773
Object.assign(host, {
6874
[key]: {
69-
...host.fixedStyle, position: 'fixed', top: '152px',
75+
...host.fixedStyle,
76+
position: 'fixed',
77+
top: '152px',
7078
},
7179
});
7280
}
7381
} else {
7482
Object.assign(host, {
7583
[key]: {
76-
...host.fixedStyle, position: 'absolute', top: '316px',
84+
...host.fixedStyle,
85+
position: 'absolute',
86+
top: '316px',
7787
},
7888
});
7989
}
@@ -105,10 +115,13 @@ export default define({
105115
};
106116
},
107117
},
108-
render: ({ fixedStyle, headless }) => html`
118+
render: ({ fixedStyle, headless, href }) =>
119+
html`
109120
<div class="TDesign-doc-phone-mask" onclick="${toggleCollapsePhone}"></div>
110121
<div class="TDesign-doc-phone" style=${fixedStyle}>
111-
${headless ? html`` : html`
122+
${headless
123+
? html``
124+
: html`
112125
<div class="TDesign-doc-phone__header">
113126
<div class="TDesign-doc-phone__header-icons">
114127
<td-doc-popup placement="left-start">
@@ -119,6 +132,8 @@ export default define({
119132
</slot>
120133
</div>
121134
</td-doc-popup>
135+
${href &&
136+
html`<a href="${href}" target="_blank"><span class="icon" innerHTML="${jumpIcon}"></span></a>`}
122137
</div>
123138
</div>
124139
`}

packages/components/src/components/td-doc-phone/style.less

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
:host {
22
--phone-display: block;
33
--phone-collapse-display: none;
4-
--phone-body-height: 520px;
5-
4+
--phone-header-height: 48px;
5+
--phone-body-height: 667px;
6+
67
@media screen and (max-width: 960px) {
78
--phone-display: none;
89
--phone-collapse-display: flex;
@@ -44,7 +45,7 @@
4445
}
4546

4647
&__header {
47-
height: 48px;
48+
height: var(--phone-header-height);
4849
padding: 8px;
4950
border-radius: 6px 6px 0 0;
5051
box-sizing: border-box;
+3
Loading

0 commit comments

Comments
 (0)