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

#HT-224: Icon node component #126

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 99 additions & 0 deletions packages/console/src/nodes/Icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import type { ReactElement } from "react";

import { FormGroup, Icon as MuiIcon } from "@mui/material";

import { useNode } from "@craftjs/core";

import PropertiesForm from "../screens/app-builder/panels/properties-editor/PropertiesForm";
import type { CraftComponent, IconColor, IconFontSize } from "../types";

interface Props {
color?: IconColor;
fontSize?: IconFontSize | string;
}

export const Icon: CraftComponent<Props> = (props: Props): ReactElement => {
const { color, fontSize } = props;

const {
connectors: { connect, drag },
} = useNode();

return (
<div ref={(ref) => connect(drag(ref as any))}>
<div ref={(ref) => connect(drag(ref as any))}>
<FormGroup>
<MuiIcon color={color} fontSize={fontSize as any} />
</FormGroup>
</div>
</div>
);
};

const defaultProps: Props = {
color: "inherit",
fontSize: "24px",
};

Icon.craft = {
props: defaultProps,
related: {
settings: () => (
<PropertiesForm
groups={[
{
title: "General",
fields: [
{
id: "fontSize",
size: "small",
help: " The size of the icon",
type: "select",
required: true,
title: "Font Size",
options: [
{
value: "inherit",
title: "determinate",
},
{
value: "large",
title: "large",
},
{
value: "medium",
title: "medium",
},
{
value: "small",
title: "small",
},
],
},
{
id: "color",
size: "small",
help: " The color of the Icon button.",
type: "select",
required: true,
title: "Color",
options: [
{ value: "inherit", title: "Inherit" },
{ value: "action", title: "Action" },
{ value: "disabled", title: "Disabled" },
{ value: "primary", title: "Primary" },
{ value: "secondary", title: "Secondary" },
{ value: "success", title: "Success" },
{ value: "error", title: "Error" },
{ value: "info", title: "Info" },
{ value: "warning", title: "Warning" },
],
},
],
},
]}
validationSchema={undefined}
/>
),
},
};
3 changes: 3 additions & 0 deletions packages/console/src/nodes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Card, CardBottom, CardTop } from "./Card";
import { Checkbox } from "./Checkbox";
import { Container } from "./Container";
import FlexLayout from "./FlexLayout";
import { Icon } from "./Icon";
import { Select } from "./Select";
import { Text } from "./Text";

Expand All @@ -16,6 +17,7 @@ export const nodeMappings = {
FlexLayout,
Select,
Checkbox,
Icon,
};

export * from "./Text";
Expand All @@ -25,3 +27,4 @@ export * from "./Card";
export { FlexLayout };
export * from "./Select";
export * from "./Checkbox";
export * from "./Icon";
10 changes: 10 additions & 0 deletions packages/console/src/screens/app-builder/navigation/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { styled } from "@mui/material/styles";
import {
AddBoxOutlined,
AddBoxTwoTone,
Apps,
ArrowDropDownCircle,
FormatShapes,
TextFields,
Expand All @@ -17,6 +18,7 @@ import {
Card,
Checkbox,
FlexLayout,
Icon,
Select,
Text,
} from "../../../nodes";
Expand Down Expand Up @@ -97,6 +99,14 @@ const Components = () => {
Select
</ItemButton>
</Grid>
<Grid item={true} xs={6}>
<ItemButton
ref={(ref) => connectors.create(ref as any, <Icon />)}
variant="contained">
<Apps fontSize="large" />
Icon
</ItemButton>
</Grid>
</ContianerGrid>
);
};
Expand Down
4 changes: 4 additions & 0 deletions packages/console/src/types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ export interface IBuilderActionsContext {
activeTab: string | null;
setActiveTab: (activeTab: string) => void;
}

export type IconColor = Color | "action" | "disabled";

export type IconFontSize = "inherit" | "large" | "medium" | "small";