diff --git a/src/footer/__test__/__snapshots__/demo.test.jsx.snap b/src/footer/__test__/__snapshots__/demo.test.jsx.snap index 259bf8c23..1e25625bd 100644 --- a/src/footer/__test__/__snapshots__/demo.test.jsx.snap +++ b/src/footer/__test__/__snapshots__/demo.test.jsx.snap @@ -4,16 +4,13 @@ exports[`Footer > Footer baseVue demo works fine 1`] = ` `; @@ -29,9 +26,7 @@ exports[`Footer > Footer linkVue demo works fine 1`] = ` -
Footer linkVue demo works fine 1`] = ` -
@@ -113,7 +104,6 @@ exports[`Footer > Footer logoVue demo works fine 1`] = ` @@ -205,16 +197,13 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = ` @@ -244,9 +233,7 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = ` -
Footer mobileVue demo works fine 1`] = ` -
@@ -341,7 +324,6 @@ exports[`Footer > Footer mobileVue demo works fine 1`] = ` diff --git a/src/footer/__test__/index.test.jsx b/src/footer/__test__/index.test.jsx index c7fea2b3f..0372164e1 100644 --- a/src/footer/__test__/index.test.jsx +++ b/src/footer/__test__/index.test.jsx @@ -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', () => { diff --git a/src/footer/footer.tsx b/src/footer/footer.tsx new file mode 100644 index 000000000..2dc3aea85 --- /dev/null +++ b/src/footer/footer.tsx @@ -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 ( + + {logo.icon && } + {logo.title && {logo.title}} + + ); + }; + + const renderText = () => { + if (props.logo) { + return; + } + + return
{props.text}
; + }; + + const renderLink = () => { + const { links, logo } = props; + const linksLength = links.length - 1; + if (logo || linksLength < 0) { + return; + } + + return ( +
+ {links.map((link, index) => { + return ( + <> + + {link.name} + + {linksLength !== index &&
|
} + + ); + })} +
+ ); + }; + + return () => { + return ( +
+ {renderLogo()} + {renderLink()} + {renderText()} +
+ ); + }; + }, +}); diff --git a/src/footer/footer.vue b/src/footer/footer.vue deleted file mode 100644 index 3b3b5a4f0..000000000 --- a/src/footer/footer.vue +++ /dev/null @@ -1,47 +0,0 @@ - - - diff --git a/src/footer/index.ts b/src/footer/index.ts index f374d5526..56086979a 100644 --- a/src/footer/index.ts +++ b/src/footer/index.ts @@ -1,4 +1,4 @@ -import Footer from './footer.vue'; +import Footer from './footer'; import { withInstall, WithInstallType } from '../shared'; import './style'; diff --git a/src/hooks/useClass.ts b/src/hooks/useClass.ts new file mode 100644 index 000000000..d7e578787 --- /dev/null +++ b/src/hooks/useClass.ts @@ -0,0 +1,10 @@ +import { computed, ref } from 'vue'; +import { useConfig } from '../config-provider/useConfig'; + +export function usePrefixClass(componentName?: string) { + const { classPrefix } = useConfig('classPrefix'); + + return computed(() => { + return componentName ? `${classPrefix.value}-${componentName}` : classPrefix.value; + }); +}