Skip to content

Commit 016436b

Browse files
committed
Improve util function
1 parent e4c5808 commit 016436b

File tree

5 files changed

+36
-36
lines changed

5 files changed

+36
-36
lines changed

client/dashboard/sites/overview/site-card.tsx

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ import { dateI18n } from '@wordpress/date';
1111
import { createInterpolateElement } from '@wordpress/element';
1212
import { __, sprintf } from '@wordpress/i18n';
1313
import { sitePHPVersionQuery, siteCurrentPlanQuery } from '../../app/queries';
14-
import { getBlurredStyles } from '../../utils/blurred-styles';
14+
import { getIsBlurredProps } from '../../utils/is-blurred';
1515
import { getSiteStatusLabel } from '../../utils/site-status';
1616
import { getFormattedWordPressVersion } from '../../utils/wp-version';
1717
import SitePreview from '../site-preview';
1818
import type { Site } from '../../data/types';
1919

2020
function PHPVersion( { siteSlug }: { siteSlug: string } ) {
2121
return (
22-
useQuery( sitePHPVersionQuery( siteSlug ) ).data ?? (
23-
<span style={ getBlurredStyles() }>X.Y</span>
24-
)
22+
useQuery( sitePHPVersionQuery( siteSlug ) ).data ?? <span { ...getIsBlurredProps() }>X.Y</span>
2523
);
2624
}
2725

@@ -124,30 +122,29 @@ function PlanDetails( { site }: { site: Site } ) {
124122
<FieldTitle>{ __( 'Plan' ) }</FieldTitle>
125123
{ product_name_short && <Text>{ product_name_short }</Text> }
126124
{ isFree ? (
127-
<Text>{ __( 'No expiration date.' ) }</Text>
125+
<>
126+
<Text>{ __( 'No expiration date.' ) }</Text>
127+
<Button href={ `/plans/${ site.slug }` } variant="link">
128+
{ __( 'Upgrade' ) }
129+
</Button>
130+
</>
128131
) : (
129-
// Show a blurred time while we wait for the current plan.
130-
<Text style={ currentPlan ? undefined : getBlurredStyles() }>
131-
{ getPlanExpirationMessage(
132-
currentPlan ? currentPlan.expiry : new Date().toISOString()
133-
) }
134-
</Text>
135-
) }
136-
{ isFree ? (
137-
<Button href={ `/plans/${ site.slug }` } variant="link">
138-
{ __( 'Upgrade' ) }
139-
</Button>
140-
) : (
141-
<Button
142-
// Show a blurred button while we wait for the plan ID.
143-
// @ts-expect-error inert is not typed
144-
inert={ currentPlan ? undefined : 'true' }
145-
style={ currentPlan ? undefined : getBlurredStyles() }
146-
href={ currentPlan ? `/purchases/subscriptions/${ site.slug }/${ currentPlan.id }` : '' }
147-
variant="link"
148-
>
149-
{ __( 'Manage subscription' ) }
150-
</Button>
132+
<>
133+
<Text { ...getIsBlurredProps( { enabled: ! currentPlan } ) }>
134+
{ getPlanExpirationMessage(
135+
currentPlan ? currentPlan.expiry : new Date().toISOString()
136+
) }
137+
</Text>
138+
<Button
139+
{ ...getIsBlurredProps( { enabled: ! currentPlan } ) }
140+
href={
141+
currentPlan ? `/purchases/subscriptions/${ site.slug }/${ currentPlan.id }` : ''
142+
}
143+
variant="link"
144+
>
145+
{ __( 'Manage subscription' ) }
146+
</Button>
147+
</>
151148
) }
152149
</VStack>
153150
);

client/dashboard/sites/overview/uptime-card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { VisuallyHidden } from '@wordpress/components';
33
import { __, sprintf } from '@wordpress/i18n';
44
import { connection } from '@wordpress/icons';
55
import { siteMonitorUptimeQuery } from '../../app/queries';
6-
import { getBlurredStyles } from '../../utils/blurred-styles';
6+
import { getIsBlurredProps } from '../../utils/is-blurred';
77
import OverviewCard, { OverviewCardProgressBar } from '../overview-card';
88
import type { Site } from '../../data/types';
99

@@ -35,7 +35,7 @@ function UptimeCardEnabled( { siteSlug }: { siteSlug: string } ) {
3535
heading={
3636
uptimePercentage === undefined ? (
3737
<>
38-
<span style={ getBlurredStyles() }>{ sprintf( percentageString, '100' ) }</span>
38+
<span { ...getIsBlurredProps() }>{ sprintf( percentageString, '100' ) }</span>
3939
<VisuallyHidden>{ __( 'Loading…' ) }</VisuallyHidden>
4040
</>
4141
) : (

client/dashboard/utils/blurred-styles.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './style.scss';
2+
3+
export function getIsBlurredProps( { enabled = true }: { enabled?: boolean } = {} ) {
4+
return enabled ? { className: 'is-blurred', inert: 'true' } : {};
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.is-blurred {
2+
user-select: none;
3+
filter: blur(0.3em);
4+
opacity: 0.5;
5+
}

0 commit comments

Comments
 (0)