Skip to content

Commit

Permalink
Reduce bundle size fortawesome (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
domschab23 authored Sep 26, 2024
1 parent 66e766c commit 969de45
Show file tree
Hide file tree
Showing 34 changed files with 209 additions and 38 deletions.
18 changes: 17 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@
"ts": "never",
"tsx": "never"
}
]
],
"no-restricted-imports": ["error", {
"patterns": [
{
"group": ["@fortawesome/free-brands-svg-icons/*", "@fortawesome/free-brands-svg-icons"],
"message": "Direct imports from @fortawesome/free-brands-svg-icons is not allowed. Import from src/ib/font_awesome/brands instead."
},
{
"group": ["@fortawesome/pro-regular-svg-icons/*", "@fortawesome/pro-regular-svg-icons"],
"message": "Direct imports from @fortawesome/pro-regular-svg-icons is not allowed. Import from src/lib/font_awesome/regular instead."
},
{
"group": ["@fortawesome/pro-solid-svg-icons/*", "@fortawesome/pro-solid-svg-icons"],
"message": "Direct imports from @fortawesome/pro-solid-svg-icons is not allowed. Import from src/lib/font_awesome/solid instead."
}
]
}]
}
}
2 changes: 1 addition & 1 deletion src/Accordion/Accordion.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { faCreditCard } from '@fortawesome/pro-regular-svg-icons';
import { faCreditCard } from '../font_awesome/regular';
import Card from '../Card';

import {
Expand Down
3 changes: 2 additions & 1 deletion src/Accordion/AccordionToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { useAccordionButton } from 'react-bootstrap/AccordionButton';
import AccordionContext from 'react-bootstrap/AccordionContext';

import { faChevronUp } from '../font_awesome/solid';

import './AccordionToggle.scss';
import { faChevronUp } from '@fortawesome/pro-solid-svg-icons';

import { isEventKeyActive } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion src/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
faExclamationTriangle,
faInfo,
faTimes,
} from '@fortawesome/pro-solid-svg-icons';
} from '../font_awesome/solid';

import './Alert.scss';

Expand Down
4 changes: 2 additions & 2 deletions src/Button/Button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import * as ComponentStories from './Button.stories';
### Iconography
- Font Awesome library
- We utilize the Regular and Solid Font Awesome icons
- Only use Solid icons on icon-only buttons. import `@fortawesome/pro-solid-svg-icons`
- Use Regular icons for all other buttons. import `@fortawesome/pro-regular-svg-icons`
- Only use Solid icons on icon-only buttons. import relatively from `src/font_awesome/solid`
- Use Regular icons for all other buttons. import relatively from `src/font_awesome/regular`
- Use a leading icon alongside a label if there is a primary action verb (e.g. Edit, Share, Copy)
- Icon-only buttons should only be permitted if
- Space is limited (e.g. too small for text alone)
Expand Down
4 changes: 2 additions & 2 deletions src/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';

import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { faFileAlt, faCaretDown, faPaperPlane } from '@fortawesome/pro-regular-svg-icons';
import { faFileAlt, faCaretDown, faPaperPlane } from '../font_awesome/regular';
import {
faGoogle, faFacebook, faLinkedin, faTwitter,
} from '@fortawesome/free-brands-svg-icons';
} from '../font_awesome/brands';
import Button from '.';
import mdx from './Button.mdx';

Expand Down
4 changes: 2 additions & 2 deletions src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React, { forwardRef } from 'react';
import classNames from 'classnames';
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSpinnerThird } from '@fortawesome/pro-regular-svg-icons';

import {
Button as RBButton,
type ButtonProps as RBButtonProps,
} from 'react-bootstrap';

import { faSpinnerThird } from '../font_awesome/regular';

import './Button.scss';

export enum ButtonSizes {
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Col.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type ColProps as ReactBootstrapColProps,
} from 'react-bootstrap';

import { useDeprecationWarning } from 'src/utils';
import { useDeprecationWarning } from '../utils';

