Skip to content

Commit

Permalink
Feat: export icon path data for direct usage in non-Svelte UIs (viamr…
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Jan 15, 2025
1 parent e33fc63 commit 2f56612
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/prime-core",
"version": "0.0.173",
"version": "0.0.174",
"repository": {
"type": "git",
"url": "https://github.com/viamrobotics/prime.git",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/icon/icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const sizes: Record<Size, string> = {

<script lang="ts">
import cx from 'classnames';
import { paths, type IconName, type CustomIcon } from './icons';
import { IconPathsByName, type IconName, type CustomIcon } from './icons';
/** The name of the icon. */
export let name: IconName;
Expand All @@ -45,7 +45,7 @@ export { extraClasses as cx };
let allPaths: CustomIcon[] = [];
$: {
const pathValue = paths[name];
const pathValue = IconPathsByName[name];
if (typeof pathValue === 'string') {
allPaths = [{ path: pathValue }];
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/lib/icon/icons.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as MDI from '@mdi/js';

type Path = string;
export type SimpleIconPath = string;

export interface CustomIcon {
path: string;
opacity?: number | undefined;
}

export type IconPath = Path | CustomIcon[];
export type IconPath = SimpleIconPath | CustomIcon[];

/**
* Keys should match MDI name
* e.g. 'account-multiple' for MDI.mdiAccountMultiple
*/
export const paths = {
export const IconPathsByName = {
'account-group-outline': MDI.mdiAccountGroupOutline,
'account-multiple': MDI.mdiAccountMultiple,
'alert-circle-outline': MDI.mdiAlertCircleOutline,
Expand Down Expand Up @@ -179,9 +179,9 @@ export const paths = {
'view-dashboard-outline': MDI.mdiViewDashboardOutline,
webhook: MDI.mdiWebhook,
windows: MDI.mdiMicrosoftWindows,
} as const;
} satisfies Record<string, IconPath>;

/**
* The possible icon names that can be rendered. This is good for typing props.
*/
export type IconName = keyof typeof paths;
export type IconName = keyof typeof IconPathsByName;
8 changes: 7 additions & 1 deletion packages/core/src/lib/icon/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
export { default as Icon } from './icon.svelte';
export type { IconName } from './icons';
export {
IconPathsByName,
type IconName,
type IconPath,
type SimpleIconPath,
type CustomIcon,
} from './icons';

0 comments on commit 2f56612

Please sign in to comment.