PluginProbe ʕ •ᴥ•ʔ
Timeline Blocks for Gutenberg / trunk
Timeline Blocks for Gutenberg vtrunk
timeline-blocks / src / blocks / components / typography / index.js
timeline-blocks / src / blocks / components / typography Last commit date
editor.scss 7 years ago font-typography.js 7 years ago fontloader.js 7 years ago index.js 7 years ago inline-styles.js 7 years ago
index.js
145 lines
1 /**
2 * WordPress dependencies
3 */
4 const { __ } = wp.i18n
5
6 /**
7 * Internal dependencies
8 */
9 import FontFamilyControl from "./font-typography"
10 import TypographyStyles from "./inline-styles"
11 import "./editor.scss"
12
13 const {
14 Button,
15 Dashicon
16 } = wp.components
17
18
19 // Extend component
20 const { Component, Fragment } = wp.element
21
22 // Export for ease of importing in individual blocks.
23 export {
24 TypographyStyles,
25 }
26
27 class TypographyControl extends Component {
28
29 constructor() {
30 super( ...arguments )
31 this.onAdvancedControlClick = this.onAdvancedControlClick.bind( this )
32 this.onAdvancedControlReset = this.onAdvancedControlReset.bind( this )
33 }
34
35 onAdvancedControlClick() {
36
37 let control = true
38 let label = __( "Hide Advanced" )
39
40 if( this.state !== null && this.state.showAdvancedControls === true ) {
41 control = false
42 label = __( "Advanced" )
43 }
44
45 this.setState(
46 {
47 showAdvancedControls: control,
48 showAdvancedControlsLabel: label
49 }
50 )
51 }
52
53 onAdvancedControlReset() {
54
55 const { setAttributes } = this.props
56
57 // Reset Font family to default.
58 setAttributes( { [ this.props.fontFamily.label ]: "" } )
59 setAttributes( { [ this.props.fontWeight.label ]: "" } )
60 setAttributes( { [ this.props.fontSubset.label ]: "" } )
61
62 }
63
64 render() {
65
66 let fontSize
67 let fontWeight
68 let fontFamily
69 let fontAdvancedControls
70 let showAdvancedFontControls
71 let resetFontAdvancedControls
72
73 const {
74 disableFontFamily,
75 disableFontSize,
76 disableLineHeight,
77 disableAdvancedOptions = false
78 } = this.props
79
80 if( true !== disableFontFamily ) {
81 fontFamily = (
82 <FontFamilyControl
83 { ...this.props }
84 />
85 )
86 }
87
88 if( true !== disableFontFamily && true !== disableFontSize ) {
89 fontAdvancedControls = (
90 <Button
91 className="tb-size-btn tb-typography-control-btn"
92 isSmall
93 aria-pressed={ ( this.state !== null ) }
94 onClick={ this.onAdvancedControlClick }
95 ><Dashicon icon="admin-tools" /></Button>
96 )
97
98 resetFontAdvancedControls = (
99 <Button
100 className="tb-size-btn tb-typography-reset-btn"
101 isSmall
102 aria-pressed={ ( this.state !== null ) }
103 onClick={ this.onAdvancedControlReset }
104 ><Dashicon icon="image-rotate" /></Button>
105 )
106 } else {
107 showAdvancedFontControls = (
108 <Fragment>
109 { fontFamily }
110 { fontWeight }
111 </Fragment>
112 )
113 }
114
115
116 if( this.state !== null && this.state.showAdvancedControls === true ) {
117
118 showAdvancedFontControls = (
119 <div className="tb-advanced-typography">
120 { fontFamily }
121 { fontWeight }
122 </div>
123 )
124 }
125
126 return (
127 <div className="tb-typography-options">
128 { fontSize }
129 { !disableAdvancedOptions &&
130 <Fragment>
131 <div className="tb-typography-option-actions">
132 <strong>{ __( "Advanced Typography" ) }</strong>
133 { fontAdvancedControls }
134 { resetFontAdvancedControls }
135 </div>
136 { showAdvancedFontControls }
137 </Fragment>
138 }
139 </div>
140 )
141 }
142 }
143
144 export default TypographyControl
145