Catalog npm
Back to packageRELEASE DETAILS

0.0.5

npm

@-ft/mode-next

Next wrapper for theme mode manager

Published10 Sept 2023
Direct dependencies2
Transitive dependenciesNot calculated

README

Current package documentation

mode-next - Theme mode manager wrapper for Next

Next wrapper of dark/light theme mode manager for web

Usage

  • Generate /public/mode.js using @-ft/mode-codegen package.
{
  "variableName": "__theme_mode",
  "persist": {
    "type": "cookie",
    "key": "THEME"
  }
}
  • Load /mode.js in src/app/layout.tsx, apply default cookie-stored theme mode to class name/ssrInitialMode and suppress hydration warning
import { ModeContextProvider } from '@-ft/mode-next';

export default function RootLayout({ children }: PropsWithChildren) {
  return (
    <html
      lang="en"
      className={cookies().get('THEME')?.value === "dark" ? "dark" : undefined}
      suppressHydrationWarning
    >
      <head>
        <script src="/mode.js" />
      </head>
      <body>
        <ModeContextProvider
          variableName="__theme_mode"
          ssrInitialMode={theme?.value ?? "system"}
        >
          {children}
        </ModeContextProvider>
      </body>
    </html>
  );
}
  • Then you can use ModeContext in your app.
'use client';

import { ModeContext } from '@-ft/mode-next';

function ModeBar() {
  const { mode, setMode } = useContext(ModeContext);

  return (
    <Bar>
      Current theme mode is {mode}.
      <Select
        onChange={useCallback((mode) => setMode(mode), [setMode])}
      >
        {['system', 'light', 'dark']}
      </Select>
    </Bar>
  )
}

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@-ft/mode-react
Environment
{
  "local_name": "@-ft/mode-react",
  "alias": false,
  "peer_metadata": null
}
^0.0.7runtime
next
Environment
{
  "local_name": "next",
  "alias": false,
  "peer_metadata": null
}
^13.4.19peer

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "80a55000af93dc4895e1487d2778ba2ca999379c",
  "tarball": "https://registry.npmjs.org/@-ft/mode-next/-/mode-next-0.0.5.tgz",
  "fileCount": 4,
  "integrity": "sha512-CMgPmxiLkiLA/i550lubXYJVHpLNMTUAczyLlS6ZFsZwNWN3BhX84g06X1NZ4+1Tubtt64Iv1RngUhuEBKigYA==",
  "signatures": [
    {
      "sig": "MEUCIQDIhozG61NUk+liVZr4aHngnGnwsiljra6GgM4SVAJrzwIges8KYm5pWZzLtKe/Gr/3RiFjB9EeQBrNPRWRIauEvYc=",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 2131
}

Repository

PENDING
42ts/-ft-mode-next

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:49 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:cc5da29d125514e340f2a9c18ebbcd90ada0c13aa01797889db18cda8d380b09

Other collected versions

0.1.716 May0.1.626 May0.1.517 Apr0.1.417 Apr0.1.317 Apr0.1.227 OctView all collected versions →