@fringeworks/react-icon-material-symbols 0.1.1 → 0.2.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 CHANGED
@@ -98,18 +98,18 @@ Material Symbols の4つの軸を、プロパティで変えられます。
98
98
 
99
99
  ```tsx
100
100
  <MaterialSymbolOutlined value="favorite" filled />
101
- <MaterialSymbolOutlined value="settings" weight={300} grade={-25} />
101
+ <MaterialSymbolOutlined value="settings" fontWeight={300} grade={-25} />
102
102
  <MaterialSymbolOutlined value="search" opticalSize={20} />
103
103
  ```
104
104
 
105
105
  | プロパティ | 軸 | 説明 |
106
106
  | -------------- | ------ | ------------------------------------------------------------------------------------------------------------- |
107
- | `weight?` | `wght` | 太さ(100〜700)。CSS の `font-weight` で描く |
108
- | `filled?` | `FILL` | 塗りつぶした形にする。既定は `false` |
107
+ | `fontWeight?` | `wght` | 太さ(100〜700)。CSS の `font-weight` で描く |
108
+ | `filled?` | `FILL` | `true` で塗りつぶした形、`false`(既定)で線の形。0〜1 の数値で途中の形にもできる |
109
109
  | `grade?` | `GRAD` | グレード(-25〜200)。太さ(アイコンの大きさ)を変えずに、線の濃さを変える |
110
110
  | `opticalSize?` | `opsz` | 光学サイズ(20〜48)。指定しなければ、ブラウザーが文字の大きさに合わせて決める(`font-optical-sizing: auto`) |
111
111
 
112
- 軸の値は CSS 変数(`--frg-materialsymbol-filled` など。下の「デザインの値」の表)から組み立てるので、CSS でも軸ごとに変えられます。
112
+ 軸のプロパティは、乗ったときなど、すべての状態に効きます(`design` に1つの値で書いたのと同じ)。軸の値は CSS 変数(`--frg-materialsymbol-filled` など。下の「デザインの値」の表)から組み立てるので、CSS でも軸ごとに変えられます。
113
113
 
114
114
  ### アイコンに乗ったときに変える
115
115
 
@@ -122,11 +122,12 @@ Material Symbols の4つの軸を、プロパティで変えられます。
122
122
  />
123
123
  ```
124
124
 
125
- ボタンなど、親の要素に乗ったときに変えるには、CSS で変数を設定します。
125
+ ボタンなど、親の要素に乗ったときに変えるには、CSS で変数を設定します。アイコン自身に乗ったときの変数(`-hover`)も書いてください。書かないと、ポインターがアイコンの上に来たときに、アイコンの `:hover` の既定の値に戻ります。
126
126
 
127
127
  ```css
128
128
  .favorite-button:hover {
129
129
  --frg-materialsymbol-filled: 1;
130
+ --frg-materialsymbol-filled-hover: 1;
130
131
  }
131
132
  ```
132
133
 
@@ -140,6 +141,21 @@ import { withDesign } from '@fringeworks/react-contract';
140
141
  const Icon = withDesign(MaterialSymbolOutlined, { filled: { hover: 1 } });
141
142
  ```
142
143
 
144
+ ### プロパティ・`design`・`withDesign` の重なり方
145
+
146
+ 同じ軸を複数の方法で指定したときは、使う場所の `design` > 軸のプロパティ > `withDesign` の値(`fallbackDesign`)の順に強くなります。強い方で指定していない状態は、弱い方の値になります。
147
+
148
+ | 指定 | 状態なし | 乗ったとき |
149
+ | ---------------------------------------------------------------------- | -------- | --------------------- |
150
+ | `fontWeight={300}` | 300 | 300 |
151
+ | `fontWeight={300}` と `design={{ fontWeight: { hover: 700 } }}` | 300 | 700 |
152
+ | `design={{ fontWeight: { base: 700 } }}` | 700 | 400(部品の既定の値) |
153
+ | `design={{ fontWeight: 700 }}` | 700 | 700 |
154
+ | `withDesign` の `{ fontWeight: { hover: 700 } }` と `fontWeight={300}` | 300 | 300 |
155
+
156
+ - `design` の状態ごとのオブジェクトで省略した状態は、`base` の値を引き継ぎません(`{ base: 700 }` は状態なしの値だけを決めます)。すべての状態で同じにするときは、1つの値(`fontWeight: 700`)で書きます。
157
+ - `withDesign` の値は、使う場所のプロパティより弱くなります。アプリで共通に決めた軸も、使う場所でプロパティを書けば変えられます。
158
+
143
159
  ### 読み上げ
144
160
 
145
161
  `aria-label`・`aria-labelledby` を渡すと、画像(`role="img"`)として読み上げられます。渡さなければ、飾りとして `aria-hidden` が付きます。
