0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NextuiのDividerが使えなかったので、Dividerを他の参考にして自作した。

Posted at

はじめに

みなさん、こんにちは torihaziです

最近、Xクローンを作っているのですが

スクリーンショット 2024-09-24 21.19.42.png

こういうやつがNextuiのDividerで作れなかったので

これを機に作ってみました。

多分よくあるやつです!

あとNextui x tailwindです

そもそもNextuiのDividerは?

みた感じこの人、childrenというか

textをpropsか何かで渡せないらしいです。

---- text ------

みたいな感じですね。

<Divider />

しかないらしくて。

個人的には

<Divider text={text} />
<Divider>テキスト</Divider>

みたいな感じを期待していたんですけど。

で、これは困った、ということで作りました。

どうしたか。

import { ReactNode } from "react";

// NextuiのDividerにはテキストを挟み込めないので自作
export const Divider = ({
  children,
  className,
}: {
  children?: ReactNode;
  className?: string;
}) => {
  return (
    <div className={`flex items-center justify-center my-2 ${className}`}>
      <div className="flex-1 border-b" />
      {children}
      <div className="flex-1 border-b" />
    </div>
  );
};

こんな感じにして、呼ぶときは

~~
<Divider className="w-[300px]">または</Divider>
<Divider className="w-[300px]"></Divider>
~~~

てすると

スクリーンショット 2024-09-24 21.32.47.png

こんな感じになります。

他のやつは

<div className="flex-1 border-b mr-2" />

とかmarginつけてたんですが、そうすると文字ないときに不自然になるのでやめました。

終わりに

Nextuiがすごいというからなんでもすごいのかと思ったら

かなり序盤でずっこけました。

あ、ちなみにそれ使ったXクローンの全体図がこちらです。

localhost_3000_auth (2).png

昔に比べたら上出来です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?