Skip to content

Commit ef2be8d

Browse files
werdnanoslengidjin
andauthored
fix!: Unify icon usage (#2411)
Co-authored-by: John Gedeon <[email protected]>
1 parent bd5dffc commit ef2be8d

File tree

10 files changed

+63
-291
lines changed

10 files changed

+63
-291
lines changed

src/components/Footer/SocialLinks/SocialLinks.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ describe('SocialLinks component', () => {
4040
describe('SocialLink component', () => {
4141
it('renders without errors', () => {
4242
const { container } = render(<SocialLink name="Instagram" />)
43-
expect(container.querySelector('.usa-social-link')).toBeInTheDocument()
44-
expect(screen.getByRole('img')).toHaveAttribute('alt', 'Instagram')
43+
const link = container.querySelector('.usa-social-link')
44+
expect(link).toBeInTheDocument()
45+
expect(link).toHaveAttribute('title', 'Instagram')
46+
expect(screen.getByRole('img')).toHaveAttribute('name', 'Instagram')
4547
})
4648
})

src/components/Footer/SocialLinks/SocialLinks.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
/* eslint-disable jsx-a11y/anchor-is-valid */
22
import React from 'react'
33
import classnames from 'classnames'
4-
5-
import iconFacebook from '@uswds/uswds/src/img/usa-icons/facebook.svg'
6-
import iconTwitter from '@uswds/uswds/src/img/usa-icons/twitter.svg'
7-
import iconYouTube from '@uswds/uswds/src/img/usa-icons/youtube.svg'
8-
import iconInstagram from '@uswds/uswds/src/img/usa-icons/instagram.svg'
9-
import iconRSS from '@uswds/uswds/src/img/usa-icons/rss_feed.svg'
4+
import { Icon } from '../../Icon/Icons'
105

116
type SocialLinksProps = {
127
links: React.ReactNode[]
@@ -39,28 +34,26 @@ export const SocialLink = ({
3934
name,
4035
...props
4136
}: SocialLinkProps & JSX.IntrinsicElements['a']): React.ReactElement => {
42-
let iconSrc = ''
37+
let icon: Icon
4338
switch (name) {
4439
case 'Facebook':
45-
iconSrc = iconFacebook
40+
icon = <Icon.Facebook className="usa-social-link__icon" name={name} />
4641
break
4742
case 'Twitter':
48-
iconSrc = iconTwitter
43+
icon = <Icon.Twitter className="usa-social-link__icon" name={name} />
4944
break
5045
case 'YouTube':
51-
iconSrc = iconYouTube
46+
icon = <Icon.Youtube className="usa-social-link__icon" name={name} />
5247
break
5348
case 'Instagram':
54-
iconSrc = iconInstagram
49+
icon = <Icon.Instagram className="usa-social-link__icon" name={name} />
5550
break
5651
case 'RSS':
57-
iconSrc = iconRSS
52+
icon = <Icon.RssFeed className="usa-social-link__icon" name={name} />
5853
break
5954
}
6055

6156
return (
62-
<a className="usa-social-link" {...props}>
63-
<img className="usa-social-link__icon" src={iconSrc} alt={name} />
64-
</a>
57+
<a className="usa-social-link" {...props} title={name}>{icon}</a>
6558
)
6659
}

src/components/Search/SearchButton/SearchButton.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import classnames from 'classnames'
33

4-
import searchImg from '@uswds/uswds/src/img/usa-icons-bg/search--white.svg'
4+
import { Icon } from '../../Icon/Icons'
55

66
import { Button } from '../../Button/Button'
77

@@ -37,11 +37,7 @@ export const SearchButton = ({
3737
{!isSmall && (
3838
<span className="usa-search__submit-text">{buttonText}</span>
3939
)}
40-
<img
41-
src={searchImg}
42-
className="usa-search__submit-icon"
43-
alt={buttonText}
44-
/>
40+
<Icon.Search className="usa-search__submit-icon" name={buttonText} size={3}/>
4541
</Button>
4642
</div>
4743
)

src/components/banner/BannerLockImage/BannerLockImage.test.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/components/banner/BannerLockImage/BannerLockImage.tsx

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/components/banner/CustomBanner.stories.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { ReactElement, useState } from 'react'
2+
import { Icon } from '../Icon/Icons'
23
import {
34
Banner,
45
BannerButton,
@@ -7,7 +8,6 @@ import {
78
BannerGuidance,
89
BannerHeader,
910
BannerIcon,
10-
BannerLockImage,
1111
MediaBlockBody,
1212
} from '../../index'
1313

@@ -18,10 +18,6 @@ import httpsIcon from '@uswds/uswds/src/img/icon-https.svg'
1818
const CustomBanner = (): ReactElement => {
1919
const [isOpen, setIsOpen] = useState(false)
2020

21-
const lock = (
22-
<BannerLockImage title="Lock" description="Locked padlock icon" />
23-
)
24-
2521
return (
2622
<Banner aria-label="Official website of the state department of something specific">
2723
<BannerHeader
@@ -55,7 +51,7 @@ const CustomBanner = (): ReactElement => {
5551
<MediaBlockBody>
5652
<p>
5753
<strong>Secure .gov websites use HTTPS</strong>
58-
<br />A <strong>lock ( {lock} )</strong> or{' '}
54+
<br />A <strong>lock (<Icon.Lock aria-label="Locked padlock icon" />)</strong> or{' '}
5955
<strong>https://</strong> means you&apos;ve safely connected to
6056
the .gov website. Share sensitive information only on official,
6157
secure websites.

src/components/banner/GovBanner/GovBanner.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BannerContent } from '../BannerContent/BannerContent'
77
import { BannerGuidance } from '../BannerGuidance/BannerGuidance'
88
import { BannerIcon } from '../BannerIcon/BannerIcon'
99
import { MediaBlockBody } from '../../mediablock/MediaBlockBody/MediaBlockBody'
10-
import { BannerLockImage } from '../BannerLockImage/BannerLockImage'
10+
import { Icon } from '../../Icon/Icons'
1111

1212
// assets
1313
import flagImg from '@uswds/uswds/src/img/us_flag_small.png'
@@ -29,10 +29,6 @@ interface GovBannerCopy {
2929
}
3030

3131
const getCopy = (language: Language, tld: TLD): GovBannerCopy => {
32-
const lock = (
33-
<BannerLockImage title="Lock" description="Locked padlock icon" />
34-
)
35-
3632
switch (language) {
3733
case 'english':
3834
return {
@@ -61,7 +57,7 @@ const getCopy = (language: Language, tld: TLD): GovBannerCopy => {
6157
httpsSectionHeader: `Secure ${tld} websites use HTTPS`,
6258
httpsSectionContent: (
6359
<>
64-
A <strong>lock ( {lock} )</strong> or <strong>https://</strong>{' '}
60+
A <strong>lock (<Icon.Lock aria-label="Locked padlock icon"/>)</strong> or <strong>https://</strong>{' '}
6561
means you’ve safely connected to the {tld} website. Share sensitive
6662
information only on official, secure websites.
6763
</>
@@ -94,7 +90,7 @@ const getCopy = (language: Language, tld: TLD): GovBannerCopy => {
9490
httpsSectionHeader: `Los sitios web seguros ${tld} usan HTTPS`,
9591
httpsSectionContent: (
9692
<>
97-
Un <strong>candado ( {lock} )</strong> o <strong>https://</strong>{' '}
93+
Un <strong>candado (<Icon.Lock aria-label="Icono de candado cerrado" />)</strong> o <strong>https://</strong>{' '}
9894
significa que usted se conectó de forma segura a un sitio web {tld}.
9995
Comparta información sensible sólo en sitios web oficiales y
10096
seguros.

0 commit comments

Comments
 (0)