@@ -201,14 +217,15 @@ MaterialSymbolSharp(props: MaterialSymbolProps): ReactElement
201
217
 
202
218
  `value` のアイコンを、`<span>` に合字の文字として描きます。そのほかの props は `<span>` に渡し(`ref` も `<span>` を指します)、`className`・`style` は合成して、同じプロパティは受け取った値を優先します。
203
219
 
204
- | プロパティ | 型 | 説明 |
205
- | -------------- | ---------------------- | -------------------------------------------------------------------------------------------- |
206
- | `value` | `MaterialSymbolValue` | アイコンの名前 |
207
- | `weight?` | `number` | 太さ(`wght`。100〜700) |
208
- | `filled?` | `boolean` | 塗りつぶした形にする(`FILL`)。既定は `false` |
209
- | `grade?` | `number` | グレード(`GRAD`。-25〜200) |
210
- | `opticalSize?` | `number` | 光学サイズ(`opsz`。20〜48)。指定しなければ文字の大きさに合わせて決まる |
211
- | `design?` | `MaterialSymbolDesign` | デザインの値(下の表)。同じ軸のプロパティを指定したら、状態なしの値はプロパティで上書きする |
220
+ | プロパティ | 型 | 説明 |
221
+ | ----------------- | ---------------------- | ------------------------------------------------------------------------------------------------------- |
222
+ | `value` | `MaterialSymbolValue` | アイコンの名前 |
223
+ | `fontWeight?` | `number` | 太さ(`wght`。100〜700) |
224
+ | `filled?` | `boolean \| number` | 塗り(`FILL`)。`true` は 1、`false`(既定)は 0。0〜1 の数値も受け付ける |
225
+ | `grade?` | `number` | グレード(`GRAD`。-25〜200) |
226
+ | `opticalSize?` | `number` | 光学サイズ(`opsz`。20〜48)。指定しなければ文字の大きさに合わせて決まる |
227
+ | `design?` | `MaterialSymbolDesign` | デザインの値(下の表)。同じ軸のプロパティより強い |
228
+ | `fallbackDesign?` | `MaterialSymbolDesign` | アプリで共通のデザインの値(`withDesign` が渡す)。プロパティと `design` で指定していない軸・状態を補う |
212
229
 
213
230
  部品の静的なプロパティ:
214
231
 
@@ -220,16 +237,16 @@ MaterialSymbolSharp(props: MaterialSymbolProps): ReactElement
220
237
 
221
238
  #### デザインの値
222
239
 
223
- `design` で渡せるデザインの値です(CSS 変数は `--frg-materialsymbol-` の後にキーを `-` でつないだもの。例: `filled.hover` → `--frg-materialsymbol-filled-hover`)。`hover` の値を指定しなければ、乗ったときも状態なしの値のままです。
240
+ `design` で渡せるデザインの値です(CSS 変数は `--frg-materialsymbol-` の後にキーを `-` でつないだもの。例: `filled.hover` → `--frg-materialsymbol-filled-hover`)。`hover` の値を指定しなければ、乗ったときは部品の既定の値です(状態なしの値を引き継ぎません)。1つの値は、`hover` にも効きます。
224
241
 
225
242
  | キー | 既定値 | 説明 |
226
243
  | ------------------ | ------ | ---------------------------------------------------------- |
227
244
  | `fontWeight` | `400` | 太さ(`wght`) |
228
- | `fontWeight.hover` | — | 乗ったときの太さ |
245
+ | `fontWeight.hover` | `400` | 乗ったときの太さ |
229
246
  | `filled` | `0` | 塗り(`FILL`。0〜1。途中の値は、アニメーションの途中の形) |
230
- | `filled.hover` | — | 乗ったときの塗り |
247
+ | `filled.hover` | `0` | 乗ったときの塗り |
231
248
  | `grade` | `0` | グレード(`GRAD`) |
232
- | `grade.hover` | — | 乗ったときのグレード |
249
+ | `grade.hover` | `0` | 乗ったときのグレード |
233
250
  | `opticalSize` | — | 光学サイズ(`opsz`)。指定したときだけ固定する |
234
251
 