export type ColProps = {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type ContainerProps as ReactBootstrapContainerProps,
} from 'react-bootstrap';

import { useDeprecationWarning } from 'src/utils';
import { useDeprecationWarning } from '../utils';

export type ContainerProps = {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type RowProps as ReactBootstrapRowProps,
} from 'react-bootstrap';

import { useDeprecationWarning } from 'src/utils';
import { useDeprecationWarning } from '../utils';

export type RowProps = {
/**
Expand Down
6 changes: 4 additions & 2 deletions src/CopyToClipboardButton/CopyToClipboardButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useState } from 'react';
import classNames from 'classnames';
import { CopyToClipboard } from 'react-copy-to-clipboard';

import { type IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCopy } from '@fortawesome/pro-regular-svg-icons';
import { CopyToClipboard } from 'react-copy-to-clipboard';

import { faCopy } from '../font_awesome/regular';

import TrackedButton from '../TrackedButton';
import Popper from '../Popper';
Expand Down
2 changes: 1 addition & 1 deletion src/DateTimePicker/PickerEnforcedInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classNames from 'classnames';
import { isValid } from 'date-fns';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCalendarAlt } from '@fortawesome/pro-regular-svg-icons';
import { faCalendarAlt } from '../font_awesome/regular';

type PickerEnforcedInputProps = {
disabled?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/Drawer/Drawer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faEnvelope, faChevronLeft, faChevronRight, faTrash,
} from '@fortawesome/pro-solid-svg-icons';
} from '../font_awesome/solid';
import {
Drawer, DrawerBody, DrawerFooter, DrawerHeader,
} from '.';
Expand Down
2 changes: 1 addition & 1 deletion src/Drawer/DrawerHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faTimes, faCompressAlt, faExpandAlt,
} from '@fortawesome/pro-solid-svg-icons';
} from '../font_awesome/solid';

import './DrawerHeader.scss';

Expand Down
5 changes: 2 additions & 3 deletions src/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faEllipsisV, faFileAlt, faChevronDown, faTag, faEnvelope, faTrashAlt,
} from '@fortawesome/pro-regular-svg-icons';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
} from '../font_awesome/regular';
import {
Dropdown, DropdownDivider, DropdownToggle, DropdownItem, DropdownMenu,
} from '.';
Expand Down
2 changes: 1 addition & 1 deletion src/EmptyState/EmptyState.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';

import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { faPlus } from '@fortawesome/pro-regular-svg-icons';
import { faPlus } from '../font_awesome/regular';

import Button from '../Button';

Expand Down
2 changes: 1 addition & 1 deletion src/Flex/Flex.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode, ElementType, createElement } from 'react';
import classNames from 'classnames';

import { useDeprecationWarning } from 'src/utils';
import { useDeprecationWarning } from '../utils';

import styles from './Flex.module.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/FormGroup/FormGroup.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { faSearch } from '@fortawesome/pro-solid-svg-icons';

import { FlexContainer } from 'src/FlexContainer';
import { faSearch } from '../font_awesome/solid';
import FormGroup from '.';
import Input from '../Input';
import FormControlLabel from '../FormControlLabel';
Expand Down
2 changes: 1 addition & 1 deletion src/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
faPencil,
faTimes,
faExpandAlt,
} from '@fortawesome/pro-regular-svg-icons';
} from '../font_awesome/regular';
import Button, { type ButtonProps } from '../Button/Button';

export const IconButtonActions = {
Expand Down
2 changes: 1 addition & 1 deletion src/IconCell/IconCell.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import {
faGlobe, faMailbox, faPaperPlane, faStar, faUser,
} from '@fortawesome/pro-regular-svg-icons';
} from '../font_awesome/regular';

import IconCell from '.';
import mdx from './IconCell.mdx';
Expand Down
2 changes: 1 addition & 1 deletion src/IconCell/IconCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { type IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { useDeprecationWarning } from 'src/utils';
import { useDeprecationWarning } from '../utils';

import './IconCell.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/LoadingOverlay/LoadingOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import classNames from 'classnames';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSpinnerThird } from '@fortawesome/pro-solid-svg-icons';
import { faSpinnerThird } from '../font_awesome/solid';

import './LoadingOverlay.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/Modal/ModalHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import './ModalHeader.scss';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faExclamationTriangle } from '@fortawesome/pro-solid-svg-icons';
import { faExclamationTriangle } from '../font_awesome/solid';

type ModalHeaderProps = {
children?: React.ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion src/Pill/Pill.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { action } from '@storybook/addon-actions';
import {
faClock, faGiftCard, faGlobe, faMicrophone, faUsers,
} from '@fortawesome/pro-solid-svg-icons';
} from '../font_awesome/solid';

import { Pill, Pills, PILL_COLORS } from '.';
import mdx from './Pill.mdx';
Expand Down
4 changes: 2 additions & 2 deletions src/Pill/Pill.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import classNames from 'classnames';
import { type IconDefinition } from '@fortawesome/pro-solid-svg-icons';
import { type IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faTimes } from '@fortawesome/pro-solid-svg-icons';
import { faTimes } from '../font_awesome/solid';

import './Pill.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/ProfileCell/ProfileCell.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { faShieldCheck } from '@fortawesome/pro-solid-svg-icons';
import { faShieldCheck } from '../font_awesome/solid';
import ProfileCell from '.';
import ProfileCellSkeleton from './ProfileCellSkeleton';
import mdx from './ProfileCell.mdx';
Expand Down
2 changes: 1 addition & 1 deletion src/RichTextEditor/RichTextEditorMenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
faListOl,
faListUl,
faUnlink,
} from '@fortawesome/pro-regular-svg-icons';
} from '../font_awesome/regular';
import IconButton from '../IconButton';

import { RichTextEditorActions } from './richTextEditorActions';
Expand Down
2 changes: 1 addition & 1 deletion src/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState } from 'react';

import { faFileAlt, faEllipsisV, faThumbtack } from '@fortawesome/pro-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { faFileAlt, faEllipsisV, faThumbtack } from '../font_awesome/solid';
import Button from '../Button';
import Card from '../Card';
import CheckboxButton from '../CheckboxButton';
Expand Down
2 changes: 1 addition & 1 deletion src/Table/TableSortLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSort } from '@fortawesome/pro-solid-svg-icons';
import { faSort } from '../font_awesome/solid';

import './TableSortLabel.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/Tooltip/Tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faQuestionCircle } from '@fortawesome/pro-solid-svg-icons';
import { faQuestionCircle } from '../font_awesome/solid';

import Popper from '../Popper';

Expand Down
2 changes: 1 addition & 1 deletion src/Tooltip/Tooltip.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { action } from '@storybook/addon-actions';

import { faExclamationTriangle } from '@fortawesome/pro-solid-svg-icons';
import { faExclamationTriangle } from '../font_awesome/solid';

import Tooltip from '.';
import mdx from './Tooltip.mdx';
Expand Down
19 changes: 19 additions & 0 deletions src/font_awesome/brands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Keep this eslint-disable here. FontAwesome imports should only be happening
// in this file and nowhere else in the codebase.
//
// Any direct import from '@fortawesome/free-brands-svg-icons' will create bloat in
// our overall bundle size.

/* eslint-disable no-restricted-imports */

import { faGoogle } from '@fortawesome/free-brands-svg-icons/faGoogle';
import { faFacebook } from '@fortawesome/free-brands-svg-icons/faFacebook';
import { faLinkedin } from '@fortawesome/free-brands-svg-icons/faLinkedin';
import { faTwitter } from '@fortawesome/free-brands-svg-icons/faTwitter';

export {
faGoogle,
faFacebook,
faLinkedin,
faTwitter,
};
Loading

0 comments on commit 969de45

Please sign in to comment.