Skip to content

Commit

Permalink
InputControl: added password visibility story (#60898)
Browse files Browse the repository at this point in the history
* Added story

* Misc. UX and a11y improvements

* Add changelog

* Address review comments.

* Reposition changelog

---------

Co-authored-by: DaniGuardiola <[email protected]>
Co-authored-by: mirka <[email protected]>
Co-authored-by: jasmussen <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
5 people authored Apr 23, 2024
1 parent 425c5c0 commit c627fac
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Enhancements

- `InputControl`: Add a password visibility toggle story ([#60898](https://github.com/WordPress/gutenberg/pull/60898)).
- `BoxControl`: Allow negative values for margin controls ([#60347](https://github.com/WordPress/gutenberg/pull/60347)).

### Bug Fix
Expand Down
32 changes: 31 additions & 1 deletion packages/components/src/input-control/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
* External dependencies
*/
import type { Meta, StoryFn } from '@storybook/react';

/**
* WordPress dependencies
*/
import { seen, unseen } from '@wordpress/icons';
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import InputControl from '..';
import { InputControlPrefixWrapper } from '../input-prefix-wrapper';
import { InputControlSuffixWrapper } from '../input-suffix-wrapper';
import Button from '../../button';

const meta: Meta< typeof InputControl > = {
title: 'Components (Experimental)/InputControl',
Expand Down Expand Up @@ -82,3 +87,28 @@ WithEdgeLabel.args = {
__unstableInputWidth: '20em',
labelPosition: 'edge',
};

export const ShowPassword: StoryFn< typeof InputControl > = ( args ) => {
const [ visible, setVisible ] = useState( false );
return (
<InputControl
type={ visible ? 'text' : 'password' }
label="Password"
suffix={
<InputControlSuffixWrapper>
<div style={ { display: 'flex' } }>
<Button
size="small"
icon={ visible ? unseen : seen }
onClick={ () => setVisible( ( value ) => ! value ) }
label={
visible ? 'Hide password' : 'Show password'
}
/>
</div>
</InputControlSuffixWrapper>
}
{ ...args }
/>
);
};

0 comments on commit c627fac

Please sign in to comment.