@noya-app/noya-designsystem 0.1.23 → 0.1.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noya-app/noya-designsystem",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -3,6 +3,7 @@ import { useKeyboardShortcuts } from "@noya-app/noya-keymap";
3
3
  import * as RadixContextMenu from "@radix-ui/react-context-menu";
4
4
  import React, { ReactNode, memo, useCallback, useMemo } from "react";
5
5
  import styled from "styled-components";
6
+ import { renderIcon } from "./Icons";
6
7
  import { Spacer } from "./Spacer";
7
8
  import {
8
9
  CHECKBOX_RIGHT_INSET,
@@ -98,7 +99,7 @@ const ContextMenuItem = memo(function ContextMenuItem<T extends string>({
98
99
  )}
99
100
  {icon && (
100
101
  <>
101
- {icon}
102
+ {renderIcon(icon)}
102
103
  <Spacer.Horizontal size={8} />
103
104
  </>
104
105
  )}
@@ -12,6 +12,7 @@ import React, {
12
12
  } from "react";
13
13
  import styled from "styled-components";
14
14
  import { MenuItemProps, MenuProps } from "./ContextMenu";
15
+ import { renderIcon } from "./Icons";
15
16
  import { Spacer } from "./Spacer";
16
17
  import {
17
18
  CHECKBOX_RIGHT_INSET,
@@ -73,7 +74,7 @@ const DropdownMenuItem = memo(function ContextMenuItem<T extends string>({
73
74
  </StyledItemIndicator>
74
75
  {icon && (
75
76
  <>
76
- {icon}
77
+ {renderIcon(icon)}
77
78
  <Spacer.Horizontal size={8} />
78
79
  </>
79
80
  )}
@@ -89,7 +90,7 @@ const DropdownMenuItem = memo(function ContextMenuItem<T extends string>({
89
90
  )}
90
91
  {icon && (
91
92
  <>
92
- {icon}
93
+ {renderIcon(icon)}
93
94
  <Spacer.Horizontal size={8} />
94
95
  </>
95
96
  )}
@@ -1,4 +1,3 @@
1
- import * as Icons from "@noya-app/noya-icons";
2
1
  import React, {
3
2
  CSSProperties,
4
3
  ForwardedRef,
@@ -8,9 +7,10 @@ import React, {
8
7
  } from "react";
9
8
  import { useTheme } from "styled-components";
10
9
  import { Button, ButtonRootProps } from "./Button";
10
+ import { IconName, Icons } from "./Icons";
11
11
 
12
12
  type Props = Omit<ButtonRootProps, "children" | "variant" | "flex" | "size"> & {
13
- iconName: keyof typeof Icons;
13
+ iconName: IconName;
14
14
  className?: string;
15
15
  style?: CSSProperties;
16
16
  selected?: boolean;
@@ -0,0 +1,18 @@
1
+ import * as Icons from "@noya-app/noya-icons";
2
+ import React, { ReactNode } from "react";
3
+
4
+ export type IconName = keyof typeof Icons;
5
+
6
+ export { Icons };
7
+
8
+ export function renderIcon(
9
+ iconName: Exclude<ReactNode, string> | IconName
10
+ ): ReactNode {
11
+ if (typeof iconName === "string") {
12
+ const Icon = Icons[iconName as IconName];
13
+
14
+ return <Icon />;
15
+ }
16
+
17
+ return iconName;
18
+ }
@@ -3,6 +3,7 @@ import * as Select from "@radix-ui/react-select";
3
3
  import React, { memo } from "react";
4
4
  import { styled } from "styled-components";
5
5
  import { Button } from "./Button";
6
+ import { renderIcon } from "./Icons";
6
7
  import { Spacer } from "./Spacer";
7
8
  import { MenuItem, RegularMenuItem, styles } from "./internal/Menu";
8
9
 
@@ -37,7 +38,7 @@ export const SelectMenu = memo(function SelectMenu<T extends string = string>({
37
38
  <Button id={id} style={style} className={className}>
38
39
  {icon && (
39
40
  <>
40
- {icon}
41
+ {renderIcon(icon)}
41
42
  <Spacer.Horizontal size={8} />
42
43
  </>
43
44
  )}
@@ -86,7 +87,7 @@ const SelectItem = React.forwardRef(
86
87
  <StyledItem {...props} ref={forwardedRef}>
87
88
  {icon && (
88
89
  <>
89
- {icon}
90
+ {renderIcon(icon)}
90
91
  <Spacer.Horizontal size={8} />
91
92
  </>
92
93
  )}
@@ -7,6 +7,7 @@ import React, {
7
7
  useContext,
8
8
  } from "react";
9
9
  import { IconButton } from "./IconButton";
10
+ import { IconName, renderIcon } from "./Icons";
10
11
  import { ListView } from "./ListView";
11
12
  import { Spacer } from "./Spacer";
12
13
 
@@ -15,7 +16,7 @@ import { Spacer } from "./Spacer";
15
16
  * ------------------------------------------------------------------------- */
16
17
 
17
18
  type TreeRowBaseProps = {
18
- icon?: ReactNode;
19
+ icon?: Exclude<ReactNode, string> | IconName;
19
20
  expanded?: boolean;
20
21
  onClickChevron?: ({ altKey }: { altKey: boolean }) => void;
21
22
  };
@@ -61,7 +62,7 @@ const TreeRow = forwardRef(function TreeRow<MenuItemType extends string>(
61
62
  )}
62
63
  {icon && (
63
64
  <>
64
- {icon}
65
+ {renderIcon(icon)}
65
66
  <Spacer.Horizontal size={10} />
66
67
  </>
67
68
  )}
@@ -4,6 +4,7 @@ import styled, { CSSObject } from "styled-components";
4
4
  import { useDesignSystemConfiguration } from "../../contexts/DesignSystemConfiguration";
5
5
  import { Theme } from "../../theme";
6
6
  import withSeparatorElements from "../../utils/withSeparatorElements";
7
+ import { IconName } from "../Icons";
7
8
 
8
9
  export const SEPARATOR_ITEM = "separator";
9
10
 
@@ -63,7 +64,7 @@ export type RegularMenuItem<T extends string> = {
63
64
  shortcut?: string;
64
65
  checked?: boolean;
65
66
  disabled?: boolean;
66
- icon?: ReactNode;
67
+ icon?: Exclude<ReactNode, string> | IconName;
67
68
  items?: MenuItem<T>[];
68
69
  role?: MenuItemRole;
69
70
  };