Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ContextMenu2 component #1699

Merged
merged 16 commits into from
Jan 28, 2025
Merged

feat: add ContextMenu2 component #1699

merged 16 commits into from
Jan 28, 2025

Conversation

yomotsu
Copy link
Collaborator

@yomotsu yomotsu commented Jan 23, 2025

この PR は、新規に ContextMenu2 コンポーネントを追加するための PR です。

  • 狭い・広いの画面幅にあわせて、パネル表示位置が変わります
  • 入れ子の多段コンテキストメニューは、hover、タップ、キーボードで展開操作できます
Screen.Recording.2025-01-23.at.16.49.20.mp4

ContextMenu2 の中には、あらかじめ用意した以下を好きなように組み合わせて配置できます。
また、ContextMenu2 の入れ子も可能です。

<ContextMenu2Container>
  <ContextMenu2
    trigger={<button type="button">開く</button>}
    width={316}
  >

    <ContextMenu2HeadingItem>
      見出し
    </ContextMenu2HeadingItem>

    <ContextMenu2SeparatorItem />

    <ContextMenu2ButtonItem onClick={() => alert("clicked")}>
      ボタン
    </ContextMenu2ButtonItem>

  </ContextMenu2>
</ContextMenu2Container>
子コンポーネント名 役割 フォーカス対象
ContextMenu2HeadingItem ラベル見出し 🚫
ContextMenu2HelpTextItem ヘルプテキスト 🚫
ContextMenu2SeparatorItem 区切り線 🚫
ContextMenu2ButtonItem ボタン(押下時コールバックあり)
ContextMenu2CheckItem チェックボックス(チェック時コールバックあり)
ContextMenu2SwitchItem スイッチ(切り替え時コールバックあり)
ContextMenu2TextInputItem テキスト入力欄(入力時コールバックあり)
ContextMenu2ButtonControlsItem Buttonコンポーネントを並べて利用するためのコンテナ -
ContextMenu2TriggerItem ContextMenu2を入れ子にしたとき用のトリガー(押下時コールバックあり)

ContextMenu2/index.ts から全て export されています。

Check List (If️ you added new component in this PR)

  • Export the component in src/components/index.ts
  • Add example to .storybook/documents/Information/Samples/Samples.stories.tsx
  • Localize added component

Copy link

changeset-bot bot commented Jan 23, 2025

🦋 Changeset detected

Latest commit: e4632ae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
ingred-ui Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Jan 23, 2025

Deploy Preview for ingred-ui ready!

Name Link
🔨 Latest commit 987d4f0
🔍 Latest deploy log https://app.netlify.com/sites/ingred-ui/deploys/6791f733dc51820008b91a3c
😎 Deploy Preview https://deploy-preview-1699--ingred-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 23, 2025

Deploy Preview for ingred-ui ready!

Name Link
🔨 Latest commit e4632ae
🔍 Latest deploy log https://app.netlify.com/sites/ingred-ui/deploys/6796f8b814cc56000870859a
😎 Deploy Preview https://deploy-preview-1699--ingred-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@noronaoki
Copy link
Contributor

@yomotsu
挙動などは特に問題無さそうなので、細かいデザインのレビューをします!

スイッチの高さを揃える

image

テキストとスイッチの水平ラインがわずかにずれているので align-items: center; などを使って揃えてください。

アイコンの色

image

アイコンの色は実装サイドで任意のものに変更できるでしょうか?
もしくはコンポーネントで決めておいた方が良ければテキスト同じ黒色にしてください。

水平線のスタイル

image

hr のデフォルトスタイルが残っていそうなので、一旦リセットを行なった上でシンプルなラインにしてください。

見出しのマージン

image

もう少し上下に余裕を持たせたいので4pxの上下マージンを 8px に変更してください。

入れ子の子要素の情報

image

例示されている 100 に当たる情報には、子要素で選択されているメニューの情報が入ることを想定しているため、check形式で複数渡されることがあります。
この時その要素分のエレメントとして渡されるのか、もしくは1つのエレメント内にカンマ区切り等の1つの文字列として渡されるのかどちらになりますか?

inputの横幅

image

inputの横スペースにもう少し余裕を持たせたいので padding: 6px 8px; として横のpaddingを追加してください。

