Skip to content

Commit b04ce6d

Browse files
jacobloganJacob Logan
andauthored
Docs password field (#1860)
* update password field * add setters * break out password field props * update passwordfield docs page * updates to passwordfield docs * add links.ts body * updates to passwordfield docs * add passwordfield themeing section to docs Co-authored-by: Jacob Logan <[email protected]>
1 parent 62edc9e commit b04ce6d

27 files changed

+1023
-493
lines changed

docs/src/components/ComponentVariableTable.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export const ComponentVariableTable = ({ componentName }) => {
4646
</TableRow>
4747
);
4848
}
49+
} else {
50+
return 'No variables available for this component';
4951
}
5052
return tableRows;
5153
}, [componentName]);

docs/src/data/links.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export const inputComponents = [
156156
{
157157
href: '/components/passwordfield',
158158
label: 'Password Field',
159-
body: ``,
159+
body: `PasswordField allows users to input passwords, featuring full password manager support and an optional show/hide password button for user convenience - Amplify UI`,
160160
platforms: ['react'],
161161
},
162162
{
Lines changed: 78 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,87 @@
1+
import { PasswordField, PasswordFieldProps } from '@aws-amplify/ui-react';
12
import * as React from 'react';
23

4+
import { Demo } from '@/components/Demo';
35
import {
4-
Flex,
5-
FlexContainerStyleProps,
6-
PasswordField,
7-
PasswordFieldProps,
8-
TextFieldProps,
9-
View,
10-
} from '@aws-amplify/ui-react';
11-
12-
import { Example } from '@/components/Example';
13-
import { GetFieldControls } from '../shared/GetFieldControls';
14-
import { useFlexContainerStyleProps } from '../shared/useFlexContainerStyleProps';
6+
filterDemoProps,
7+
getDemoProps,
8+
objectEntriesToPropString,
9+
} from '../utils/demoProps';
10+
import { PasswordFieldPropControls } from './passwordFieldPropControls';
1511
import { usePasswordFieldProps } from './usePasswordFieldProps';
12+
import { demoState } from '@/utils/demoState';
13+
14+
export const propsToCode = (props) => {
15+
const filteredProps = filterDemoProps(props);
16+
return `
17+
<PasswordField
18+
${objectEntriesToPropString(Object.entries(filteredProps))}
19+
/>`;
20+
};
1621

1722
export const PasswordFieldDemo = () => {
18-
const flexStyleProps = useFlexContainerStyleProps({
19-
alignItems: '',
20-
alignContent: '',
21-
direction: 'column',
22-
gap: '',
23-
justifyContent: '',
24-
wrap: 'nowrap',
25-
});
26-
const textFieldProps = usePasswordFieldProps({
27-
autoComplete: 'new-password',
28-
defaultValue: '',
29-
descriptiveText: 'Please enter password with at least 8 characters',
30-
errorMessage: '',
31-
hasError: false,
32-
inputMode: 'text',
33-
isDisabled: false,
34-
isReadOnly: false,
35-
isRequired: false,
36-
label: 'Password',
37-
labelHidden: false,
38-
name: 'password',
39-
placeholder: '',
40-
size: '',
41-
type: null,
42-
value: undefined,
43-
variation: '',
44-
hideShowPassword: false,
45-
});
46-
const FlexPropControls = GetFieldControls({
47-
typeName: 'Flex',
48-
fields: flexStyleProps,
49-
});
50-
const TextFieldPropControls = GetFieldControls({
51-
typeName: 'PasswordField',
52-
fields: textFieldProps,
53-
});
54-
const [
55-
[alignItems],
56-
[alignContent],
57-
[direction],
58-
[gap],
59-
[justifyContent],
60-
[wrap],
61-
] = flexStyleProps;
62-
const [
63-
[autoComplete],
64-
[defaultValue],
65-
[descriptiveText],
66-
[errorMessage],
67-
[hasError],
68-
[inputMode],
69-
[isDisabled],
70-
[isReadOnly],
71-
[isRequired],
72-
[label],
73-
[labelHidden],
74-
[name],
75-
[placeholder],
76-
[size],
77-
[type],
78-
[value],
79-
[variation],
80-
[hideShowPassword],
81-
] = textFieldProps;
23+
const passwordFieldProps = usePasswordFieldProps(
24+
(demoState.get(PasswordField.displayName) as PasswordFieldProps) || {
25+
autoComplete: 'new-password',
26+
defaultValue: '',
27+
descriptiveText: 'Please enter password',
28+
errorMessage: '',
29+
hasError: false,
30+
hideShowPassword: false,
31+
isDisabled: false,
32+
isReadOnly: false,
33+
isRequired: false,
34+
label: 'Password',
35+
labelHidden: false,
36+
name: 'password',
37+
placeholder: '',
38+
size: 'small',
39+
value: '',
40+
variation: null,
41+
}
42+
);
43+
const demoProps = [
44+
'autoComplete',
45+
'defaultValue',
46+
'descriptiveText',
47+
'errorMessage',
48+
'hasError',
49+
'hideShowPassword',
50+
'isDisabled',
51+
'isReadOnly',
52+
'isRequired',
53+
'label',
54+
'labelHidden',
55+
'name',
56+
'placeholder',
57+
'size',
58+
'value',
59+
'variation',
60+
];
61+
const passwordFieldDemoProps = getDemoProps(passwordFieldProps, demoProps);
8262
return (
83-
<View width="100%">
84-
{TextFieldPropControls}
85-
{FlexPropControls}
86-
<Example>
87-
<View maxWidth="500px" padding="2rem">
88-
<Flex gap="2rem" direction="column">
89-
<form>
90-
<input
91-
autoComplete="username"
92-
name="username"
93-
defaultValue="[email protected]"
94-
type="hidden"
95-
/>
96-
<PasswordField
97-
alignContent={
98-
alignContent as FlexContainerStyleProps['alignContent']
99-
}
100-
alignItems={alignItems as FlexContainerStyleProps['alignItems']}
101-
autoComplete={autoComplete as TextFieldProps['autoComplete']}
102-
descriptiveText={
103-
descriptiveText as TextFieldProps['descriptiveText']
104-
}
105-
defaultValue={defaultValue as TextFieldProps['defaultValue']}
106-
direction={direction as FlexContainerStyleProps['direction']}
107-
errorMessage={errorMessage as TextFieldProps['errorMessage']}
108-
gap={gap as FlexContainerStyleProps['gap']}
109-
hasError={hasError as unknown as boolean}
110-
inputMode={inputMode as TextFieldProps['inputMode']}
111-
isDisabled={isDisabled as unknown as boolean}
112-
isReadOnly={isReadOnly as unknown as boolean}
113-
isRequired={isRequired as unknown as boolean}
114-
justifyContent={
115-
justifyContent as FlexContainerStyleProps['justifyContent']
116-
}
117-
label={label as TextFieldProps['label']}
118-
labelHidden={labelHidden as unknown as boolean}
119-
name={name as TextFieldProps['name']}
120-
placeholder={placeholder as TextFieldProps['placeholder']}
121-
size={size as TextFieldProps['size']}
122-
variation={variation as TextFieldProps['variation']}
123-
wrap={wrap as FlexContainerStyleProps['wrap']}
124-
hideShowPassword={
125-
hideShowPassword as unknown as PasswordFieldProps['hideShowPassword']
126-
}
127-
/>
128-
</form>
129-
</Flex>
130-
</View>
131-
</Example>
132-
</View>
63+
<Demo
64+
code={propsToCode(passwordFieldDemoProps)}
65+
propControls={<PasswordFieldPropControls {...passwordFieldProps} />}
66+
>
67+
<PasswordField
68+
autoComplete={passwordFieldProps.autoComplete}
69+
descriptiveText={passwordFieldProps.descriptiveText}
70+
defaultValue={passwordFieldProps.defaultValue}
71+
errorMessage={passwordFieldProps.errorMessage}
72+
hasError={passwordFieldProps.hasError}
73+
hideShowPassword={passwordFieldProps.hideShowPassword}
74+
isDisabled={passwordFieldProps.isDisabled}
75+
isReadOnly={passwordFieldProps.isReadOnly}
76+
isRequired={passwordFieldProps.isRequired}
77+
label={passwordFieldProps.label}
78+
labelHidden={passwordFieldProps.labelHidden}
79+
name={passwordFieldProps.name}
80+
placeholder={passwordFieldProps.placeholder}
81+
size={passwordFieldProps.size}
82+
value={passwordFieldProps.value || null}
83+
variation={passwordFieldProps.variation}
84+
/>
85+
</Demo>
13386
);
13487
};

docs/src/pages/[platform]/components/passwordfield/examples.tsx

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)