diff --git a/pages/attribute-editor/form-field-label.page.tsx b/pages/attribute-editor/form-field-label.page.tsx new file mode 100644 index 0000000000..3d172b76e9 --- /dev/null +++ b/pages/attribute-editor/form-field-label.page.tsx @@ -0,0 +1,82 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +import React, { useState, useCallback, useMemo } from 'react'; +import AttributeEditor, { AttributeEditorProps } from '~components/attribute-editor'; +import { Box, FormField, Input, InputProps, NonCancelableCustomEvent } from '~components'; + +interface Tag { + key?: string; + value?: string; +} + +interface ControlProps extends InputProps { + index: number; + setItems?: any; + prop: keyof Tag; +} + +const i18nStrings = { + addButtonText: 'Add new user', + removeButtonText: 'Remove', + empty: 'No secondary owners assigned to this resource.', +}; + +const Control = React.memo(({ value, index, setItems, prop }: ControlProps) => { + return ( + { + setItems((items: any) => { + const updatedItems = [...items]; + updatedItems[index] = { ...updatedItems[index], [prop]: detail.value }; + return updatedItems; + }); + }} + /> + ); +}); + +export default function AttributeEditorPage() { + const [items, setItems] = useState([{ key: '' }]); + + const definition: AttributeEditorProps.FieldDefinition[] = useMemo( + () => [ + { + control: ({ key = '' }, itemIndex) => , + }, + ], + [] + ); + + const onAddButtonClick = useCallback(() => { + setItems(items => [...items, {}]); + }, []); + + const onRemoveButtonClick = useCallback( + ({ detail: { itemIndex } }: NonCancelableCustomEvent) => { + setItems(items => { + const newItems = items.slice(); + newItems.splice(itemIndex, 1); + return newItems; + }); + }, + [] + ); + + return ( + +

Attribute Editor - Using a form field label

+ + + +
+ ); +} diff --git a/src/attribute-editor/row.tsx b/src/attribute-editor/row.tsx index 19a26c9f17..ef18dfea69 100644 --- a/src/attribute-editor/row.tsx +++ b/src/attribute-editor/row.tsx @@ -88,7 +88,11 @@ export const Row = React.memo( ))} {removable && ( - + row.label)} + > ( +const ButtonContainer = ({ index, children, isNarrowViewport, hasLabel }: ButtonContainer) => (
diff --git a/src/attribute-editor/styles.scss b/src/attribute-editor/styles.scss index dfb8960620..8b2f097c59 100644 --- a/src/attribute-editor/styles.scss +++ b/src/attribute-editor/styles.scss @@ -37,7 +37,7 @@ /* used in test-utils */ } -.button-container { +.button-container-haslabel { // We only support vertical alignment of the remove button for labels with exactly one line. // The value is calculated as follows: // padding-top = awsui-form-field-controls: 4px + @@ -45,6 +45,10 @@ padding-top: calc(#{awsui.$space-xxs} + #{awsui.$font-body-m-line-height}); } +.button-container-nolabel { + padding-top: #{awsui.$space-xxs}; +} + .divider { border-bottom: awsui.$border-divider-section-width solid awsui.$color-border-divider-default; }