Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/design-system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ export { ToastBar } from './toast-bar';
export * from './tooltip';
export { Message } from './message';
export { Metadata, MetadataLink } from './metadata';
export { PasswordBox, UncontrolledPasswordBox } from './password-box';
export { PasswordBox } from './password-box';
export type {
UncontrolledPasswordBoxProps,
PasswordBoxProps,
OnPasswordChange,
Password,
Expand Down
4 changes: 1 addition & 3 deletions src/design-system/password-box/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export { PasswordBox } from './password-box.component';
export type { PasswordBoxProps } from './password-box.component';
export { UncontrolledPasswordBox } from './uncontrolled-password-box.component';
export type { UncontrolledPasswordBoxProps } from './uncontrolled-password-box.component';
export type {
OnPasswordChange,
Password,
} from './uncontrolled-password-box-input.component';
} from './password-box-input.component';
38 changes: 29 additions & 9 deletions src/design-system/password-box/password-box-input.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ import { Text } from '../text';
import { PasswordInputButton } from './password-box-button.component';
import * as cx from './password-box-input.css';

export interface PasswordInputProps extends Form.FormControlProps {
export type Password = {
input: HTMLInputElement;
// TODO: convert this to UInt8Array
value: string;
};

export type OnPasswordChange = (event: Readonly<Password>) => void;

export interface PasswordInputProps
extends Omit<Form.FormControlProps, 'value' | 'onChange'> {
required?: boolean;
disabled?: boolean;
id?: string;
label: string;
name?: string;
value: string;
errorMessage?: string;
onChange?: (event: Readonly<React.ChangeEvent<HTMLInputElement>>) => void;
onChange: OnPasswordChange;
defaultIsPasswordVisible?: boolean;
containerClassName?: string;
containerStyle?: React.CSSProperties;
Expand All @@ -30,10 +38,10 @@ export const PasswordInput = ({
id,
label,
name,
value,
errorMessage = '',
containerClassName = '',
onChange,
autoFocus,
defaultIsPasswordVisible = false,
containerStyle,
testId,
Expand All @@ -42,8 +50,11 @@ export const PasswordInput = ({
defaultIsPasswordVisible,
);

const onChangeHandler: React.ChangeEventHandler<HTMLInputElement> = event =>
onChange({ input: event.target, value: event.target.value });

return (
<div className={cx.root}>
<div className={cx.root} data-testid={testId && `${testId}-container`}>
<Form.Field
name="field"
className={cn(cx.container, {
Expand All @@ -58,11 +69,11 @@ export const PasswordInput = ({
type={isPasswordVisible ? 'text' : 'password'}
required={required}
placeholder=""
autoFocus={autoFocus}
className={cn(cx.input, { [cx.largeDots]: !isPasswordVisible })}
disabled={disabled}
name={name}
value={value}
onChange={onChange}
onChange={onChangeHandler}
id={id}
data-testid={testId}
/>
Expand All @@ -73,7 +84,12 @@ export const PasswordInput = ({
{label}
</Form.Label>
<PasswordInputButton
testId={testId && `${testId}-toggle`}
testId={
testId &&
(isPasswordVisible
? `${testId}-hide-icon`
: `${testId}-show-icon`)
}
onClick={(event): void => {
event.preventDefault();
setIsPasswordVisible(!isPasswordVisible);
Expand All @@ -84,7 +100,11 @@ export const PasswordInput = ({
</Flex>
</Form.Field>
{errorMessage && (
<Text.Label color="error" className={cx.errorMessage}>
<Text.Label
color="error"
className={cx.errorMessage}
data-testid={testId && `${testId}-error`}
>
{errorMessage}
</Text.Label>
)}
Expand Down
34 changes: 16 additions & 18 deletions src/design-system/password-box/password-box.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';

Check warning on line 1 in src/design-system/password-box/password-box.stories.tsx

View workflow job for this annotation

GitHub Actions / Verify

'useState' is defined but never used

import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
Expand Down Expand Up @@ -29,15 +29,17 @@
<Variants.Row>
<Variants.Cell>
<PasswordBox
value="Input Text"
placeholder="Input Text"
label="Password"
onChange={v => console.log(v.value)}
defaultIsPasswordVisible
onSubmit={action('onSubmit')}
/>
</Variants.Cell>
<Variants.Cell>
<PasswordBox
value="Input Text"
onChange={v => console.log(v.value)}
placeholder="Input Text"
label="Password"
onSubmit={action('onSubmit')}
/>
Expand All @@ -49,11 +51,10 @@

const PasswordBoxComponent = ({
label = 'Password',
value = '',
...props
}: Readonly<Partial<PasswordBoxProps>>): JSX.Element => (
<PasswordBox
value={value}
onChange={v => console.log(v.value)}
label={label}
rootStyle={{ width: '200px' }}
onSubmit={action('onSubmit')}
Expand Down Expand Up @@ -85,12 +86,15 @@
<HoverPasswordBoxComponent />
</Variants.Cell>
<Variants.Cell>
<PasswordBoxComponent value="Input Text" defaultIsPasswordVisible />
<PasswordBoxComponent
placeholder="Input Text"
defaultIsPasswordVisible
/>
</Variants.Cell>
<Variants.Cell>
<PasswordBox
<PasswordBoxComponent
label="Password"
value="Input Text"
placeholder="Input Text"
defaultIsPasswordVisible
errorMessage="Error"
rootStyle={{ width: '200px' }}
Expand All @@ -106,18 +110,18 @@
</Variants.Row>
<Variants.Row>
<Variants.Cell>
<PasswordBoxComponent value="" />
<PasswordBoxComponent placeholder="" />
</Variants.Cell>
<Variants.Cell>
<HoverPasswordBoxComponent />
</Variants.Cell>
<Variants.Cell>
<PasswordBoxComponent value="Input Text" />
<PasswordBoxComponent placeholder="Input Text" />
</Variants.Cell>
<Variants.Cell>
<PasswordBox
<PasswordBoxComponent
label="Password"
value="Input Text"
placeholder="Input Text"
defaultIsPasswordVisible
errorMessage="Error"
rootStyle={{ width: '200px', marginTop: '20px' }}
Expand All @@ -135,19 +139,13 @@
);

export const Overview = (): JSX.Element => {
const [value, setValue] = useState('');

return (
<Grid>
<Cell>
<Section title="Copy for use">
<Flex flexDirection="column" alignItems="center" w="$fill" my="$32">
<PasswordBox
value={value}
<PasswordBoxComponent
label="Password"
onChange={(event): void => {
setValue(event.target.value);
}}
rootStyle={{ width: '500px' }}
onSubmit={action('onSubmit')}
/>
Expand Down

This file was deleted.

This file was deleted.