235
252
  `design` の値は、[`@fringeworks/react-contract`](https://www.npmjs.com/package/@fringeworks/react-contract) の `createDesignStyle` の規則で書きます。`filled`・`grade`・`opticalSize` は、CSS のプロパティが無い可変フォントの軸のための名前です。
package/README.md CHANGED
@@ -98,18 +98,18 @@ You can change the four Material Symbols axes with props.
98
98
 
99
99
  ```tsx
100
100
  <MaterialSymbolOutlined value="favorite" filled />
101
- <MaterialSymbolOutlined value="settings" weight={300} grade={-25} />
101
+ <MaterialSymbolOutlined value="settings" fontWeight={300} grade={-25} />
102
102
  <MaterialSymbolOutlined value="search" opticalSize={20} />
103
103
  ```
104
104
 
105
- | Prop | Axis | Description |
106
- | -------------- | ------ | ----------------------------------------------------------------------------------------------------------- |
107
- | `weight?` | `wght` | Weight (100–700). Drawn with the CSS `font-weight` |
108
- | `filled?` | `FILL` | Use the filled shape. Defaults to `false` |
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`) |
105
+ | Prop | Axis | Description |
106
+ | -------------- | ------ | ------------------------------------------------------------------------------------------------------------------ |
107
+ | `fontWeight?` | `wght` | Weight (100–700). Drawn with the CSS `font-weight` |
108
+ | `filled?` | `FILL` | `true` for the filled shape, `false` (default) for the outlined one. A number from 0 to 1 gives a shape in between |
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`) |
111
111
 
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.
112
+ 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
113
 
114
114
  ### Changing on hover
115
115
 
@@ -122,11 +122,12 @@ With `design`, you can set the value for each axis when the pointer is over the
122
122
  />
123
123
  ```
124
124
 
125
- To change it when the pointer is over a parent element such as a button, set the variable with CSS.
125
+ 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
126
 
127
127
  ```css
128
128
  .favorite-button:hover {
129
129
  --frg-materialsymbol-filled: 1;
130
+ --frg-materialsymbol-filled-hover: 1;
130
131
  }
131
132
  ```
132
133
 
@@ -140,6 +141,21 @@ import { withDesign } from '@fringeworks/react-contract';
140
141
  const Icon = withDesign(MaterialSymbolOutlined, { filled: { hover: 1 } });
141
142
  ```
142
143
 
