Skip to content

Commit

Permalink
♻️ refactor(icons): move to system icons
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Jan 16, 2024
1 parent 89f3120 commit 188b143
Show file tree
Hide file tree
Showing 98 changed files with 469 additions and 407 deletions.
4 changes: 2 additions & 2 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"src/**/*.{json,ts,tsx}": [
"node ./scripts/ci",
"npm run lint:fix"
"npm run lint:fix",
"node ./scripts/ci"
]
}
4 changes: 1 addition & 3 deletions scripts/ci/check-file-segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ for (const fileName of files) {
if (errors.length > 0) {
console.error(`${errors.length} files not placed in the correct folders`);

errors.forEach((error) => {
console.error(error);
});
console.error(errors.join(","));

process.exit(1);
}
18 changes: 11 additions & 7 deletions src/frontend/_layouts/app/LayoutImpl/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SYSTEM_COLORS } from "frontend/design-system/theme/system";
import { Typo } from "frontend/design-system/primitives/Typo";
import { ILabelValue } from "shared/types/options";
import { DropDownMenu } from "frontend/design-system/components/DropdownMenu";
import { SystemIconsKeys } from "shared/constants/Icons";
import { useConstantNavigationMenuItems } from "./portal";

const ProfileRoot = styled(Stack)`
Expand All @@ -25,12 +26,14 @@ interface IProps {
isFullWidth: boolean;
}

const constantNavigation: ILabelValue[] = [
{
label: "My Account",
value: NAVIGATION_LINKS.ACCOUNT.PROFILE,
},
];
const constantNavigation: Array<ILabelValue & { systemIcon: SystemIconsKeys }> =
[
{
label: "My Account",
systemIcon: "User",
value: NAVIGATION_LINKS.ACCOUNT.PROFILE,
},
];

export function ProfileOnNavigation({ isFullWidth }: IProps) {
const currentUser = useAuthenticatedUserBag();
Expand All @@ -53,9 +56,10 @@ export function ProfileOnNavigation({ isFullWidth }: IProps) {
ellipsis
ariaLabel="Toggle Profile Menu"
menuItems={[...constantNavigation, ...constantNavigationMenuItems].map(
({ label, value }) => ({
({ label, value, systemIcon }) => ({
id: label,
label,
systemIcon,
onClick: () => router.push(value),
})
)}
Expand Down
27 changes: 6 additions & 21 deletions src/frontend/_layouts/app/LayoutImpl/RenderNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
SystemLinks,
} from "shared/types/menu";
import { NAVIGATION_LINKS } from "frontend/lib/routing/links";
import { systemIconToSVG } from "shared/constants/Icons";
import { ChevronRight } from "react-feather";
import { SYSTEM_COLORS } from "frontend/design-system/theme/system";
import { Typo } from "frontend/design-system/primitives/Typo";
Expand All @@ -16,6 +15,7 @@ import { Stack } from "frontend/design-system/primitives/Stack";
import { useThemeColorShade } from "frontend/design-system/theme/useTheme";
import { useNavigationStack } from "frontend/lib/routing/useNavigationStack";
import { ActionIntegrations } from "shared/types/actions";
import { SystemIcon } from "frontend/design-system/Icons/System";
import { PORTAL_SYSTEM_LINK_CONFIG_LINKS } from "./portal";

const SYSTEM_LINKS_CONFIG_MAP: Record<
Expand Down Expand Up @@ -71,24 +71,14 @@ const LeftSideNavMenuListAnchor = styled.a<{
}
`;

const IconRoot = styled.span<{ $isFullWidth: boolean }>`
color: ${SYSTEM_COLORS.white};
width: 20px;
height: 20px;
display: inline-block;
svg {
vertical-align: initial;
}
`;

const LeftSideNavMenu = styled.ul<{}>`
padding: 0;
margin-bottom: 0;
`;

