Skip to content

Commit 893060c

Browse files
minor tweaks + fix error when selecting default font family
1 parent a5e6f19 commit 893060c

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/components/font-pair-picker/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ const FontPairPicker = props => {
2929
}
3030

3131
// Use the font family value for styling the buttons
32-
const headingFontFamilyValue = getFontFamily( headingStyles.fontFamily ).replace( /"/g, '' ) || ''
33-
const paragraphFontFamilyValue = getFontFamily( paragraphStyles.fontFamily ).replace( /"/g, '' ) || ''
32+
const headingFontFamilyValue = getFontFamily( headingStyles.fontFamily )?.replaceAll( '"', '' ) || ''
33+
const paragraphFontFamilyValue = getFontFamily( paragraphStyles.fontFamily )?.replaceAll( '"', '' ) || ''
3434

3535
const label = (
3636
<div>
3737
<span
3838
style={ omit( { ...headingStyles, fontFamily: headingFontFamilyValue }, [ 'fontSize', 'lineHeight' ] ) }
3939
className="ugb-global-settings-font-pair__label"
4040
>
41-
{ headingStyles?.fontFamily ? getFontFamilyLabel( headingStyles.fontFamily ) : __( 'Default Heading', i18n ) }
41+
{ getFontFamilyLabel( headingStyles?.fontFamily, __( 'Default Heading', i18n ) ) }
4242
</span>
4343
<span
4444
style={ omit( { ...paragraphStyles, fontFamily: paragraphFontFamilyValue }, [ 'fontSize', 'lineHeight' ] ) }
4545
className="ugb-global-settings-font-pair__sub-label"
4646
>
47-
{ paragraphStyles?.fontFamily ? getFontFamilyLabel( paragraphStyles?.fontFamily ) : __( 'Default Body', i18n ) }
47+
{ getFontFamilyLabel( paragraphStyles?.fontFamily, __( 'Default Body', i18n ) ) }
4848
</span>
4949
</div>
5050
)

src/plugins/global-settings/typography/editor.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
.ugb-global-settings-font-pair-control {
9797
.components-base-control__field {
9898
border: 1px solid #ddd;
99-
padding: 8px;
99+
padding: 12px;
100100
margin-bottom: 8px;
101101
gap: 8px;
102102
cursor: pointer;
@@ -107,7 +107,7 @@
107107
}
108108

109109
.ugb-global-settings-font-pair__container {
110-
max-height: 250px;
110+
max-height: 270px;
111111
overflow: auto;
112112
border: 1px solid #ddd;
113113
border: none;
@@ -123,7 +123,7 @@
123123
.ugb-global-settings-font-pair__label {
124124
font-size: 1.2rem;
125125
display: block;
126-
margin-bottom: 4px;
126+
margin-bottom: 6px;
127127
line-height: 1.2;
128128
}
129129
.ugb-global-settings-font-pair__sub-label {

src/util/font.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export const isGoogleFontEnqueued = ( fontName, head = document.querySelector( '
184184
}
185185

186186
// Outputs the font family name for display purposes.
187-
export const getFontFamilyLabel = fontName => {
187+
export const getFontFamilyLabel = ( fontName, defaultLabel = '' ) => {
188188
// Modern font stacks.
189189
if ( MODERN_FONT_STACKS[ fontName ] ) {
190190
return MODERN_FONT_STACKS[ fontName ].label
@@ -195,10 +195,15 @@ export const getFontFamilyLabel = fontName => {
195195
return SYSTEM_FONT_STACKS[ fontName ].label
196196
}
197197

198-
return fontName || __( 'Default', i18n )
198+
return fontName || defaultLabel || __( 'Default', i18n )
199199
}
200200

201201
export const getFontFamily = fontName => {
202+
const defaultFontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"'
203+
if ( ! fontName ) {
204+
return defaultFontFamily
205+
}
206+
202207
// If the font is a CSS custom property, return it directly.
203208
if ( fontName.match( /^\s*var\(--/ ) ) {
204209
return fontName
@@ -219,7 +224,7 @@ export const getFontFamily = fontName => {
219224
return SYSTEM_FONT_STACKS[ fontName ].value
220225
}
221226

222-
return '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"'
227+
return defaultFontFamily
223228
}
224229

225230
/** TODO: deprecate this.

0 commit comments

Comments
 (0)