Skip to content

Commit 2b1e944

Browse files
committed
feat: separate pro features
1 parent 0d452f4 commit 2b1e944

File tree

3 files changed

+61
-56
lines changed

3 files changed

+61
-56
lines changed

src/plugins/global-settings/typography/font-pair-picker.js renamed to src/components/font-pair-picker/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const FontPairPicker = props => {
6161
label={ label }
6262
className={ classes }
6363
>
64-
{ props.fontPair?.isCustom &&
64+
{ props?.isCustom &&
6565
<div className="ugb-button-icon-control__wrapper">
6666
<Button
6767
className="ugb-button-icon-control__edit"

src/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,4 @@ export { default as HelpTooltip } from './help-tooltip'
117117
export { default as RichText } from './rich-text'
118118
export { default as SortablePicker } from './sortable-picker'
119119
export { default as InspectorSubHeader } from './inspector-sub-header'
120+
export { default as FontPairPicker } from './font-pair-picker'

src/plugins/global-settings/typography/index.js

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@ import { GlobalTypographyStyles } from './editor-loader'
55
import TypographyPicker from './typography-picker'
66
import { getThemeStyles } from './get-theme-styles'
77
import FONT_PAIRS from './font-pairs.json'
8-
import FontPairPicker from './font-pair-picker'
98

109
/**
1110
* External dependencies
1211
*/
1312
import {
14-
PanelAdvancedSettings, AdvancedSelectControl, ControlSeparator, InspectorSubHeader, Button,
13+
PanelAdvancedSettings, AdvancedSelectControl, ControlSeparator, FontPairPicker, ProControl,
1514
} from '~stackable/components'
1615
import { fetchSettings } from '~stackable/util'
17-
import { i18n } from 'stackable'
16+
import { i18n, isPro } from 'stackable'
1817
import { omit, head } from 'lodash'
1918

2019
/**
2120
* WordPress dependencies
2221
*/
2322
import {
24-
Fragment, useEffect, useMemo, useRef, useState,
23+
Fragment, useEffect, useRef, useState,
2524
} from '@wordpress/element'
2625
import { models } from '@wordpress/api'
27-
import { addFilter, doAction } from '@wordpress/hooks'
26+
import {
27+
addFilter, applyFilters, doAction,
28+
} from '@wordpress/hooks'
2829
import { __, sprintf } from '@wordpress/i18n'
2930

3031
export { GlobalTypographyStyles }
@@ -110,15 +111,6 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
110111
}
111112
}, [ isPanelOpen ] )
112113

113-
const allFontPairs = useMemo( () => [
114-
FONT_PAIRS[ 0 ],
115-
...customFontPairs.map( fontPair => ( {
116-
...fontPair,
117-
isCustom: true,
118-
} ) ),
119-
...FONT_PAIRS.slice( 1 ),
120-
], [ customFontPairs ] )
121-
122114
const updateTypography = newSettings => {
123115
setTypographySettings( newSettings )
124116

@@ -205,29 +197,10 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
205197
model.save()
206198
}
207199

208-
const addFontPair = () => {
209-
const newFontPair = {
210-
...allFontPairs.find( fontPair => fontPair.name === selectedFontPairName ),
211-
name: `custom-${ Math.floor( Math.random() * new Date().getTime() ) % 100000 }`,
212-
}
213-
214-
setEditingFontPairName( newFontPair.name )
215-
updateSelectedFontPair( newFontPair.name )
216-
updateCustomFontPairs( [ newFontPair, ...customFontPairs ] )
217-
}
218-
219-
const deleteFontPair = name => {
220-
// eslint-disable-next-line no-alert
221-
const confirmDelete = window.confirm( __( 'Are you sure you want to delete this font pair?', i18n ) )
222-
if ( ! confirmDelete ) {
223-
return
224-
}
225-
const updatedCustomFontPairs = customFontPairs.filter( fontPair => fontPair.name !== name )
226-
227-
setEditingFontPairName( '' )
228-
updateSelectedFontPair( '' )
229-
updateCustomFontPairs( updatedCustomFontPairs )
230-
}
200+
const CustomFontPairPickers = applyFilters(
201+
'stackable.global-settings.typography.font-pairs.customPicker',
202+
Fragment,
203+
)
231204

