Closed8

【雑記】プリミティブなコンポーネントとは?

1zushun1zushun

モチベーション

どこかの記事で「プリミティブなコンポーネントは〜」という内容を見て「プリミティブってなんだっけ」と思った。Radix Premitivesを使っていてなんとなくプリミティブのニュアンスはわかっているが誰かに説明できるほど理解できていないためプリミティブに言及している記事とかがないか探していく

https://www.radix-ui.com/primitives

1zushun1zushun

https://www.npmjs.com/package/primitive-components

premitive-componentsというライブラリがあって、そちらのdocsにプリミティブの定義があった

This is a library of 'primitive' components. I define primitive to meaning a component that returns a HTML tag, not a React component.

-> プリミティブとは、Reactコンポーネントではなく、HTMLタグを返すコンポーネントを意味する。

1zushun1zushun

https://alexkondov.com/building-low-level-components-the-radix-way/

Radix Primitives is a collection of extensible, unstyled, and accessible components made to serve as the building blocks of your application.

-> Radix Primitivesは、拡張可能で、スタイルがなく、アクセス可能なコンポーネントのコレクションで、アプリケーションの構成要素として使用できます。

1zushun1zushun

https://github.com/lelandrichardson/react-primitives

This library attempts to propose an ideal set of primitives around building React applications, regardless of Platform. In the future, this could be used as a shared interface among React and React Native components that don't use platform-specific APIs.

Reactアプリケーションを構築するための理想的なプリミティブのセットを提案しようとしている。が、この「プリミティブ」の意味を知りたいんだよなあと。

以下の記事でReact Premitivesについて触れていてプリミティブ = 小さなコンポーネントとして説明している

https://medium.com/@valentinowong/using-react-primitives-to-write-once-run-anywhere-79873442aca1

https://qiita.com/Shagamii/items/73f5270ac600ba1c93d8

primitivesという名前はこの共通の必要最低限のものと言った意味で命名されているようです。

1zushun1zushun

https://dev.to/sanjampreetsingh/tailwind-css-primitive-component-libraries-react-uis-future-1aeg

Primitive components - Components that are accessible but without styling, so you can personalise them anyway you want.

-> スタイリングなしでアクセスできるコンポーネントです。

These are more like skeletons without css. Basically providing you with HTML like elements but without any opinionated design language.]

-> これらはどちらかというと、CSSなしのスケルトンのようなものだ。 基本的にはHTMLのような要素を提供するが、デザイン言語としての意見はない。

フォーカス管理、キーボード・ナビゲーション、イベント・リスナー、アクセシビリティ属性、有効なマークアップ、スクリーン・リーダーのサポートなどのエッジケースに対応するのは大変なのでheadless librariesとしてRadix UI, Headless UI, React Ariaが人気があると触れている。

1zushun1zushun

まとめ

プリミティブなコンポーネントとは?

コンテキストによって意味はまちまちだが「スタイリングされていないコンポーネント」「InputやButtonレベルのコンポーネント」という認識で良さそう。Premitive Components = Headless Components(ライブラリとしてRadix UI, Headless UI, React Ariaなどが提供されている)

もっと言及されている記事やエビデンスがあれば優しく教えていただけると🙏

このスクラップは2024/12/24にクローズされました