@yomotsu
Copy link
Collaborator Author

yomotsu commented Jan 24, 2025

@noronaoki

スイッチの高さを揃える

調整しました

アイコンの色

アイコンには好きな色を指定できるようになっています。
(さらに、アイコンではないものも入れられます)

参考になる状態を用意しておきました。

image

水平線のスタイル

調整しました

見出しのマージン

調整しました

入れ子の子要素の情報

「check形式で複数渡される」はどのような状態か、絵でお知らせいただくことできますでしょうか?
想定に合わせて、それができるように調整しようと思います

inputの横幅

現状で padding: 6px 8px となっていました。
もう少しあけて、padding: 6px 10pxなどにしてみますか?

Screenshot 2025-01-24 at 11 46 48

@noronaoki
Copy link
Contributor

@yomotsu

アイコンの件、了解です。

「check形式で複数渡される」はどのような状態か、絵でお知らせいただくことできますでしょうか?

例えばこのような形を想定していまして、横幅の状況によっては3点リーダーで端折りたいケースもあるかもしれません。
image

現状で padding: 6px 8px となっていました。

あ、input自体のpaddingはそのままでOKです。
大枠との余白を取りたいのでラッパーの方のpaddingでしたね。
image

あと一点失念してまして、ドラッグ機能は今回のスコープ外となりますでしょうか?
image

@yomotsu
Copy link
Collaborator Author

yomotsu commented Jan 24, 2025

@noronaoki

例えばこのような形を想定

その形式も問題なさそうです
何でも入れられるようにしてみました

image

image

ラッパーの方のpadding

なるほど補足ありがとうございます。
お知らせいただいた数値で対応しました

image

ドラッグ機能は今回のスコープ外

はい、その通りの想定でした

  • ドラッグ並べ替え
  • コンボボックス

の 2 つについては機能が複雑なため、この PR がマージされたあと、それぞれ単体の別の PR として用意しようと考えています。

Copy link
Collaborator

@deatiger deatiger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yomotsu
クライアントで ContextMenu2 を利用する人間としての観点でコメントさせていただきました 🙏

Comment on lines 49 to 61
/**
* コンテキストメニューを開くかどうか。省略時は内部で開閉状態を管理される
*/
open?: boolean;
/**
* 開閉トリガーとなるボタン要素
*/
trigger: ReactElement<
ButtonHTMLAttributes<HTMLButtonElement> & {
ref?: React.Ref<HTMLButtonElement>;
},
"button"
>;
Copy link
Collaborator

@deatiger deatiger Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yomotsu FYI @noronaoki
コンテキストメニューの開閉をクライアントから制御したい場合に open と onOpenChange を使うと理解しました。現状は trigger がオプショナルではないものの、trigger となる button 要素が不要なケースもありえるのかな?と思いました。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

現状は trigger がオプショナルではないものの、trigger となる button 要素が不要なケースもありえるのかな?と思いました。

新 DataTable を実装する際にもあり得そう
https://www.figma.com/design/fUeoFzCzL4rwRuW7CFW4m0/INGRED-UI?node-id=2622-1783&t=gVX4UAFldWFJp9H1-0

Copy link
Collaborator Author

@yomotsu yomotsu Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

button 要素が不要なケース

具体的なユースケースとしては、OS のコンテキストメニューのように、クリックした箇所がそのままトリガーのような振る舞いをする、ということで認識あっているでしょうか?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yomotsu
スクリーンショット 2025-01-24 15 15 16

添付画像の箇所は button じゃないかもと思ったのですが、私の勘違いかもしれないです!

@noronaoki
ContextMenu2 のユースケースとして、button クリック以外をトリガーに表示したいことってありえますかね? 💭

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

トリガー要素無しでクリックした座標をアンカーにできる機能を追加してみました

Screen.Recording.2025-01-24.at.15.40.36.mp4
const { position, setPosition } = useContextMenu2Anchor();
const [open, setOpen] = useState<boolean>(false);

return (
    <ContextMenu2Container>
        <ContextMenu2 open={open} trigger={position} width={316}>
            ...
        </ContextMenu2>
    </ContextMenu2Container>
);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なお、ページネーションの場合は、「ボタン」の機能を持つコンポーネントをクリックして表示することを想定していました

