@fringeworks/react-icon-material-symbols 0.0.0-stage → 0.1.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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/MaterialSymbolOutlined/MaterialSymbolOutlined.cjs +16 -0
  3. package/MaterialSymbolOutlined/MaterialSymbolOutlined.d.cts +13 -0
  4. package/MaterialSymbolOutlined/MaterialSymbolOutlined.d.mts +13 -0
  5. package/MaterialSymbolOutlined/MaterialSymbolOutlined.mjs +15 -0
  6. package/MaterialSymbolOutlined/index.cjs +5 -0
  7. package/MaterialSymbolOutlined/index.d.cts +2 -0
  8. package/MaterialSymbolOutlined/index.d.mts +2 -0
  9. package/MaterialSymbolOutlined/index.mjs +3 -0
  10. package/MaterialSymbolRounded/MaterialSymbolRounded.cjs +16 -0
  11. package/MaterialSymbolRounded/MaterialSymbolRounded.d.cts +13 -0
  12. package/MaterialSymbolRounded/MaterialSymbolRounded.d.mts +13 -0
  13. package/MaterialSymbolRounded/MaterialSymbolRounded.mjs +15 -0
  14. package/MaterialSymbolRounded/index.cjs +5 -0
  15. package/MaterialSymbolRounded/index.d.cts +2 -0
  16. package/MaterialSymbolRounded/index.d.mts +2 -0
  17. package/MaterialSymbolRounded/index.mjs +3 -0
  18. package/MaterialSymbolSharp/MaterialSymbolSharp.cjs +16 -0
  19. package/MaterialSymbolSharp/MaterialSymbolSharp.d.cts +13 -0
  20. package/MaterialSymbolSharp/MaterialSymbolSharp.d.mts +13 -0
  21. package/MaterialSymbolSharp/MaterialSymbolSharp.mjs +15 -0
  22. package/MaterialSymbolSharp/index.cjs +5 -0
  23. package/MaterialSymbolSharp/index.d.cts +2 -0
  24. package/MaterialSymbolSharp/index.d.mts +2 -0
  25. package/MaterialSymbolSharp/index.mjs +3 -0
  26. package/README.ja.md +282 -0
  27. package/README.md +281 -2
  28. package/_internal/_createMaterialSymbol.cjs +59 -0
  29. package/_internal/_createMaterialSymbol.d.cts +14 -0
  30. package/_internal/_createMaterialSymbol.d.mts +14 -0
  31. package/_internal/_createMaterialSymbol.mjs +58 -0
  32. package/_internal/_materialSymbolValue.cjs +1 -0
  33. package/_internal/_materialSymbolValue.d.cts +8 -0
  34. package/_internal/_materialSymbolValue.d.mts +8 -0
  35. package/_internal/_materialSymbolValue.mjs +1 -0
  36. package/_styles.scss.cjs +5 -0
  37. package/_styles.scss.d.cts +1 -0
  38. package/_styles.scss.d.mts +1 -0
  39. package/_styles.scss.mjs +6 -0
  40. package/constants.cjs +17 -0
  41. package/constants.d.cts +15 -0
  42. package/constants.d.mts +15 -0
  43. package/constants.mjs +16 -0
  44. package/font-outlined.css +1 -0
  45. package/font-rounded.css +1 -0
  46. package/font-sharp.css +1 -0
  47. package/index.cjs +13 -0
  48. package/index.d.cts +10 -0
  49. package/index.d.mts +10 -0
  50. package/index.mjs +9 -0
  51. package/package.json +78 -4
  52. package/styles.css +44 -0
  53. package/types.cjs +1 -0
  54. package/types.d.cts +53 -0
  55. package/types.d.mts +53 -0
  56. package/types.mjs +1 -0
