Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix link icon alignment #7996

Merged
merged 14 commits into from
Dec 15, 2023
2 changes: 1 addition & 1 deletion assets/js/components/KeyMetrics/ChangeMetricsLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export default function ChangeMetricsLink() {
linkButton
className="googlesitekit-km-change-metrics-cta"
onClick={ openMetricsSelectionPanel }
leadingIcon={ <PencilIcon width={ 22 } height={ 22 } /> }
>
<PencilIcon width={ 22 } height={ 22 } />
{ __( 'Change Metrics', 'google-site-kit' ) }
</Link>
<SetupCompletedSurveyTrigger />
Expand Down
47 changes: 33 additions & 14 deletions assets/js/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const Link = forwardRef( ( props, ref ) => {
standalone = false,
linkButton = false,
to,
leadingIcon,
trailingIcon,
...otherProps
} = props;

Expand Down Expand Up @@ -151,6 +153,27 @@ const Link = forwardRef( ( props, ref ) => {
const LinkComponent = getLinkComponent();
const ariaLabel = getAriaLabel();

// Set the prefix/suffix icons, based on the type of link this is and
// the props supplied.
let leadingIconToUse = leadingIcon;
let trailingIconToUse = trailingIcon;
Comment on lines +156 to +159
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO if an icon is passed as a prop, it should override the default icons that are related to specific kinds of links as below. It's fine for now but just a thought.


if ( back ) {
leadingIconToUse = <BackIcon width={ 14 } height={ 14 } />;
}

if ( external && ! hideExternalIndicator ) {
trailingIconToUse = <ExternalIcon width={ 14 } height={ 14 } />;
}

if ( arrow && ! inverse ) {
trailingIconToUse = <ArrowIcon width={ 14 } height={ 14 } />;
}

if ( arrow && inverse ) {
trailingIconToUse = <ArrowInverseIcon width={ 14 } height={ 14 } />;
}

return (
<LinkComponent
aria-label={ ariaLabel }
Expand All @@ -177,23 +200,17 @@ const Link = forwardRef( ( props, ref ) => {
to={ to }
{ ...otherProps }
>
{ back && (
{ !! leadingIconToUse && (
<IconWrapper marginRight={ 5 }>
<BackIcon width={ 14 } height={ 14 } />
{ leadingIconToUse }
</IconWrapper>
) }
<span>{ children }</span>
{ external && ! hideExternalIndicator && (
<span className="googlesitekit-cta-link__contents">
{ children }
</span>
{ !! trailingIconToUse && (
<IconWrapper marginLeft={ 5 }>
<ExternalIcon width={ 14 } height={ 14 } />
</IconWrapper>
) }
{ arrow && (
<IconWrapper marginLeft={ 5 }>
{ ! inverse && <ArrowIcon width={ 14 } height={ 14 } /> }
{ inverse && (
<ArrowInverseIcon width={ 14 } height={ 14 } />
) }
{ trailingIconToUse }
</IconWrapper>
) }
</LinkComponent>
Expand All @@ -212,11 +229,13 @@ Link.propTypes = {
hideExternalIndicator: PropTypes.bool,
href: PropTypes.string,
inverse: PropTypes.bool,
leadingIcon: PropTypes.node,
linkButton: PropTypes.bool,
onClick: PropTypes.func,
small: PropTypes.bool,
standalone: PropTypes.bool,
linkButton: PropTypes.bool,
to: PropTypes.string,
trailingIcon: PropTypes.node,
};

export default Link;
24 changes: 14 additions & 10 deletions assets/js/components/settings/SettingsActiveModule/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,15 @@ export default function Footer( props ) {
__( 'Edit %s settings', 'google-site-kit' ),
name
) }
trailingIcon={
<PencilIcon
className="googlesitekit-settings-module__edit-button-icon"
width={ 10 }
height={ 10 }
/>
}
>
{ __( 'Edit', 'google-site-kit' ) }
<PencilIcon
className="googlesitekit-settings-module__edit-button-icon"
width="10"
height="10"
/>
</Link>
);
}
Expand All @@ -262,17 +264,19 @@ export default function Footer( props ) {
className="googlesitekit-settings-module__remove-button"
onClick={ handleDialog }
danger
trailingIcon={
<TrashIcon
className="googlesitekit-settings-module__remove-button-icon"
width={ 13 }
height={ 13 }
/>
}
>
{ sprintf(
/* translators: %s: module name */
__( 'Disconnect %s from Site Kit', 'google-site-kit' ),
name
) }
<TrashIcon
className="googlesitekit-settings-module__remove-button-icon"
width="13"
height="13"
/>
</Link>
);
} else if ( ! isEditing && moduleHomepage ) {
Expand Down
5 changes: 3 additions & 2 deletions assets/js/components/user-input/UserInputPreviewGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ export default function UserInputPreviewGroup( {
( !! currentlyEditingSlug && ! isEditing )
}
linkButton
trailingIcon={
<ChevronDownIcon width={ 20 } height={ 20 } />
}
>
{ __( 'Edit', 'google-site-kit' ) }

<ChevronDownIcon width={ 20 } height={ 20 } />
</Link>
</LoadingWrapper>
</div>
Expand Down
5 changes: 0 additions & 5 deletions assets/sass/components/global/_googlesitekit-cta-link.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
fill: currentColor;
}

> span > svg {
vertical-align: bottom;
}

&:hover {
color: $c-link;
text-decoration: underline;
Expand Down Expand Up @@ -117,7 +113,6 @@
button {
&.googlesitekit-cta-link {
color: $c-content-primary;
display: inline-block;

svg {
fill: currentColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
}

a {
display: inline-block;
margin: 4px; // Allow outline on focus to be visible.
max-width: 100%;
text-decoration: underline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@
strong {
font-weight: $fw-medium;
}

.googlesitekit-cta-link {
display: inline;
}
}

.googlesitekit-km-widget-tile__table-plain-text {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@
font-size: 0.75rem;
}

.googlesitekit-settings-module__edit-button-icon,
.googlesitekit-settings-module__remove-button-icon {
margin-left: $grid-gap-phone;
}

.googlesitekit-settings-module__edit-button-icon {

svg {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@
text-align: center;
}

.googlesitekit-widget--analyticsAllTraffic__legend .googlesitekit-cta-link__contents {
align-items: center;
display: inline-flex;
}

.googlesitekit-widget--analyticsAllTraffic__legend-slice {
align-items: center;
border-radius: 4px;
Expand All @@ -315,7 +320,7 @@
}

.googlesitekit-widget--analyticsAllTraffic__label {
display: flex;
display: inline-flex;
flex-direction: column;

&::after {
Expand Down
50 changes: 42 additions & 8 deletions stories/links.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,45 @@ storiesOf( 'Global', module ).add(
</Link>
</p>
<p>
<Link onClick={ () => {} }>
<PencilIcon width={ 18 } height={ 18 } />
Default Link Button With Icon
<Link
onClick={ () => {} }
leadingIcon={
<PencilIcon width={ 18 } height={ 18 } />
}
>
Default Link Button With Icon Prefix
</Link>
</p>
<p>
<Link
onClick={ () => {} }
className="googlesitekit-cta-link--hover"
leadingIcon={
<PencilIcon width={ 18 } height={ 18 } />
}
>
<PencilIcon width={ 18 } height={ 18 } />
VRT: Default Link Button With Icon Hovered
VRT: Default Link Button With Icon Prefix Hovered
</Link>
</p>
<p>
<Link
onClick={ () => {} }
trailingIcon={
<PencilIcon width={ 18 } height={ 18 } />
}
>
Default Link Button With Icon Suffix
</Link>
</p>
<p>
<Link
onClick={ () => {} }
className="googlesitekit-cta-link--hover"
trailingIcon={
<PencilIcon width={ 18 } height={ 18 } />
}
>
VRT: Default Link Button With Icon Suffix Hovered
</Link>
</p>
<p>
Expand All @@ -99,8 +126,13 @@ storiesOf( 'Global', module ).add(
</Link>
</p>
<p>
<Link onClick={ () => {} } secondary>
<PencilIcon width={ 18 } height={ 18 } />
<Link
onClick={ () => {} }
secondary
leadingIcon={
<PencilIcon width={ 18 } height={ 18 } />
}
>
Secondary Link Button With Icon
</Link>
</p>
Expand All @@ -109,8 +141,10 @@ storiesOf( 'Global', module ).add(
onClick={ () => {} }
className="googlesitekit-cta-link--hover"
secondary
leadingIcon={
<PencilIcon width={ 18 } height={ 18 } />
}
>
<PencilIcon width={ 18 } height={ 18 } />
VRT: Secondary Link Button With Icon Hovered
</Link>
</p>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.