diff --git a/src/blocks/donate/edit/FrequencyBasedLayout.tsx b/src/blocks/donate/edit/FrequencyBasedLayout.tsx index fdbaeaa86..4b44c88e0 100644 --- a/src/blocks/donate/edit/FrequencyBasedLayout.tsx +++ b/src/blocks/donate/edit/FrequencyBasedLayout.tsx @@ -14,7 +14,7 @@ import { RichText } from '@wordpress/block-editor'; * Internal dependencies */ import { AmountValueInput } from './components'; -import { getColorForContrast } from '../utils'; +import { getColorForContrast, getFrequencyLabel } from '../utils'; import { FREQUENCIES } from '../consts'; import type { ComponentProps, DonationFrequencySlug } from '../types'; @@ -89,17 +89,6 @@ const FrequencyBasedLayout = ( props: { isTiered: boolean } & ComponentProps ) = ); - const getFrequencyLabel = ( frequencySlug: DonationFrequencySlug ) => { - switch ( frequencySlug ) { - case 'once': - return ''; - case 'month': - return __( ' per month', 'newspack-blocks' ); - case 'year': - return __( ' per year', 'newspack-blocks' ); - } - }; - // This code is fired on tab select and updates aria elements, tabindex states, and radio buttons const displayAmount = ( amount: number ) => amount.toFixed( 2 ).replace( /\.?0*$/, '' ); @@ -148,9 +137,15 @@ const FrequencyBasedLayout = ( props: { isTiered: boolean } & ComponentProps ) = className="tier-select-label tier-label" htmlFor={ `newspack-${ frequencySlug }-${ uid }-untiered-input` } > - { settings.currencySymbol + - untieredAmount.toFixed( 2 ).replace( /\.?0*$/, '' ) + - getFrequencyLabel( frequencySlug ) } +
) } diff --git a/src/blocks/donate/edit/TierBasedLayout.tsx b/src/blocks/donate/edit/TierBasedLayout.tsx index a699d12ef..0d886f7ba 100644 --- a/src/blocks/donate/edit/TierBasedLayout.tsx +++ b/src/blocks/donate/edit/TierBasedLayout.tsx @@ -15,20 +15,9 @@ import type { DonateBlockAttributes, TierBasedOptionValue, } from '../types'; -import { getColorForContrast } from '../utils'; +import { getColorForContrast, getFrequencyLabel } from '../utils'; import { FREQUENCIES, DISABLED_IN_TIERS_BASED_LAYOUT_TIER_INDEX } from '../consts'; -const getFrequencyLabel = ( frequencySlug: DonationFrequencySlug ) => { - switch ( frequencySlug ) { - case 'once': - return __( 'once', 'newspack-blocks' ); - case 'month': - return __( 'per month', 'newspack-blocks' ); - case 'year': - return __( 'per year', 'newspack-blocks' ); - } -}; - const TierBasedLayout = ( props: ComponentProps ) => { const { amounts, availableFrequencies, attributes } = props; const [ currentFrequency, setCurrencyFrequency ] = useState( availableFrequencies[ 0 ] ); @@ -108,14 +97,15 @@ const TierBasedLayout = ( props: ComponentProps ) => {
-

- { props.settings.currencySymbol } - { amount } -

- - { ' ' } - { getFrequencyLabel( currentFrequency ) } - +
$100 + * per month + */ + $formatted_amount = sprintf( + _x( // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment + '%1$s %2$s', + '%1$s is the amount (with currency symbol). %2$s is the frequency of the donation. Inludes embedded HTML tags for styling.', + 'newspack-blocks' + ), + '

' . $currency_symbol . $amount . '

', + '' . self::get_frequency_label( $frequency, $hide_once_label ) . '' + ); + + return $formatted_amount; + } + /** * Get configuration, based on block attributes and global settings. * diff --git a/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-frequency-based.php b/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-frequency-based.php index e9e3aa461..ab60d4a27 100644 --- a/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-frequency-based.php +++ b/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-frequency-based.php @@ -180,7 +180,7 @@ class='donate-label' class='tier-select-label tier-label' for='newspack--untiered-input' > - +
diff --git a/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-tiers-based.php b/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-tiers-based.php index 1c9d3695d..5bbc68cfa 100644 --- a/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-tiers-based.php +++ b/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-tiers-based.php @@ -61,8 +61,7 @@ private static function render_single_tier( $attributes, $index, $amount, $selec data-amount="" data-tier-index="" > -

- + diff --git a/src/blocks/donate/styles/view.scss b/src/blocks/donate/styles/view.scss index 15128d607..1927a52f3 100644 --- a/src/blocks/donate/styles/view.scss +++ b/src/blocks/donate/styles/view.scss @@ -19,6 +19,19 @@ } } + &__tiers { + &__amount { + margin-bottom: 16px; + &__number { + display: inline; + font-size: 29px; + } + &__frequency { + font-size: 13px; + } + } + } + mark { background-color: transparent; } diff --git a/src/blocks/donate/utils.ts b/src/blocks/donate/utils.ts index f2ad326c0..83c76d128 100644 --- a/src/blocks/donate/utils.ts +++ b/src/blocks/donate/utils.ts @@ -1,3 +1,4 @@ +import { __, _x, sprintf } from '@wordpress/i18n'; import type { DonationFrequencySlug } from './types'; const hexToRGB = ( hex: string ): number[] => { @@ -48,3 +49,37 @@ export const getMigratedAmount = ( untieredAmount * multiplier, ]; }; + +export const getFrequencyLabel = ( + currencySymbol: string, + amount: string, + frequencySlug: DonationFrequencySlug +) => { + let frequencyLabel = ''; + switch ( frequencySlug ) { + case 'once': + frequencyLabel = __( 'once', 'newspack-blocks' ); + break; + case 'month': + frequencyLabel = __( 'per month', 'newspack-blocks' ); + break; + case 'year': + frequencyLabel = __( 'per year', 'newspack-blocks' ); + break; + } + + /* + * Translators: This formatted HTML string displays the amount and frequency of a donation. The relative order may depend on the language being translated to. + * Example string:

$100

+ * per month + */ + return sprintf( + _x( + '%1$s %2$s', + '%1$s is the amount (with currency symbol). %2$s is the frequency of the donation. Inludes embedded HTML tags for styling.', + 'newspack-blocks' + ), + `

${ currencySymbol }${ amount }

`, + `${ frequencyLabel }` + ); +};