232205
return (
233206
<Fragment>
@@ -263,15 +236,45 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
263236

264237
<div className="ugb-global-settings-font-pair__heading">
265238
<h3>Preset Font Pairs</h3>
266-
<Button
267-
className="ugb-global-settings-color-picker__add-button"
268-
onClick={ addFontPair }
269-
icon="plus-alt2"
270-
/>
239+
{ isPro && applyFilters(
240+
'stackable.global-settings.typography.font-pairs.addFontPair',
241+
[ ...FONT_PAIRS, ...customFontPairs ],
242+
selectedFontPairName,
243+
newFontPair => {
244+
setEditingFontPairName( newFontPair.name )
245+
updateSelectedFontPair( newFontPair.name )
246+
updateCustomFontPairs( [ newFontPair, ...customFontPairs ] )
247+
}
248+
) }
271249
</div>
272250

273251
<div className="ugb-global-settings-font-pair__container" ref={ fontPairContainerRef }>
274-
{ allFontPairs.map( fontPair => {
252+
{ /* Theme Default */ }
253+
<FontPairPicker
254+
key={ FONT_PAIRS[ 0 ].name }
255+
fontPair={ FONT_PAIRS[ 0 ] }
256+
isSelected={ selectedFontPairName === FONT_PAIRS[ 0 ].name }
257+
onClick={ () => {
258+
updateSelectedFontPair( FONT_PAIRS[ 0 ].name )
259+
changeStyles( FONT_PAIRS[ 0 ].typography )
260+
} }
261+
/>
262+
{ /* Custom Font Pairs */ }
263+
<CustomFontPairPickers
264+
customFontPairs={ customFontPairs }
265+
selected={ selectedFontPairName }
266+
onClick={ ( name, typography ) => {
267+
updateSelectedFontPair( name )
268+
changeStyles( typography )
269+
} }
270+
onEdit={ ( name, typography ) => {
271+
setEditingFontPairName( name )
272+
updateSelectedFontPair( name )
273+
changeStyles( typography )
274+
} }
275+
/>
276+
{ /* Font Pair Presets */ }
277+
{ FONT_PAIRS.slice( 1 ).map( fontPair => {
275278
return <FontPairPicker
276279
key={ fontPair.name }
277280
fontPair={ fontPair }
@@ -280,24 +283,25 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
280283
updateSelectedFontPair( fontPair.name )
281284
changeStyles( fontPair.typography )
282285
} }
283-
onEdit={ () => {
284-
setEditingFontPairName( fontPair.name )
285-
updateSelectedFontPair( fontPair.name )
286-
changeStyles( fontPair.typography )
287-
} }
288286
/>
289287
} ) }
290288
</div>
291-
289+
{ ! isPro && <ProControl type="global-font-pairs" title="Creating and editing Custom Font Pairs are premium features" /> }
292290
<ControlSeparator />
293291
</div>
294292
}
295-
{ editingFontPairName &&
296-
<InspectorSubHeader
297-
title="Editing Font Pair"
298-
onBack={ () => setEditingFontPairName( '' ) }
299-
onTrash={ () => deleteFontPair( editingFontPairName ) }
300-
/>
293+
{ isPro && editingFontPairName &&
294+
applyFilters(
295+
'stackable.global-settings.typography.font-pairs.inspector-sub-header',
296+
customFontPairs,
297+
editingFontPairName,
298+
() => setEditingFontPairName( '' ),
299+
updatedCustomFontPairs => {
300+
setEditingFontPairName( '' )
301+
updateSelectedFontPair( '' )
302+
updateCustomFontPairs( updatedCustomFontPairs )
303+
}
304+
)
301305
}
302306

303307
<h3>Typography Settings</h3>

0 commit comments

Comments
 (0)