@fringeworks/react-layouts 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.ja.md +234 -0
- package/README.md +236 -0
- package/_internal/_constants.cjs +27 -0
- package/_internal/_constants.d.cts +7 -0
- package/_internal/_constants.d.mts +7 -0
- package/_internal/_constants.mjs +25 -0
- package/_internal/applyLayout/applyLayout.cjs +26 -0
- package/_internal/applyLayout/applyLayout.d.cts +13 -0
- package/_internal/applyLayout/applyLayout.d.mts +14 -0
- package/_internal/applyLayout/applyLayout.mjs +24 -0
- package/_internal/applyLayout/index.cjs +3 -0
- package/_internal/applyLayout/index.d.cts +3 -0
- package/_internal/applyLayout/index.d.mts +3 -0
- package/_internal/applyLayout/index.mjs +3 -0
- package/_internal/applyLayout/types.cjs +0 -0
- package/_internal/applyLayout/types.d.cts +37 -0
- package/_internal/applyLayout/types.d.mts +37 -0
- package/_internal/applyLayout/types.mjs +1 -0
- package/_internal/withLayoutBase/index.cjs +3 -0
- package/_internal/withLayoutBase/index.d.cts +3 -0
- package/_internal/withLayoutBase/index.d.mts +3 -0
- package/_internal/withLayoutBase/index.mjs +3 -0
- package/_internal/withLayoutBase/types.cjs +0 -0
- package/_internal/withLayoutBase/types.d.cts +43 -0
- package/_internal/withLayoutBase/types.d.mts +43 -0
- package/_internal/withLayoutBase/types.mjs +1 -0
- package/_internal/withLayoutBase/withLayoutBase.cjs +50 -0
- package/_internal/withLayoutBase/withLayoutBase.d.cts +13 -0
- package/_internal/withLayoutBase/withLayoutBase.d.mts +14 -0
- package/_internal/withLayoutBase/withLayoutBase.mjs +47 -0
- package/_virtual/_rolldown/runtime.cjs +43 -0
- package/_virtual/_rolldown/runtime.mjs +18 -0
- package/constants.cjs +57 -0
- package/constants.d.cts +20 -0
- package/constants.d.mts +20 -0
- package/constants.mjs +20 -0
- package/css/balance.css +171 -0
- package/css/center.css +189 -0
- package/css/flow.css +205 -0
- package/css/layer.css +72 -0
- package/css/matrix.css +184 -0
- package/css/pack.css +42 -0
- package/css/pin.css +23 -0
- package/css/stack.css +216 -0
- package/css/styles.css +1346 -0
- package/css/tile.css +236 -0
- package/index.cjs +61 -0
- package/index.d.cts +22 -0
- package/index.d.mts +22 -0
- package/index.mjs +13 -0
- package/package.json +56 -0
- package/with-css/index.cjs +68 -0
- package/with-css/index.d.cts +23 -0
- package/with-css/index.d.mts +23 -0
- package/with-css/index.mjs +14 -0
- package/with-css/styles.cjs +14 -0
- package/with-css/styles.d.cts +2 -0
- package/with-css/styles.d.mts +2 -0
- package/with-css/styles.mjs +8 -0
- package/with-css/withBalanceLayout/index.cjs +4 -0
- package/with-css/withBalanceLayout/index.d.cts +3 -0
- package/with-css/withBalanceLayout/index.d.mts +3 -0
- package/with-css/withBalanceLayout/index.mjs +4 -0
- package/with-css/withCenterLayout/index.cjs +4 -0
- package/with-css/withCenterLayout/index.d.cts +3 -0
- package/with-css/withCenterLayout/index.d.mts +3 -0
- package/with-css/withCenterLayout/index.mjs +4 -0
- package/with-css/withFlowLayout/index.cjs +4 -0
- package/with-css/withFlowLayout/index.d.cts +3 -0
- package/with-css/withFlowLayout/index.d.mts +3 -0
- package/with-css/withFlowLayout/index.mjs +4 -0
- package/with-css/withLayerLayout/index.cjs +4 -0
- package/with-css/withLayerLayout/index.d.cts +3 -0
- package/with-css/withLayerLayout/index.d.mts +3 -0
- package/with-css/withLayerLayout/index.mjs +4 -0
- package/with-css/withLayout/index.cjs +4 -0
- package/with-css/withLayout/index.d.cts +3 -0
- package/with-css/withLayout/index.d.mts +3 -0
- package/with-css/withLayout/index.mjs +4 -0
- package/with-css/withMatrixLayout/index.cjs +4 -0
- package/with-css/withMatrixLayout/index.d.cts +3 -0
- package/with-css/withMatrixLayout/index.d.mts +3 -0
- package/with-css/withMatrixLayout/index.mjs +4 -0
- package/with-css/withPackLayout/index.cjs +4 -0
- package/with-css/withPackLayout/index.d.cts +3 -0
- package/with-css/withPackLayout/index.d.mts +3 -0
- package/with-css/withPackLayout/index.mjs +4 -0
- package/with-css/withPinLayout/index.cjs +4 -0
- package/with-css/withPinLayout/index.d.cts +3 -0
- package/with-css/withPinLayout/index.d.mts +3 -0
- package/with-css/withPinLayout/index.mjs +4 -0
- package/with-css/withStackLayout/index.cjs +4 -0
- package/with-css/withStackLayout/index.d.cts +3 -0
- package/with-css/withStackLayout/index.d.mts +3 -0
- package/with-css/withStackLayout/index.mjs +4 -0
- package/with-css/withTileLayout/index.cjs +4 -0
- package/with-css/withTileLayout/index.d.cts +3 -0
- package/with-css/withTileLayout/index.d.mts +3 -0
- package/with-css/withTileLayout/index.mjs +4 -0
- package/withBalanceLayout/index.cjs +3 -0
- package/withBalanceLayout/index.d.cts +3 -0
- package/withBalanceLayout/index.d.mts +3 -0
- package/withBalanceLayout/index.mjs +3 -0
- package/withBalanceLayout/types.cjs +0 -0
- package/withBalanceLayout/types.d.cts +10 -0
- package/withBalanceLayout/types.d.mts +10 -0
- package/withBalanceLayout/types.mjs +1 -0
- package/withBalanceLayout/withBalanceLayout.cjs +18 -0
- package/withBalanceLayout/withBalanceLayout.d.cts +12 -0
- package/withBalanceLayout/withBalanceLayout.d.mts +13 -0
- package/withBalanceLayout/withBalanceLayout.mjs +16 -0
- package/withCenterLayout/index.cjs +3 -0
- package/withCenterLayout/index.d.cts +3 -0
- package/withCenterLayout/index.d.mts +3 -0
- package/withCenterLayout/index.mjs +3 -0
- package/withCenterLayout/types.cjs +0 -0
- package/withCenterLayout/types.d.cts +10 -0
- package/withCenterLayout/types.d.mts +10 -0
- package/withCenterLayout/types.mjs +1 -0
- package/withCenterLayout/withCenterLayout.cjs +18 -0
- package/withCenterLayout/withCenterLayout.d.cts +12 -0
- package/withCenterLayout/withCenterLayout.d.mts +13 -0
- package/withCenterLayout/withCenterLayout.mjs +16 -0
- package/withFlowLayout/index.cjs +3 -0
- package/withFlowLayout/index.d.cts +3 -0
- package/withFlowLayout/index.d.mts +3 -0
- package/withFlowLayout/index.mjs +3 -0
- package/withFlowLayout/types.cjs +0 -0
- package/withFlowLayout/types.d.cts +10 -0
- package/withFlowLayout/types.d.mts +10 -0
- package/withFlowLayout/types.mjs +1 -0
- package/withFlowLayout/withFlowLayout.cjs +18 -0
- package/withFlowLayout/withFlowLayout.d.cts +12 -0
- package/withFlowLayout/withFlowLayout.d.mts +13 -0
- package/withFlowLayout/withFlowLayout.mjs +16 -0
- package/withLayerLayout/index.cjs +3 -0
- package/withLayerLayout/index.d.cts +3 -0
- package/withLayerLayout/index.d.mts +3 -0
- package/withLayerLayout/index.mjs +3 -0
- package/withLayerLayout/types.cjs +0 -0
- package/withLayerLayout/types.d.cts +10 -0
- package/withLayerLayout/types.d.mts +10 -0
- package/withLayerLayout/types.mjs +1 -0
- package/withLayerLayout/withLayerLayout.cjs +18 -0
- package/withLayerLayout/withLayerLayout.d.cts +12 -0
- package/withLayerLayout/withLayerLayout.d.mts +13 -0
- package/withLayerLayout/withLayerLayout.mjs +16 -0
- package/withLayout/index.cjs +3 -0
- package/withLayout/index.d.cts +3 -0
- package/withLayout/index.d.mts +3 -0
- package/withLayout/index.mjs +3 -0
- package/withLayout/types.cjs +0 -0
- package/withLayout/types.d.cts +37 -0
- package/withLayout/types.d.mts +37 -0
- package/withLayout/types.mjs +1 -0
- package/withLayout/withLayout.cjs +48 -0
- package/withLayout/withLayout.d.cts +14 -0
- package/withLayout/withLayout.d.mts +15 -0
- package/withLayout/withLayout.mjs +38 -0
- package/withMatrixLayout/index.cjs +3 -0
- package/withMatrixLayout/index.d.cts +3 -0
- package/withMatrixLayout/index.d.mts +3 -0
- package/withMatrixLayout/index.mjs +3 -0
- package/withMatrixLayout/types.cjs +0 -0
- package/withMatrixLayout/types.d.cts +10 -0
- package/withMatrixLayout/types.d.mts +10 -0
- package/withMatrixLayout/types.mjs +1 -0
- package/withMatrixLayout/withMatrixLayout.cjs +18 -0
- package/withMatrixLayout/withMatrixLayout.d.cts +12 -0
- package/withMatrixLayout/withMatrixLayout.d.mts +13 -0
- package/withMatrixLayout/withMatrixLayout.mjs +16 -0
- package/withPackLayout/index.cjs +3 -0
- package/withPackLayout/index.d.cts +3 -0
- package/withPackLayout/index.d.mts +3 -0
- package/withPackLayout/index.mjs +3 -0
- package/withPackLayout/types.cjs +0 -0
- package/withPackLayout/types.d.cts +10 -0
- package/withPackLayout/types.d.mts +10 -0
- package/withPackLayout/types.mjs +1 -0
- package/withPackLayout/withPackLayout.cjs +18 -0
- package/withPackLayout/withPackLayout.d.cts +12 -0
- package/withPackLayout/withPackLayout.d.mts +13 -0
- package/withPackLayout/withPackLayout.mjs +16 -0
- package/withPinLayout/index.cjs +3 -0
- package/withPinLayout/index.d.cts +3 -0
- package/withPinLayout/index.d.mts +3 -0
- package/withPinLayout/index.mjs +3 -0
- package/withPinLayout/types.cjs +0 -0
- package/withPinLayout/types.d.cts +10 -0
- package/withPinLayout/types.d.mts +10 -0
- package/withPinLayout/types.mjs +1 -0
- package/withPinLayout/withPinLayout.cjs +18 -0
- package/withPinLayout/withPinLayout.d.cts +12 -0
- package/withPinLayout/withPinLayout.d.mts +13 -0
- package/withPinLayout/withPinLayout.mjs +16 -0
- package/withStackLayout/index.cjs +3 -0
- package/withStackLayout/index.d.cts +3 -0
- package/withStackLayout/index.d.mts +3 -0
- package/withStackLayout/index.mjs +3 -0
- package/withStackLayout/types.cjs +0 -0
- package/withStackLayout/types.d.cts +10 -0
- package/withStackLayout/types.d.mts +10 -0
- package/withStackLayout/types.mjs +1 -0
- package/withStackLayout/withStackLayout.cjs +18 -0
- package/withStackLayout/withStackLayout.d.cts +12 -0
- package/withStackLayout/withStackLayout.d.mts +13 -0
- package/withStackLayout/withStackLayout.mjs +16 -0
- package/withTileLayout/index.cjs +3 -0
- package/withTileLayout/index.d.cts +3 -0
- package/withTileLayout/index.d.mts +3 -0
- package/withTileLayout/index.mjs +3 -0
- package/withTileLayout/types.cjs +0 -0
- package/withTileLayout/types.d.cts +10 -0
- package/withTileLayout/types.d.mts +10 -0
- package/withTileLayout/types.mjs +1 -0
- package/withTileLayout/withTileLayout.cjs +18 -0
- package/withTileLayout/withTileLayout.d.cts +12 -0
- package/withTileLayout/withTileLayout.d.mts +13 -0
- package/withTileLayout/withTileLayout.mjs +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mitsuhiro Seino
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ja.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# @fringeworks/react-layouts
|
|
2
|
+
|
|
3
|
+
`@fringeworks/react-layouts` は、CSSによる子要素のレイアウト制御に特化したニッチなライブラリです。\
|
|
4
|
+
プロパティに応じたクラス名とCSS変数を自動的に設定するHOCを提供します。
|
|
5
|
+
|
|
6
|
+
**[English README is available here](./README.md)**
|
|
7
|
+
|
|
8
|
+
## インストール
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @fringeworks/react-layouts
|
|
12
|
+
# または
|
|
13
|
+
pnpm add @fringeworks/react-layouts
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 使い方
|
|
17
|
+
|
|
18
|
+
任意のコンポーネントをHOCに渡すことで、レイアウト機能の適用されたコンポーネントを作成することができます。
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { withStackLayout } from '@fringeworks/react-layouts';
|
|
22
|
+
|
|
23
|
+
// ※ classNameやstyle(CSS変数用)を透過するコンポーネントである必要があります
|
|
24
|
+
const MyContainer = (props: React.ComponentProps<'div'>) => <div {...props} />;
|
|
25
|
+
|
|
26
|
+
const StackContainer = withStackLayout(MyContainer);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
<StackContainer>
|
|
31
|
+
<div>Item 1</div>
|
|
32
|
+
<div>Item 2</div>
|
|
33
|
+
</StackContainer>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### CSSの読み込み
|
|
37
|
+
|
|
38
|
+
HOCはCSSをインポートしないため、SSRやReact Server Componentsでもそのまま使用できます。CSSは別途インポートしてください。
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { withStackLayout } from '@fringeworks/react-layouts';
|
|
42
|
+
|
|
43
|
+
// 全レイアウトをまとめてインポート
|
|
44
|
+
import '@fringeworks/react-layouts/styles.css';
|
|
45
|
+
|
|
46
|
+
// 必要なレイアウトのみインポート
|
|
47
|
+
import '@fringeworks/react-layouts/stack.css';
|
|
48
|
+
import '@fringeworks/react-layouts/tile.css';
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
CSSを自動的に読み込みたい場合は `with-css` 配下のモジュールを使用してください。CSSのインポートを扱えるバンドラーが必要です。
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { withStackLayout } from '@fringeworks/react-layouts/with-css';
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## レイアウト種別
|
|
58
|
+
|
|
59
|
+
### `stack`
|
|
60
|
+
|
|
61
|
+
子要素を縦または横方向に一列に並べます。
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { withStackLayout } from '@fringeworks/react-layouts';
|
|
65
|
+
|
|
66
|
+
const StackContainer = withStackLayout(Container);
|
|
67
|
+
|
|
68
|
+
// ----------------------
|
|
69
|
+
|
|
70
|
+
<StackContainer
|
|
71
|
+
direction="x"
|
|
72
|
+
alignX="left"
|
|
73
|
+
alignY="top"
|
|
74
|
+
adjustX="grow"
|
|
75
|
+
itemSizeX="200px"
|
|
76
|
+
spacing="8px"
|
|
77
|
+
/>;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### `flow`
|
|
81
|
+
|
|
82
|
+
`stack`と同様ですが、コンテナサイズを超えた場合に子要素を折り返します。
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { withFlowLayout } from '@fringeworks/react-layouts';
|
|
86
|
+
|
|
87
|
+
const FlowContainer = withFlowLayout(Container);
|
|
88
|
+
|
|
89
|
+
// ----------------------
|
|
90
|
+
|
|
91
|
+
<FlowContainer
|
|
92
|
+
direction="x"
|
|
93
|
+
alignX="left"
|
|
94
|
+
alignY="top"
|
|
95
|
+
adjustX="grow"
|
|
96
|
+
itemSizeX="200px"
|
|
97
|
+
spacing="8px"
|
|
98
|
+
/>;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
> 交差軸方向の `adjust` に `grow`、`shrink`、`fit` は指定できません。
|
|
102
|
+
|
|
103
|
+
### `matrix`
|
|
104
|
+
|
|
105
|
+
列数・行数を指定して子要素を格子状に並べます。
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
import { withMatrixLayout } from '@fringeworks/react-layouts';
|
|
109
|
+
|
|
110
|
+
const MatrixContainer = withMatrixLayout(Container);
|
|
111
|
+
|
|
112
|
+
// ----------------------
|
|
113
|
+
|
|
114
|
+
<MatrixContainer
|
|
115
|
+
direction="x"
|
|
116
|
+
itemCountX={3}
|
|
117
|
+
childY={[200, 100, '1fr']}
|
|
118
|
+
itemSizeX="200px"
|
|
119
|
+
adjustX="fit"
|
|
120
|
+
spacing="8px"
|
|
121
|
+
/>;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
各軸で `itemCount` または `child` のどちらか一方が必須です(両方は指定不可)。
|
|
125
|
+
|
|
126
|
+
> **注意:** このレイアウトはコンテナのサイズが外部から確定していることを前提としています。`width: max-content` など、子要素によってサイズが決まる親要素では、パーセンテージ値が意図通りに動作しない場合があります。
|
|
127
|
+
|
|
128
|
+
### `tile`
|
|
129
|
+
|
|
130
|
+
子要素のサイズを基準にして格子状に並べます。列数は親要素のサイズと子要素のサイズに応じて自動で決まります。
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import { withTileLayout } from '@fringeworks/react-layouts';
|
|
134
|
+
|
|
135
|
+
const TileContainer = withTileLayout(Container);
|
|
136
|
+
|
|
137
|
+
// ----------------------
|
|
138
|
+
|
|
139
|
+
<TileContainer direction="x" itemSizeX="200px" adjustX="fit" spacing="8px" />;
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
> **注意:** `matrix` と同様に、コンテナのサイズが外部から確定していることを前提としています。
|
|
143
|
+
|
|
144
|
+
### `balance`
|
|
145
|
+
|
|
146
|
+
子要素を一列に均等に並べます。
|
|
147
|
+
|
|
148
|
+
- `adjust` なし: 子要素のサイズを維持したまま、余白を均等に配分します
|
|
149
|
+
- `adjust` あり: 子要素のサイズを調整してコンテナを満たします
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
import { withBalanceLayout } from '@fringeworks/react-layouts';
|
|
153
|
+
|
|
154
|
+
const BalanceContainer = withBalanceLayout(Container);
|
|
155
|
+
|
|
156
|
+
// ----------------------
|
|
157
|
+
|
|
158
|
+
<BalanceContainer
|
|
159
|
+
direction="x"
|
|
160
|
+
adjustX="grow"
|
|
161
|
+
itemSizeX="200px"
|
|
162
|
+
spacing="8px"
|
|
163
|
+
/>;
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### `pack`
|
|
167
|
+
|
|
168
|
+
子要素を親要素のサイズに合わせて均等にサイズ調整し並べます。
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { withPackLayout } from '@fringeworks/react-layouts';
|
|
172
|
+
|
|
173
|
+
const PackContainer = withPackLayout(Container);
|
|
174
|
+
|
|
175
|
+
// ----------------------
|
|
176
|
+
|
|
177
|
+
<PackContainer direction="x" spacing="8px" />;
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### `pin`
|
|
181
|
+
|
|
182
|
+
子要素を指定の座標に配置します。子要素は `top` / `left` / `bottom` / `right` スタイルで位置を指定してください。
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
import { withPinLayout } from '@fringeworks/react-layouts';
|
|
186
|
+
|
|
187
|
+
const PinContainer = withPinLayout(Container);
|
|
188
|
+
|
|
189
|
+
// ----------------------
|
|
190
|
+
|
|
191
|
+
<PinContainer itemSizeX="100px" itemSizeY="80px" />;
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## オプション
|
|
195
|
+
|
|
196
|
+
### オプション一覧
|
|
197
|
+
|
|
198
|
+
| オプション | 型 | 説明 |
|
|
199
|
+
| ------------- | ------------------------ | ---------------------------- |
|
|
200
|
+
| `direction?` | `'x' \| 'y'` | 主軸の方向 |
|
|
201
|
+
| `alignX?` | [`AlignX`](#alignx-の値) | 子要素の横位置 |
|
|
202
|
+
| `alignY?` | [`AlignY`](#aligny-の値) | 子要素の縦位置 |
|
|
203
|
+
| `adjustX?` | [`Adjust`](#adjust-の値) | 子要素の横方向のサイズ調整 |
|
|
204
|
+
| `adjustY?` | [`Adjust`](#adjust-の値) | 子要素の縦方向のサイズ調整 |
|
|
205
|
+
| `spacing?` | `string \| number` | 子要素間の余白(横縦共通) |
|
|
206
|
+
| `spacingX?` | `string \| number` | 子要素間の余白(横方向) |
|
|
207
|
+
| `spacingY?` | `string \| number` | 子要素間の余白(縦方向) |
|
|
208
|
+
| `itemSizeX?` | `string \| number` | 子要素の幅 |
|
|
209
|
+
| `itemSizeY?` | `string \| number` | 子要素の高さ |
|
|
210
|
+
| `itemCountX?` | `number` | 子要素の横方向の数 |
|
|
211
|
+
| `itemCountY?` | `number` | 子要素の縦方向の数 |
|
|
212
|
+
| `tracksX?` | `(string \| number)[]` | 子要素の横方向の個々のサイズ |
|
|
213
|
+
| `tracksY?` | `(string \| number)[]` | 子要素の縦方向の個々のサイズ |
|
|
214
|
+
|
|
215
|
+
### `Adjust` の値
|
|
216
|
+
|
|
217
|
+
| 値 | 子が親より小さい時 | 子が親より大きい時 |
|
|
218
|
+
| -------- | ------------------ | ------------------ |
|
|
219
|
+
| `none` | そのまま | そのまま |
|
|
220
|
+
| `grow` | 伸びる | そのまま |
|
|
221
|
+
| `shrink` | そのまま | 縮む |
|
|
222
|
+
| `fit` | 伸びる | 縮む |
|
|
223
|
+
|
|
224
|
+
### `AlignX` の値
|
|
225
|
+
|
|
226
|
+
`'left'` | `'center'` | `'right'` | `'space-between'` | `'space-around'` | `'space-evenly'`
|
|
227
|
+
|
|
228
|
+
### `AlignY` の値
|
|
229
|
+
|
|
230
|
+
`'top'` | `'middle'` | `'bottom'` | `'space-between'` | `'space-around'` | `'space-evenly'`
|
|
231
|
+
|
|
232
|
+
## ライセンス
|
|
233
|
+
|
|
234
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# @fringeworks/react-layouts
|
|
2
|
+
|
|
3
|
+
`@fringeworks/react-layouts` is a niche library tailored for controlling child element layouts via CSS.
|
|
4
|
+
|
|
5
|
+
It provides Higher-Order Components (HOCs) that automatically apply class names and CSS variables based on the passed props.
|
|
6
|
+
|
|
7
|
+
**[日本語のREADMEはこちら](./README.ja.md)**
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @fringeworks/react-layouts
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @fringeworks/react-layouts
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
You can create a component with layout capabilities by passing any base component to the HOC.
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { withStackLayout } from '@fringeworks/react-layouts';
|
|
24
|
+
|
|
25
|
+
// * The wrapped component must pass down `className` and `style` (used for CSS variables) to its underlying element.
|
|
26
|
+
const MyContainer = (props: React.ComponentProps<'div'>) => <div {...props} />;
|
|
27
|
+
|
|
28
|
+
const StackContainer = withStackLayout(MyContainer);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
<StackContainer>
|
|
33
|
+
<div>Item 1</div>
|
|
34
|
+
<div>Item 2</div>
|
|
35
|
+
</StackContainer>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Loading CSS
|
|
39
|
+
|
|
40
|
+
The HOCs do not import any CSS, so they work as-is in SSR and React Server Components. Import the CSS separately.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { withStackLayout } from '@fringeworks/react-layouts';
|
|
44
|
+
|
|
45
|
+
// Import all layouts at once
|
|
46
|
+
import '@fringeworks/react-layouts/styles.css';
|
|
47
|
+
|
|
48
|
+
// Or import only what you need
|
|
49
|
+
import '@fringeworks/react-layouts/stack.css';
|
|
50
|
+
import '@fringeworks/react-layouts/tile.css';
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
If you want the CSS to be loaded automatically, use the modules under `with-css`. This requires a bundler that can handle CSS imports.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { withStackLayout } from '@fringeworks/react-layouts/with-css';
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Layout Types
|
|
60
|
+
|
|
61
|
+
### `stack`
|
|
62
|
+
|
|
63
|
+
Arranges child elements in a single row or column (linear layout).
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { withStackLayout } from '@fringeworks/react-layouts';
|
|
67
|
+
|
|
68
|
+
const StackContainer = withStackLayout(Container);
|
|
69
|
+
|
|
70
|
+
// ----------------------
|
|
71
|
+
|
|
72
|
+
<StackContainer
|
|
73
|
+
direction="x"
|
|
74
|
+
alignX="left"
|
|
75
|
+
alignY="top"
|
|
76
|
+
adjustX="grow"
|
|
77
|
+
itemSizeX="200px"
|
|
78
|
+
spacing="8px"
|
|
79
|
+
/>;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### `flow`
|
|
83
|
+
|
|
84
|
+
Similar to `stack`, but wraps child elements onto multiple lines if they exceed the container size.
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { withFlowLayout } from '@fringeworks/react-layouts';
|
|
88
|
+
|
|
89
|
+
const FlowContainer = withFlowLayout(Container);
|
|
90
|
+
|
|
91
|
+
// ----------------------
|
|
92
|
+
|
|
93
|
+
<FlowContainer
|
|
94
|
+
direction="x"
|
|
95
|
+
alignX="left"
|
|
96
|
+
alignY="top"
|
|
97
|
+
adjustX="grow"
|
|
98
|
+
itemSizeX="200px"
|
|
99
|
+
spacing="8px"
|
|
100
|
+
/>;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
> `grow`, `shrink`, and `fit` cannot be specified for `adjust` on the cross-axis.
|
|
104
|
+
|
|
105
|
+
### `matrix`
|
|
106
|
+
|
|
107
|
+
Arranges child elements in a grid by specifying the number of columns and rows.
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
import { withMatrixLayout } from '@fringeworks/react-layouts';
|
|
111
|
+
|
|
112
|
+
const MatrixContainer = withMatrixLayout(Container);
|
|
113
|
+
|
|
114
|
+
// ----------------------
|
|
115
|
+
|
|
116
|
+
<MatrixContainer
|
|
117
|
+
direction="x"
|
|
118
|
+
itemCountX={3}
|
|
119
|
+
childY={[200, 100, '1fr']}
|
|
120
|
+
itemSizeX="200px"
|
|
121
|
+
adjustX="fit"
|
|
122
|
+
spacing="8px"
|
|
123
|
+
/>;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
For each axis, either `itemCount` or `child` is required (specifying both is not allowed).
|
|
127
|
+
|
|
128
|
+
> **Note:** This layout assumes the container's size is determined externally. Percentage values may not work as intended in parent elements whose sizes are determined by their children (e.g., `width: max-content`).
|
|
129
|
+
|
|
130
|
+
### `tile`
|
|
131
|
+
|
|
132
|
+
Arranges child elements in a grid based on the child size. The number of columns is automatically calculated depending on the parent container's size and the child elements' sizes.
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
import { withTileLayout } from '@fringeworks/react-layouts';
|
|
136
|
+
|
|
137
|
+
const TileContainer = withTileLayout(Container);
|
|
138
|
+
|
|
139
|
+
// ----------------------
|
|
140
|
+
|
|
141
|
+
<TileContainer direction="x" itemSizeX="200px" adjustX="fit" spacing="8px" />;
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
> **Note:** Similar to `matrix`, this layout assumes the container's size is determined externally.
|
|
145
|
+
|
|
146
|
+
### `balance`
|
|
147
|
+
|
|
148
|
+
Distributes child elements evenly in a single row or column.
|
|
149
|
+
|
|
150
|
+
- **Without `adjust`:** Maintains the original size of child elements and distributes the remaining space evenly.
|
|
151
|
+
- **With `adjust`:** Adjusts the size of child elements to fill the container.
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
import { withBalanceLayout } from '@fringeworks/react-layouts';
|
|
155
|
+
|
|
156
|
+
const BalanceContainer = withBalanceLayout(Container);
|
|
157
|
+
|
|
158
|
+
// ----------------------
|
|
159
|
+
|
|
160
|
+
<BalanceContainer
|
|
161
|
+
direction="x"
|
|
162
|
+
adjustX="grow"
|
|
163
|
+
itemSizeX="200px"
|
|
164
|
+
spacing="8px"
|
|
165
|
+
/>;
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### `pack`
|
|
169
|
+
|
|
170
|
+
Scales and packs child elements evenly to perfectly fit the size of the parent container.
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
import { withPackLayout } from '@fringeworks/react-layouts';
|
|
174
|
+
|
|
175
|
+
const PackContainer = withPackLayout(Container);
|
|
176
|
+
|
|
177
|
+
// ----------------------
|
|
178
|
+
|
|
179
|
+
<PackContainer direction="x" spacing="8px" />;
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### `pin`
|
|
183
|
+
|
|
184
|
+
Positions child elements at specific coordinates. Children should specify their positions using `top` / `left` / `bottom` / `right` styles.
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
import { withPinLayout } from '@fringeworks/react-layouts';
|
|
188
|
+
|
|
189
|
+
const PinContainer = withPinLayout(Container);
|
|
190
|
+
|
|
191
|
+
// ----------------------
|
|
192
|
+
|
|
193
|
+
<PinContainer itemSizeX="100px" itemSizeY="80px" />;
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Options
|
|
197
|
+
|
|
198
|
+
### Option List
|
|
199
|
+
|
|
200
|
+
| Option | Type | Description |
|
|
201
|
+
| ------------- | ---------------------- | --------------------------------------------------------- |
|
|
202
|
+
| `direction?` | `'x' \| 'y'` | Direction of the main axis |
|
|
203
|
+
| `alignX?` | [`AlignX`]() | Horizontal alignment of child elements |
|
|
204
|
+
| `alignY?` | [`AlignY`]() | Vertical alignment of child elements |
|
|
205
|
+
| `adjustX?` | [`Adjust`]() | Horizontal size adjustment for child elements |
|
|
206
|
+
| `adjustY?` | [`Adjust`]() | Vertical size adjustment for child elements |
|
|
207
|
+
| `spacing?` | `string \| number` | Gap between child elements (both horizontal and vertical) |
|
|
208
|
+
| `spacingX?` | `string \| number` | Horizontal gap between child elements |
|
|
209
|
+
| `spacingY?` | `string \| number` | Vertical gap between child elements |
|
|
210
|
+
| `itemSizeX?` | `string \| number` | Width of child elements |
|
|
211
|
+
| `itemSizeY?` | `string \| number` | Height of child elements |
|
|
212
|
+
| `itemCountX?` | `number` | Number of child elements horizontally |
|
|
213
|
+
| `itemCountY?` | `number` | Number of child elements vertically |
|
|
214
|
+
| `tracksX?` | `(string \| number)[]` | Individual horizontal sizes for each child element |
|
|
215
|
+
| `tracksY?` | `(string \| number)[]` | Individual vertical sizes for each child element |
|
|
216
|
+
|
|
217
|
+
### `Adjust` Values
|
|
218
|
+
|
|
219
|
+
| Value | When child is smaller than parent | When child is larger than parent |
|
|
220
|
+
| -------- | --------------------------------- | -------------------------------- |
|
|
221
|
+
| `none` | Keeps original size | Keeps original size |
|
|
222
|
+
| `grow` | Expands | Keeps original size |
|
|
223
|
+
| `shrink` | Keeps original size | Shrinks |
|
|
224
|
+
| `fit` | Expands | Shrinks |
|
|
225
|
+
|
|
226
|
+
### `AlignX` Values
|
|
227
|
+
|
|
228
|
+
`'left'` | `'center'` | `'right'` | `'space-between'` | `'space-around'` | `'space-evenly'`
|
|
229
|
+
|
|
230
|
+
### `AlignY` Values
|
|
231
|
+
|
|
232
|
+
`'top'` | `'middle'` | `'bottom'` | `'space-between'` | `'space-around'` | `'space-evenly'`
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
MIT
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/_internal/_constants.ts
|
|
4
|
+
const LAYOUT_PROPS_KEYS = {
|
|
5
|
+
className: 1,
|
|
6
|
+
scroll: 1,
|
|
7
|
+
style: 1,
|
|
8
|
+
direction: 1,
|
|
9
|
+
alignX: 1,
|
|
10
|
+
alignY: 1,
|
|
11
|
+
adjustX: 1,
|
|
12
|
+
adjustY: 1,
|
|
13
|
+
gap: 1,
|
|
14
|
+
gapX: 1,
|
|
15
|
+
gapY: 1,
|
|
16
|
+
itemSizeX: 1,
|
|
17
|
+
itemSizeY: 1,
|
|
18
|
+
itemRatioX: 1,
|
|
19
|
+
itemRatioY: 1,
|
|
20
|
+
itemCountX: 1,
|
|
21
|
+
itemCountY: 1,
|
|
22
|
+
tracksX: 1,
|
|
23
|
+
tracksY: 1
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.LAYOUT_PROPS_KEYS = LAYOUT_PROPS_KEYS;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ApplyLayoutOptions } from "./applyLayout/types.cjs";
|
|
2
|
+
import { BalanceLayoutOptions, FlowLayoutOptions, MatrixLayoutOptions, PackLayoutOptions, PinLayoutOptions, StackLayoutOptions, TileLayoutOptions } from "@fringeworks/style-layouts";
|
|
3
|
+
|
|
4
|
+
//#region src/_internal/_constants.d.ts
|
|
5
|
+
declare const LAYOUT_PROPS_KEYS: { [K in keyof Required<ApplyLayoutOptions & BalanceLayoutOptions & FlowLayoutOptions & MatrixLayoutOptions & PackLayoutOptions & PinLayoutOptions & StackLayoutOptions & TileLayoutOptions>]: 1 };
|
|
6
|
+
//#endregion
|
|
7
|
+
export { LAYOUT_PROPS_KEYS };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ApplyLayoutOptions } from "./applyLayout/types.mjs";
|
|
2
|
+
import { BalanceLayoutOptions, FlowLayoutOptions, MatrixLayoutOptions, PackLayoutOptions, PinLayoutOptions, StackLayoutOptions, TileLayoutOptions } from "@fringeworks/style-layouts";
|
|
3
|
+
|
|
4
|
+
//#region src/_internal/_constants.d.ts
|
|
5
|
+
declare const LAYOUT_PROPS_KEYS: { [K in keyof Required<ApplyLayoutOptions & BalanceLayoutOptions & FlowLayoutOptions & MatrixLayoutOptions & PackLayoutOptions & PinLayoutOptions & StackLayoutOptions & TileLayoutOptions>]: 1 };
|
|
6
|
+
//#endregion
|
|
7
|
+
export { LAYOUT_PROPS_KEYS };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/_internal/_constants.ts
|
|
2
|
+
const LAYOUT_PROPS_KEYS = {
|
|
3
|
+
className: 1,
|
|
4
|
+
scroll: 1,
|
|
5
|
+
style: 1,
|
|
6
|
+
direction: 1,
|
|
7
|
+
alignX: 1,
|
|
8
|
+
alignY: 1,
|
|
9
|
+
adjustX: 1,
|
|
10
|
+
adjustY: 1,
|
|
11
|
+
gap: 1,
|
|
12
|
+
gapX: 1,
|
|
13
|
+
gapY: 1,
|
|
14
|
+
itemSizeX: 1,
|
|
15
|
+
itemSizeY: 1,
|
|
16
|
+
itemRatioX: 1,
|
|
17
|
+
itemRatioY: 1,
|
|
18
|
+
itemCountX: 1,
|
|
19
|
+
itemCountY: 1,
|
|
20
|
+
tracksX: 1,
|
|
21
|
+
tracksY: 1
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { LAYOUT_PROPS_KEYS };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let _fringeworks_utils = require("@fringeworks/utils");
|
|
3
|
+
let clsx = require("clsx");
|
|
4
|
+
clsx = require_runtime.__toESM(clsx, 1);
|
|
5
|
+
|
|
6
|
+
//#region src/_internal/applyLayout/applyLayout.ts
|
|
7
|
+
/**
|
|
8
|
+
* レイアウト用のスタイルを適用する
|
|
9
|
+
* @param layout レイアウトを作る関数
|
|
10
|
+
* @param options レイアウトのオプション
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
function applyLayout(layout, options = (0, _fringeworks_utils.unsafeCast)({})) {
|
|
14
|
+
const { className, scroll, style: optionStyle, ...rest } = options;
|
|
15
|
+
const style = { ...optionStyle };
|
|
16
|
+
const { className: layoutedClassName, style: layoutedStyle } = layout((0, _fringeworks_utils.unsafeCast)(rest));
|
|
17
|
+
if (scroll) style.overflow = "auto";
|
|
18
|
+
if (layoutedStyle) Object.assign(style, layoutedStyle);
|
|
19
|
+
return {
|
|
20
|
+
className: (0, clsx.default)(className, layoutedClassName),
|
|
21
|
+
style
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
module.exports = applyLayout;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ApplyLayoutOptions, ApplyLayoutResult } from "./types.cjs";
|
|
2
|
+
import { CreateLayoutStyle } from "@fringeworks/style-layouts";
|
|
3
|
+
import { LooseDictionary } from "@fringeworks/types";
|
|
4
|
+
|
|
5
|
+
//#region src/_internal/applyLayout/applyLayout.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* レイアウト用のスタイルを適用する
|
|
8
|
+
* @param layout レイアウトを作る関数
|
|
9
|
+
* @param options レイアウトのオプション
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
declare function applyLayout<O extends object = LooseDictionary>(layout: CreateLayoutStyle<O>, options?: ApplyLayoutOptions<O>): ApplyLayoutResult;
|
|
13
|
+
export = applyLayout;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ApplyLayoutOptions, ApplyLayoutResult } from "./types.mjs";
|
|
2
|
+
import { CreateLayoutStyle } from "@fringeworks/style-layouts";
|
|
3
|
+
import { LooseDictionary } from "@fringeworks/types";
|
|
4
|
+
|
|
5
|
+
//#region src/_internal/applyLayout/applyLayout.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* レイアウト用のスタイルを適用する
|
|
8
|
+
* @param layout レイアウトを作る関数
|
|
9
|
+
* @param options レイアウトのオプション
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
declare function applyLayout<O extends object = LooseDictionary>(layout: CreateLayoutStyle<O>, options?: ApplyLayoutOptions<O>): ApplyLayoutResult;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { applyLayout as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { unsafeCast } from "@fringeworks/utils";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
|
|
4
|
+
//#region src/_internal/applyLayout/applyLayout.ts
|
|
5
|
+
/**
|
|
6
|
+
* レイアウト用のスタイルを適用する
|
|
7
|
+
* @param layout レイアウトを作る関数
|
|
8
|
+
* @param options レイアウトのオプション
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
function applyLayout(layout, options = unsafeCast({})) {
|
|
12
|
+
const { className, scroll, style: optionStyle, ...rest } = options;
|
|
13
|
+
const style = { ...optionStyle };
|
|
14
|
+
const { className: layoutedClassName, style: layoutedStyle } = layout(unsafeCast(rest));
|
|
15
|
+
if (scroll) style.overflow = "auto";
|
|
16
|
+
if (layoutedStyle) Object.assign(style, layoutedStyle);
|
|
17
|
+
return {
|
|
18
|
+
className: clsx(className, layoutedClassName),
|
|
19
|
+
style
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { applyLayout as default };
|
|
File without changes
|