Skip to content

Commit

Permalink
feat: doc-phone support href link (#411)
Browse files Browse the repository at this point in the history
* feat(doc-phone): add href link

* chore: update stylelint rules
  • Loading branch information
fennghuang authored Nov 22, 2023
1 parent 1699189 commit cd4e724
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
10 changes: 10 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,15 @@ module.exports = {
'number-leading-zero': 'never',
'color-function-notation': 'legacy',
'alpha-value-notation': 'number',
// TODO 后面统一改 class 小写 且 BEM,当前按警告提示
'selector-class-pattern': [
'^[a-z]+([-]?[a-z0-9]+)*(__[a-z0-9]([-]?[a-z0-9]+)*)?(--[a-z0-9]([-]?[a-z0-9]+)*)?$',
{
resolveNestedSelectors: true,
message: 'Expected class selector "%s" to be lowercase and BEM format',
severity: 'warning',
},
],
'media-feature-range-notation': 'prefix',
},
};
31 changes: 23 additions & 8 deletions packages/components/src/components/td-doc-phone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import style from './style.less';
import qrcodeIcon from '@images/qrcode.svg?raw';
import mobileIcon from '@images/mobile.svg?raw';
import closeIcon from '@images/close.svg?raw';
import jumpIcon from '@images/jump.svg?raw';

function toggleCollapsePhone(host) {
if (!host.shadowRoot) return;
Expand All @@ -20,6 +21,7 @@ function toggleCollapsePhone(host) {
export default define({
tag: 'td-doc-phone',
headless: false,
href: '',
QRCode: () => QRCode,
qrCanvas: ({ render }) => render().querySelector('#qrcode'),
qrcodeUrl: {
Expand Down Expand Up @@ -50,30 +52,38 @@ export default define({
const { scrollTop, scrollHeight, clientHeight } = document.documentElement;

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

if (scrollTop >= 228) {
if ((scrollTop + 88) >= maxPhonePos && canViewPhoneAndFooter) {
if (scrollTop + 88 >= maxPhonePos && canViewPhoneAndFooter) {
Object.assign(host, {
[key]: {
...host.fixedStyle, position: 'absolute', top: `${maxPhonePos}px`,
...host.fixedStyle,
position: 'absolute',
top: `${maxPhonePos}px`,
},
});
} else {
Object.assign(host, {
[key]: {
...host.fixedStyle, position: 'fixed', top: '152px',
...host.fixedStyle,
position: 'fixed',
top: '152px',
},
});
}
} else {
Object.assign(host, {
[key]: {
...host.fixedStyle, position: 'absolute', top: '316px',
...host.fixedStyle,
position: 'absolute',
top: '316px',
},
});
}
Expand Down Expand Up @@ -105,10 +115,13 @@ export default define({
};
},
},
render: ({ fixedStyle, headless }) => html`
render: ({ fixedStyle, headless, href }) =>
html`
<div class="TDesign-doc-phone-mask" onclick="${toggleCollapsePhone}"></div>
<div class="TDesign-doc-phone" style=${fixedStyle}>
${headless ? html`` : html`
${headless
? html``
: html`
<div class="TDesign-doc-phone__header">
<div class="TDesign-doc-phone__header-icons">
<td-doc-popup placement="left-start">
Expand All @@ -119,6 +132,8 @@ export default define({
</slot>
</div>
</td-doc-popup>
${href &&
html`<a href="${href}" target="_blank"><span class="icon" innerHTML="${jumpIcon}"></span></a>`}
</div>
</div>
`}
Expand Down
7 changes: 4 additions & 3 deletions packages/components/src/components/td-doc-phone/style.less
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
:host {
--phone-display: block;
--phone-collapse-display: none;
--phone-body-height: 520px;

--phone-header-height: 48px;
--phone-body-height: 667px;

@media screen and (max-width: 960px) {
--phone-display: none;
--phone-collapse-display: flex;
Expand Down Expand Up @@ -44,7 +45,7 @@
}

&__header {
height: 48px;
height: var(--phone-header-height);
padding: 8px;
border-radius: 6px 6px 0 0;
box-sizing: border-box;
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/images/jump.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cd4e724

Please sign in to comment.