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

refactor(footer): sfc to tsx #1304

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 16 additions & 32 deletions src/footer/__test__/__snapshots__/demo.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ exports[`Footer > Footer baseVue demo works fine 1`] = `
<div
class="t-footer"
>
<!-- logo -->

<!-- text -->
<!--v-if-->
<!---->
<!---->
<div
class="t-footer__text"
>
Copyright © 2019-2023 TDesign.All Rights Reserved.
</div>

</div>
`;

Expand All @@ -29,9 +26,7 @@ exports[`Footer > Footer linkVue demo works fine 1`] = `
<div
class="t-footer"
>
<!-- logo -->

<!-- text -->
<!---->
<div
class="t-footer__link-list"
>
Expand All @@ -43,7 +38,7 @@ exports[`Footer > Footer linkVue demo works fine 1`] = `
>
底部链接
</a>
<!--v-if-->
<!---->


</div>
Expand All @@ -52,7 +47,6 @@ exports[`Footer > Footer linkVue demo works fine 1`] = `
>
Copyright © 2021-2031 TD.All Rights Reserved.
</div>

</div>
</div>
<div
Expand All @@ -61,9 +55,7 @@ exports[`Footer > Footer linkVue demo works fine 1`] = `
<div
class="t-footer"
>
<!-- logo -->

<!-- text -->
<!---->
<div
class="t-footer__link-list"
>
Expand All @@ -88,7 +80,7 @@ exports[`Footer > Footer linkVue demo works fine 1`] = `
>
底部链接
</a>
<!--v-if-->
<!---->


</div>
Expand All @@ -97,7 +89,6 @@ exports[`Footer > Footer linkVue demo works fine 1`] = `
>
Copyright © 2021-2031 TD.All Rights Reserved.
</div>

</div>
</div>

Expand All @@ -113,7 +104,6 @@ exports[`Footer > Footer logoVue demo works fine 1`] = `
<div
class="t-footer"
>
<!-- logo -->
<a
class="t-footer__logo"
>
Expand Down Expand Up @@ -166,6 +156,8 @@ exports[`Footer > Footer logoVue demo works fine 1`] = `
品牌名称
</span>
</a>
<!---->
<!---->
</div>

</div>
Expand Down Expand Up @@ -205,16 +197,13 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = `
<div
class="t-footer"
>
<!-- logo -->

<!-- text -->
<!--v-if-->
<!---->
<!---->
<div
class="t-footer__text"
>
Copyright © 2019-2023 TDesign.All Rights Reserved.
</div>

</div>

</div>
Expand Down Expand Up @@ -244,9 +233,7 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = `
<div
class="t-footer"
>
<!-- logo -->

<!-- text -->
<!---->
<div
class="t-footer__link-list"
>
Expand All @@ -258,7 +245,7 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = `
>
底部链接
</a>
<!--v-if-->
<!---->


</div>
Expand All @@ -267,7 +254,6 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = `
>
Copyright © 2021-2031 TD.All Rights Reserved.
</div>

</div>
</div>
<div
Expand All @@ -276,9 +262,7 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = `
<div
class="t-footer"
>
<!-- logo -->

<!-- text -->
<!---->
<div
class="t-footer__link-list"
>
Expand All @@ -303,7 +287,7 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = `
>
底部链接
</a>
<!--v-if-->
<!---->


