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

feat(astro): add support for footer override #423

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

RonithManikonda
Copy link
Collaborator

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

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
Copy link

stackblitz bot commented Nov 21, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@AriPerkkio AriPerkkio changed the title feat(dev): add support for footer override feat(astro): add support for footer override Nov 22, 2024
Copy link

cloudflare-workers-and-pages bot commented Nov 22, 2024

Deploying tutorialkit-demo-page with  Cloudflare Pages  Cloudflare Pages

Latest commit: 696ee1b
Status: ✅  Deploy successful!
Preview URL: https://fe31838d.tutorialkit-demo-page.pages.dev
Branch Preview URL: https://ronith-overriding-footer.tutorialkit-demo-page.pages.dev

View logs

Copy link
Member

@AriPerkkio AriPerkkio left a 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:

"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:

  • Add types here:

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:

/**
* 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';
}

AriPerkkio and others added 2 commits November 22, 2024 18:20
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.
Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FooterWrapper.astro should have following elements:

{
editPageLink && (
<div class="pb-4 mt-8 border-b border-tk-border-secondary">
<a
href={editPageLink}
class="inline-flex flex-items-center text-tk-elements-link-secondaryColor hover:text-tk-elements-link-secondaryColorHover hover:underline"
>
<span class="icon i-ph-note-pencil pointer-events-none h-5 w-5 mr-2" />
<span>{lesson.data.i18n!.editPageText}</span>
</a>
</div>
)
}
<div class="grid grid-cols-[1fr_1fr] gap-4 mt-8 mb-6">
<div class="flex">
{prev && <NavCard lesson={prev} type="prev" />}
</div>
<div class="flex">
{next && <NavCard lesson={next} type="next" />}
</div>
</div>
<a
class="inline-block mt-auto font-size-3.5 underline text-tk-elements-link-secondaryColor hover:text-tk-elements-link-secondaryColorHover"
href="https://webcontainers.io/"
>
{lesson.data.i18n!.webcontainerLinkText}
</a>

These should be passed to Footer with following named slots:

  • edit-page-link
  • lesson-link
  • webcontainers-link

So for example the Edit Page -link becomes something like

-<div class="pb-4 mt-8 border-b border-tk-border-secondary">
+<div slot="edit-page-link" class="pb-4 mt-8 border-b border-tk-border-secondary">
  <a
    href={editPageLink}
    class="inline-flex flex-items-center text-tk-elements-link-secondaryColor hover:text-tk-elements-link-secondaryColorHover hover:underline"

Then in Footer.astro we would have those slots like:

<footer>
  <slot name="edit-page-link" />
  <slot name="lesson-links" />
  <slot name="webcontainers-link" />
</footer>

Then the FooterWrapper.astro should be used in TutorialContent.astro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overriding the footer
2 participants