Skip to content

Commit 696ee1b

Browse files
feat(vite-plugins): add support for overriding Footer component
extend the override-components plugin to allow customization of the Footer component. added a new `Footer` option to the `OverrideComponentsOptions` interface, updated the `load` function to export the Footer, and introduced a `resolveDefaultFooter` helper function to handle default paths based on the `defaultRoutes` option. BREAKING CHANGE: users upgrading to this version must update their `astro.config.ts` if they wish to customize the new Footer component. refer to the updated documentation for usage.
1 parent 1c6f358 commit 696ee1b

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

docs/tutorialkit.dev/src/content/docs/guides/overriding-components.mdx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,31 @@ When overriding `HeadTags` you can place TutorialKit's default components using
110110
<slot name="meta" />
111111
{/** Add your own tags */}
112112
<link rel="sitemap" href="/sitemap-index.xml" />
113-
```
113+
```
114+
115+
### Footer
116+
117+
The `Footer` component can be overridden to customize the footer content, including legal terms, contact information, and copyrights.
118+
119+
When overriding `Footer`, you can use the following [Astro slots](https://docs.astro.build/en/basics/astro-components/#named-slots) to customize specific parts of the default footer:
120+
121+
- `legal-info`: Content for legal terms or disclaimers
122+
- `contact-info`: Contact details such as email or phone number
123+
- `copyright`: Copyright text for the website
124+
125+
Example override:
126+
127+
```jsx title="src/components/CustomFooter.astro"
128+
<footer>
129+
<slot name="legal-info">
130+
<p>Default legal info</p>
131+
</slot>
132+
133+
<slot name="contact-info">
134+
<p>Contact us at example@example.com</p>
135+
</slot>
136+
137+
<slot name="copyright">
138+
<p>© 2024 Example Company</p>
139+
</slot>
140+
</footer>

packages/astro/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"./default/pages/[...slug].astro": "./dist/default/pages/[...slug].astro",
2222
"./default/components/TopBar.astro": "./dist/default/components/TopBar.astro",
2323
"./default/components/HeadTags.astro": "./dist/default/components/HeadTags.astro",
24+
"./default/components/Footer.astro": "./dist/default/components/Footer.astro",
2425
"./package.json": "./package.json"
2526
},
2627
"files": [

packages/astro/src/default/env-default.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ interface WebContainerConfig {
1010
declare module 'tutorialkit:override-components' {
1111
const topBar: typeof import('./src/default/components/TopBar.astro').default;
1212
const headTags: typeof import('./src/default/components/HeadTags.astro').default;
13+
const footer: typeof import('./src/default/components/Footer.astro').default;
1314
const dialog: typeof import('@tutorialkit/react/dialog').default;
1415

15-
export { topBar as TopBar, dialog as Dialog, headTags as HeadTags };
16+
export { topBar as TopBar, dialog as Dialog, footer as Footer };
1617
}
1718

1819
declare const __ENTERPRISE__: boolean;

packages/astro/src/vite-plugins/override-components.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ export interface OverrideComponentsOptions {
7272
* ```
7373
*/
7474
HeadTags?: string;
75+
76+
/**
77+
* Component for overriding the footer.
78+
*
79+
* This component can be customized to include your own footer elements.
80+
*
81+
* ```jsx
82+
* <footer>
83+
* <p>Custom Footer Content</p>
84+
* </footer>
85+
* ```
86+
*/
87+
Footer?: string;
7588
}
7689

7790
interface Options {
@@ -97,11 +110,13 @@ export function overrideComponents({ components, defaultRoutes }: Options): Vite
97110
const topBar = components?.TopBar || resolveDefaultTopBar(defaultRoutes);
98111
const headTags = components?.HeadTags || resolveDefaultHeadTags(defaultRoutes);
99112
const dialog = components?.Dialog || '@tutorialkit/react/dialog';
113+
const footer = components?.Footer || resolveDefaultFooter(defaultRoutes);
100114

101115
return `
102116
export { default as TopBar } from '${topBar}';
103117
export { default as Dialog } from '${dialog}';
104118
export { default as HeadTags } from '${headTags}';
119+
export { default as Footer } from '${footer}';
105120
`;
106121
}
107122

@@ -127,3 +142,12 @@ function resolveDefaultHeadTags(defaultRoutes: boolean) {
127142
// default `HeadTags` is used from local file when `defaultRoutes` is disabled
128143
return './src/components/HeadTags.astro';
129144
}
145+
146+
function resolveDefaultFooter(defaultRoutes: boolean) {
147+
if (defaultRoutes) {
148+
return '@tutorialkit/astro/default/components/Footer.astro';
149+
}
150+
151+
// default `Footer` is used from local file when `defaultRoutes` is disabled
152+
return './src/components/Footer.astro';
153+
}

0 commit comments

Comments
 (0)