generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: made a new password input component #108
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
810becd
feat(Password): made a new input password
NasgulNexus e7ea3aa
fix: deleted unnecessary files
NasgulNexus f69fd7f
fix: delete lodash
NasgulNexus 77b7def
fix: add stories WithGenerateRandomValueTemplate
NasgulNexus 9f89baa
fix: added browser default to ignore
NasgulNexus 110608c
fix: correct remarks
NasgulNexus 868a5ac
fix: corrected comments
NasgulNexus 7603a3d
fix: name helpers function
NasgulNexus 5c5959d
fix: fix spread control props
NasgulNexus a8098e4
Merge branch 'main' into password
NasgulNexus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@use '../variables'; | ||
|
||
$block: '.#{variables.$ns}password'; | ||
|
||
#{$block} { | ||
display: flex; | ||
|
||
&__button { | ||
--yc-button-background-color-hover: transparent; | ||
} | ||
} |
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,66 @@ | ||
import React from 'react'; | ||
|
||
import {Copy, CopyCheck, Eye, EyeSlash} from '@gravity-ui/icons'; | ||
import { | ||
Button, | ||
CopyToClipboard, | ||
CopyToClipboardStatus, | ||
Icon, | ||
TextInput, | ||
TextInputProps, | ||
} from '@gravity-ui/uikit'; | ||
import _ from 'lodash'; | ||
|
||
import {block} from '../utils/cn'; | ||
|
||
import './Password.scss'; | ||
|
||
const b = block('password'); | ||
|
||
export type PasswordProps = Required<Pick<TextInputProps, 'onUpdate' | 'value'>> & | ||
Omit<TextInputProps, 'rightContent' | 'type'> & { | ||
amje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
showCopyButton?: boolean; | ||
amje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export const Password: React.FC<PasswordProps> = (props) => { | ||
amje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const {autoComplete, value, showCopyButton} = props; | ||
|
||
const [hideValue, setHideValue] = React.useState(true); | ||
|
||
const additionalRightContent = React.useMemo(() => { | ||
const onClick = () => { | ||
setHideValue((hideValue) => !hideValue); | ||
}; | ||
|
||
return ( | ||
<div className={b()}> | ||
amje marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{value && showCopyButton ? ( | ||
<CopyToClipboard text={String(value)} timeout={500}> | ||
{(state) => ( | ||
<Button view="flat-secondary" className={b('button')} size="s"> | ||
<Icon | ||
size={14} | ||
data={ | ||
state === CopyToClipboardStatus.Pending ? Copy : CopyCheck | ||
} | ||
/> | ||
</Button> | ||
)} | ||
</CopyToClipboard> | ||
) : null} | ||
<Button view="flat-secondary" onClick={onClick} className={b('button')} size="s"> | ||
<Icon data={hideValue ? Eye : EyeSlash} size={14} /> | ||
</Button> | ||
</div> | ||
); | ||
}, [hideValue, value, showCopyButton]); | ||
|
||
return ( | ||
<TextInput | ||
{...props} | ||
type={hideValue ? 'password' : 'text'} | ||
rightContent={additionalRightContent} | ||
autoComplete={autoComplete ? autoComplete : 'new-password'} | ||
/> | ||
); | ||
}; |
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,26 @@ | ||
## Password | ||
|
||
Password display component | ||
|
||
### PropTypes | ||
|
||
Same as [TextInput component](https://github.com/gravity-ui/uikit/blob/main/src/components/controls/TextInput/README.md), with some exceptions: | ||
|
||
- `value` is required property; | ||
- `onUpdate` is required property; | ||
- `rightContent` is omitted; | ||
- `type` is omitted; | ||
|
||
| Property | Type | Required | Description | | ||
| :------------- | :-------- | :------- | :--------------- | | ||
| showCopyButton | `boolean` | | show copy button | | ||
|
||
#### Usage example | ||
|
||
```jsx harmony | ||
function MyComponent() { | ||
const [value, setValue] = React.useState(''); | ||
|
||
return <Password showCopyButton={true} onUpdate={setValue} value={value} />; | ||
} | ||
``` |
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,18 @@ | ||
import React from 'react'; | ||
|
||
import type {Meta, StoryFn} from '@storybook/react'; | ||
|
||
import {Password} from '../Password'; | ||
|
||
export default { | ||
title: 'Components/Password', | ||
component: Password, | ||
} as Meta; | ||
|
||
const DefaultTemplate: StoryFn<React.ComponentProps<typeof Password>> = () => { | ||
const [value, setValue] = React.useState(''); | ||
|
||
return <Password showCopyButton={true} onUpdate={setValue} value={value} />; | ||
}; | ||
|
||
export const Default = DefaultTemplate.bind({}); |
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 @@ | ||
export * from './Password'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
зачем тут lodash?