package/README.md CHANGED
@@ -1,3 +1,282 @@
1
- # Temporary Holding Version
1
+ # @fringeworks/react-icon-material-symbols
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@fringeworks/react-icon-material-symbols` is a library some will find handy, for using Google's [Material Symbols](https://fonts.google.com/icons) as React components with typed icon names and variable font axes.
4
+
5
+ **[日本語のREADMEはこちら](./README.ja.md)**
6
+
7
+ It is an adapter for [`@fringeworks/react-icon`](https://www.npmjs.com/package/@fringeworks/react-icon). Like the react-icon components, you render it as `<Icon value="home" />`, and you can combine it with react-icon's `createPrefixedIcon` and so on. react-icon is installed along with this package, so you do not need to install it separately.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @fringeworks/react-icon-material-symbols
13
+ ```
14
+
15
+ Supports React 18 and 19.
16
+
17
+ ## Usage
18
+
19
+ 1. Load this package's CSS once in your app. It includes the icon box CSS (from react-icon).
20
+ 2. Load the font for the style you use. The easiest way is this package's `font-<style>.css` (for other ways, see "Loading the font" below).
21
+ 3. Pass an icon name to the component's `value`.
22
+
23
+ ```tsx
24
+ import { MaterialSymbolOutlined } from '@fringeworks/react-icon-material-symbols';
25
+ import '@fringeworks/react-icon-material-symbols/styles.css';
26
+ import '@fringeworks/react-icon-material-symbols/font-outlined.css';
27
+
28
+ <MaterialSymbolOutlined value="home" />;
29
+ ```
30
+
31
+ The type of `value` is the Material Symbols icon names (`MaterialSymbolValue`), so you get completion, and typos are type errors.
32
+
33
+ ### Three styles
34
+
35
+ There is one component per Material Symbols style. Apps usually stick to one style, so give it a short name with an import alias.
36
+
37
+ | Component | Font family |
38
+ | ------------------------ | --------------------------- |
39
+ | `MaterialSymbolOutlined` | `Material Symbols Outlined` |
40
+ | `MaterialSymbolRounded` | `Material Symbols Rounded` |
41
+ | `MaterialSymbolSharp` | `Material Symbols Sharp` |
42
+
43
+ ```tsx
44
+ import { MaterialSymbolRounded as Icon } from '@fringeworks/react-icon-material-symbols';
45
+ ```
46
+
47
+ ### Loading the font
48
+
49
+ Loading the font is a separate entry point from the icon styles (`styles.css`). Load the font for the styles you use in one of the following ways. All of them use only the `@font-face`; the classes that come with the font (`.material-symbols-outlined` and so on) are not used.
50
+
51
+ **From this package's entry point**
52
+
53
+ ```ts
54
+ import '@fringeworks/react-icon-material-symbols/font-outlined.css';
55
+ ```
56
+
57
+ | Entry point | Font loaded |
58
+ | ------------------- | --------------------------- |
59
+ | `font-outlined.css` | `Material Symbols Outlined` |
60
+ | `font-rounded.css` | `Material Symbols Rounded` |
61
+ | `font-sharp.css` | `Material Symbols Sharp` |
62
+
63
+ It is an `@import` of the CSS from the npm [`material-symbols`](https://www.npmjs.com/package/material-symbols) package, which is installed along with this package. Your app's bundler (Vite, webpack, Next.js, and so on) picks up the font files from `material-symbols`. The fonts include every icon, 3.5–5.4 MB per style.
64
+
65
+ **From Google Fonts**
66
+
67
+ ```html
68
+ <link
69
+ rel="stylesheet"
70
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-25..200&display=block"
71
+ />
72
+ ```
73
+
74
+ To use the variable font axes, put the axis ranges in the URL (`opsz,wght,FILL,GRAD@20..48,100..700,0..1,-25..200`). Adding `&icon_names=home,search` gives you a font with only the icons you use, which makes the file smaller.
75
+
76
+ **Serving it yourself**
77
+
78
+ When you serve your own font, such as a subset with only the icons you use in a setup that must not access external servers, write the `@font-face` yourself. Use the font family names in the table above.
79
+
80
+ If you do not load this package's entry points, the `material-symbols` fonts do not end up in your app (they are still installed).
81
+
82
+ Use `font-display: block` when you serve it yourself too. Icons are not drawn until the font arrives (up to about 3 seconds), so the icon names are not shown as text (this package's entry points and the Google Fonts URL above use `block`). To show a skeleton meanwhile, see "Showing a skeleton while the font loads" below.
83
+
84
+ ### Size and color
85
+
86
+ Icons are drawn in a `1em` square box and inherit the parent's `font-size` and `color`. In text and buttons they match the size and color of the surrounding text. Unlike the classes that come with Material Symbols, the size is not fixed at 24px; set `font-size` when you want 24px.
87
+
88
+ ```tsx
89
+ <MaterialSymbolOutlined
90
+ value="home"
91
+ style={{ fontSize: 24, color: 'tomato' }}
92
+ />
93
+ ```
94
+
95
+ ### Variable font axes
96
+
97
+ You can change the four Material Symbols axes with props.
98
+
99
+ ```tsx
100
+ <MaterialSymbolOutlined value="favorite" filled />
101
+ <MaterialSymbolOutlined value="settings" weight={300} grade={-25} />
102
+ <MaterialSymbolOutlined value="search" opticalSize={20} />
103
+ ```
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`) |
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.
113
+
114
+ ### Changing on hover
115
+
116
+ With `design`, you can set the value for each axis when the pointer is over the icon (`:hover`).
117
+
118
+ ```tsx
119
+ <MaterialSymbolOutlined
120
+ value="favorite"
121
+ design={{ filled: { hover: 1 }, fontWeight: { hover: 600 } }}
122
+ />
123
+ ```
124
+
125
+ To change it when the pointer is over a parent element such as a button, set the variable with CSS.
126
+
127
+ ```css
128
+ .favorite-button:hover {
129
+ --frg-materialsymbol-filled: 1;
130
+ }
131
+ ```
132
+
133
+ Props such as `filled` write the variable on the element, so they win over values inherited from the parent. Do not set that prop on icons that the parent's CSS changes.
134
+
135
+ To set a design shared across your app, use `withDesign` from [`@fringeworks/react-contract`](https://www.npmjs.com/package/@fringeworks/react-contract). The components have their design definition in the static property `designDefinition`.
136
+
137
+ ```tsx
138
+ import { withDesign } from '@fringeworks/react-contract';
139
+
140
+ const Icon = withDesign(MaterialSymbolOutlined, { filled: { hover: 1 } });
141
+ ```
142
+
143
+ ### Accessibility
144
+
145
+ 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`.
146
+
147
+ ```tsx
148
+ <button type="button">
149
+ <MaterialSymbolOutlined value="search" /> Search {/* decoration */}
150
+ </button>
151
+ <button type="button">
152
+ <MaterialSymbolOutlined value="search" aria-label="Search" /> {/* icon-only button */}
153
+ </button>
154
+ ```
155
+
156
+ ### Showing a skeleton while the font loads
157
+
158
+ The components have the web fonts they need in `webFonts`. You can pass it as is to `useDeferUntilWebFontReady` from [`@fringeworks/react-defer-rendering`](https://www.npmjs.com/package/@fringeworks/react-defer-rendering).
159
+
160
+ ```tsx
161
+ import { useDeferUntilWebFontReady } from '@fringeworks/react-defer-rendering';
162
+
163
+ function Toolbar() {
164
+ const { node } = useDeferUntilWebFontReady(
165
+ <MaterialSymbolOutlined value="home" />,
166
+ MaterialSymbolOutlined.webFonts,
167
+ { pending: <Skeleton /> },
168
+ );
169
+ return node;
170
+ }
171
+ ```
172
+
173
+ ### Using names missing from the type
174
+
175
+ `MaterialSymbolValue` holds the Material Symbols names as of the version of this package. To use names missing from the type, such as newly added icons, create a component with a wider name type with react-icon's `createFontIcon` (it does not have the variable font axis props or `design`).
176
+
177
+ ```tsx
178
+ import { createFontIcon } from '@fringeworks/react-icon';
179
+ import type { MaterialSymbolValue } from '@fringeworks/react-icon-material-symbols';
180
+
181
+ const Icon = createFontIcon<MaterialSymbolValue | 'new_icon'>({
182
+ fontFamily: 'Material Symbols Outlined',
183
+ });
184
+ ```
185
+
186
+ ## API
187
+
188
+ | Component | Description |
189
+ | ------------------------ | -------------------------------- |
190
+ | `MaterialSymbolOutlined` | A Material Symbols Outlined icon |
191
+ | `MaterialSymbolRounded` | A Material Symbols Rounded icon |
192
+ | `MaterialSymbolSharp` | A Material Symbols Sharp icon |
193
+
194
+ ### `MaterialSymbolOutlined`, `MaterialSymbolRounded`, `MaterialSymbolSharp`
195
+
196
+ ```ts
197
+ MaterialSymbolOutlined(props: MaterialSymbolProps): ReactElement
198
+ MaterialSymbolRounded(props: MaterialSymbolProps): ReactElement
199
+ MaterialSymbolSharp(props: MaterialSymbolProps): ReactElement
200
+ ```
201
+
202
+ 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
+
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 |
212
+
213
+ Static properties of the components:
214
+
215
+ | Property | Type | Description |
216
+ | ------------------ | --------------------------------------- | ------------------------------------------------------------------------------------ |
217
+ | `webFonts` | `readonly FontIconWebFont[]` | The web fonts needed to draw (`[{ family: 'Material Symbols Outlined' }]` and so on) |
218
+ | `designDefinition` | `typeof materialSymbolDesignDefinition` | The design definition (read by react-contract's `withDesign`) |
219
+ | `displayName` | `string` | `MaterialSymbolOutlined` and so on |
220
+
221
+ #### Design values
222
+
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.
224
+
225
+ | Key | Default | Description |
226
+ | ------------------ | ------- | -------------------------------------------------------------- |
227
+ | `fontWeight` | `400` | Weight (`wght`) |
228
+ | `fontWeight.hover` | — | Weight on hover |
229
+ | `filled` | `0` | Fill (`FILL`, 0–1; values in between are mid-animation shapes) |
230
+ | `filled.hover` | — | Fill on hover |
231
+ | `grade` | `0` | Grade (`GRAD`) |
232
+ | `grade.hover` | — | Grade on hover |
233
+ | `opticalSize` | — | Optical size (`opsz`). Fixed only when set |
234
+
235
+ `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.
236
+
237
+ When you set `opticalSize` with a CSS variable, also add the `frg-materialsymbol-opticalSize` class to the element. Writing `opsz` in `font-variation-settings` disables the automatic optical size that follows the text size, so `opsz` is written only when this class is present (the component adds it when you set `opticalSize` or `design.opticalSize`).
238
+
239
+ ### CSS entry points
240
+
241
+ | Entry point | Description |
242
+ | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
243
+ | `styles.css` | The icon styles (including react-icon's box CSS). Does not include the fonts |
244
+ | `font-outlined.css`, `font-rounded.css`, `font-sharp.css` | Loads the font for each style (the `@font-face` from the npm `material-symbols` package). Do not load them when you use Google Fonts or serve the font yourself |
245
+
246
+ ### CSS classes
247
+
248
+ | Class | Description |
249
+ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
250
+ | `frg-icon`, `frg-fonticon` | react-icon classes (the `1em` square box and the icon font settings) |
251
+ | `frg-materialsymbol` | Every Material Symbols icon. Builds the variable font axes from CSS variables |
252
+ | `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
+ | `frg-materialsymbol-opticalSize` | Added when the optical size is fixed |
254
+
255
+ The class rules have zero specificity (`:where()`), so your own CSS overrides them as is.
256
+
257
+ ### Constants
258
+
259
+ | Constant | Description |
260
+ | -------------------------------- | ------------------------------------------------------ |
261
+ | `materialSymbolDesignDefinition` | The components' design definition (`designDefinition`) |
262
+
263
+ ### Types
264
+
265
+ | Type | Description |
266
+ | ------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
267
+ | `MaterialSymbolValue` | The Material Symbols icon names (copied from the npm `material-symbols` package) |
268
+ | `MaterialSymbolProps` | The components' props |
269
+ | `MaterialSymbolDesign` | The components' `design` value |
270
+ | `MaterialSymbolComponent` | The component type (including static properties) |
271
+ | `FontIconWebFont` | An element of `webFonts` (a type from `@fringeworks/react-icon`) |
272
+ | `DesignDefinition` | A component's design definition (the type of `materialSymbolDesignDefinition`) (a type from `@fringeworks/react-contract`) |
273
+ | `DesignPartDefinition` | The properties a root or part accepts and the states they apply in (a type from `@fringeworks/react-contract`) |
274
+ | `DesignPropertyValues` | Design property names and their value types (a type from `@fringeworks/react-contract`) |
275
+ | `DesignState` | The states design values are split by (a type from `@fringeworks/react-contract`) |
276
+ | `DesignValue<T, S>` | A single value, or an object per state (a type from `@fringeworks/react-contract`) |
277
+
278
+ ## License
279
+
280
+ MIT
281
+
282
+ The icon name type (`MaterialSymbolValue`) is copied from the npm [`material-symbols`](https://github.com/marella/material-symbols) package. Material Symbols is by Google; both are distributed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
@@ -0,0 +1,59 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_constants = require("../constants.cjs");
3
+ let _fringeworks_react_contract = require("@fringeworks/react-contract");
4
+ let _fringeworks_react_icon = require("@fringeworks/react-icon");
5
+ let _fringeworks_react_merge = require("@fringeworks/react-merge");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+
8
+ // src/_internal/_createMaterialSymbol.tsx
9
+ const PREFIX = "frg-materialsymbol";
10
+ /**
11
+ * 軸のプロパティを、design と同じ CSS 変数(状態なしの値)にする
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;
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
+ function createMaterialSymbol(variant) {
30
+ const fontFamily = `Material Symbols ${variant}`;
31
+ const definition = { fontFamily };
32
+ function MaterialSymbol({ weight, filled, grade, opticalSize, design, ...props }) {
33
+ const fixesOpticalSize = opticalSize !== void 0 || design?.opticalSize !== void 0;
34
+ const ownProps = {
35
+ className: [
36
+ PREFIX,
37
+ `${PREFIX}${variant.toLowerCase()}`,
38
+ fixesOpticalSize && `${PREFIX}-opticalSize`
39
+ ],
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
+ }
49
+ };
50
+ const merged = (0, _fringeworks_react_merge.mergeProps)(ownProps, props);
51
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { ...(0, _fringeworks_react_icon.createFontIconProps)(definition, merged) });
52
+ }
53
+ MaterialSymbol.displayName = `MaterialSymbol${variant}`;
54
+ MaterialSymbol.webFonts = [{ family: fontFamily }];
55
+ MaterialSymbol.designDefinition = require_constants.materialSymbolDesignDefinition;
56
+ return MaterialSymbol;
57
+ }
58
+
59
+ exports.default = createMaterialSymbol;
@@ -0,0 +1,14 @@
1
+ import { MaterialSymbolComponent } from "../types.cjs";
2
+ /**
3
+ * Material Symbols の種類(フォントファミリーの名前の後ろの部分)
4
+ */
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
+ export default function createMaterialSymbol(variant: MaterialSymbolVariant): MaterialSymbolComponent;
@@ -0,0 +1,14 @@
1
+ import { MaterialSymbolComponent } from "../types.mjs";
2
+ /**
3
+ * Material Symbols の種類(フォントファミリーの名前の後ろの部分)
4
+ */
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
+ export default function createMaterialSymbol(variant: MaterialSymbolVariant): MaterialSymbolComponent;
@@ -0,0 +1,58 @@
1
+ import { materialSymbolDesignDefinition } from "../constants.mjs";
2
+ import { createDesignStyle } from "@fringeworks/react-contract";
3
+ import { createFontIconProps } from "@fringeworks/react-icon";
4
+ import { mergeProps } from "@fringeworks/react-merge";
5
+ import { jsx } from "react/jsx-runtime";
6
+
7
+ // src/_internal/_createMaterialSymbol.tsx
8
+ const PREFIX = "frg-materialsymbol";
9
+ /**
10
+ * 軸のプロパティを、design と同じ CSS 変数(状態なしの値)にする
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;
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
+ function createMaterialSymbol(variant) {
29
+ const fontFamily = `Material Symbols ${variant}`;
30
+ const definition = { fontFamily };
31
+ function MaterialSymbol({ weight, filled, grade, opticalSize, design, ...props }) {
32
+ const fixesOpticalSize = opticalSize !== void 0 || design?.opticalSize !== void 0;
33
+ const ownProps = {
34
+ className: [
35
+ PREFIX,
36
+ `${PREFIX}${variant.toLowerCase()}`,
37
+ fixesOpticalSize && `${PREFIX}-opticalSize`
38
+ ],
39
+ style: {
40
+ ...createDesignStyle(PREFIX, materialSymbolDesignDefinition, design),
41
+ ...createAxisStyle({
42
+ weight,
43
+ filled,
44
+ grade,
45
+ opticalSize
46
+ })
47
+ }
48
+ };
49
+ const merged = mergeProps(ownProps, props);
50
+ return /* @__PURE__ */ jsx("span", { ...createFontIconProps(definition, merged) });
51
+ }
52
+ MaterialSymbol.displayName = `MaterialSymbol${variant}`;
53
+ MaterialSymbol.webFonts = [{ family: fontFamily }];
54
+ MaterialSymbol.designDefinition = materialSymbolDesignDefinition;
55
+ return MaterialSymbol;
56
+ }
57
+
58
+ export { createMaterialSymbol as default };
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });