LoginSignup
0
0

More than 1 year has passed since last update.

ライブラリなしでおしゃれなカラーピッカーを実装する【React】

Posted at

はじめに

<input type="color" />を使うことでカラーピッカー(ユーザーに色を選択させるUI)を簡単に実装できますが.見た目があまりかわいくない…

そう思い,色々試してデザインする方法を編み出したので残しておきます.

スクリーンショット 2021-09-16 0.13.30.png

結論

inputタグにopacity: 0;を設定することで透明にし,divタグで囲ってデザインする.

実装例

React+TypeScript+TailwindCSSで今回は円形にデザインした実装例です
スクリーンショット 2021-09-16 0.10.20.png

color.tsx

const Color: React.VFC = () => {
  const [color, setColor] = useState<string>("#000000");

  return (
        <div
          className="w-8 h-8 rounded-full border border-gray-400"
          style={{ background: color }}
        >
          <input
            type="color"
            value={color}
            onChange={(e) => {
              setColor(e.target.value);
            }}
            className="w-full h-full opacity-0"
          />
        </div>
  );
};

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