Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix icons in tooltips #1663

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading