-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat(astro): add support for footer override #423
base: main
Are you sure you want to change the base?
Conversation
adds support for overriding the footer component, similar to the TopBar override setup. Users can now customize footer content such as legal terms, contact info, and copyrights. this change introduces `Footer.astro` and `FooterWrapper.astro` files to allow flexible slotting of footer items, improving customization for standalone tutorial deployments close #323
Run & review this pull request in StackBlitz Codeflow. |
Deploying tutorialkit-demo-page with Cloudflare Pages
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @RonithManikonda, looks good so far! 💯
There are still couple of places we need to update:
- Add the entrypoint here:
tutorialkit/packages/astro/package.json
Lines 16 to 25 in 2740bc9
"exports": { | |
".": "./dist/index.js", | |
"./types": "./types.d.ts", | |
"./default-theme.css": "./dist/default/styles/variables.css", | |
"./default/pages/index.astro": "./dist/default/pages/index.astro", | |
"./default/pages/[...slug].astro": "./dist/default/pages/[...slug].astro", | |
"./default/components/TopBar.astro": "./dist/default/components/TopBar.astro", | |
"./default/components/HeadTags.astro": "./dist/default/components/HeadTags.astro", | |
"./package.json": "./package.json" | |
}, |
- Mention the component here in the documentation:
tutorialkit/docs/tutorialkit.dev/src/content/docs/guides/overriding-components.mdx
Line 12 in 04ea97f
## Configuration |
- Add types here:
tutorialkit/packages/astro/src/default/env-default.d.ts
Lines 10 to 15 in 04ea97f
declare module 'tutorialkit:override-components' { | |
const topBar: typeof import('./src/default/components/TopBar.astro').default; | |
const dialog: typeof import('@tutorialkit/react/dialog').default; | |
export { topBar as TopBar, dialog as Dialog }; | |
} |
- Add component here:
tutorialkit/packages/astro/src/vite-plugins/override-components.ts
Lines 1 to 129 in 2740bc9
/** | |
* A plugin that lets users override TutorialKit's components. | |
* | |
* The virtual module can be imported as: | |
* | |
* ```ts | |
* import { TopBar } from 'tutorialkit:override-components'; | |
* | |
* <TopBar /> | |
* ``` | |
* | |
* User can override the components in `astro.config.ts`: | |
* | |
* ```ts | |
* export default defineConfig({ | |
* integrations: [ | |
* tutorialkit({ | |
* components: { | |
* TopBar: './CustomTopBar.astro', | |
* Dialog: './CustomDialog.tsx', | |
* HeadTags: './CustomHeadLinks.astro', | |
* }, | |
* }), | |
* ], | |
* }); | |
* ``` | |
*/ | |
import type { VitePlugin } from '../types.js'; | |
export interface OverrideComponentsOptions { | |
/** | |
* Component for overriding the top bar. | |
* | |
* This component has slots that are used to pass TutorialKit's default components: | |
* - `logo`: Logo of the application | |
* - `open-in-stackblitz-link`: Link for opening current lesson in StackBlitz | |
* - `theme-switch`: Switch for changing the theme | |
* - `login-button`: For StackBlitz Enterprise user, the login button | |
* | |
* Usage: | |
* | |
* ```jsx | |
* <slot name="logo" /> | |
* <slot name="open-in-stackblitz-link" /> | |
* <slot name="theme-switch" /> | |
* <slot name="login-button" /> | |
* ``` | |
*/ | |
TopBar?: string; | |
/** | |
* Component for overriding confirmation dialogs. | |
* | |
* This component has to be a React component and be the default export of that module. | |
* It will receive same props that `@tutorialkit/react/dialog` supports. | |
*/ | |
Dialog?: string; | |
/** | |
* Component for overriding title, links and metadata in the `<head>` tag. | |
* | |
* This component has slots that are used to pass TutorialKit's default tags: | |
* | |
* - `title`: The page title | |
* - `links`: Links for the favicon, fonts and other assets | |
* - `meta`: Metadata and Open Graph tags | |
* | |
* ```jsx | |
* <slot name="title" /> | |
* <slot name="links" /> | |
* <slot name="meta" /> | |
* ``` | |
*/ | |
HeadTags?: string; | |
} | |
interface Options { | |
components?: OverrideComponentsOptions; | |
defaultRoutes: boolean; | |
} | |
const virtualModuleId = 'tutorialkit:override-components'; | |
const resolvedId = `\0${virtualModuleId}`; | |
export function overrideComponents({ components, defaultRoutes }: Options): VitePlugin { | |
return { | |
name: 'tutorialkit-override-components-plugin', | |
resolveId(id) { | |
if (id === virtualModuleId) { | |
return resolvedId; | |
} | |
return undefined; | |
}, | |
async load(id) { | |
if (id === resolvedId) { | |
const topBar = components?.TopBar || resolveDefaultTopBar(defaultRoutes); | |
const headTags = components?.HeadTags || resolveDefaultHeadTags(defaultRoutes); | |
const dialog = components?.Dialog || '@tutorialkit/react/dialog'; | |
return ` | |
export { default as TopBar } from '${topBar}'; | |
export { default as Dialog } from '${dialog}'; | |
export { default as HeadTags } from '${headTags}'; | |
`; | |
} | |
return undefined; | |
}, | |
}; | |
} | |
function resolveDefaultTopBar(defaultRoutes: boolean) { | |
if (defaultRoutes) { | |
return '@tutorialkit/astro/default/components/TopBar.astro'; | |
} | |
// default `TopBar` is used from local file when `defaultRoutes` is disabled | |
return './src/components/TopBar.astro'; | |
} | |
function resolveDefaultHeadTags(defaultRoutes: boolean) { | |
if (defaultRoutes) { | |
return '@tutorialkit/astro/default/components/HeadTags.astro'; | |
} | |
// default `HeadTags` is used from local file when `defaultRoutes` is disabled | |
return './src/components/HeadTags.astro'; | |
} |
adds support for overriding the footer component, similar to the TopBar override setup. Users can now customize footer content such as legal terms, contact info, and copyrights.
this change introduces
Footer.astro
andFooterWrapper.astro
files to allow flexible slotting of footer items, improving customization for standalone tutorial deploymentsclose #323