Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 4 additions & 30 deletions app/javascript/packages/components/icon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ComponentType } from 'react';
import { getAssetPath } from '@18f/identity-assets';

const SPRITE_URL = getAssetPath('identity-style-guide/dist/assets/img/sprite.svg');
Expand Down Expand Up @@ -246,39 +245,18 @@ export type DesignSystemIcon =
| 'zoom_out'
| 'zoom_out_map';

interface BaseIconProps {
interface IconProps {
/**
* Optional class name to apply to SVG element.
*/
className?: string;
}

interface IconProps extends BaseIconProps {
/**
* Name of design system icon to show.
*/
icon: DesignSystemIcon;
}

interface CustomIconProps extends BaseIconProps {}

/**
* Creates a new icon component, accepting common props, and applying common wrapping elements.
*
* @param path SVG icon path definition.
*/
function createIconComponent(path: string): ComponentType<CustomIconProps> {
return ({ className }) => (
<svg
aria-hidden
focusable={false}
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512"
className={className}
>
<path fill="currentColor" d={path} />
</svg>
);
}

function Icon({ icon, className }: IconProps) {
const classes = ['usa-icon', className].filter(Boolean).join(' ');

Expand All @@ -289,8 +267,4 @@ function Icon({ icon, className }: IconProps) {
);
}

Icon.Camera = createIconComponent(
'M512 144v288c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V144c0-26.5 21.5-48 48-48h88l12.3-32.9c7-18.7 24.9-31.1 44.9-31.1h125.5c20 0 37.9 12.4 44.9 31.1L376 96h88c26.5 0 48 21.5 48 48zM376 288c0-66.2-53.8-120-120-120s-120 53.8-120 120 53.8 120 120 120 120-53.8 120-120zm-32 0c0 48.5-39.5 88-88 88s-88-39.5-88-88 39.5-88 88-88 88 39.5 88 88z',
);

export default Icon;
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function SelfieCapture({ value, onChange, errorMessage, className }, ref) {
aria-label={t('doc_auth.buttons.take_picture')}
onClick={onCapture}
>
<Icon.Camera className="selfie-capture__capture-icon" />
<Icon icon="photo_camera" className="selfie-capture__capture-icon" />
</button>
</>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ div.selfie-capture__label[tabindex='-1']:focus {
.selfie-capture__capture-icon {
height: 2rem;
width: 2rem;

.usa-button:not(.usa-button--unstyled) > &.usa-icon:first-child {
// Unset icon placement where assumed to be adjacent to text, since the selfie capture button
// uses a standalone icon.
margin: 0;
Comment on lines +161 to +164
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference:

// Upstream: https://github.com/uswds/uswds/pull/4493
.usa-icon {
.usa-button > &:first-child {
// Note: This diverges from the upstream pull request in a couple ways:
// 1. There should not be any margins offsetting to account for line height, since Login.gov
// Design System normalizes button line height to 1.
// 2. Float is replaced by `vertical-align`, since otherwise it will have the effect of having
// the icon appear to the far edge of the button, rather than next to the text.
vertical-align: bottom;
margin-right: 0.25rem;
}
.usa-button:not(.usa-button--unstyled) > &:first-child {
margin-left: -1 * $icon-min-padding;
margin-right: #{0.5rem - px-to-rem($icon-min-padding)};
}
}

}
}

.selfie-capture__preview-heading.usa-file-input__preview-heading {
Expand Down