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

Where is the Masthead Component? #249

Closed
2 tasks done
clukhei opened this issue Jul 24, 2024 · 4 comments
Closed
2 tasks done

Where is the Masthead Component? #249

clukhei opened this issue Jul 24, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@clukhei
Copy link
Collaborator

clukhei commented Jul 24, 2024

Prerequisites

Describe the issue

I have looked through storybook documentation and cannot find the Masthead or Official Government Banner from govtechsg/sgds-react library.

What operating system(s) are you seeing the problem on?

macOS

What browser(s) are you seeing the problem on?

Chrome

Describe your frontend stack. What version of React and @govtechsg/sgds-react are you using? CSR or SSR?

React v2.5.2

@clukhei clukhei added the bug Something isn't working label Jul 24, 2024
@clukhei
Copy link
Collaborator Author

clukhei commented Jul 24, 2024

Masthead component seats in the web component library under SGDS.

  1. Install the web component library

npm install @govtechsg/sgds-web-component

  1. Import the React wrapped form of the Masthead web component
import SgdsMasthead from "@govtechsg/sgds-web-component/react/masthead/index.js"

const GovernmentBanner = () => (
  return <SgdsMasthead></SgdsMasthead>
);

export default GovernmentBanner;

For more information on the library : https://www.webcomponent.designsystem.tech.gov.sg/?path=/story/getting-started-introduction--page

Masthead Documentation: https://www.webcomponent.designsystem.tech.gov.sg/?path=/docs/components-masthead--basic

@clukhei clukhei closed this as completed Jul 24, 2024
@clukhei clukhei pinned this issue Jul 24, 2024
@rav3 rav3 unpinned this issue Aug 20, 2024
@soedar
Copy link
Contributor

soedar commented Aug 31, 2024

I think the readme of https://github.com/GovTechSG/sgds-masthead/tree/master should include a link to this post, if this post is not pinned. There probably are quite a few projects still using the old masthead (~540 download this week), and the migration steps is not really straightforward imo.


I was running into an issue where importing the @govtechsg/sgds-web-component in a Next.js/T3 project (probably due to Server Side Rending). I got the following error:

ReferenceError: HTMLElement is not defined

A way to resolve this is to create a client component that wraps the SgdsMasthead, which is dynamically imported without ssr:

// _components/masthead.tsx
'use client'

import dynamic from 'next/dynamic';

const SgdsMasthead = dynamic(() => import('@govtechsg/sgds-web-component/react/masthead/index.js'), {
  ssr: false,
});

export default SgdsMasthead;
// layout.tsx
import "~/styles/globals.css";

import { GeistSans } from "geist/font/sans";
import { type Metadata } from "next";

import { TRPCReactProvider } from "~/trpc/react";
import SgdsMasthead from "./_components/masthead"

export const metadata: Metadata = {
  title: "Create T3 App",
  description: "Generated by create-t3-app",
  icons: [{ rel: "icon", url: "/favicon.ico" }],
};

export default function RootLayout({
  children,
}: Readonly<{ children: React.ReactNode }>) {
  return (
    <html lang="en" className={`${GeistSans.variable}`}>
      <body>
        <SgdsMasthead />
        <TRPCReactProvider>{children}</TRPCReactProvider>
      </body>
    </html>
  );
}

@clukhei clukhei pinned this issue Sep 2, 2024
@clukhei
Copy link
Collaborator Author

clukhei commented Sep 3, 2024

pinned! https://github.com/GovTechSG/sgds-masthead/issues

@soedar yup nextjs usage with web component has another level of complexity because web components cant be server rendered.

The documentation about nextjs and web components is here. Another way is to load it via Script to make it fully client
https://webcomponent.designsystem.tech.gov.sg/?path=/docs/getting-started-frameworks-nextjs--docs

We have also just released v2 of web components, do check it out! Migration guide here
https://webcomponent.designsystem.tech.gov.sg/?path=/docs/getting-started-migration--docs

@soedar
Copy link
Contributor

soedar commented Sep 3, 2024

Awesome! Congrats on the release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants