-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display the help text in the TextareaArray setting #62
Changes from 2 commits
69408f4
9176d61
dbfdfac
e0c1fc5
4af23d4
a344c51
5e84929
81c1820
66452fe
f1c4aff
67ae09b
236e885
19632aa
7cb75db
5028610
5492839
abd6979
4a8b58a
094953f
ce7d120
a538af9
96156f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
*/ | ||
import * as React from 'react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
@@ -11,7 +16,7 @@ import { convertSettingsStringToArray, convertSettingsArrayToString } from '../. | |
/** | ||
* @typedef {Object} TextareaArrayProps The component props. | ||
* @property {Function} handleOnChange Handles a change in this setting. | ||
* @property {Object} setting This setting. | ||
* @property {import('../editor').Setting} setting This setting. | ||
* @property {Array|undefined} value The setting value. | ||
*/ | ||
|
||
|
@@ -25,6 +30,7 @@ const TextareaArray = ( { handleOnChange, setting, value } ) => { | |
const id = `setting-textarea-array-${ setting.name }`; | ||
const stringValue = convertSettingsArrayToString( value ); | ||
const textAreaValue = undefined === stringValue ? setting.default : stringValue; | ||
const helpClass = 'block italic text-xs mt-1'; | ||
|
||
return ( | ||
<> | ||
|
@@ -40,6 +46,28 @@ const TextareaArray = ( { handleOnChange, setting, value } ) => { | |
} } | ||
value={ textAreaValue } | ||
/> | ||
{ Boolean( setting.help ) | ||
? ( | ||
<p className={ helpClass }> | ||
{ setting.help } | ||
</p> | ||
) : ( | ||
<> | ||
<p className={ helpClass }> | ||
{ __( | ||
'Each choice on a new line. To specify the value and label separately, use this format:', | ||
'genesis-custom-blocks' | ||
) } | ||
</p> | ||
<p className={ helpClass }> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before, this help text was in So instead of doing |
||
foo : Foo | ||
</p> | ||
<p className={ helpClass }> | ||
bar : Bar | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentionally not translated |
||
</p> | ||
</> | ||
) | ||
} | ||
</> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,13 +53,7 @@ public function register_settings() { | |
'label' => __( 'Choices', 'genesis-custom-blocks' ), | ||
'type' => 'textarea_array', | ||
'default' => '', | ||
'help' => sprintf( | ||
'%s %s<br />%s<br />%s', | ||
__( 'Enter each choice on a new line.', 'genesis-custom-blocks' ), | ||
__( 'To specify the value and label separately, use this format:', 'genesis-custom-blocks' ), | ||
_x( 'foo : Foo', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' ), | ||
_x( 'bar : Bar', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' ) | ||
), | ||
'help' => '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now in the React file. This is |
||
'sanitize' => [ $this, 'sanitize_textarea_assoc_array' ], | ||
] | ||
); | ||
|
@@ -69,7 +63,7 @@ public function register_settings() { | |
'label' => __( 'Default Value', 'genesis-custom-blocks' ), | ||
'type' => 'textarea_array', | ||
'default' => '', | ||
'help' => __( 'Enter each default value on a new line.', 'genesis-custom-blocks' ), | ||
'help' => __( 'Each default value on a new line.', 'genesis-custom-blocks' ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be similar to the other text. I removed this word from the other text to display on 2 lines instead of 3. |
||
'sanitize' => [ $this, 'sanitize_textarea_array' ], | ||
'validate' => [ $this, 'validate_options' ], | ||
] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, but noticed I forgot to give
Setting
a@typedef
before.