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

Update "improve your measurement" section mobile design to match Figma #9832

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,32 @@ export default function ConversionTrackingToggle( { children, loading } ) {
return (
<div>
<LoadingWrapper loading={ loading } width="180px" height="21.3px">
<Switch
label={ __(
'Enhanced conversion tracking',
'google-site-kit'
) }
checked={ isConversionTrackingEnabled }
disabled={ isSaving || loading }
onClick={ () => {
// If Conversion Tracking is currently enabled, show a confirmation
// dialog warning users about the impact of disabling it.
if ( isConversionTrackingEnabled ) {
trackEvent( `${ viewContext }`, 'ect_disable' );
<div className="googlesitekit-module-settings-group__switch">
<Switch
label={ __(
'Enhanced conversion tracking',
'google-site-kit'
) }
checked={ isConversionTrackingEnabled }
disabled={ isSaving || loading }
onClick={ () => {
// If Conversion Tracking is currently enabled, show a confirmation
// dialog warning users about the impact of disabling it.
if ( isConversionTrackingEnabled ) {
trackEvent( `${ viewContext }`, 'ect_disable' );

setShowConfirmDialog( true );
} else {
trackEvent( `${ viewContext }`, 'ect_enable' );
setShowConfirmDialog( true );
} else {
trackEvent( `${ viewContext }`, 'ect_enable' );

// Conversion Tracking is not currently enabled, so this toggle
// enables it.
setConversionTrackingEnabled( true );
}
} }
hideLabel={ false }
/>
// Conversion Tracking is not currently enabled, so this toggle
// enables it.
setConversionTrackingEnabled( true );
}
} }
hideLabel={ false }
/>
</div>
</LoadingWrapper>
{ !! saveError && <ErrorText message={ saveError.message } /> }
<LoadingWrapper
Expand Down
18 changes: 10 additions & 8 deletions assets/js/components/first-party-mode/FirstPartyModeToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useMount } from 'react-use';
/**
* WordPress dependencies
*/
import { Fragment, useCallback } from '@wordpress/element';
import { useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function FirstPartyModeToggle( { className } ) {
/>
) }
{ ! isLoading && (
<Fragment>
<div className="googlesitekit-module-settings-group__switch">
<Switch
label={ __( 'First-party mode', 'google-site-kit' ) }
checked={
Expand All @@ -85,12 +85,14 @@ export default function FirstPartyModeToggle( { className } ) {
onClick={ handleClick }
hideLabel={ false }
/>
<Badge
className="googlesitekit-badge--beta"
hasLeftSpacing
label={ __( 'Beta', 'google-site-kit' ) }
/>
</Fragment>
<div className="googlesitekit-first-party-mode-toggle__switch-badge">
<Badge
className="googlesitekit-badge--beta"
hasLeftSpacing
label={ __( 'Beta', 'google-site-kit' ) }
/>
</div>
</div>
) }
<p className="googlesitekit-module-settings-group__helper-text">
{ __(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,51 @@ exports[`FirstPartyModeToggle should render in default state 1`] = `
class="googlesitekit-first-party-mode-toggle"
>
<div
aria-checked="false"
class="mdc-switch"
role="switch"
tabindex="0"
class="googlesitekit-module-settings-group__switch"
>
<div
class="mdc-switch__track"
aria-checked="false"
class="mdc-switch"
role="switch"
tabindex="0"
>

<div
class="mdc-switch__track"
>

</div>
<div
class="mdc-switch__thumb-underlay"
>
<div
class="mdc-switch__thumb"
>
<input
class="mdc-switch__native-control"
id="googlesitekit-switch-4"
readonly=""
role="switch"
type="checkbox"
/>
</div>
</div>
</div>
<label
class=""
for="googlesitekit-switch-4"
>
First-party mode
</label>
<div
class="mdc-switch__thumb-underlay"
class="googlesitekit-first-party-mode-toggle__switch-badge"
>
<div
class="mdc-switch__thumb"
<span
class="googlesitekit-badge googlesitekit-badge--beta googlesitekit-badge--has-left-spacing"
>
<input
class="mdc-switch__native-control"
id="googlesitekit-switch-4"
readonly=""
role="switch"
type="checkbox"
/>
</div>
Beta
</span>
</div>
</div>
<label
class=""
for="googlesitekit-switch-4"
>
First-party mode
</label>
<span
class="googlesitekit-badge googlesitekit-badge--beta googlesitekit-badge--has-left-spacing"
>
Beta
</span>
<p
class="googlesitekit-module-settings-group__helper-text"
>
Expand All @@ -58,44 +66,52 @@ exports[`FirstPartyModeToggle should render in disabled state if server requirem
class="googlesitekit-first-party-mode-toggle"
>
<div
aria-checked="false"
class="mdc-switch mdc-switch--disabled"
role="switch"
tabindex="0"
class="googlesitekit-module-settings-group__switch"
>
<div
class="mdc-switch__track"
aria-checked="false"
class="mdc-switch mdc-switch--disabled"
role="switch"
tabindex="0"
>

<div
class="mdc-switch__track"
>

</div>
<div
class="mdc-switch__thumb-underlay"
>
<div
class="mdc-switch__thumb"
>
<input
class="mdc-switch__native-control"
disabled=""
id="googlesitekit-switch-6"
readonly=""
role="switch"
type="checkbox"
/>
</div>
</div>
</div>
<label
class=""
for="googlesitekit-switch-6"
>
First-party mode
</label>
<div
class="mdc-switch__thumb-underlay"
class="googlesitekit-first-party-mode-toggle__switch-badge"
>
<div
class="mdc-switch__thumb"
<span
class="googlesitekit-badge googlesitekit-badge--beta googlesitekit-badge--has-left-spacing"
>
<input
class="mdc-switch__native-control"
disabled=""
id="googlesitekit-switch-6"
readonly=""
role="switch"
type="checkbox"
/>
</div>
Beta
</span>
</div>
</div>
<label
class=""
for="googlesitekit-switch-6"
>
First-party mode
</label>
<span
class="googlesitekit-badge googlesitekit-badge--beta googlesitekit-badge--has-left-spacing"
>
Beta
</span>
<p
class="googlesitekit-module-settings-group__helper-text"
>
Expand Down
25 changes: 19 additions & 6 deletions assets/sass/components/settings/_googlesitekit-settings-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
display: flex;
flex-direction: column;
gap: 20px;
padding: $grid-gap-desktop;
padding: $grid-gap-desktop $grid-gap-phone;

@media (min-width: $bp-tablet) {
padding: $grid-gap-desktop;
}

h4 {
font-family: $f-primary;
Expand All @@ -34,15 +38,24 @@
margin: 0;
}

.googlesitekit-module-settings-group__switch {
display: flex;

.mdc-switch {
top: 3px;
}
}

.googlesitekit-first-party-mode-toggle__switch-badge {
position: relative;
top: -2px;
}

.googlesitekit-module-settings-group__helper-text {
color: $c-surfaces-on-surface-variant;
flex-basis: 100%;
font-size: $fs-label-sm;
margin: 6px 0 0;

@media (min-width: $bp-tablet) {
margin-left: 42px; // margin-left = 32px switch width + 10px margin-left of label.
}
margin: 6px 0 0 calc(32px + 10px);
Copy link
Collaborator Author

@techanvil techanvil Dec 9, 2024

Choose a reason for hiding this comment

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

I'm not sure if this is what @aaemnnosttv had in mind with his suggestion - using calc() to add two unnamed values isn't really an improvement on what we had before, it's less readable and introduces an unnecessary calc() to add two static values.

Unfortunately as things stand I don't see that we can use calc() to reference the values of the relevant element dimension/properties. We could do something like this to derive the value:

diff --git a/assets/sass/components/settings/_googlesitekit-settings-group.scss b/assets/sass/components/settings/_googlesitekit-settings-group.scss
index c1625f2fb2..1eade3778c 100644
--- a/assets/sass/components/settings/_googlesitekit-settings-group.scss
+++ b/assets/sass/components/settings/_googlesitekit-settings-group.scss
@@ -55,7 +55,7 @@
 			color: $c-surfaces-on-surface-variant;
 			flex-basis: 100%;
 			font-size: $fs-label-sm;
-			margin: 6px 0 0 calc(32px + 10px);
+			margin: 6px 0 0 $mdc-switch-track-width + $mdc-switch-label-margin-left;
 		}
 
 		.googlesitekit-analytics-enable-enhanced-measurement--loading {
diff --git a/assets/sass/config/_variables.scss b/assets/sass/config/_variables.scss
index e341c8792c..ef560d2231 100644
--- a/assets/sass/config/_variables.scss
+++ b/assets/sass/config/_variables.scss
@@ -308,6 +308,8 @@ $mdc-text-field-error: $c-utility-error;
 $mdc-text-field-placeholder-ink-color: $c-interactive-on-disable-container;
 $mdc-text-field-label: $c-interactive-on-disable-container;
 
+$mdc-switch-label-margin-left: 10px;
+
 // Custom max width for settings notice content
 $max-width-settings-notice-content: 1098px;
 
diff --git a/assets/sass/vendor/_mdc-switch.scss b/assets/sass/vendor/_mdc-switch.scss
index 0e0b0d0a7e..53b4a86ed7 100644
--- a/assets/sass/vendor/_mdc-switch.scss
+++ b/assets/sass/vendor/_mdc-switch.scss
@@ -40,7 +40,7 @@
 		font-size: $fs-body-md;
 		letter-spacing: $ls-s;
 		line-height: $lh-body-md;
-		margin-left: 10px;
+		margin-left: $mdc-switch-label-margin-left;
 	}
 
 	.mdc-switch__track {

$mdc-switch-track-width comes from the vendor's mixin and is defined here: https://github.com/material-components/material-components-web/blob/3a1767ea4da308dbee272763a377deff39cf0471/packages/mdc-switch/_variables.scss#L25

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @techanvil, I couldn't find those variables initially.

}

.googlesitekit-analytics-enable-enhanced-measurement--loading {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading