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

PCH Performance Stats: Add Multi-percentage bar hover state #2257

Merged
merged 4 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion build/content-helper/editor-sidebar.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'b4904bfe548e7a752a72');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => '8a7a2dd73718a70e2a36');
2 changes: 1 addition & 1 deletion build/content-helper/editor-sidebar.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/content-helper/editor-sidebar.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { SelectControl, Spinner } from '@wordpress/components';
import { SelectControl, Spinner, Tooltip } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';

Expand Down Expand Up @@ -89,42 +89,43 @@ export const PerformanceCategoriesPanel = ( {
</SelectControl>
</div>
) }
{
( isLoading ? (
<div className="parsely-spinner-wrapper" data-testid="parsely-spinner-wrapper">
<Spinner />
</div>
) : (
<div>
<div className="multi-percentage-bar">{
Object.entries( data.referrers.types ).map( ( [ key, value ] ) => {
const ariaLabel = sprintf(
/* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */
__( '%1$s: %2$s%%', 'wp-parsely' ),
getKeyTitle( key ), value.viewsPercentage
);
{ isLoading ? (
<div className="parsely-spinner-wrapper" data-testid="parsely-spinner-wrapper">
<Spinner />
</div>
) : (
<div>
<div className="multi-percentage-bar">
{ Object.entries( data.referrers.types ).map( ( [ key, value ] ) => {
const ariaLabel = sprintf(
/* translators: 1: Referrer type, 2: Percentage value, %%: Escaped percent sign */
__( '%1$s: %2$s%%', 'wp-parsely' ),
getKeyTitle( key ),
value.viewsPercentage,
);

return (
<div aria-label={ ariaLabel }
className={ 'bar-fill ' + key } key={ key }
style={ { width: value.viewsPercentage + '%' } }>
</div>
);
} ) }
</div>
<div className="percentage-bar-labels">
{
Object.entries( data.referrers.types ).map( ( [ key, value ] ) => (
<div className={ 'single-label ' + key } key={ key }>
<div className={ 'label-color ' + key }></div>
<div className="label-text">{ getKeyTitle( key ) }</div>
<div className="label-value">{ formatToImpreciseNumber( value.views ) }</div>
</div>
) )
}
</div>
return (
<Tooltip text={ `${ getKeyTitle( key ) } - ${ value.viewsPercentage }%` } delay={ 150 } key={ key }>
acicovic marked this conversation as resolved.
Show resolved Hide resolved
<div
aria-label={ ariaLabel }
className={ 'bar-fill ' + key }
style={ { width: value.viewsPercentage + '%' } }
></div>
</Tooltip>
);
} ) }
</div>
) ) }
<div className="percentage-bar-labels">
{ Object.entries( data.referrers.types ).map( ( [ key, value ] ) => (
<div className={ 'single-label ' + key } key={ key }>
<div className={ 'label-color ' + key }></div>
<div className="label-text">{ getKeyTitle( key ) }</div>
<div className="label-value">{ formatToImpreciseNumber( value.views ) }</div>
</div>
) ) }
</div>
</div>
) }
</PerformanceStatPanel>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@

// Multi-percentage bar.
div.multi-percentage-bar {
position: relative;
display: flex;
height: to_rem(16px);
align-items: flex-start;
Expand All @@ -175,7 +176,16 @@
margin: to_rem(16px) 0;

.bar-fill {
position: relative;
align-self: stretch;
transition: filter 0.1s ease, transform 0.1s ease;

&:hover {
filter: brightness(1);
transform: scaleX(1.05) scaleY(1.2);
border-radius: to_rem(2px);
z-index: 2;
}

// Border radiuses for first and last bar-fills.
&:first-child {
Expand Down Expand Up @@ -207,6 +217,10 @@
background-color: hsl(var(--ref-other));
}
}

&:hover .bar-fill {
filter: brightness(0.8);
}
}

.percentage-bar-labels {
Expand Down