144
+ ### How props, `design`, and `withDesign` combine
145
+
146
+ 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.
147
+
148
+ | Set | Stateless | On hover |
149
+ | ----------------------------------------------------------------------- | --------- | ----------------------------- |
150
+ | `fontWeight={300}` | 300 | 300 |
151
+ | `fontWeight={300}` and `design={{ fontWeight: { hover: 700 } }}` | 300 | 700 |
152
+ | `design={{ fontWeight: { base: 700 } }}` | 700 | 400 (the component's default) |
153
+ | `design={{ fontWeight: 700 }}` | 700 | 700 |
154
+ | `{ fontWeight: { hover: 700 } }` in `withDesign` and `fontWeight={300}` | 300 | 300 |
155
+
156
+ - 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`).
157
+ - 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.
158
+
143
159
  ### Accessibility
144
160
 
145
161
  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 +217,15 @@ MaterialSymbolSharp(props: MaterialSymbolProps): ReactElement
201
217
 
202
218
  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
219
 
204
- | Property | Type | Description |
205
- | -------------- | ---------------------- | ------------------------------------------------------------------------------------------------- |
206
- | `value` | `MaterialSymbolValue` | The icon name |
207
- | `weight?` | `number` | Weight (`wght`, 100–700) |
208
- | `filled?` | `boolean` | Use the filled shape (`FILL`). Defaults to `false` |
209
- | `grade?` | `number` | Grade (`GRAD`, -25–200) |
210
- | `opticalSize?` | `number` | Optical size (`opsz`, 20–48). If omitted, it follows the text size |
211
- | `design?` | `MaterialSymbolDesign` | Design values (table below). If a prop for the same axis is set, it overrides the stateless value |
220
+ | Property | Type | Description |
221
+ | ----------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------- |
222
+ | `value` | `MaterialSymbolValue` | The icon name |
223
+ | `fontWeight?` | `number` | Weight (`wght`, 100–700) |
224
+ | `filled?` | `boolean \| number` | Fill (`FILL`). `true` is 1, `false` (default) is 0. Also takes a number from 0 to 1 |
225
+ | `grade?` | `number` | Grade (`GRAD`, -25–200) |
226
+ | `opticalSize?` | `number` | Optical size (`opsz`, 20–48). If omitted, it follows the text size |
227
+ | `design?` | `MaterialSymbolDesign` | Design values (table below). Stronger than the prop for the same axis |
228
+ | `fallbackDesign?` | `MaterialSymbolDesign` | The app-wide design values (passed by `withDesign`). Fill the axes and states the props and `design` do not set |
212
229
 
213
230
  Static properties of the components:
214
231
 
@@ -220,16 +237,16 @@ Static properties of the components:
220
237
 
221
238
  #### Design values
222
239
 
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 stays on hover.
240
+ 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
241
 
225
242
  | Key | Default | Description |
226
243
  | ------------------ | ------- | -------------------------------------------------------------- |
227
244
  | `fontWeight` | `400` | Weight (`wght`) |
228
- | `fontWeight.hover` | — | Weight on hover |
245
+ | `fontWeight.hover` | `400` | Weight on hover |
229
246
  | `filled` | `0` | Fill (`FILL`, 0–1; values in between are mid-animation shapes) |
230
- | `filled.hover` | — | Fill on hover |
247
+ | `filled.hover` | `0` | Fill on hover |
231
248
  | `grade` | `0` | Grade (`GRAD`) |
232
- | `grade.hover` | — | Grade on hover |
249
+ | `grade.hover` | `0` | Grade on hover |
233
250
  | `opticalSize` | — | Optical size (`opsz`). Fixed only when set |
234
251
 
235
252
  `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.
@@ -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 と同じ CSS 変数(状態なしの値)にする
11
+ * 軸のプロパティを、design と同じ形の値にする(1つの値として、すべての状態に効く)
12
12
  */
13
- function createAxisStyle({ weight, filled, grade, opticalSize }) {
14
- const style = {};
15
- if (weight !== void 0) style[`--${PREFIX}-fontWeight`] = String(weight);
16
- if (filled !== void 0) style[`--${PREFIX}-filled`] = filled ? "1" : "0";
17
- if (grade !== void 0) style[`--${PREFIX}-grade`] = String(grade);
18
- if (opticalSize !== void 0) style[`--${PREFIX}-opticalSize`] = String(opticalSize);
19
- return style;
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({ weight, filled, grade, opticalSize, design, ...props }) {
33
- const fixesOpticalSize = opticalSize !== void 0 || design?.opticalSize !== void 0;
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 と同じ CSS 変数(状態なしの値)にする
10
+ * 軸のプロパティを、design と同じ形の値にする(1つの値として、すべての状態に効く)
11
11
  */
12
- function createAxisStyle({ weight, filled, grade, opticalSize }) {
13
- const style = {};
14
- if (weight !== void 0) style[`--${PREFIX}-fontWeight`] = String(weight);
15
- if (filled !== void 0) style[`--${PREFIX}-filled`] = filled ? "1" : "0";
16
- if (grade !== void 0) style[`--${PREFIX}-grade`] = String(grade);
17
- if (opticalSize !== void 0) style[`--${PREFIX}-opticalSize`] = String(opticalSize);
18
- return style;
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({ weight, filled, grade, opticalSize, design, ...props }) {
32
- const fixesOpticalSize = opticalSize !== void 0 || design?.opticalSize !== void 0;
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.1.1",
3
+ "version": "0.2.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.2.2",
73
- "@fringeworks/react-icon": "^0.1.0",
72
+ "@fringeworks/react-contract": "^0.3.0",
73
+ "@fringeworks/react-icon": "^0.1.1",
74
74
  "@fringeworks/react-merge": "^0.9.2",
75
75
  "material-symbols": "^0.49.0"
76
76
  },
package/styles.css CHANGED
@@ -35,10 +35,10 @@
35
35
  }
36
36
 
37
37
  :where(.frg-materialsymbol:hover) {
38
- font-weight: var(--frg-materialsymbol-fontWeight-hover, var(--frg-materialsymbol-fontWeight, 400));
39
- font-variation-settings: "FILL" var(--frg-materialsymbol-filled-hover, var(--frg-materialsymbol-filled, 0)), "GRAD" var(--frg-materialsymbol-grade-hover, var(--frg-materialsymbol-grade, 0));
38
+ font-weight: var(--frg-materialsymbol-fontWeight-hover, 400);
39
+ font-variation-settings: "FILL" var(--frg-materialsymbol-filled-hover, 0), "GRAD" var(--frg-materialsymbol-grade-hover, 0);
40
40
  }
41
41
 
42
42
  :where(.frg-materialsymbol-opticalSize:hover) {
43
- font-variation-settings: "FILL" var(--frg-materialsymbol-filled-hover, var(--frg-materialsymbol-filled, 0)), "GRAD" var(--frg-materialsymbol-grade-hover, var(--frg-materialsymbol-grade, 0)), "opsz" var(--frg-materialsymbol-opticalSize, 24);
43
+ font-variation-settings: "FILL" var(--frg-materialsymbol-filled-hover, 0), "GRAD" var(--frg-materialsymbol-grade-hover, 0), "opsz" var(--frg-materialsymbol-opticalSize, 24);
44
44
  }
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
- weight?: number;
20
+ fontWeight?: number;
20
21
  /**
21
- * 塗りつぶした形にする(`FILL` の軸)
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
- weight?: number;
20
+ fontWeight?: number;
20
21
  /**
21
- * 塗りつぶした形にする(`FILL` の軸)
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`)