@fringeworks/react-icon-material-symbols 0.1.1 → 0.3.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/README.ja.md +38 -19
- package/README.md +42 -23
- package/_internal/_createMaterialSymbol.cjs +21 -27
- package/_internal/_createMaterialSymbol.d.cts +0 -8
- package/_internal/_createMaterialSymbol.d.mts +0 -8
- package/_internal/_createMaterialSymbol.mjs +22 -28
- package/package.json +3 -3
- package/styles.css +21 -6
- package/types.d.cts +10 -4
- package/types.d.mts +10 -4
package/README.ja.md
CHANGED
|
@@ -83,7 +83,9 @@ import '@fringeworks/react-icon-material-symbols/font-outlined.css';
|
|
|
83
83
|
|
|
84
84
|
### 大きさと色
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
アイコンは正方形の箱に描き、色は `color` を受け継ぎます。大きさは、周りの文字と同じに見える大きさ(親の `font-size` の 1.25 倍)です。Material Symbols は字形の周りに余白が多く、1em では文字より小さく見えるためです(react-icon の `--frg-icon-glyphScale` を `1.25` にしています)。縦の位置は、どのフォントの日本語や英字と並べても真ん中がそろって見えるよう、文字のベースラインを基準に決めています(react-icon の「大きさ・位置・色」)。
|
|
87
|
+
|
|
88
|
+
Material Symbols の付属のクラスのように 24px に固定しないので、24px にしたいときは `font-size` を指定します(指定した大きさになります)。ボタンの中など、react-components の部品の中のアイコンは、部品が決めた大きさになります。
|
|
87
89
|
|
|
88
90
|
```tsx
|
|
89
91
|
<MaterialSymbolOutlined
|
|
@@ -98,18 +100,18 @@ Material Symbols の4つの軸を、プロパティで変えられます。
|
|
|
98
100
|
|
|
99
101
|
```tsx
|
|
100
102
|
<MaterialSymbolOutlined value="favorite" filled />
|
|
101
|
-
<MaterialSymbolOutlined value="settings"
|
|
103
|
+
<MaterialSymbolOutlined value="settings" fontWeight={300} grade={-25} />
|
|
102
104
|
<MaterialSymbolOutlined value="search" opticalSize={20} />
|
|
103
105
|
```
|
|
104
106
|
|
|
105
107
|
| プロパティ | 軸 | 説明 |
|
|
106
108
|
| -------------- | ------ | ------------------------------------------------------------------------------------------------------------- |
|
|
107
|
-
| `
|
|
108
|
-
| `filled?` | `FILL` |
|
|
109
|
+
| `fontWeight?` | `wght` | 太さ(100〜700)。CSS の `font-weight` で描く |
|
|
110
|
+
| `filled?` | `FILL` | `true` で塗りつぶした形、`false`(既定)で線の形。0〜1 の数値で途中の形にもできる |
|
|
109
111
|
| `grade?` | `GRAD` | グレード(-25〜200)。太さ(アイコンの大きさ)を変えずに、線の濃さを変える |
|
|
110
112
|
| `opticalSize?` | `opsz` | 光学サイズ(20〜48)。指定しなければ、ブラウザーが文字の大きさに合わせて決める(`font-optical-sizing: auto`) |
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
軸のプロパティは、乗ったときなど、すべての状態に効きます(`design` に1つの値で書いたのと同じ)。軸の値は CSS 変数(`--frg-materialsymbol-filled` など。下の「デザインの値」の表)から組み立てるので、CSS でも軸ごとに変えられます。
|
|
113
115
|
|
|
114
116
|
### アイコンに乗ったときに変える
|
|
115
117
|
|
|
@@ -122,11 +124,12 @@ Material Symbols の4つの軸を、プロパティで変えられます。
|
|
|
122
124
|
/>
|
|
123
125
|
```
|
|
124
126
|
|
|
125
|
-
ボタンなど、親の要素に乗ったときに変えるには、CSS
|
|
127
|
+
ボタンなど、親の要素に乗ったときに変えるには、CSS で変数を設定します。アイコン自身に乗ったときの変数(`-hover`)も書いてください。書かないと、ポインターがアイコンの上に来たときに、アイコンの `:hover` の既定の値に戻ります。
|
|
126
128
|
|
|
127
129
|
```css
|
|
128
130
|
.favorite-button:hover {
|
|
129
131
|
--frg-materialsymbol-filled: 1;
|
|
132
|
+
--frg-materialsymbol-filled-hover: 1;
|
|
130
133
|
}
|
|
131
134
|
```
|
|
132
135
|
|
|
@@ -140,6 +143,21 @@ import { withDesign } from '@fringeworks/react-contract';
|
|
|
140
143
|
const Icon = withDesign(MaterialSymbolOutlined, { filled: { hover: 1 } });
|
|
141
144
|
```
|
|
142
145
|
|
|
146
|
+
### プロパティ・`design`・`withDesign` の重なり方
|
|
147
|
+
|
|
148
|
+
同じ軸を複数の方法で指定したときは、使う場所の `design` > 軸のプロパティ > `withDesign` の値(`fallbackDesign`)の順に強くなります。強い方で指定していない状態は、弱い方の値になります。
|
|
149
|
+
|
|
150
|
+
| 指定 | 状態なし | 乗ったとき |
|
|
151
|
+
| ---------------------------------------------------------------------- | -------- | --------------------- |
|
|
152
|
+
| `fontWeight={300}` | 300 | 300 |
|
|
153
|
+
| `fontWeight={300}` と `design={{ fontWeight: { hover: 700 } }}` | 300 | 700 |
|
|
154
|
+
| `design={{ fontWeight: { base: 700 } }}` | 700 | 400(部品の既定の値) |
|
|
155
|
+
| `design={{ fontWeight: 700 }}` | 700 | 700 |
|
|
156
|
+
| `withDesign` の `{ fontWeight: { hover: 700 } }` と `fontWeight={300}` | 300 | 300 |
|
|
157
|
+
|
|
158
|
+
- `design` の状態ごとのオブジェクトで省略した状態は、`base` の値を引き継ぎません(`{ base: 700 }` は状態なしの値だけを決めます)。すべての状態で同じにするときは、1つの値(`fontWeight: 700`)で書きます。
|
|
159
|
+
- `withDesign` の値は、使う場所のプロパティより弱くなります。アプリで共通に決めた軸も、使う場所でプロパティを書けば変えられます。
|
|
160
|
+
|
|
143
161
|
### 読み上げ
|
|
144
162
|
|
|
145
163
|
`aria-label`・`aria-labelledby` を渡すと、画像(`role="img"`)として読み上げられます。渡さなければ、飾りとして `aria-hidden` が付きます。
|
|
@@ -201,14 +219,15 @@ MaterialSymbolSharp(props: MaterialSymbolProps): ReactElement
|
|
|
201
219
|
|
|
202
220
|
`value` のアイコンを、`<span>` に合字の文字として描きます。そのほかの props は `<span>` に渡し(`ref` も `<span>` を指します)、`className`・`style` は合成して、同じプロパティは受け取った値を優先します。
|
|
203
221
|
|
|
204
|
-
| プロパティ
|
|
205
|
-
|
|
|
206
|
-
| `value`
|
|
207
|
-
| `
|
|
208
|
-
| `filled?`
|
|
209
|
-
| `grade?`
|
|
210
|
-
| `opticalSize?`
|
|
211
|
-
| `design?`
|
|
222
|
+
| プロパティ | 型 | 説明 |
|
|
223
|
+
| ----------------- | ---------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
224
|
+
| `value` | `MaterialSymbolValue` | アイコンの名前 |
|
|
225
|
+
| `fontWeight?` | `number` | 太さ(`wght`。100〜700) |
|
|
226
|
+
| `filled?` | `boolean \| number` | 塗り(`FILL`)。`true` は 1、`false`(既定)は 0。0〜1 の数値も受け付ける |
|
|
227
|
+
| `grade?` | `number` | グレード(`GRAD`。-25〜200) |
|
|
228
|
+
| `opticalSize?` | `number` | 光学サイズ(`opsz`。20〜48)。指定しなければ文字の大きさに合わせて決まる |
|
|
229
|
+
| `design?` | `MaterialSymbolDesign` | デザインの値(下の表)。同じ軸のプロパティより強い |
|
|
230
|
+
| `fallbackDesign?` | `MaterialSymbolDesign` | アプリで共通のデザインの値(`withDesign` が渡す)。プロパティと `design` で指定していない軸・状態を補う |
|
|
212
231
|
|
|
213
232
|
部品の静的なプロパティ:
|
|
214
233
|
|
|
@@ -220,16 +239,16 @@ MaterialSymbolSharp(props: MaterialSymbolProps): ReactElement
|
|
|
220
239
|
|
|
221
240
|
#### デザインの値
|
|
222
241
|
|
|
223
|
-
`design` で渡せるデザインの値です(CSS 変数は `--frg-materialsymbol-` の後にキーを `-` でつないだもの。例: `filled.hover` → `--frg-materialsymbol-filled-hover`)。`hover`
|
|
242
|
+
`design` で渡せるデザインの値です(CSS 変数は `--frg-materialsymbol-` の後にキーを `-` でつないだもの。例: `filled.hover` → `--frg-materialsymbol-filled-hover`)。`hover` の値を指定しなければ、乗ったときは部品の既定の値です(状態なしの値を引き継ぎません)。1つの値は、`hover` にも効きます。
|
|
224
243
|
|
|
225
244
|
| キー | 既定値 | 説明 |
|
|
226
245
|
| ------------------ | ------ | ---------------------------------------------------------- |
|
|
227
246
|
| `fontWeight` | `400` | 太さ(`wght`) |
|
|
228
|
-
| `fontWeight.hover` |
|
|
247
|
+
| `fontWeight.hover` | `400` | 乗ったときの太さ |
|
|
229
248
|
| `filled` | `0` | 塗り(`FILL`。0〜1。途中の値は、アニメーションの途中の形) |
|
|
230
|
-
| `filled.hover` |
|
|
249
|
+
| `filled.hover` | `0` | 乗ったときの塗り |
|
|
231
250
|
| `grade` | `0` | グレード(`GRAD`) |
|
|
232
|
-
| `grade.hover` |
|
|
251
|
+
| `grade.hover` | `0` | 乗ったときのグレード |
|
|
233
252
|
| `opticalSize` | — | 光学サイズ(`opsz`)。指定したときだけ固定する |
|
|
234
253
|
|
|
235
254
|
`design` の値は、[`@fringeworks/react-contract`](https://www.npmjs.com/package/@fringeworks/react-contract) の `createDesignStyle` の規則で書きます。`filled`・`grade`・`opticalSize` は、CSS のプロパティが無い可変フォントの軸のための名前です。
|
|
@@ -247,7 +266,7 @@ MaterialSymbolSharp(props: MaterialSymbolProps): ReactElement
|
|
|
247
266
|
|
|
248
267
|
| クラス | 説明 |
|
|
249
268
|
| ------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
|
|
250
|
-
| `frg-icon`・`frg-fonticon` | react-icon
|
|
269
|
+
| `frg-icon`・`frg-fonticon` | react-icon のクラス(正方形の箱と、アイコンフォントの指定) |
|
|
251
270
|
| `frg-materialsymbol` | Material Symbols のすべてのアイコン。可変フォントの軸を CSS 変数から組み立てる |
|
|
252
271
|
| `frg-materialsymboloutlined`・`frg-materialsymbolrounded`・`frg-materialsymbolsharp` | 種類ごとのクラス。種類を選ぶためのもので、CSS の規則は持たない(フォントファミリーは部品が `style` で指定する) |
|
|
253
272
|
| `frg-materialsymbol-opticalSize` | 光学サイズを固定するときに付く |
|
package/README.md
CHANGED
|
@@ -83,7 +83,9 @@ Use `font-display: block` when you serve it yourself too. Icons are not drawn un
|
|
|
83
83
|
|
|
84
84
|
### Size and color
|
|
85
85
|
|
|
86
|
-
Icons are drawn in a
|
|
86
|
+
Icons are drawn in a square box and inherit `color`. The size looks the same as the surrounding text (1.25 times the parent's `font-size`), because Material Symbols has a lot of space around the glyphs and looks smaller than the text at 1em (react-icon's `--frg-icon-glyphScale` is set to `1.25`). The vertical position is based on the baseline of the text, so that icons look centered next to Japanese and Latin text in any font (see "Size, position and color" in react-icon).
|
|
87
|
+
|
|
88
|
+
Unlike the classes that come with Material Symbols, the size is not fixed at 24px; set `font-size` when you want 24px (the icon gets that size). Icons inside components of react-components, such as buttons, get the size the component decides.
|
|
87
89
|
|
|
88
90
|
```tsx
|
|
89
91
|
<MaterialSymbolOutlined
|
|
@@ -98,18 +100,18 @@ You can change the four Material Symbols axes with props.
|
|
|
98
100
|
|
|
99
101
|
```tsx
|
|
100
102
|
<MaterialSymbolOutlined value="favorite" filled />
|
|
101
|
-
<MaterialSymbolOutlined value="settings"
|
|
103
|
+
<MaterialSymbolOutlined value="settings" fontWeight={300} grade={-25} />
|
|
102
104
|
<MaterialSymbolOutlined value="search" opticalSize={20} />
|
|
103
105
|
```
|
|
104
106
|
|
|
105
|
-
| Prop | Axis | Description
|
|
106
|
-
| -------------- | ------ |
|
|
107
|
-
| `
|
|
108
|
-
| `filled?` | `FILL` |
|
|
109
|
-
| `grade?` | `GRAD` | Grade (-25–200). Changes the stroke thickness without changing the weight (the icon's size)
|
|
110
|
-
| `opticalSize?` | `opsz` | Optical size (20–48). If omitted, the browser picks it to match the text size (`font-optical-sizing: auto`)
|
|
107
|
+
| Prop | Axis | Description |
|
|
108
|
+
| -------------- | ------ | ------------------------------------------------------------------------------------------------------------------ |
|
|
109
|
+
| `fontWeight?` | `wght` | Weight (100–700). Drawn with the CSS `font-weight` |
|
|
110
|
+
| `filled?` | `FILL` | `true` for the filled shape, `false` (default) for the outlined one. A number from 0 to 1 gives a shape in between |
|
|
111
|
+
| `grade?` | `GRAD` | Grade (-25–200). Changes the stroke thickness without changing the weight (the icon's size) |
|
|
112
|
+
| `opticalSize?` | `opsz` | Optical size (20–48). If omitted, the browser picks it to match the text size (`font-optical-sizing: auto`) |
|
|
111
113
|
|
|
112
|
-
The axis values are built from CSS variables (`--frg-materialsymbol-filled` and so on; see the "Design values" table below), so you can also change each axis with CSS.
|
|
114
|
+
The axis props apply in every state, including hover (the same as a single value in `design`). The axis values are built from CSS variables (`--frg-materialsymbol-filled` and so on; see the "Design values" table below), so you can also change each axis with CSS.
|
|
113
115
|
|
|
114
116
|
### Changing on hover
|
|
115
117
|
|
|
@@ -122,11 +124,12 @@ With `design`, you can set the value for each axis when the pointer is over the
|
|
|
122
124
|
/>
|
|
123
125
|
```
|
|
124
126
|
|
|
125
|
-
To change it when the pointer is over a parent element such as a button, set the variable with CSS.
|
|
127
|
+
To change it when the pointer is over a parent element such as a button, set the variable with CSS. Set the variable for hovering the icon itself (`-hover`) too. Otherwise, when the pointer moves onto the icon, the icon's `:hover` falls back to the default value.
|
|
126
128
|
|
|
127
129
|
```css
|
|
128
130
|
.favorite-button:hover {
|
|
129
131
|
--frg-materialsymbol-filled: 1;
|
|
132
|
+
--frg-materialsymbol-filled-hover: 1;
|
|
130
133
|
}
|
|
131
134
|
```
|
|
132
135
|
|
|
@@ -140,6 +143,21 @@ import { withDesign } from '@fringeworks/react-contract';
|
|
|
140
143
|
const Icon = withDesign(MaterialSymbolOutlined, { filled: { hover: 1 } });
|
|
141
144
|
```
|
|
142
145
|
|
|
146
|
+
### How props, `design`, and `withDesign` combine
|
|
147
|
+
|
|
148
|
+
When the same axis is set in more than one way, the `design` where it is used > the axis prop > the `withDesign` values (`fallbackDesign`). States a stronger one does not set take the weaker one's value.
|
|
149
|
+
|
|
150
|
+
| Set | Stateless | On hover |
|
|
151
|
+
| ----------------------------------------------------------------------- | --------- | ----------------------------- |
|
|
152
|
+
| `fontWeight={300}` | 300 | 300 |
|
|
153
|
+
| `fontWeight={300}` and `design={{ fontWeight: { hover: 700 } }}` | 300 | 700 |
|
|
154
|
+
| `design={{ fontWeight: { base: 700 } }}` | 700 | 400 (the component's default) |
|
|
155
|
+
| `design={{ fontWeight: 700 }}` | 700 | 700 |
|
|
156
|
+
| `{ fontWeight: { hover: 700 } }` in `withDesign` and `fontWeight={300}` | 300 | 300 |
|
|
157
|
+
|
|
158
|
+
- States omitted in an object per state in `design` do not take over the `base` value (`{ base: 700 }` sets only the stateless value). To use the same value in every state, write a single value (`fontWeight: 700`).
|
|
159
|
+
- The `withDesign` values are weaker than the props where the component is used. You can change an axis set app-wide by writing the prop where it is used.
|
|
160
|
+
|
|
143
161
|
### Accessibility
|
|
144
162
|
|
|
145
163
|
If you pass `aria-label` or `aria-labelledby`, the icon is announced as an image (`role="img"`). Otherwise it is marked as decoration with `aria-hidden`.
|
|
@@ -201,14 +219,15 @@ MaterialSymbolSharp(props: MaterialSymbolProps): ReactElement
|
|
|
201
219
|
|
|
202
220
|
Draws the `value` icon as ligature text in a `<span>`. Other props are passed to the `<span>` (`ref` also points to the `<span>`); `className` and `style` are merged, and for the same property the received value wins.
|
|
203
221
|
|
|
204
|
-
| Property
|
|
205
|
-
|
|
|
206
|
-
| `value`
|
|
207
|
-
| `
|
|
208
|
-
| `filled?`
|
|
209
|
-
| `grade?`
|
|
210
|
-
| `opticalSize?`
|
|
211
|
-
| `design?`
|
|
222
|
+
| Property | Type | Description |
|
|
223
|
+
| ----------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
224
|
+
| `value` | `MaterialSymbolValue` | The icon name |
|
|
225
|
+
| `fontWeight?` | `number` | Weight (`wght`, 100–700) |
|
|
226
|
+
| `filled?` | `boolean \| number` | Fill (`FILL`). `true` is 1, `false` (default) is 0. Also takes a number from 0 to 1 |
|
|
227
|
+
| `grade?` | `number` | Grade (`GRAD`, -25–200) |
|
|
228
|
+
| `opticalSize?` | `number` | Optical size (`opsz`, 20–48). If omitted, it follows the text size |
|
|
229
|
+
| `design?` | `MaterialSymbolDesign` | Design values (table below). Stronger than the prop for the same axis |
|
|
230
|
+
| `fallbackDesign?` | `MaterialSymbolDesign` | The app-wide design values (passed by `withDesign`). Fill the axes and states the props and `design` do not set |
|
|
212
231
|
|
|
213
232
|
Static properties of the components:
|
|
214
233
|
|
|
@@ -220,16 +239,16 @@ Static properties of the components:
|
|
|
220
239
|
|
|
221
240
|
#### Design values
|
|
222
241
|
|
|
223
|
-
The design values you can pass with `design` (the CSS variable is `--frg-materialsymbol-` followed by the key joined with `-`, e.g. `filled.hover` → `--frg-materialsymbol-filled-hover`). If you do not set the `hover` value, the stateless value
|
|
242
|
+
The design values you can pass with `design` (the CSS variable is `--frg-materialsymbol-` followed by the key joined with `-`, e.g. `filled.hover` → `--frg-materialsymbol-filled-hover`). If you do not set the `hover` value, the component's default applies on hover (the stateless value is not taken over). A single value also applies to `hover`.
|
|
224
243
|
|
|
225
244
|
| Key | Default | Description |
|
|
226
245
|
| ------------------ | ------- | -------------------------------------------------------------- |
|
|
227
246
|
| `fontWeight` | `400` | Weight (`wght`) |
|
|
228
|
-
| `fontWeight.hover` |
|
|
247
|
+
| `fontWeight.hover` | `400` | Weight on hover |
|
|
229
248
|
| `filled` | `0` | Fill (`FILL`, 0–1; values in between are mid-animation shapes) |
|
|
230
|
-
| `filled.hover` |
|
|
249
|
+
| `filled.hover` | `0` | Fill on hover |
|
|
231
250
|
| `grade` | `0` | Grade (`GRAD`) |
|
|
232
|
-
| `grade.hover` |
|
|
251
|
+
| `grade.hover` | `0` | Grade on hover |
|
|
233
252
|
| `opticalSize` | — | Optical size (`opsz`). Fixed only when set |
|
|
234
253
|
|
|
235
254
|
`design` values follow the rules of `createDesignStyle` from [`@fringeworks/react-contract`](https://www.npmjs.com/package/@fringeworks/react-contract). `filled`, `grade`, and `opticalSize` are names for variable font axes that have no CSS property.
|
|
@@ -247,7 +266,7 @@ When you set `opticalSize` with a CSS variable, also add the `frg-materialsymbol
|
|
|
247
266
|
|
|
248
267
|
| Class | Description |
|
|
249
268
|
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
|
|
250
|
-
| `frg-icon`, `frg-fonticon` | react-icon classes (the
|
|
269
|
+
| `frg-icon`, `frg-fonticon` | react-icon classes (the square box and the icon font settings) |
|
|
251
270
|
| `frg-materialsymbol` | Every Material Symbols icon. Builds the variable font axes from CSS variables |
|
|
252
271
|
| `frg-materialsymboloutlined`, `frg-materialsymbolrounded`, `frg-materialsymbolsharp` | One per style, for selecting a style. They have no CSS rules (the component sets the font family in `style`) |
|
|
253
272
|
| `frg-materialsymbol-opticalSize` | Added when the optical size is fixed |
|
|
@@ -8,44 +8,38 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
8
8
|
// src/_internal/_createMaterialSymbol.tsx
|
|
9
9
|
const PREFIX = "frg-materialsymbol";
|
|
10
10
|
/**
|
|
11
|
-
* 軸のプロパティを、design
|
|
11
|
+
* 軸のプロパティを、design と同じ形の値にする(1つの値として、すべての状態に効く)
|
|
12
12
|
*/
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
function createPropsDesign({ fontWeight, filled, grade, opticalSize }) {
|
|
14
|
+
return {
|
|
15
|
+
fontWeight,
|
|
16
|
+
filled: filled === void 0 ? void 0 : Number(filled),
|
|
17
|
+
grade,
|
|
18
|
+
opticalSize
|
|
19
|
+
};
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Material Symbols の種類ごとの部品を作る
|
|
23
|
-
*
|
|
24
|
-
* - クラスは `frg-icon frg-fonticon`(react-icon)に、`frg-materialsymbol` と種類のクラス(`frg-materialsymboloutlined` など)を足す
|
|
25
|
-
* - 光学サイズを指定したとき(プロパティか design)だけ `frg-materialsymbol-opticalSize` を足す。
|
|
26
|
-
* `font-variation-settings` に `opsz` を書くと、文字の大きさに合わせた自動の光学サイズが効かなくなるため
|
|
27
|
-
* - 軸の値は design と同じ CSS 変数に書き、プロパティは design の状態なしの値を上書きする
|
|
28
|
-
*/
|
|
29
21
|
function createMaterialSymbol(variant) {
|
|
30
22
|
const fontFamily = `Material Symbols ${variant}`;
|
|
31
23
|
const definition = { fontFamily };
|
|
32
|
-
function MaterialSymbol({
|
|
33
|
-
const
|
|
24
|
+
function MaterialSymbol({ fontWeight, filled, grade, opticalSize, design, fallbackDesign, ...props }) {
|
|
25
|
+
const effectiveDesign = (0, _fringeworks_react_contract.createEffectiveDesign)(require_constants.materialSymbolDesignDefinition, {
|
|
26
|
+
design,
|
|
27
|
+
propsDesign: createPropsDesign({
|
|
28
|
+
fontWeight,
|
|
29
|
+
filled,
|
|
30
|
+
grade,
|
|
31
|
+
opticalSize
|
|
32
|
+
}),
|
|
33
|
+
fallbackDesign
|
|
34
|
+
});
|
|
35
|
+
const fixesOpticalSize = effectiveDesign.opticalSize !== void 0;
|
|
34
36
|
const ownProps = {
|
|
35
37
|
className: [
|
|
36
38
|
PREFIX,
|
|
37
39
|
`${PREFIX}${variant.toLowerCase()}`,
|
|
38
40
|
fixesOpticalSize && `${PREFIX}-opticalSize`
|
|
39
41
|
],
|
|
40
|
-
style:
|
|
41
|
-
...(0, _fringeworks_react_contract.createDesignStyle)(PREFIX, require_constants.materialSymbolDesignDefinition, design),
|
|
42
|
-
...createAxisStyle({
|
|
43
|
-
weight,
|
|
44
|
-
filled,
|
|
45
|
-
grade,
|
|
46
|
-
opticalSize
|
|
47
|
-
})
|
|
48
|
-
}
|
|
42
|
+
style: (0, _fringeworks_react_contract.createDesignStyle)(PREFIX, require_constants.materialSymbolDesignDefinition, effectiveDesign)
|
|
49
43
|
};
|
|
50
44
|
const merged = (0, _fringeworks_react_merge.mergeProps)(ownProps, props);
|
|
51
45
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { ...(0, _fringeworks_react_icon.createFontIconProps)(definition, merged) });
|
|
@@ -3,12 +3,4 @@ import { MaterialSymbolComponent } from "../types.cjs";
|
|
|
3
3
|
* Material Symbols の種類(フォントファミリーの名前の後ろの部分)
|
|
4
4
|
*/
|
|
5
5
|
export type MaterialSymbolVariant = 'Outlined' | 'Rounded' | 'Sharp';
|
|
6
|
-
/**
|
|
7
|
-
* Material Symbols の種類ごとの部品を作る
|
|
8
|
-
*
|
|
9
|
-
* - クラスは `frg-icon frg-fonticon`(react-icon)に、`frg-materialsymbol` と種類のクラス(`frg-materialsymboloutlined` など)を足す
|
|
10
|
-
* - 光学サイズを指定したとき(プロパティか design)だけ `frg-materialsymbol-opticalSize` を足す。
|
|
11
|
-
* `font-variation-settings` に `opsz` を書くと、文字の大きさに合わせた自動の光学サイズが効かなくなるため
|
|
12
|
-
* - 軸の値は design と同じ CSS 変数に書き、プロパティは design の状態なしの値を上書きする
|
|
13
|
-
*/
|
|
14
6
|
export default function createMaterialSymbol(variant: MaterialSymbolVariant): MaterialSymbolComponent;
|
|
@@ -3,12 +3,4 @@ import { MaterialSymbolComponent } from "../types.mjs";
|
|
|
3
3
|
* Material Symbols の種類(フォントファミリーの名前の後ろの部分)
|
|
4
4
|
*/
|
|
5
5
|
export type MaterialSymbolVariant = 'Outlined' | 'Rounded' | 'Sharp';
|
|
6
|
-
/**
|
|
7
|
-
* Material Symbols の種類ごとの部品を作る
|
|
8
|
-
*
|
|
9
|
-
* - クラスは `frg-icon frg-fonticon`(react-icon)に、`frg-materialsymbol` と種類のクラス(`frg-materialsymboloutlined` など)を足す
|
|
10
|
-
* - 光学サイズを指定したとき(プロパティか design)だけ `frg-materialsymbol-opticalSize` を足す。
|
|
11
|
-
* `font-variation-settings` に `opsz` を書くと、文字の大きさに合わせた自動の光学サイズが効かなくなるため
|
|
12
|
-
* - 軸の値は design と同じ CSS 変数に書き、プロパティは design の状態なしの値を上書きする
|
|
13
|
-
*/
|
|
14
6
|
export default function createMaterialSymbol(variant: MaterialSymbolVariant): MaterialSymbolComponent;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { materialSymbolDesignDefinition } from "../constants.mjs";
|
|
2
|
-
import { createDesignStyle } from "@fringeworks/react-contract";
|
|
2
|
+
import { createDesignStyle, createEffectiveDesign } from "@fringeworks/react-contract";
|
|
3
3
|
import { createFontIconProps } from "@fringeworks/react-icon";
|
|
4
4
|
import { mergeProps } from "@fringeworks/react-merge";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -7,44 +7,38 @@ import { jsx } from "react/jsx-runtime";
|
|
|
7
7
|
// src/_internal/_createMaterialSymbol.tsx
|
|
8
8
|
const PREFIX = "frg-materialsymbol";
|
|
9
9
|
/**
|
|
10
|
-
* 軸のプロパティを、design
|
|
10
|
+
* 軸のプロパティを、design と同じ形の値にする(1つの値として、すべての状態に効く)
|
|
11
11
|
*/
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
function createPropsDesign({ fontWeight, filled, grade, opticalSize }) {
|
|
13
|
+
return {
|
|
14
|
+
fontWeight,
|
|
15
|
+
filled: filled === void 0 ? void 0 : Number(filled),
|
|
16
|
+
grade,
|
|
17
|
+
opticalSize
|
|
18
|
+
};
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Material Symbols の種類ごとの部品を作る
|
|
22
|
-
*
|
|
23
|
-
* - クラスは `frg-icon frg-fonticon`(react-icon)に、`frg-materialsymbol` と種類のクラス(`frg-materialsymboloutlined` など)を足す
|
|
24
|
-
* - 光学サイズを指定したとき(プロパティか design)だけ `frg-materialsymbol-opticalSize` を足す。
|
|
25
|
-
* `font-variation-settings` に `opsz` を書くと、文字の大きさに合わせた自動の光学サイズが効かなくなるため
|
|
26
|
-
* - 軸の値は design と同じ CSS 変数に書き、プロパティは design の状態なしの値を上書きする
|
|
27
|
-
*/
|
|
28
20
|
function createMaterialSymbol(variant) {
|
|
29
21
|
const fontFamily = `Material Symbols ${variant}`;
|
|
30
22
|
const definition = { fontFamily };
|
|
31
|
-
function MaterialSymbol({
|
|
32
|
-
const
|
|
23
|
+
function MaterialSymbol({ fontWeight, filled, grade, opticalSize, design, fallbackDesign, ...props }) {
|
|
24
|
+
const effectiveDesign = createEffectiveDesign(materialSymbolDesignDefinition, {
|
|
25
|
+
design,
|
|
26
|
+
propsDesign: createPropsDesign({
|
|
27
|
+
fontWeight,
|
|
28
|
+
filled,
|
|
29
|
+
grade,
|
|
30
|
+
opticalSize
|
|
31
|
+
}),
|
|
32
|
+
fallbackDesign
|
|
33
|
+
});
|
|
34
|
+
const fixesOpticalSize = effectiveDesign.opticalSize !== void 0;
|
|
33
35
|
const ownProps = {
|
|
34
36
|
className: [
|
|
35
37
|
PREFIX,
|
|
36
38
|
`${PREFIX}${variant.toLowerCase()}`,
|
|
37
39
|
fixesOpticalSize && `${PREFIX}-opticalSize`
|
|
38
40
|
],
|
|
39
|
-
style:
|
|
40
|
-
...createDesignStyle(PREFIX, materialSymbolDesignDefinition, design),
|
|
41
|
-
...createAxisStyle({
|
|
42
|
-
weight,
|
|
43
|
-
filled,
|
|
44
|
-
grade,
|
|
45
|
-
opticalSize
|
|
46
|
-
})
|
|
47
|
-
}
|
|
41
|
+
style: createDesignStyle(PREFIX, materialSymbolDesignDefinition, effectiveDesign)
|
|
48
42
|
};
|
|
49
43
|
const merged = mergeProps(ownProps, props);
|
|
50
44
|
return /* @__PURE__ */ jsx("span", { ...createFontIconProps(definition, merged) });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fringeworks/react-icon-material-symbols",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A library some will find handy, for using Material Symbols as typed React components with variable font axes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"module": "./index.mjs",
|
|
70
70
|
"types": "./index.d.cts",
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@fringeworks/react-contract": "^0.
|
|
73
|
-
"@fringeworks/react-icon": "^0.
|
|
72
|
+
"@fringeworks/react-contract": "^0.3.1",
|
|
73
|
+
"@fringeworks/react-icon": "^0.2.0",
|
|
74
74
|
"@fringeworks/react-merge": "^0.9.2",
|
|
75
75
|
"material-symbols": "^0.49.0"
|
|
76
76
|
},
|
package/styles.css
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
:where(.frg-icon) {
|
|
2
|
-
display: inline-
|
|
2
|
+
display: inline-flex;
|
|
3
3
|
flex-shrink: 0;
|
|
4
|
+
align-items: center;
|
|
5
|
+
justify-content: center;
|
|
4
6
|
box-sizing: content-box;
|
|
5
7
|
width: 1em;
|
|
6
8
|
height: 1em;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
clip-path: inset(0);
|
|
10
|
+
font-size: var(--frg-icon-size, calc(1em * var(--frg-icon-scale, 1) * var(--frg-icon-glyphScale, 1)));
|
|
9
11
|
line-height: 1;
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
:where(.frg-icon)::before {
|
|
15
|
+
content: "";
|
|
16
|
+
align-self: center;
|
|
17
|
+
margin-top: calc(2 * var(--frg-icon-centerY, 0.37) * 1em / (var(--frg-icon-scale, 1) * var(--frg-icon-glyphScale, 1)));
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
:where(.frg-fonticon) {
|
|
13
21
|
font-style: normal;
|
|
14
22
|
font-weight: normal;
|
|
@@ -25,7 +33,14 @@
|
|
|
25
33
|
user-select: none;
|
|
26
34
|
}
|
|
27
35
|
|
|
36
|
+
:where(.frg-svgicon) > svg {
|
|
37
|
+
display: block;
|
|
38
|
+
width: 100%;
|
|
39
|
+
height: 100%;
|
|
40
|
+
}
|
|
41
|
+
|
|
28
42
|
:where(.frg-materialsymbol) {
|
|
43
|
+
--frg-icon-glyphScale: 1.25;
|
|
29
44
|
font-weight: var(--frg-materialsymbol-fontWeight, 400);
|
|
30
45
|
font-variation-settings: "FILL" var(--frg-materialsymbol-filled, 0), "GRAD" var(--frg-materialsymbol-grade, 0);
|
|
31
46
|
}
|
|
@@ -35,10 +50,10 @@
|
|
|
35
50
|
}
|
|
36
51
|
|
|
37
52
|
:where(.frg-materialsymbol:hover) {
|
|
38
|
-
font-weight: var(--frg-materialsymbol-fontWeight-hover,
|
|
39
|
-
font-variation-settings: "FILL" var(--frg-materialsymbol-filled-hover,
|
|
53
|
+
font-weight: var(--frg-materialsymbol-fontWeight-hover, 400);
|
|
54
|
+
font-variation-settings: "FILL" var(--frg-materialsymbol-filled-hover, 0), "GRAD" var(--frg-materialsymbol-grade-hover, 0);
|
|
40
55
|
}
|
|
41
56
|
|
|
42
57
|
:where(.frg-materialsymbol-opticalSize:hover) {
|
|
43
|
-
font-variation-settings: "FILL" var(--frg-materialsymbol-filled-hover,
|
|
58
|
+
font-variation-settings: "FILL" var(--frg-materialsymbol-filled-hover, 0), "GRAD" var(--frg-materialsymbol-grade-hover, 0), "opsz" var(--frg-materialsymbol-opticalSize, 24);
|
|
44
59
|
}
|
package/types.d.cts
CHANGED
|
@@ -11,17 +11,18 @@ export type MaterialSymbolDesign = Design<typeof materialSymbolDesignDefinition>
|
|
|
11
11
|
* Material Symbols の部品のプロパティ
|
|
12
12
|
*
|
|
13
13
|
* `value` でアイコンの名前を受け取る。そのほかの props は `<span>` に渡す。
|
|
14
|
+
* 軸のプロパティ(`fontWeight`・`filled`・`grade`・`opticalSize`)は、すべての状態に効く。
|
|
14
15
|
*/
|
|
15
16
|
export type MaterialSymbolProps = FontIconProps<MaterialSymbolValue> & {
|
|
16
17
|
/**
|
|
17
18
|
* 太さ(`wght` の軸。100〜700)。`font-weight` で描く
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
fontWeight?: number;
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
+
* 塗り(`FILL` の軸)。`true` で塗りつぶした形、`false` で線の形。0〜1 の数値で途中の形にもできる(`true` は 1、`false` は 0)
|
|
22
23
|
* @default false
|
|
23
24
|
*/
|
|
24
|
-
filled?: boolean;
|
|
25
|
+
filled?: boolean | number;
|
|
25
26
|
/**
|
|
26
27
|
* グレード(`GRAD` の軸。-25〜200)。太さを変えずに線の濃さを変える
|
|
27
28
|
*/
|
|
@@ -31,9 +32,14 @@ export type MaterialSymbolProps = FontIconProps<MaterialSymbolValue> & {
|
|
|
31
32
|
*/
|
|
32
33
|
opticalSize?: number;
|
|
33
34
|
/**
|
|
34
|
-
* デザインの値(軸ごとに、`hover`
|
|
35
|
+
* デザインの値(軸ごとに、`hover` の値も指定できる)。同じ軸のプロパティより強い。
|
|
36
|
+
* 状態ごとのオブジェクトで省略した状態は、プロパティの値(プロパティも無ければ部品の既定の値)になる
|
|
35
37
|
*/
|
|
36
38
|
design?: MaterialSymbolDesign;
|
|
39
|
+
/**
|
|
40
|
+
* アプリで共通のデザインの値(react-contract の `withDesign` が渡す)。プロパティと `design` で指定していない軸・状態を補う
|
|
41
|
+
*/
|
|
42
|
+
fallbackDesign?: MaterialSymbolDesign;
|
|
37
43
|
};
|
|
38
44
|
/**
|
|
39
45
|
* Material Symbols の部品(`MaterialSymbolOutlined`・`MaterialSymbolRounded`・`MaterialSymbolSharp`)
|
package/types.d.mts
CHANGED
|
@@ -11,17 +11,18 @@ export type MaterialSymbolDesign = Design<typeof materialSymbolDesignDefinition>
|
|
|
11
11
|
* Material Symbols の部品のプロパティ
|
|
12
12
|
*
|
|
13
13
|
* `value` でアイコンの名前を受け取る。そのほかの props は `<span>` に渡す。
|
|
14
|
+
* 軸のプロパティ(`fontWeight`・`filled`・`grade`・`opticalSize`)は、すべての状態に効く。
|
|
14
15
|
*/
|
|
15
16
|
export type MaterialSymbolProps = FontIconProps<MaterialSymbolValue> & {
|
|
16
17
|
/**
|
|
17
18
|
* 太さ(`wght` の軸。100〜700)。`font-weight` で描く
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
fontWeight?: number;
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
+
* 塗り(`FILL` の軸)。`true` で塗りつぶした形、`false` で線の形。0〜1 の数値で途中の形にもできる(`true` は 1、`false` は 0)
|
|
22
23
|
* @default false
|
|
23
24
|
*/
|
|
24
|
-
filled?: boolean;
|
|
25
|
+
filled?: boolean | number;
|
|
25
26
|
/**
|
|
26
27
|
* グレード(`GRAD` の軸。-25〜200)。太さを変えずに線の濃さを変える
|
|
27
28
|
*/
|
|
@@ -31,9 +32,14 @@ export type MaterialSymbolProps = FontIconProps<MaterialSymbolValue> & {
|
|
|
31
32
|
*/
|
|
32
33
|
opticalSize?: number;
|
|
33
34
|
/**
|
|
34
|
-
* デザインの値(軸ごとに、`hover`
|
|
35
|
+
* デザインの値(軸ごとに、`hover` の値も指定できる)。同じ軸のプロパティより強い。
|
|
36
|
+
* 状態ごとのオブジェクトで省略した状態は、プロパティの値(プロパティも無ければ部品の既定の値)になる
|
|
35
37
|
*/
|
|
36
38
|
design?: MaterialSymbolDesign;
|
|
39
|
+
/**
|
|
40
|
+
* アプリで共通のデザインの値(react-contract の `withDesign` が渡す)。プロパティと `design` で指定していない軸・状態を補う
|
|
41
|
+
*/
|
|
42
|
+
fallbackDesign?: MaterialSymbolDesign;
|
|
37
43
|
};
|
|
38
44
|
/**
|
|
39
45
|
* Material Symbols の部品(`MaterialSymbolOutlined`・`MaterialSymbolRounded`・`MaterialSymbolSharp`)
|