-
Notifications
You must be signed in to change notification settings - Fork 239
feat: Input prefix suffix #4755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8a170c5
feat: Input prefix suffix
NathanZlion bb3a569
chore: truncate long text
NathanZlion f8d8de0
chore: Change naming into RTL friendly name
NathanZlion 1d1ef2d
chore: Make prefixes cursor selectable and ally
NathanZlion 80ad8d3
chore: Remove duplicate prmutation entry
NathanZlion c12f33c
chore: replace adornment with prefix suffix
NathanZlion 8e59d70
fix: revert back test util change
NathanZlion 990f8fa
chore: falsy 0 value ignored as edgecase
NathanZlion f84afbd
chore: clean up default style
NathanZlion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,148 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React, { useContext } from 'react'; | ||
|
|
||
| import Box from '~components/box'; | ||
| import FormField from '~components/form-field'; | ||
| import Icon from '~components/icon'; | ||
| import Input, { InputProps } from '~components/input'; | ||
| import Select, { SelectProps } from '~components/select'; | ||
| import SpaceBetween from '~components/space-between'; | ||
| import Toggle from '~components/toggle'; | ||
|
|
||
| import AppContext, { AppContextType } from '../app/app-context'; | ||
| import { SimplePage } from '../app/templates'; | ||
|
|
||
| type PrefixSuffixMode = 'none' | 'short' | 'long' | 'icon'; | ||
|
|
||
| type PageContext = React.Context< | ||
| AppContextType<{ | ||
| type?: InputProps.Type; | ||
| prefix?: PrefixSuffixMode; | ||
| suffix?: PrefixSuffixMode; | ||
| disabled?: boolean; | ||
| readOnly?: boolean; | ||
| invalid?: boolean; | ||
| warning?: boolean; | ||
| value?: string; | ||
| }> | ||
| >; | ||
|
|
||
| const typeOptions: ReadonlyArray<SelectProps.Option> = [ | ||
| { value: 'text', label: 'Text' }, | ||
| { value: 'password', label: 'Password' }, | ||
| { value: 'number', label: 'Number' }, | ||
| { value: 'email', label: 'Email' }, | ||
| { value: 'url', label: 'URL' }, | ||
| { value: 'search', label: 'Search' }, | ||
| ]; | ||
|
|
||
| const prefixSuffixOptions: ReadonlyArray<SelectProps.Option> = [ | ||
| { value: 'none', label: 'None' }, | ||
| { value: 'short', label: 'Short text' }, | ||
| { value: 'long', label: 'Long text' }, | ||
| { value: 'icon', label: 'Icon' }, | ||
| ]; | ||
|
|
||
| function getPrefix(mode: PrefixSuffixMode): React.ReactNode { | ||
| switch (mode) { | ||
| case 'short': | ||
| return '$'; | ||
| case 'long': | ||
| return 'https://example.com/very-long-prefix-that-overflows'; | ||
| case 'icon': | ||
| return <Icon name="search" />; | ||
| default: | ||
| return undefined; | ||
| } | ||
| } | ||
|
|
||
| function getSuffix(mode: PrefixSuffixMode): React.ReactNode { | ||
| switch (mode) { | ||
| case 'short': | ||
| return '%'; | ||
| case 'long': | ||
| return '.ec2.internal.very-long-domain-that-overflows'; | ||
| case 'icon': | ||
| return <Icon name="settings" />; | ||
| default: | ||
| return undefined; | ||
| } | ||
| } | ||
|
|
||
| export default function PrefixSuffixPage() { | ||
| const { urlParams, setUrlParams } = useContext(AppContext as PageContext); | ||
| const type = urlParams.type ?? 'text'; | ||
| const prefixMode = urlParams.prefix ?? 'short'; | ||
| const suffixMode = urlParams.suffix ?? 'short'; | ||
| const disabled = urlParams.disabled ?? false; | ||
| const readOnly = urlParams.readOnly ?? false; | ||
| const invalid = urlParams.invalid ?? false; | ||
| const warning = urlParams.warning ?? false; | ||
|
|
||
| return ( | ||
| <SimplePage | ||
| title="Input prefix and suffix" | ||
| settings={ | ||
| <SpaceBetween direction="horizontal" size="s" alignItems="center"> | ||
| <Select | ||
| inlineLabelText="Type" | ||
| selectedOption={typeOptions.find(option => option.value === type) ?? null} | ||
| options={typeOptions} | ||
| onChange={({ detail }) => setUrlParams({ type: detail.selectedOption.value as InputProps.Type })} | ||
| /> | ||
| <Select | ||
| inlineLabelText="Prefix" | ||
| selectedOption={prefixSuffixOptions.find(option => option.value === prefixMode) ?? null} | ||
| options={prefixSuffixOptions} | ||
| onChange={({ detail }) => setUrlParams({ prefix: detail.selectedOption.value as PrefixSuffixMode })} | ||
| /> | ||
| <Select | ||
| inlineLabelText="Suffix" | ||
| selectedOption={prefixSuffixOptions.find(option => option.value === suffixMode) ?? null} | ||
| options={prefixSuffixOptions} | ||
| onChange={({ detail }) => setUrlParams({ suffix: detail.selectedOption.value as PrefixSuffixMode })} | ||
| /> | ||
| <Toggle checked={disabled} onChange={({ detail }) => setUrlParams({ disabled: detail.checked })}> | ||
| Disabled | ||
| </Toggle> | ||
| <Toggle checked={readOnly} onChange={({ detail }) => setUrlParams({ readOnly: detail.checked })}> | ||
| Read-only | ||
| </Toggle> | ||
| <Toggle checked={invalid} onChange={({ detail }) => setUrlParams({ invalid: detail.checked })}> | ||
| Invalid | ||
| </Toggle> | ||
| <Toggle checked={warning} onChange={({ detail }) => setUrlParams({ warning: detail.checked })}> | ||
| Warning | ||
| </Toggle> | ||
| </SpaceBetween> | ||
| } | ||
| > | ||
| <FormField | ||
| label="Input with prefix and suffix" | ||
| errorText={invalid ? 'Validation error.' : undefined} | ||
| warningText={warning && !invalid ? 'Validation warning.' : undefined} | ||
| > | ||
| <Input | ||
| value={urlParams.value ?? ''} | ||
| onChange={({ detail }) => setUrlParams({ value: detail.value })} | ||
| type={type} | ||
| prefix={getPrefix(prefixMode)} | ||
| suffix={getSuffix(suffixMode)} | ||
| disabled={disabled} | ||
| readOnly={readOnly} | ||
| invalid={invalid} | ||
| warning={warning} | ||
| placeholder="Enter a value" | ||
| clearAriaLabel="Clear" | ||
| /> | ||
| </FormField> | ||
|
|
||
| {type === 'search' && ( | ||
| <Box variant="small" color="text-body-secondary"> | ||
| Prefix and suffix are ignored for search inputs. | ||
| </Box> | ||
| )} | ||
| </SimplePage> | ||
| ); | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest renaming prefix-suffix or similar to match feature naming