npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mirrorform

v0.0.29

Published

Reusable form utilities (custom element).

Downloads

29

Readme

mirrorform

再利用可能なフォームユーティリティ(Web Components)

インストール

# npm
npm install mirrorform

# yarn
yarn add mirrorform

# pnpm
pnpm add mirrorform

基本的な使用方法

HTML(スタンドアロン)

<!DOCTYPE html>
<html>
  <head>
    <script
      type="module"
      src="https://unpkg.com/mirrorform/dist/element.global.js"
    ></script>
  </head>
  <body>
    <sales-form title="お問い合わせフォーム" endpoint="/api/contact">
    </sales-form>
  </body>
</html>

React

import { SalesFormReact } from "mirrorform/react";

function App() {
  return (
    <SalesFormReact title="お問い合わせフォーム" endpoint="/api/contact" />
  );
}

Node.js/ES Modules

import { SalesForm } from "mirrorform";

// Web Components として利用
// HTMLで <sales-form> タグが使用可能になります

カスタムスタイリング

1. カスタムスタイルファイルの作成

パッケージをインストールすると、自動的に mirrorform-style.css ファイルがプロジェクトルートに作成されます。このファイルは自動的に読み込まれるため、css属性を指定する必要はありません。

重要: mirrorform-style.css ファイルは、Web サーバーのドキュメントルート(/mirrorform-style.css)からアクセス可能な場所に配置する必要があります。

フォールバック機能: mirrorform-style.css ファイルが存在しない、または読み込みに失敗した場合、自動的にデフォルトスタイルが適用されます。そのため、カスタムスタイルファイルがなくてもフォームは正常に動作します。

一般的な配置場所:

  • 静的サイト: public/mirrorform-style.css または プロジェクトルート
  • Next.js: public/mirrorform-style.css
  • Vite/Webpack: public/mirrorform-style.css
  • Express.js: 静的ファイル提供ディレクトリ内

プロジェクト構成例

Next.js プロジェクト:

my-nextjs-project/
├── public/
│   ├── mirrorform-style.css  ← ここに配置
│   └── favicon.ico
├── pages/
│   └── index.js
└── package.json

Vite プロジェクト:

my-vite-project/
├── public/
│   ├── mirrorform-style.css  ← ここに配置
│   └── vite.svg
├── src/
│   └── main.js
└── package.json

静的サイト:

my-website/
├── mirrorform-style.css  ← ここに配置
├── index.html
└── package.json

ファイル移動手順

パッケージインストール後、作成された mirrorform-style.css ファイルを適切な場所に移動してください:

# Next.js / Vite プロジェクトの場合
mv mirrorform-style.css public/

# 静的サイトの場合(既に正しい場所にあります)
# 移動不要

手動で作成・再作成したい場合は、以下のコマンドを使用できます:

# npm
npx mirrorform init-styles

# yarn
yarn dlx mirrorform init-styles

# 確認なしで自動作成
npx mirrorform init-styles --auto

# 既存ファイルを上書きする場合
npx mirrorform init-styles --force

2. フォームの使用

<sales-form title="お問い合わせフォーム" endpoint="/api/contact"> </sales-form>

注意: mirrorform-style.css ファイルは自動的に読み込まれるため、属性で指定する必要はありません。

3. スタイルのカスタマイズ

mirrorform-style.css ファイルを編集して、以下の要素をスタイリングできます:

  • form - フォーム全体
  • h2 - タイトル
  • label - ラベル
  • input[name="name"] - 名前入力フィールド
  • input[name="company"] - 会社名入力フィールド
  • input[name="email"] - メールアドレス入力フィールド
  • textarea[name="message"] - メッセージ入力フィールド
  • button - 送信ボタン
  • .status.success - 成功メッセージ
  • .status.error - エラーメッセージ

カスタマイズ例

mirrorform-style.css ファイルに以下のように記述することで、フォームをカスタマイズできます:

/* 名前フィールドに青いボーダーを追加 */
input[name="name"] {
  border-left: 4px solid #4299e1;
  background: linear-gradient(90deg, #ebf8ff 0%, #ffffff 100%);
}

/* 送信ボタンのカスタマイズ */
button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

API リファレンス

属性

| 属性 | 型 | デフォルト | 説明 | | ---------- | ------ | -------------- | ------------------------------ | | title | string | "Contact us" | フォームのタイトル | | endpoint | string | "/api/contact" | フォーム送信先のエンドポイント |

注意: 以前のバージョンでは css 属性がありましたが、現在は mirrorform-style.css ファイルが自動的に読み込まれるため不要です。

フォームデータ

送信されるデータの形式:

{
  "name": "田中太郎",
  "company": "株式会社サンプル",
  "email": "[email protected]",
  "message": "お問い合わせ内容..."
}

サーバーサイドの実装例

Express.js

app.post("/api/contact", express.json(), (req, res) => {
  const { name, company, email, message } = req.body;

  // バリデーション
  if (!name || !email || !message) {
    return res.status(400).json({ error: "Required fields are missing" });
  }

  // メール送信やデータベース保存などの処理
  // ...

  res.json({ success: true });
});

Next.js API Routes

export default async function handler(req, res) {
  if (req.method !== "POST") {
    return res.status(405).json({ error: "Method not allowed" });
  }

  const { name, company, email, message } = req.body;

  // バリデーション
  if (!name || !email || !message) {
    return res.status(400).json({ error: "Required fields are missing" });
  }

  // 処理...

  res.json({ success: true });
}

ブラウザサポート

  • Chrome 54+
  • Firefox 63+
  • Safari 10.1+
  • Edge 79+

ライセンス

MIT

開発・貢献

# クローン
git clone https://github.com/stellaps/form.git
cd form

# 依存関係のインストール
yarn install

# 開発モード
yarn dev

# ビルド
yarn build

更新履歴

0.0.8

  • カスタムスタイリング機能を追加
  • mirrorform-style.css ファイルを自動作成・自動読み込み
  • init-styles CLI コマンドを追加
  • css 属性を削除(固定で mirrorform-style.css を読み込み)