diff --git a/CHANGELOG.md b/CHANGELOG.md index 261a67a18..b21206eb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `SuggestionProductCard` component. - `EmptyState` component. - `EmptyState` at the `ProductGallery` section. +- `IconSVG` component to load SVG Icons. ### Changed @@ -48,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - API style redirects from `/_v/private/graphql` since they have no effect - Display box from `` component - `useTotalCount` hook +- Phosphor-react library ### Fixed diff --git a/README.md b/README.md index cd01c8174..2cc9a3f7b 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,50 @@ The aforementioned guide works well for UI components. However, components like ) ``` +### Managing SVG Icons +Icons help build web pages by illustrating concepts and improving website navigation. However, using icons can decrease the page's performance. One option to avoid the decrease of the page's performance is to use SVGs from a single SVG file, located in `/static/icons/icons.svg`, and load them with the `IconSVG` component. + +In the following steps, learn how to add and use a new SVG icon and avoid decreasing page performance while using an icon. + +> ⚠️ Warning +> +> This is a recommendation while using icons on a web page. Evaluate if this fits in your project. + +#### Adding an SVG icon +1. In the SVG file, change the `svg` tag to `symbol`. +2. Add an `id` to the symbol. Remember to use an unique `id` and do not replicate it. +3. Remove unnecessary HTML/SVG properties to allow you to style and decrease the final file size, such as `fill`, `stroke-width`, `width`, `height`, and `color`. + +An example adding Bell icon: + +```svg + + + +``` + +#### Using an SVG icon + +1. Get the icon's `id` that you created in the SVG icon file. +2. Add the `id` in the React component that you desire to use the SVG icon. For example + +```tsx +// src/components/ui/MyIconButton/MyIconButton.tsx +import React from 'react' +import IconSVG from 'src/components/common/IconSVG' // this path can be outdated. + +function IconButton() { + return ( + + ) +} + +export default IconButton +``` +This project uses SVGs from [Phosphor icons](https://phosphoricons.com/). + ## 🖊️ Styling Components Our customized themes are based on [Design Tokens](https://css-tricks.com/what-are-design-tokens/) using [CSS Variables](https://developer.mozilla.org/en-US/docs/Web/CSS/--*) or a CSS class for each token. Today, we have the following files in the `src/styles` folder: diff --git a/package.json b/package.json index 64f1dcc8d..9410c113f 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "gatsby-plugin-sass": "^5.3.0", "gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.26", "include-media": "^1.4.10", - "phosphor-react": "^1.3.1", "react": "^17.0.2", "react-dom": "^17.0.2", "react-helmet-async": "^1.2.2", diff --git a/src/components/cart/CartItem/CartItem.tsx b/src/components/cart/CartItem/CartItem.tsx index 08fcf4ddd..f0530e8ce 100644 --- a/src/components/cart/CartItem/CartItem.tsx +++ b/src/components/cart/CartItem/CartItem.tsx @@ -1,5 +1,4 @@ import { Card, CardActions, CardContent, CardImage } from '@faststore/ui' -import { XCircle as XCircleIcon } from 'phosphor-react' import React from 'react' import Button from 'src/components/ui/Button' import { Image } from 'src/components/ui/Image' @@ -9,6 +8,7 @@ import { useCart } from 'src/sdk/cart/useCart' import { useRemoveButton } from 'src/sdk/cart/useRemoveButton' import { useFormattedPrice } from 'src/sdk/product/useFormattedPrice' import type { CartItem as ICartItem } from 'src/sdk/cart/validate' +import IconSVG from 'src/components/common/IconSVG' import './cart-item.scss' @@ -72,7 +72,7 @@ function CartItem({ item }: Props) { )} diff --git a/src/components/ui/Breadcrumb/Breadcrumb.tsx b/src/components/ui/Breadcrumb/Breadcrumb.tsx index f7b407a16..1af171b22 100644 --- a/src/components/ui/Breadcrumb/Breadcrumb.tsx +++ b/src/components/ui/Breadcrumb/Breadcrumb.tsx @@ -2,7 +2,7 @@ import React, { memo } from 'react' import { Breadcrumb as UIBreadcrumb } from '@faststore/ui' import Link from 'src/components/ui/Link' import type { BreadcrumbProps as UIBreadcrumbProps } from '@faststore/ui' -import { House as HouseIcon } from 'phosphor-react' +import IconSVG from 'src/components/common/IconSVG' import './breadcrumb.scss' @@ -19,7 +19,7 @@ function Breadcrumb({ breadcrumbList }: BreadcrumbProps) { return ( - + {breadcrumbList.map(({ item, name }, index) => { diff --git a/src/components/ui/BuyButton/BuyButton.tsx b/src/components/ui/BuyButton/BuyButton.tsx index 9e57a958f..705ba582f 100644 --- a/src/components/ui/BuyButton/BuyButton.tsx +++ b/src/components/ui/BuyButton/BuyButton.tsx @@ -1,7 +1,7 @@ import React from 'react' import { Button as UIButton } from '@faststore/ui' import type { ButtonProps } from '@faststore/ui' -import { ShoppingCart as ShoppingCartIcon } from 'phosphor-react' +import IconSVG from 'src/components/common/IconSVG' import './buy-button.scss' @@ -10,7 +10,7 @@ type Props = ButtonProps function BuyButton({ children, ...props }: Props) { return ( - + {children} ) diff --git a/src/components/ui/QuantitySelector/QuantitySelector.tsx b/src/components/ui/QuantitySelector/QuantitySelector.tsx index 2cc62e85b..2c4c76201 100644 --- a/src/components/ui/QuantitySelector/QuantitySelector.tsx +++ b/src/components/ui/QuantitySelector/QuantitySelector.tsx @@ -1,6 +1,6 @@ import React, { memo, useEffect, useState } from 'react' import { QuantitySelector as UIQuantitySelector } from '@faststore/ui' -import { Plus as PlusIcon, Minus as MinusIcon } from 'phosphor-react' +import IconSVG from 'src/components/common/IconSVG' import './quantity-selector.scss' @@ -65,12 +65,12 @@ export function QuantitySelector({ leftButtonProps={{ onClick: decrease, disabled: isLeftDisabled || disabled, - icon: , + icon: , }} rightButtonProps={{ onClick: increase, disabled: isRightDisabled || disabled, - icon: , + icon: , }} inputProps={{ onChange: validateInput, diff --git a/src/components/ui/ScrollToTopButton/ScrollToTopButton.tsx b/src/components/ui/ScrollToTopButton/ScrollToTopButton.tsx index aaade54f5..a2cc418bd 100644 --- a/src/components/ui/ScrollToTopButton/ScrollToTopButton.tsx +++ b/src/components/ui/ScrollToTopButton/ScrollToTopButton.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { CaretUp as CareUpIcon } from 'phosphor-react' +import IconSVG from 'src/components/common/IconSVG' import type { UIButtonProps } from '../Button' import Button from '../Button' @@ -12,7 +12,7 @@ interface ScrollToTopButtonProps { text?: string /** * Button's icon. - * @default + * @default */ icon?: UIButtonProps['icon'] /** @@ -24,7 +24,7 @@ interface ScrollToTopButtonProps { function ScrollToTopButton({ text = 'Scroll to top', - icon = , + icon = , iconPosition = 'left', }: ScrollToTopButtonProps) { return ( diff --git a/src/components/ui/Select/Select.tsx b/src/components/ui/Select/Select.tsx index ed11d82fd..5f9987989 100644 --- a/src/components/ui/Select/Select.tsx +++ b/src/components/ui/Select/Select.tsx @@ -1,7 +1,7 @@ import React from 'react' import { Select as UISelect } from '@faststore/ui' import type { SelectProps } from '@faststore/ui' -import { CaretDown as CaretDownIcon } from 'phosphor-react' +import IconSVG from 'src/components/common/IconSVG' import './select.scss' @@ -50,7 +50,7 @@ export default function Select({ ))} - + ) } diff --git a/src/components/ui/SignInLink/SignInLink.tsx b/src/components/ui/SignInLink/SignInLink.tsx index 7040caa27..8abf87f47 100644 --- a/src/components/ui/SignInLink/SignInLink.tsx +++ b/src/components/ui/SignInLink/SignInLink.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { User as UserIcon } from 'phosphor-react' +import IconSVG from 'src/components/common/IconSVG' import { LinkButton } from '../Button' @@ -11,7 +11,7 @@ const SignInLink: React.FC = () => { className="title-sub-subsection signin-link" variant="tertiary" > - + Sign In ) diff --git a/src/pages/{StoreCollection.slug}.tsx b/src/pages/{StoreCollection.slug}.tsx index 282a18e85..056a0ebe9 100644 --- a/src/pages/{StoreCollection.slug}.tsx +++ b/src/pages/{StoreCollection.slug}.tsx @@ -1,7 +1,6 @@ import { SearchProvider, useSession } from '@faststore/sdk' import { graphql } from 'gatsby' import { BreadcrumbJsonLd, GatsbySeo } from 'gatsby-plugin-next-seo' -import { Headphones as HeadphonesIcon } from 'phosphor-react' import React from 'react' import Breadcrumb from 'src/components/sections/Breadcrumb' import Hero from 'src/components/sections/Hero' @@ -14,6 +13,7 @@ import { useSearchParams } from 'src/hooks/useSearchParams' import { applySearchState } from 'src/sdk/search/state' import { mark } from 'src/sdk/tests/mark' import type { Props } from 'src/hooks/useSearchParams' +import IconSVG from 'src/components/common/IconSVG' import '../styles/pages/product-listing-page.scss' @@ -81,7 +81,9 @@ function Page(props: Props) { subtitle={`All the amazing ${title} from the brands we partner with.`} imageSrc="https://storeframework.vtexassets.com/arquivos/ids/190897/Photo.jpg" imageAlt="Quest 2 Controller on a table" - icon={} + icon={ + + } /> diff --git a/static/icons/icons.svg b/static/icons/icons.svg new file mode 100644 index 000000000..eb15d5003 --- /dev/null +++ b/static/icons/icons.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/yarn.lock b/yarn.lock index 4474e812c..5c035e9d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12443,11 +12443,6 @@ performance-now@^2.1.0: resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= -phosphor-react@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/phosphor-react/-/phosphor-react-1.3.1.tgz#96e33f44370d83cda15b60cccc17087ad0060684" - integrity sha512-N4dk4Lrl8Pa2V9cImw/6zP8x9oPFOSh6ixtSvB73zmcpKrX6Sb+lPlu6Y222VOwZx19mfo01bP+OeAbXHw95Jg== - physical-cpu-count@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/physical-cpu-count/-/physical-cpu-count-2.0.0.tgz#18de2f97e4bf7a9551ad7511942b5496f7aba660"