Git Product home page Git Product logo

nextjs-components's Introduction

nextjs-components

A collection of React components, transcribed from https://vercel.com/design. 1

npm latest package npm next package

nextjs-components

Motivation

Blog post from 01/09/2022

Installation

# with npm
npm i nextjs-components
# with yarn
yarn add nextjs-components

This project needs to be transpiled to work with your Next.js application. It is recommended to use Next.js 13.1.0’s built-in module tranpilation. (Up until Next.js 13.1.0, next-transpile-modules handled this use case.)

// next.config.js

/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
  reactStrictMode: true,
  pageExtensions: ["tsx", "ts"],
  swcMinify: true,
  transpilePackages: ["nextjs-components"],
};

module.exports = nextConfig;

Usage

Using Next 13's app directory

"use client";

// ./app/layout.tsx
import { ThemeContextProvider } from "nextjs-components/src/contexts/ThemeContext";
import "nextjs-components/src/styles/globals.css";

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <ThemeContextProvider>{children}</ThemeContextProvider>
      </body>
    </html>
  );
}

Using the traditional custom _app.tsx

// ./pages/_app.tsx
import {
  ThemeContextProvider,
  ToastArea,
  ToastsProvider,
} from "nextjs-components";
import "nextjs-components/src/styles/globals.css";

function App({ Component, pageProps }) {
  return (
    <ThemeContextProvider>
      <ToastsProvider>
        <Component {...pageProps} />
        <ToastArea />
      </ToastsProvider>
    </ThemeContextProvider>
  );
}

export default App;

Check out the documentation site for more examples!

Warning: Dropped create-react-app support.

In older versions, usage with create-react-app was supported. However, from >=v1.0.0, the pre-built /dist folder was dropped.

Footnotes

  1. This is not affiliated with Vercel ↩

nextjs-components's People

Contributors

actions-user avatar danishweb avatar dtsuper3 avatar g1mishra avatar github-actions[bot] avatar thiskevinwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nextjs-components's Issues

node_module ERROR

I ran it for the first time to test some examples and this happened

(node:17100) [DEP_WEBPACK_MODULE_ISSUER] DeprecationWarning: Module.issuer: Use new ModuleGraph API
(Use `node --trace-deprecation ...` to show where the warning was created)
error - ./node_modules/nextjs-components/dist/components/Avatar/Avatar.module.css
CSS Modules cannot be imported from within node_modules.
Read more: https://nextjs.org/docs/messages/css-modules-npm
Location: node_modules\nextjs-components\dist\components\Avatar\Avatar.js
wait  - compiling /_error (client and server)...
error - ./node_modules/nextjs-components/dist/components/Avatar/Avatar.module.css
CSS Modules cannot be imported from within node_modules.
Read more: https://nextjs.org/docs/messages/css-modules-npm
Location: node_modules\nextjs-components\dist\components\Avatar\Avatar.js
error - SyntaxError: Unexpected token '.'
wait  - compiling...
event - compiled client and server successfully in 122.7s (172 modules)
wait  - compiling /_error (client and server)...
event - compiled client and server successfully in 57 ms (172 modules)
wait  - compiling / (client and server)...
error - ./node_modules/nextjs-components/dist/components/Avatar/Avatar.module.css
CSS Modules cannot be imported from within node_modules.
Read more: https://nextjs.org/docs/messages/css-modules-npm
Location: node_modules\nextjs-components\dist\components\Avatar\Avatar.js
error - SyntaxError: Unexpected token '.'

Combobox

https://vercel.com/design/combobox looks like it uses Radix so I'll need to bring that in as a set of new dependencies

<Combobox placeholder="Search...">
  <Combobox.Input />
  <Combobox.List>
    <Combobox.Option value="a">One</Combobox.Option>
    <Combobox.Option value="b">Two</Combobox.Option>
    <Combobox.Option value="c">Three</Combobox.Option>
  </Combobox.List>
</Combobox>

export dark mode script

<script
          type="text/javascript"
          dangerouslySetInnerHTML={{
            __html: `
(function () {
  let m, t;
  try {
    m = localStorage.getItem("mode");
  } catch (e) {}
  let d = window.matchMedia("(prefers-color-scheme: dark)");
  typeof d.matches == "boolean" && (t = d.matches);
  m === null && t && document.documentElement.classList.add("dark-theme");
  m === "dark" && document.documentElement.classList.add("dark-theme");
  m === "system" && t && document.documentElement.classList.add("dark-theme");
  (window.__mode = m || "system");
})();
`,
          }}
        />

Website updates

Current

CleanShot 2023-01-15 at 10 16 25@2x