</div>
Expand All @@ -312,7 +296,6 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = `
>
Copyright © 2021-2031 TD.All Rights Reserved.
</div>

</div>
</div>

Expand Down Expand Up @@ -341,7 +324,6 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = `
<div
class="t-footer"
>
<!-- logo -->
<a
class="t-footer__logo"
>
Expand Down Expand Up @@ -394,6 +376,8 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = `
品牌名称
</span>
</a>
<!---->
<!---->
</div>


Expand Down
2 changes: 1 addition & 1 deletion src/footer/__test__/index.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils';
import { describe, it, expect } from 'vitest';
import Footer from '../footer.vue';
import Footer from '../footer';

describe('footer', () => {
describe('props', () => {
Expand Down
71 changes: 71 additions & 0 deletions src/footer/footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { defineComponent } from 'vue';
import TImage from '../image';
import FooterProps from './props';
import config from '../config';
import { usePrefixClass } from '../hooks/useClass';

const { prefix } = config;
const name = `${prefix}-footer`;
export default defineComponent({
name,
props: FooterProps,
setup(props) {
const footerClass = usePrefixClass('footer');
const footerLinkClass = usePrefixClass('footer__link');

const renderLogo = () => {
const { logo } = props;
if (!logo) {
return;
}

return (
<a class={`${footerClass.value}__logo`} href={logo.url} target={logo.target}>
{logo.icon && <TImage class={`${footerClass.value}__icon`} src={logo.icon} />}
{logo.title && <span class={`${footerClass.value}__title`}>{logo.title}</span>}
</a>
);
};

const renderText = () => {
if (props.logo) {
return;
}

return <div class={`${footerClass.value}__text`}>{props.text}</div>;
};

const renderLink = () => {
const { links, logo } = props;
const linksLength = links.length - 1;
if (logo || linksLength < 0) {
return;
}

return (
<div class={`${footerLinkClass.value}-list`}>
{links.map((link, index) => {
return (
<>
<a href={link.url} target={link.target} class={`${footerLinkClass.value}-item`}>
{link.name}
</a>
{linksLength !== index && <div class={`${footerLinkClass.value}-line`}>|</div>}
</>
);
})}
</div>
);
};

return () => {
return (
<div class={footerClass.value}>
{renderLogo()}
{renderLink()}
{renderText()}
</div>
);
};
},
});
47 changes: 0 additions & 47 deletions src/footer/footer.vue

This file was deleted.

2 changes: 1 addition & 1 deletion src/footer/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Footer from './footer.vue';
import Footer from './footer';
import { withInstall, WithInstallType } from '../shared';

import './style';
Expand Down
44 changes: 44 additions & 0 deletions src/hooks/useClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { computed, ref } from 'vue';

export function usePrefixClass(componentName?: string) {
// 等 config-provider 支持 classPrefix,从config-provider 导出 classPrefix
const classPrefix = ref('t');

return computed(() => {
return componentName ? `${classPrefix.value}-${componentName}` : classPrefix.value;
});
}

export function useCommonClassName() {
anlyyao marked this conversation as resolved.
Show resolved Hide resolved
// 等 config-provider 支持 classPrefix,从config-provider 导出 classPrefix
const classPrefix = ref('t');

return {
SIZE: computed(() => ({
small: `${classPrefix.value}-size-s`,
medium: `${classPrefix.value}-size-m`,
large: `${classPrefix.value}-size-l`,
default: '',
xs: `${classPrefix.value}-size-xs`,
xl: `${classPrefix.value}-size-xl`,
block: `${classPrefix.value}-size-full-width`,
})),
STATUS: computed(() => ({
loading: `${classPrefix.value}-is-loading`,
loadMore: `${classPrefix.value}-is-load-more`,
disabled: `${classPrefix.value}-is-disabled`,
focused: `${classPrefix.value}-is-focused`,
success: `${classPrefix.value}-is-success`,
error: `${classPrefix.value}-is-error`,
warning: `${classPrefix.value}-is-warning`,
selected: `${classPrefix.value}-is-selected`,
active: `${classPrefix.value}-is-active`,
checked: `${classPrefix.value}-is-checked`,
current: `${classPrefix.value}-is-current`,
hidden: `${classPrefix.value}-is-hidden`,
visible: `${classPrefix.value}-is-visible`,
expanded: `${classPrefix.value}-is-expanded`,
indeterminate: `${classPrefix.value}-is-indeterminate`,
})),
};
}
Loading