-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce scroll snapping to responsive tabs (#3088)
- Loading branch information
Showing
12 changed files
with
139 additions
and
125 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,97 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React, { useContext, useRef, useState } from 'react'; | ||
|
||
import { Badge, Box, Checkbox, ExpandableSection, Header, SpaceBetween } from '~components'; | ||
import Autosuggest, { AutosuggestProps } from '~components/autosuggest'; | ||
|
||
import AppContext, { AppContextType } from '../app/app-context'; | ||
|
||
type PageContext = React.Context< | ||
AppContextType<{ | ||
empty?: boolean; | ||
showEnteredTextOption?: boolean; | ||
showMatchesCount?: boolean; | ||
}> | ||
>; | ||
|
||
const options = [ | ||
{ value: '__apple__', label: 'Apple' }, | ||
{ value: '__orange__', label: 'Orange', tags: ['sweet'] }, | ||
{ value: '__banana__', label: 'Banana', tags: ['sweet'] }, | ||
{ value: '__pineapple__', label: 'Pineapple', description: 'pine+apple' }, | ||
]; | ||
const enteredTextLabel = (value: string) => `Use: ${value}`; | ||
|
||
export default function AutosuggestPage() { | ||
const { | ||
urlParams: { empty = false, showEnteredTextOption = true, showMatchesCount = true }, | ||
setUrlParams, | ||
} = useContext(AppContext as PageContext); | ||
const [value, setValue] = useState(''); | ||
const [selection, setSelection] = useState(''); | ||
const ref = useRef<AutosuggestProps.Ref>(null); | ||
return ( | ||
<Box margin="m"> | ||
<SpaceBetween size="m"> | ||
<Header | ||
variant="h1" | ||
description="This demo shows how an updated version of Autosuggest can be used as a search input" | ||
> | ||
Search | ||
</Header> | ||
|
||
<ExpandableSection defaultExpanded={true} headerText="Settings"> | ||
<Checkbox checked={empty} onChange={({ detail }) => setUrlParams({ empty: detail.checked })}> | ||
Empty | ||
</Checkbox> | ||
<Checkbox | ||
checked={showEnteredTextOption} | ||
onChange={({ detail }) => setUrlParams({ showEnteredTextOption: detail.checked })} | ||
> | ||
Show entered text option | ||
</Checkbox> | ||
<Checkbox | ||
checked={showMatchesCount} | ||
onChange={({ detail }) => setUrlParams({ showMatchesCount: detail.checked })} | ||
> | ||
Show matches count | ||
</Checkbox> | ||
</ExpandableSection> | ||
|
||
<Autosuggest | ||
ref={ref} | ||
value={value} | ||
options={empty ? [] : options} | ||
onChange={event => setValue(event.detail.value)} | ||
onSelect={event => { | ||
if (event.detail.selectedOption?.value) { | ||
setSelection(event.detail.selectedOption.value); | ||
setValue(''); | ||
} | ||
}} | ||
enteredTextLabel={enteredTextLabel} | ||
ariaLabel={'simple autosuggest'} | ||
selectedAriaLabel="Selected" | ||
empty="No suggestions" | ||
showEnteredTextOption={showEnteredTextOption} | ||
filteringResultsText={ | ||
showMatchesCount | ||
? matchesCount => { | ||
matchesCount = showEnteredTextOption ? matchesCount - 1 : matchesCount; | ||
return matchesCount ? `${matchesCount} items` : `No matches`; | ||
} | ||
: undefined | ||
} | ||
/> | ||
|
||
<SpaceBetween size="s" direction="horizontal"> | ||
<Badge color={selection === '__apple__' ? 'green' : 'grey'}>Apple</Badge> | ||
<Badge color={selection === '__orange__' ? 'green' : 'grey'}>Orange</Badge> | ||
<Badge color={selection === '__banana__' ? 'green' : 'grey'}>Banana</Badge> | ||
<Badge color={selection === '__pineapple__' ? 'green' : 'grey'}>Pineapple</Badge> | ||
</SpaceBetween> | ||
</SpaceBetween> | ||
</Box> | ||
); | ||
} |
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
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.