|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +import React from 'react'; |
| 4 | + |
| 5 | +import { Box, Input, Select } from '~components'; |
| 6 | +import AttributeEditor from '~components/attribute-editor'; |
| 7 | + |
| 8 | +import ScreenshotArea from '../utils/screenshot-area'; |
| 9 | + |
| 10 | +const longOptions = [ |
| 11 | + { label: 'Thisisaverylonglonglonglonglonglonglonglonglonglonglonglonglonglabel', value: '0' }, |
| 12 | + { |
| 13 | + label: 'This is a very longlonglonglong longlonglonglonglong longlonglonglonglabel with spaces', |
| 14 | + value: '1', |
| 15 | + }, |
| 16 | +]; |
| 17 | + |
| 18 | +const shortOptions = [ |
| 19 | + { label: 'Short', value: '0' }, |
| 20 | + { |
| 21 | + label: 'Short value 1', |
| 22 | + value: '1', |
| 23 | + }, |
| 24 | +]; |
| 25 | + |
| 26 | +export default function AttributeEditorSelect() { |
| 27 | + const [items, setItems] = React.useState([ |
| 28 | + { |
| 29 | + key: 'some-key-1', |
| 30 | + value: 'some-value-1', |
| 31 | + longSelect: longOptions[0], |
| 32 | + shortSelect: shortOptions[0], |
| 33 | + }, |
| 34 | + { |
| 35 | + key: 'some-key-2', |
| 36 | + value: 'some-value-2', |
| 37 | + longSelect: longOptions[1], |
| 38 | + shortSelect: shortOptions[1], |
| 39 | + }, |
| 40 | + ]); |
| 41 | + |
| 42 | + return ( |
| 43 | + <Box margin="xl"> |
| 44 | + <h1>Attribute Editor - Long select</h1> |
| 45 | + <ScreenshotArea> |
| 46 | + <AttributeEditor |
| 47 | + items={items} |
| 48 | + hideAddButton={true} |
| 49 | + onRemoveButtonClick={({ detail: { itemIndex } }) => { |
| 50 | + const tmpItems = [...items]; |
| 51 | + tmpItems.splice(itemIndex, 1); |
| 52 | + setItems(tmpItems); |
| 53 | + }} |
| 54 | + addButtonText="Add new item" |
| 55 | + removeButtonText="Remove" |
| 56 | + definition={[ |
| 57 | + { |
| 58 | + label: 'Key', |
| 59 | + control: item => <Input value={item.key} placeholder="Enter key" onChange={() => {}} />, |
| 60 | + }, |
| 61 | + { |
| 62 | + label: 'Long select', |
| 63 | + control: item => <Select selectedOption={item.longSelect} options={longOptions} />, |
| 64 | + }, |
| 65 | + { |
| 66 | + label: 'Short select', |
| 67 | + control: item => <Select selectedOption={item.shortSelect} options={shortOptions} />, |
| 68 | + }, |
| 69 | + ]} |
| 70 | + /> |
| 71 | + </ScreenshotArea> |
| 72 | + </Box> |
| 73 | + ); |
| 74 | +} |
0 commit comments