forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QuickEdit: Add password field to the pages quick edit (WordPress#66567)
Co-authored-by: louwie17 <[email protected]> Co-authored-by: jameskoster <[email protected]> Co-authored-by: oandregal <[email protected]>
- Loading branch information
1 parent
66c541e
commit 3d88e31
Showing
8 changed files
with
154 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
CheckboxControl, | ||
__experimentalVStack as VStack, | ||
TextControl, | ||
} from '@wordpress/components'; | ||
import type { DataFormControlProps } from '@wordpress/dataviews'; | ||
import { useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { BasePost } from '../../types'; | ||
|
||
function PasswordEdit( { | ||
data, | ||
onChange, | ||
field, | ||
}: DataFormControlProps< BasePost > ) { | ||
const [ showPassword, setShowPassword ] = useState( | ||
!! field.getValue( { item: data } ) | ||
); | ||
|
||
const handleTogglePassword = ( value: boolean ) => { | ||
setShowPassword( value ); | ||
if ( ! value ) { | ||
onChange( { password: '' } ); | ||
} | ||
}; | ||
|
||
return ( | ||
<VStack | ||
as="fieldset" | ||
spacing={ 4 } | ||
className="fields-controls__password" | ||
> | ||
<CheckboxControl | ||
__nextHasNoMarginBottom | ||
label={ __( 'Password protected' ) } | ||
help={ __( 'Only visible to those who know the password' ) } | ||
checked={ showPassword } | ||
onChange={ handleTogglePassword } | ||
/> | ||
{ showPassword && ( | ||
<div className="fields-controls__password-input"> | ||
<TextControl | ||
label={ __( 'Password' ) } | ||
onChange={ ( value ) => | ||
onChange( { | ||
password: value, | ||
} ) | ||
} | ||
value={ field.getValue( { item: data } ) || '' } | ||
placeholder={ __( 'Use a secure password' ) } | ||
type="text" | ||
__next40pxDefaultSize | ||
__nextHasNoMarginBottom | ||
maxLength={ 255 } | ||
/> | ||
</div> | ||
) } | ||
</VStack> | ||
); | ||
} | ||
export default PasswordEdit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import type { Field } from '@wordpress/dataviews'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { BasePost } from '../../types'; | ||
import PasswordEdit from './edit'; | ||
|
||
const passwordField: Field< BasePost > = { | ||
id: 'password', | ||
type: 'text', | ||
getValue: ( { item } ) => item.password, | ||
Edit: PasswordEdit, | ||
enableSorting: false, | ||
enableHiding: false, | ||
isVisible: ( item ) => item.status !== 'private', | ||
}; | ||
|
||
/** | ||
* This field is used to display the post password. | ||
*/ | ||
export default passwordField; |