Skip to content

Commit d8610c0

Browse files
committed
feat(menu): font-icon usage notes
1 parent 67bd990 commit d8610c0

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

content/plugins/menu.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ registerElement('menuimage', MenuImage);
102102
```typescript
103103
import { MenuAction } from '@nstudio/nativescript-menu';
104104

105+
const parseHexFontIcon = (hexCode: string) =>
106+
String.fromCharCode(parseInt(hexCode, 16));
107+
105108
const addOptions: MenuAction[] = [
106109
{
107110
id: 1,
@@ -133,6 +136,17 @@ const addOptions: MenuAction[] = [
133136
{ id: 41, name: 'Add Protocol', icon: 'plus' },
134137
],
135138
},
139+
{
140+
id: 45,
141+
name: 'Create Customer',
142+
subtitle: 'Create a new customer record',
143+
icon: {
144+
fontFamily: 'Font Awesome 7 Free-Solid-900.otf',
145+
text: parseHexFontIcon('f234'),
146+
fontWeight: 900,
147+
color: '#212121',
148+
},
149+
},
136150
{
137151
id: 5,
138152
name: '',
@@ -146,6 +160,35 @@ const addOptions: MenuAction[] = [
146160
];
147161
```
148162

163+
## Font Icons
164+
165+
Font icons are supported through `MenuAction.icon` using the `FontIcon` object shape.
166+
167+
```typescript
168+
type FontIcon = {
169+
fontFamily: string;
170+
text: string;
171+
fontWeight?: number;
172+
color?: string | Color;
173+
};
174+
```
175+
176+
- `fontFamily`: the font filename available in your app `fonts` directory (for example `remixicon.ttf`)
177+
- `text`: the actual glyph character (commonly produced from a hex code)
178+
- `fontWeight`: optional numeric weight (for example `900` for Font Awesome solid)
179+
- `color`: optional icon tint color
180+
181+
Font folder location by NativeScript flavor:
182+
183+
- Angular: `src/app/fonts`
184+
- React: `src/fonts`
185+
- Solid: `src/fonts`
186+
- Svelte: `app/fonts`
187+
- Vue: `app/fonts`
188+
- Core (JS/TS): `app/fonts`
189+
190+
If both `iconColor` (on `MenuAction`) and `icon.color` are provided, use `icon.color` for font icons.
191+
149192
## Events
150193

151194
### selected
@@ -172,6 +215,13 @@ Registered at the View level, so they can be used on MenuButton, MenuImage, or o
172215
| contextMenu | Array<MenuAction> \| MenuAction | Long-press menu configuration |
173216
| androidBackgroundOpacity | number | Android-only background opacity for the glass menu (`0..1`) |
174217

218+
`MenuAction.icon` supports:
219+
220+
- system symbol string (for example `'square.and.pencil'`)
221+
- `{ systemIcon, color? }`
222+
- `{ src, color? }`
223+
- `{ fontFamily, text, fontWeight?, color? }` (font icon)
224+
175225
## Classes
176226

177227
- MenuButton extends NativeScript Button

0 commit comments

Comments
 (0)