const NavLabel = styled(Typo.XS)<{ $isFullWidth: boolean }>`
color: ${SYSTEM_COLORS.white};
margin-left: 20px;
margin-left: 8px;
transition: all 0.3s;
${(props) =>
!props.$isFullWidth &&
Expand Down Expand Up @@ -173,13 +163,8 @@ export function RenderNavigation({
{navigation.map(({ title, icon, type, link, id, children }) => {
const isActive = activeItem[depth] === id;

const iconComponent = (
<IconRoot
$isFullWidth={isFullWidth}
dangerouslySetInnerHTML={{
__html: systemIconToSVG(icon, isActive ? 2 : 1),
}}
/>
const menuIcon = depth === 1 && (
<SystemIcon strokeWidth={isActive ? 2 : 1} icon={icon} size={20} />
);

return (
Expand All @@ -200,7 +185,7 @@ export function RenderNavigation({
setActiveItem(depth, isActive ? "" : id);
}}
>
{iconComponent}
{menuIcon}
{isFullWidth && (
<Stack justify="space-between" spacing={0} align="center">
<NavLabel ellipsis $isFullWidth={isFullWidth}>
Expand Down Expand Up @@ -241,7 +226,7 @@ export function RenderNavigation({
}
hoverColor={getBackgroundColor("primary-color", 45)}
>
{icon && iconComponent}
{icon && menuIcon}
<NavLabel ellipsis $isFullWidth={isFullWidth}>
{title}
</NavLabel>
Expand Down
7 changes: 6 additions & 1 deletion src/frontend/_layouts/app/LayoutImpl/portal/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { NAVIGATION_LINKS } from "frontend/lib/routing/links";
import { SystemIconsKeys } from "shared/constants/Icons";
import { PortalSystemLinks } from "shared/constants/portal/menu/main";
import { ILabelValue } from "shared/types/options";

export const useConstantNavigationMenuItems = () => {
export const useConstantNavigationMenuItems = (): Array<
ILabelValue & { systemIcon: SystemIconsKeys }
> => {
return [
{
label: "Menu Settings",
value: NAVIGATION_LINKS.SETTINGS.MENU,
systemIcon: "List",
},
];
};
Expand Down
20 changes: 13 additions & 7 deletions src/frontend/_layouts/app/constant.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
import { GitHub, Globe, Twitter, Users } from "react-feather";
import { SystemIconsKeys } from "shared/constants/Icons";

export const DEMO_LINKS = [
export const DEMO_LINKS: {
id: string;
systemIcon: SystemIconsKeys;
label: string;
description: string;
link: string;
}[] = [
{
id: "github",
IconComponent: GitHub,
systemIcon: "Github",
label: "Star us on Github",
description: `Tell us DashPress is a useful project by dropping us a star`,
link: "https://github.com/dashpresshq/dashpress",
},
{
id: "twitter",
IconComponent: Twitter,
systemIcon: "Twitter",
label: "Follow us on Twitter",
description: `Tweet at @dashpressHQ if you know others will benefit using DashPress`,
link: "https://twitter.com/dashpressHQ",
},
{
id: "users",
IconComponent: Users,
id: "discord",
systemIcon: "Discord",
label: "Join our Discord community",
description: `Ask your questions here`,
link: "https://discord.gg/aV6DxwXhzN",
},
{
id: "website",
IconComponent: Globe,
systemIcon: "Link",
label: "Visit our website",
description: `For more links on documentation, roadmap, blog etc`,
link: "https://dashpress.io",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function TestComponent({

<FormButton
text={() => "Save"}
icon="add"
systemIcon="Plus"
isMakingRequest={false}
disabled={pristine}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/components/IconInputField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function IconInputField({ value }: { value: string }) {
input={input}
rightActions={[
{
systemIcon: "ToggleLeft",
label: "Use SVG",
action: () => input.onChange(""),
},
Expand All @@ -36,6 +37,7 @@ export function IconInputField({ value }: { value: string }) {
input={input}
rightActions={[
{
systemIcon: "ToggleRight",
label: "Use Icon",
action: () => input.onChange(SystemIconsList[0]),
},
Expand Down
30 changes: 15 additions & 15 deletions src/frontend/components/SchemaForm/SchemaForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={BASE_FIELDS}
/>
</ApplicationRoot>
Expand All @@ -90,7 +90,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={BASE_FIELDS}
resetForm
/>
Expand All @@ -114,7 +114,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={BASE_FIELDS}
formExtension={{
beforeSubmit: "",
Expand All @@ -140,7 +140,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={BASE_FIELDS}
action="custom-action"
formExtension={{
Expand Down Expand Up @@ -169,7 +169,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={BASE_FIELDS}
formExtension={{
beforeSubmit: "sm ks ks dsldm sl dm",
Expand All @@ -195,7 +195,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={BASE_FIELDS}
action="custom-action"
formExtension={{
Expand Down Expand Up @@ -223,7 +223,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={BASE_FIELDS}
action="edit"
initialValues={{
Expand Down Expand Up @@ -259,7 +259,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={{
...BASE_FIELDS,
}}
Expand Down Expand Up @@ -290,7 +290,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={{
...BASE_FIELDS,
}}
Expand Down Expand Up @@ -321,7 +321,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={{
...BASE_FIELDS,
}}
Expand Down Expand Up @@ -353,7 +353,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<IAccount>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={{
...BASE_FIELDS,
}}
Expand Down Expand Up @@ -395,7 +395,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<{ name: string }>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={{
name: {
type: "text",
Expand Down Expand Up @@ -424,7 +424,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<{ hello: string }>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={{
...BASE_FIELDS,
hello: {
Expand All @@ -447,7 +447,7 @@ describe("<SchemaForm />", () => {
<SchemaForm<{ name: string }>
onSubmit={mockOnSubmit}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={{
name: {
type: "text",
Expand All @@ -473,7 +473,7 @@ describe("<SchemaForm />", () => {
onSubmit={jest.fn()}
onChange={onChangeMock}
buttonText={buttonText}
icon="save"
systemIcon="Save"
fields={{
...BASE_FIELDS,
}}
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/components/SchemaForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { ToastService } from "frontend/lib/toast";
import { resetFormValues } from "frontend/lib/form/utils";
import { FormButton } from "frontend/design-system/components/Button/FormButton";
import { userFriendlyCase } from "shared/lib/strings/friendly-case";
import { ButtonIconTypes } from "frontend/design-system/components/Button/constants";
import styled from "styled-components";
import { gridItem, gridRoot } from "frontend/design-system/constants/grid";
import { GridSpanSizes } from "shared/types/ui";
import { SystemIconsKeys } from "shared/constants/Icons";
import { RenderFormInput } from "./_RenderFormInput";
import { IFormExtension } from "./types";
import { runFormBeforeSubmit, runFormFieldState } from "./form-run";
Expand All @@ -23,7 +23,7 @@ interface IProps<T> {
initialValues?: Partial<T>;
buttonText?: (submitting: boolean) => string;
action?: string;
icon: ButtonIconTypes | "no-icon";
systemIcon: SystemIconsKeys;
onChange?: (data: T) => void;
resetForm?: true;
formExtension?: Partial<IFormExtension>;
Expand All @@ -46,7 +46,7 @@ export function SchemaForm<T extends Record<string, unknown>>({
onChange,
buttonText,
initialValues,
icon,
systemIcon,
action,
formExtension,
resetForm,
Expand Down Expand Up @@ -138,7 +138,7 @@ export function SchemaForm<T extends Record<string, unknown>>({
text={buttonText}
isMakingRequest={submitting}
disabled={pristine}
icon={icon === "no-icon" ? undefined : icon}
systemIcon={systemIcon}
/>
)}
</form>
Expand Down
Loading

0 comments on commit 188b143

Please sign in to comment.