Skip to content

Commit

Permalink
Fix icons in tooltips (#1663)
Browse files Browse the repository at this point in the history
It wasn't possible to use Comet icons as children of tooltips. This was
due to missing ref-forwarding.
  • Loading branch information
johnnyomair authored Feb 8, 2024
1 parent 8e20c88 commit 08e0da0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-actors-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/admin-icons": patch
---

Fix icons inside tooltips by forwarding the ref
6 changes: 3 additions & 3 deletions packages/admin/admin-icons/generate-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ const writeComponent = async (icon: Icon, pathData: string) => {
*/`
: ""
};
export function ${icon.componentName}(props: SvgIconProps): JSX.Element {
export const ${icon.componentName} = React.forwardRef<SVGSVGElement, SvgIconProps>((props, ref) => {
return (
<SvgIcon {...props} viewBox="0 0 16 16">
<SvgIcon {...props} ref={ref} viewBox="0 0 16 16">
<path d="${pathData}" />
</SvgIcon>
);
}
});
`);

if (icon.componentName != null && component != null) {
Expand Down
14 changes: 14 additions & 0 deletions packages/admin/admin-stories/src/admin/tooltip/IconWithTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Tooltip } from "@comet/admin";
import { Add } from "@comet/admin-icons";
import { storiesOf } from "@storybook/react";
import * as React from "react";

storiesOf("@comet/admin", module).add("Icon with Tooltip", () => {
return (
<>
<Tooltip title="Add something">
<Add />
</Tooltip>
</>
);
});
4 changes: 3 additions & 1 deletion packages/admin/cms-admin/src/contentScope/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import ContentScopeSelect from "./Select";
export type ContentScopeControlsConfig<S extends ContentScopeInterface = ContentScopeInterface> = {
[P in keyof S]?: {
label?: string;
icon?: (props: SvgIconProps) => JSX.Element;
icon?:
| React.ComponentType<SvgIconProps>
| React.ForwardRefExoticComponent<React.PropsWithoutRef<SvgIconProps> & React.RefAttributes<SVGSVGElement>>;
searchable?: boolean;
};
};
Expand Down
4 changes: 3 additions & 1 deletion packages/admin/cms-admin/src/contentScope/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export interface ContentScopeSelectProps {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onChange: (newValue: any) => void;
defaultLabel?: string;
icon?: (p: SvgIconProps) => JSX.Element;
icon?:
| React.ComponentType<SvgIconProps>
| React.ForwardRefExoticComponent<React.PropsWithoutRef<SvgIconProps> & React.RefAttributes<SVGSVGElement>>;
disabled?: boolean;
searchable?: boolean;
}
Expand Down

0 comments on commit 08e0da0

Please sign in to comment.