New

  • new sideber
  • new light/dark/system toggle
  • new footer nav

CleanShot 2023-01-15 at 10 17 03@2x

πŸ› `<style jsx>`

Observed

Example in Container

styled-jsx usage

      <style jsx>{`
        .geist-container > :global(*) {
          --gap-ratio: ${gap};
        }
      `}</style>

incorrectly results in a plain style dom tag
image

Expected

This doesn't work in the local docs site. It should behave like how it does for https://thekevinwang.com/design/grid/

Implement search

use Lyra search

  1. process all .mdx files, and use Lyra to generate a json blob
  2. use this json blob with Lyra in a API Handler (or edge function)
  3. update frontend to call the resulting endpoint from above

Touch devices / Next ssr issue

const prevFocusedEl = useRef<HTMLElement>(document.activeElement as HTMLElement);

document is not defined

in SSR document is not available
If I pass null
another error ocurred

TypeError: Cannot read properties of null (reading 'contains')

listRef.current.contains(e.target as Node) || ...

Status Dot

@thiskevinwang

  • Please consider renaming the status-dot as SatusDot as we are using this particular kind of naming convention here.
  • Please correct me if I'm wrong. In the Status Dot element
const statusDotState = {
  QUEUED: "This deployment is queued.",
  BUILDING: "This deployment is building.", // building
  READY: "This deployment is ready.",
  ERROR: "This deployment had an error.",
  CANCELED: "This deployment was canceled.",
  INITIALIZING: "This deployment is initializing.", // building
  UPLOADING: "This deployment is uploading.", // building
  DEPLOYING: "This deployment is deploying.", // building
  ARCHIVED: "This deployment is archived.",
} as const;

is used. Now just an opinion that, in this design system we are making similiar design like Vercel, but our motto is not making another Vercel. Instead people would be able to use it in different other projects. But in this line we are totally doing opposite <span className={styles["status-label"]}>{capitalize(state)}</span> user is the one who should be able to set the message of the Status Dot, it shouldn't be pre defined.

Menu (mobile version) bug when used in iframe

Steps to reproduce:

  1. Open demo
    https://codesandbox.io/s/nextjs-components-next-forked-w07pv
  2. Open chrome devtools, enable mobile resolution (touch device) an make sure that width of demo window is less then 600px;
  3. Click on trigger and see that menu is opened and closed in the same time.
    If you tap with directional movement - menu open correctly.

The same bug I found when I tested that component with storybook locally
Video demo with details
https://youtu.be/k78An8Czvhc?t=28

TextField: enable passing `ref`

Description

This allows for imperative input focusing like via a / press handler

const inputRef = useRef<HTMLInputElement>()

// on `/` press
inputRef.current?.focus()

Note

The second ref argument only exists when you define a component with React.forwardRef call. Regular function or class
components don’t receive the ref argument, and ref is not available in props either.

Ref forwarding is not limited to DOM components. You can forward refs to class component instances, too.
https://reactjs.org/docs/forwarding-refs.html

bug(`Menu`) ReferenceError: document is not defined

image

When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.
When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.
error - node_modules/nextjs-components/src/components/Menu/Menu.tsx (138:4) @ Menu
ReferenceError: document is not defined

`Textarea` should allow a ref to be passed

The one use case I've come across is if the textarea is rendered with a large body of text, its height should show all the text when the browser paints.

  const textareaRef = useRef();
  useEffect(() => {
    if (textareaRef.current) {
      textareaRef.current.style.height =
        textareaRef.current.scrollHeight + "px";
    }
  }, [textareaRef.current]);

How to use useButton from '@react-aria/button' with Button component?

I want to use useButton hook from @react-aria/button to get some accesibility props when I work with controlled version of components like SliveOver

import { useButton } from '@react-aria/button';


const triggerRef = useRef();
  // Get props for the trigger and overlay. This also handles
  // hiding the overlay when a parent element of the trigger scrolls
  // (which invalidates the popover positioning).

const { buttonProps: openButtonProps } = useButton(
    {
      onPress: open,
    },
    triggerRef,
 );

...

<Button ref={triggerRef} {...openButtonProps}>
        Open
</Button>

<SomeSlideOverComponentHere />

Props received from useButton hook contain onClick and others

source code of onClick

      onClick(e) {
        if (e && !e.currentTarget.contains(e.target)) {
          return;
        }
       ...
      }

I get error at the line of accessing e.currentTarget.contains
Issue is located inside Button component

onPressEnd: (e) => {
if (e.pointerType === "touch") {
onClick?.(e as any);

There e.currentTarget at least in onPressEnd and onPressStart e.currentTarget in undefined.

How to figure out with this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.