Skip to content

Commit e8f2870

Browse files
committed
feat: global font pairs
1 parent b4eb246 commit e8f2870

File tree

5 files changed

+2058
-36
lines changed

5 files changed

+2058
-36
lines changed

src/global-settings.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,53 @@ public function register_global_settings() {
282282
)
283283
);
284284

285+
register_setting(
286+
'stackable_global_settings',
287+
'stackable_font_pair_name',
288+
array(
289+
'type' => 'string',
290+
'description' => __( 'Stackable global font pair', STACKABLE_I18N ),
291+
'sanitize_callback' => 'sanitize_text_field',
292+
'show_in_rest' => true,
293+
'default' => '',
294+
)
295+
);
296+
297+
register_setting(
298+
'stackable_global_settings',
299+
'stackable_custom_font_pairs',
300+
array(
301+
'type' => 'array',
302+
'description' => __( 'Stackable added custom font pairs', STACKABLE_I18N ),
303+
'sanitize_callback' => array( $this, 'sanitize_array_setting' ),
304+
'show_in_rest' => array(
305+
'schema' => array(
306+
'items' => array(
307+
'type' => 'object',
308+
'properties' => array(
309+
'name' => array(
310+
'type' => 'string',
311+
),
312+
'value' => array(
313+
'type' => 'array',
314+
'items' => array(
315+
'type' => 'object',
316+
'properties' => array(
317+
'selector' => array(
318+
'type' => 'string',
319+
),
320+
'styles' => $stackable_global_typography_schema
321+
),
322+
),
323+
),
324+
)
325+
)
326+
)
327+
),
328+
'default' => '',
329+
)
330+
);
331+
285332
register_setting(
286333
'stackable_global_settings',
287334
'stackable_icon_library',

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,57 @@
7272
overflow: hidden;
7373
white-space: nowrap;
7474
}
75+
76+
.ugb-global-settings-font-pair__heading {
77+
display: flex;
78+
flex-direction: row;
79+
justify-content: space-between;
80+
align-items: center;
81+
margin-bottom: 4px;
82+
h3 {
83+
margin: 0;
84+
}
85+
}
86+
87+
.ugb-global-settings-font-pair-control {
88+
.components-base-control__field {
89+
border: 1px solid #ddd;
90+
padding: 8px;
91+
margin-bottom: 8px;
92+
cursor: pointer;
93+
.ugb-base-control-multi-label {
94+
margin-bottom: 0px;
95+
}
96+
}
97+
}
98+
99+
.ugb-global-settings-font-pair__container {
100+
width: calc(100% - 32px);
101+
margin: 0 16px;
102+
max-height: 310px;
103+
overflow: auto;
104+
border: 1px solid #ddd;
105+
padding: 8px;
106+
.ugb-global-settings-font-pair__selected {
107+
.components-base-control__field {
108+
border: 2px solid #000;
109+
}
110+
}
111+
.ugb-global-settings-font-pair__label {
112+
font-size: 1.2rem;
113+
display: block;
114+
margin-bottom: 4px;
115+
line-height: 1.2;
116+
}
117+
.ugb-global-settings-font-pair__sub-label {
118+
font-size: 1rem;
119+
display: block;
120+
line-height: 1;
121+
}
122+
}
123+
124+
.ugb-global-typography__panel {
125+
.stk-inspector-sub-header {
126+
margin-bottom: 16px;
127+
}
128+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
import { BaseControl, Button } from '~stackable/components'
5+
6+
/**
7+
* External dependencies
8+
*/
9+
import { i18n } from 'stackable'
10+
import classnames from 'classnames'
11+
12+
/**
13+
* WordPress dependencies
14+
*/
15+
import { __ } from '@wordpress/i18n'
16+
17+
const FontPairPicker = props => {
18+
const mainClasses = classnames( [
19+
props.className,
20+
'ugb-button-icon-control',
21+
'ugb-global-settings-font-pair-control',
22+
] )
23+
24+
return (
25+
<div onClick={ props.onClick } ref={ props?.ref } role="button" tabIndex={ 0 } onKeyDown={ event => {
26+
if ( event.key === 'Enter' || event.key === 'Space' ) {
27+
props.onClick()
28+
event.preventDefault()
29+
}
30+
} } >
31+
<BaseControl
32+
key={ props.key }
33+
label={ props.label }
34+
className={ mainClasses }
35+
>
36+
{ props?.isCustom &&
37+
<div className="ugb-button-icon-control__wrapper">
38+
<Button
39+
className="ugb-button-icon-control__edit"
40+
label={ __( 'Edit', i18n ) }
41+
icon="edit"
42+
onClick={ event => {
43+
props.onEdit()
44+
event.stopPropagation()
45+
} }
46+
/>
47+
</div>
48+
}
49+
</BaseControl>
50+
</div>
51+
)
52+
}
53+
54+
FontPairPicker.defaultProps = {
55+
label: '',
56+
classname: '',
57+
onClick: () => {},
58+
onEdit: () => {},
59+
}
60+
61+
export default FontPairPicker

0 commit comments

Comments
 (0)