-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal: add Field primitive (#3663)
- Loading branch information
1 parent
579ace5
commit 7475161
Showing
12 changed files
with
109 additions
and
13 deletions.
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,6 @@ | ||
--- | ||
"@aws-amplify/ui-react": patch | ||
"@aws-amplify/ui": patch | ||
--- | ||
|
||
Adding an internal Field primitive |
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
23 changes: 16 additions & 7 deletions
23
examples/next/pages/ui/components/storage/storage-manager/index.page.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 |
---|---|---|
@@ -1,19 +1,28 @@ | ||
import { Amplify } from 'aws-amplify'; | ||
import { withAuthenticator } from '@aws-amplify/ui-react'; | ||
import { Field } from '@aws-amplify/ui-react/internal'; | ||
import { StorageManager } from '@aws-amplify/ui-react-storage'; | ||
import '@aws-amplify/ui-react/styles.css'; | ||
import awsExports from './aws-exports'; | ||
Amplify.configure(awsExports); | ||
|
||
export function StorageManagerExample() { | ||
return ( | ||
<StorageManager | ||
acceptedFileTypes={['image/*']} | ||
accessLevel="private" | ||
maxFileCount={3} | ||
isResumable | ||
showThumbnails={true} | ||
/> | ||
<Field | ||
label="Images" | ||
isReadOnly={false} | ||
isRequired={false} | ||
errorMessage={'error'} | ||
hasError={false} | ||
> | ||
<StorageManager | ||
acceptedFileTypes={['image/*']} | ||
accessLevel="private" | ||
maxFileCount={3} | ||
isResumable | ||
showThumbnails={true} | ||
/> | ||
</Field> | ||
); | ||
} | ||
export default withAuthenticator(StorageManagerExample); |
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
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
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,68 @@ | ||
import * as React from 'react'; | ||
import classNames from 'classnames'; | ||
import { | ||
Primitive, | ||
FlexContainerStyleProps, | ||
ViewProps, | ||
InputProps, | ||
FieldProps, | ||
} from '../types'; | ||
import { classNameModifier } from '../shared/utils'; | ||
import { ComponentClassNames } from '../shared/constants'; | ||
import { Flex } from '../Flex'; | ||
import { FieldDescription } from './FieldDescription'; | ||
import { FieldErrorMessage } from './FieldErrorMessage'; | ||
import { Label } from '../Label'; | ||
|
||
interface FieldPrimitiveProps | ||
extends FieldProps, | ||
InputProps, | ||
FlexContainerStyleProps, | ||
ViewProps {} | ||
|
||
const FieldPrimitive: Primitive<FieldPrimitiveProps, typeof Flex> = ( | ||
props, | ||
ref | ||
) => { | ||
const { | ||
className, | ||
size, | ||
testId, | ||
children, | ||
label, | ||
labelHidden, | ||
errorMessage, | ||
hasError, | ||
descriptiveText, | ||
...rest | ||
} = props; | ||
|
||
return ( | ||
<Flex | ||
className={classNames( | ||
ComponentClassNames.Field, | ||
classNameModifier(ComponentClassNames.Field, size), | ||
className | ||
)} | ||
data-size={size} | ||
testId={testId} | ||
ref={ref} | ||
{...rest} | ||
> | ||
{label ? <Label visuallyHidden={labelHidden}>{label}</Label> : null} | ||
{descriptiveText ? ( | ||
<FieldDescription labelHidden={labelHidden}> | ||
{descriptiveText} | ||
</FieldDescription> | ||
) : null} | ||
{children} | ||
{errorMessage ? ( | ||
<FieldErrorMessage hasError={hasError} errorMessage={errorMessage} /> | ||
) : null} | ||
</Flex> | ||
); | ||
}; | ||
|
||
export const Field = React.forwardRef(FieldPrimitive); | ||
|
||
Field.displayName = 'Field'; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { FieldClearButton } from './FieldClearButton'; | ||
export { FieldDescription } from './FieldDescription'; | ||
export { FieldErrorMessage } from './FieldErrorMessage'; | ||
export { Field } from './Field'; |
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
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
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
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
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