-
Notifications
You must be signed in to change notification settings - Fork 2
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: Add PasswordInput and PasswordHiddenText components #75
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions
7
packages/module/patternfly-docs/content/examples/PasswordInput/PasswordHiddenTextExample.tsx
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,7 @@ | ||
import React from 'react'; | ||
import { PasswordHiddenText } from "@patternfly/ai-infra-ui-components"; | ||
|
||
|
||
export const PasswordHiddenTextExample: React.FunctionComponent = () => ( | ||
<PasswordHiddenText password="Password123!"/> | ||
); |
29 changes: 29 additions & 0 deletions
29
packages/module/patternfly-docs/content/examples/PasswordInput/PasswordInput.md
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,29 @@ | ||
--- | ||
# Sidenav top-level section | ||
# should be the same for all markdown files | ||
section: AI-infra-ui-components | ||
# Sidenav secondary level section | ||
# should be the same for all markdown files | ||
id: PasswordInput | ||
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility) | ||
source: react | ||
# If you use typescript, the name of the interface to display props for | ||
# These are found through the sourceProps function provided in patternfly-docs.source.js | ||
propComponents: ['PasswordInput, PasswordHiddenText'] | ||
--- | ||
|
||
import { PasswordInput, PasswordHiddenText } from "@patternfly/ai-infra-ui-components"; | ||
|
||
Note: this component documents the API and enhances the [existing PasswordInput](https://github.com/opendatahub-io/odh-dashboard/blob/main/frontend/src/components/PasswordInput.tsx) component and [existing PasswordHiddenText](https://github.com/opendatahub-io/odh-dashboard/blob/main/frontend/src/components/PasswordHiddenText.tsx) component from odh-dashboard. It can be imported from [@patternfly/ai-infra-ui-components](https://www.npmjs.com/package/@patternfly/AI-infra-ui-components). Alternatively, it can be used within the odh-dashboard via the import: `~/components/PasswordInput`. | ||
|
||
### Password input example | ||
|
||
```js file="./PasswordInputExample.tsx" | ||
|
||
``` | ||
|
||
### Password hidden text example | ||
|
||
```js file="./PasswordHiddenTextExample.tsx" | ||
|
||
``` |
7 changes: 7 additions & 0 deletions
7
packages/module/patternfly-docs/content/examples/PasswordInput/PasswordInputExample.tsx
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,7 @@ | ||
import React from 'react'; | ||
import { PasswordInput } from "@patternfly/ai-infra-ui-components"; | ||
|
||
|
||
export const PasswordInputExample: React.FunctionComponent = () => ( | ||
<PasswordInput value="Password123!" /> | ||
); |
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,43 @@ | ||
import { Button, Flex, FlexItem, Content } from '@patternfly/react-core'; | ||
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons'; | ||
import React from 'react'; | ||
|
||
export type PasswordHiddenTextProps = { | ||
/** Read only password text to display */ | ||
password: string; | ||
/** Test id to pass to the view password toggle button */ | ||
testId: string; | ||
}; | ||
|
||
export const PasswordHiddenText: React.FunctionComponent<PasswordHiddenTextProps> = ({ | ||
password, | ||
testId | ||
}: PasswordHiddenTextProps) => { | ||
const [isHidden, setIsHidden] = React.useState(true); | ||
|
||
const passwordText = isHidden ? Array(password.length).fill('\u25CF').join('') : password; | ||
|
||
return ( | ||
<Flex | ||
spaceItems={{ default: 'spaceItemsNone' }} | ||
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. Can this be |
||
spacer={{ default: 'spacerNone' }} | ||
alignItems={{ default: 'alignItemsCenter' }} | ||
flexWrap={{ default: 'nowrap' }} | ||
> | ||
<FlexItem> | ||
<Content>{passwordText}</Content> | ||
</FlexItem> | ||
<FlexItem> | ||
<Button | ||
variant="plain" | ||
onClick={() => setIsHidden(!isHidden)} | ||
data-testid={testId} | ||
> | ||
{isHidden ? <EyeSlashIcon /> : <EyeIcon />} | ||
</Button> | ||
</FlexItem> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default PasswordHiddenText; |
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,37 @@ | ||
import * as React from 'react'; | ||
import { Button, InputGroup, TextInput, TextInputProps, InputGroupItem } from '@patternfly/react-core'; | ||
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons'; | ||
|
||
export type PasswordInputProps = TextInputProps & { | ||
/** Aria label to display on the view password toggle while the password is hidden */ | ||
ariaLabelShow?: string; | ||
/** Aria label to display on the view password toggle while the password is visible */ | ||
ariaLabelHide?: string; | ||
}; | ||
|
||
export const PasswordInput: React.FunctionComponent<PasswordInputProps> = ({ | ||
ariaLabelShow = 'Show password', | ||
ariaLabelHide = 'Hide password', | ||
...props | ||
}: PasswordInputProps) => { | ||
const [isPasswordHidden, setPasswordHidden] = React.useState(true); | ||
|
||
return ( | ||
<InputGroup> | ||
<InputGroupItem isFill> | ||
<TextInput {...props} type={isPasswordHidden ? 'password' : 'text'} /> | ||
</InputGroupItem> | ||
<InputGroupItem> | ||
<Button | ||
aria-label={isPasswordHidden ? ariaLabelShow : ariaLabelHide} | ||
variant="control" | ||
onClick={() => setPasswordHidden(!isPasswordHidden)} | ||
> | ||
{isPasswordHidden ? <EyeSlashIcon /> : <EyeIcon />} | ||
</Button> | ||
</InputGroupItem> | ||
</InputGroup> | ||
); | ||
}; | ||
|
||
export default PasswordInput; |
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,2 @@ | ||
export * from './PasswordInput'; | ||
export * from './PasswordHiddenText'; |
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
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.
Maybe rewrite this to
these components document ...
and add the PasswordHiddenText import'~/components/PasswordHiddenText'
too.