Copy link
Collaborator

@deatiger deatiger Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

素敵です!
これがあればほとんどのユースケースに対応できると思います。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yomotsu @deatiger

ContextMenu2 のユースケースとして、button クリック以外をトリガーに表示したいことってありえますかね?

はい、ボタン無しで決定するケースもあります!

@noronaoki
Copy link
Contributor

@yomotsu
すみません、入れ子メニューなどに用いている矢印アイコンを違うスタイルのものに変更したいのですが、まだ登録されていない新しいアイコンになるのでこれは別で対応いただく方がいいでしょうか?
image

@yomotsu
Copy link
Collaborator Author

yomotsu commented Jan 24, 2025

@noronaoki
既存から選んだほうがいいかなと思っていたのですが、この PR で Icon に追加するということでも大丈夫です。
ただ、既存のものとほぼ形が同じため、似たものが 2 つある状態になってしまい、デザインの揺れが出てしまうのが心配です。

  • 今後も共存して、運用で使い分けの基準を作ってもらうという認識でいいでしょうか?
  • あるいは、既存の方角アイコンを完全に入れ替えにしてしまうのがいいでしょうか?

@noronaoki
Copy link
Contributor

noronaoki commented Jan 24, 2025

@yomotsu

既存の方角アイコンを完全に入れ替えにしてしまう

ありがとうございます、ご指摘のとおり、差し替えたいと思ってます!

@yomotsu
Copy link
Collaborator Author

yomotsu commented Jan 27, 2025

@noronaoki

既存の方向アイコンの形状を最新 Figma に合わせて差し替えました。
arrow_bottom だったものは、arrow_down に変更しています
(arrow_bottom は名前として残っていますが、今後、arrow_down への参照となります)

image

image

Storybook 上で、Icon コンポーネントの説明に注意書きを出しています
Screenshot 2025-01-27 at 12 32 40

@noronaoki
Copy link
Contributor

@yomotsu LGTM!!

Copy link
Collaborator

@deatiger deatiger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

私からも Approve をば。LGTM 👏

@yomotsu
Copy link
Collaborator Author

yomotsu commented Jan 28, 2025

@deatiger
レビューありがとうございます。
PR のマージはどなたかにお願いするのがいいでしょうか?
または、Approve をいただいたあとは私がしてしまって大丈夫でしょうか?

@deatiger
Copy link
Collaborator

@yomotsu

PR のマージはどなたかにお願いするのがいいでしょうか? または、Approve をいただいたあとは私がしてしまって大丈夫でしょうか?

なるほど、確認しますね。

@noronaoki
この運用を決めていないようですが、そもそも現状は従来通りの npm package へリリースするフローで良いのでしたっけ?

@noronaoki
Copy link
Contributor

@deatiger
はい、既存のリリースフローでお願いしたいです!

@deatiger
Copy link
Collaborator

@noronaoki

はい、既存のリリースフローでお願いしたいです!

小山田さんにやっていただきますか?それともこちらでやった方が良いでしょうか?

@deatiger
Copy link
Collaborator

小山田さんにやっていただきますか?それともこちらでやった方が良いでしょうか?

従来は INGRED UI チャンネルに報知したりもしていたので、私の方でやりましょか

@yomotsu
Copy link
Collaborator Author

yomotsu commented Jan 28, 2025

マージしたあとの付随する作業の把握ができていないため、それですと私も大変助かります🙇‍♂️

@noronaoki
Copy link
Contributor

@deatiger では稲垣さんにお願いできればと思います 🙇🏻

@deatiger
Copy link
Collaborator

@yomotsu @noronaoki
では私のほうでマージ・リリースいたします!

@deatiger deatiger merged commit e24e719 into master Jan 28, 2025
3 checks passed
@deatiger deatiger deleted the feat/context-menu-2 branch January 28, 2025 03:12
@FluctMember FluctMember mentioned this pull request Jan 28, 2025
@deatiger
Copy link
Collaborator

FYI @yomotsu 3件まとめてリリースまで完了しております 🙏

@yomotsu
Copy link
Collaborator Author

yomotsu commented Jan 28, 2025

ありがとうございます。助かりました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants