-
Notifications
You must be signed in to change notification settings - Fork 34
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
Style Autocomplete #1725
Merged
Merged
Style Autocomplete #1725
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
595efa6
chore: example of broken Autocomplete behavior
edburyenegren-okta 5e632db
chore: label examples in doc
edburyenegren-okta 5b345e3
chore: set up working examples for all states
edburyenegren-okta c994737
chore: set default props for Autocomplete
edburyenegren-okta cd297cb
chore: remove defaults from stories
edburyenegren-okta ff432c0
Merge branch 'develop' into ee/autocomplete
KevinGhadyani-Okta dbb1210
fix: created Autocomplete wrapper component
KevinGhadyani-Okta 28be391
fix: export types for Autocomplete
KevinGhadyani-Okta a93542c
fix: separated InputProps and params in Autocomplete
KevinGhadyani-Okta d7aff4a
fix: added extra props to Autocomplete to fix MUI types
KevinGhadyani-Okta ab84734
fix: removed explicit displayName from MenuItem
KevinGhadyani-Okta 8d28a8c
fix: types for Autocomplete in stories
KevinGhadyani-Okta 66e7710
chore: remove unnec ComponentStory
edburyenegren-okta 79d42e1
fix: minor type improvement in Autocomplete stories
KevinGhadyani-Okta 2a3c46a
Merge remote-tracking branch 'origin/ee/autocomplete' into ee/autocom…
KevinGhadyani-Okta 0f32442
chore: update stories to match new props
edburyenegren-okta f2da4da
chore: remove MUI-only stories
edburyenegren-okta eaef418
chore: remove mui-only exports
edburyenegren-okta b03516b
feat(odyssey-react-mui): add styling for Autocomplete
edburyenegren-okta 42f6c03
chore: enable and styling loading state
edburyenegren-okta 5397b59
chore: add and style isReadOnly state
edburyenegren-okta 5923b59
chore: fix border color hover behavior
edburyenegren-okta 0254034
chore: remove unnec autocomplete classes
edburyenegren-okta 7680cfe
chore: add readonly and disabled examples
edburyenegren-okta 72c40f1
chore: tune disabled states for Autocomplete tags
edburyenegren-okta 26d732d
docs(odyssey-storybook): update Select and Autocomplete stories
edburyenegren-okta 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 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,132 @@ | ||
/*! | ||
* Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved. | ||
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") | ||
* | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { | ||
Autocomplete as MuiAutocomplete, | ||
AutocompleteProps as MuiAutocompleteProps, | ||
InputBase, | ||
} from "@mui/material"; | ||
import { memo, useCallback } from "react"; | ||
|
||
import { Field } from "./Field"; | ||
|
||
export type AutocompleteProps< | ||
OptionType, | ||
HasMultipleChoices extends boolean | undefined, | ||
IsCustomValueAllowed extends boolean | undefined | ||
> = { | ||
hasMultipleChoices?: MuiAutocompleteProps< | ||
OptionType, | ||
HasMultipleChoices, | ||
undefined, | ||
IsCustomValueAllowed | ||
>["multiple"]; | ||
hint?: string; | ||
isCustomValueAllowed?: MuiAutocompleteProps< | ||
OptionType, | ||
HasMultipleChoices, | ||
undefined, | ||
IsCustomValueAllowed | ||
>["freeSolo"]; | ||
isDisabled?: MuiAutocompleteProps< | ||
OptionType, | ||
HasMultipleChoices, | ||
undefined, | ||
IsCustomValueAllowed | ||
>["disabled"]; | ||
isLoading?: MuiAutocompleteProps< | ||
OptionType, | ||
HasMultipleChoices, | ||
undefined, | ||
IsCustomValueAllowed | ||
>["loading"]; | ||
isReadOnly?: MuiAutocompleteProps< | ||
OptionType, | ||
HasMultipleChoices, | ||
undefined, | ||
IsCustomValueAllowed | ||
>["readOnly"]; | ||
label: string; | ||
onChange?: MuiAutocompleteProps< | ||
OptionType, | ||
HasMultipleChoices, | ||
undefined, | ||
IsCustomValueAllowed | ||
>["onChange"]; | ||
options: MuiAutocompleteProps< | ||
OptionType, | ||
HasMultipleChoices, | ||
undefined, | ||
IsCustomValueAllowed | ||
>["options"]; | ||
value?: MuiAutocompleteProps< | ||
OptionType, | ||
HasMultipleChoices, | ||
undefined, | ||
IsCustomValueAllowed | ||
>["value"]; | ||
}; | ||
|
||
const Autocomplete = < | ||
OptionType, | ||
HasMultipleChoices extends boolean | undefined, | ||
IsCustomValueAllowed extends boolean | undefined | ||
>({ | ||
isCustomValueAllowed, | ||
hasMultipleChoices, | ||
isDisabled, | ||
isLoading, | ||
isReadOnly, | ||
hint, | ||
label, | ||
onChange, | ||
options, | ||
value, | ||
}: AutocompleteProps<OptionType, HasMultipleChoices, IsCustomValueAllowed>) => { | ||
const renderInput = useCallback( | ||
({ InputLabelProps, InputProps, ...params }) => ( | ||
<Field | ||
{...InputLabelProps} | ||
hasVisibleLabel | ||
hint={hint} | ||
label={label} | ||
renderFieldComponent={({ ariaDescribedBy, id }) => ( | ||
<InputBase | ||
{...params} | ||
{...InputProps} | ||
aria-describedby={ariaDescribedBy} | ||
id={id} | ||
/> | ||
)} | ||
/> | ||
), | ||
[hint, label] | ||
); | ||
|
||
return ( | ||
<MuiAutocomplete | ||
disabled={isDisabled} | ||
freeSolo={isCustomValueAllowed} | ||
loading={isLoading} | ||
multiple={hasMultipleChoices} | ||
onChange={onChange} | ||
options={options} | ||
readOnly={isReadOnly} | ||
renderInput={renderInput} | ||
value={value} | ||
/> | ||
); | ||
}; | ||
|
||
const MemoizedAutocomplete = memo(Autocomplete) as typeof Autocomplete; | ||
|
||
export { MemoizedAutocomplete as Autocomplete }; |
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
79 changes: 79 additions & 0 deletions
79
...ages/odyssey-storybook/src/components/odyssey-mui/Autocomplete/Autocomplete.mdx
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,79 @@ | ||
import { ArgsTable, Canvas, Meta, Story } from "@storybook/addon-docs"; | ||
|
||
<Meta anchor /> | ||
|
||
# Autocomplete | ||
|
||
Similar to <a href="?path=/docs/mui-components-forms-select--default">Select</a>, this input triggers a menu of options a user can select. Country and state Autocompletes are common examples. | ||
|
||
<Canvas> | ||
<Story id="mui-components-forms-autocomplete--default" /> | ||
</Canvas> | ||
|
||
## Behavior | ||
|
||
Interacting with an Autocomplete displays a list of values to choose from. Users may filter the options list by typing. | ||
|
||
## Variants | ||
|
||
Odyssey provides support for both single and multi-value Autocompletes. | ||
|
||
### Single-select | ||
|
||
With the single-select variant, choosing a value will override any previous selection and close the Autocomplete. | ||
|
||
#### Enabled | ||
|
||
<Canvas> | ||
<Story id="mui-components-forms-autocomplete--default" /> | ||
</Canvas> | ||
|
||
#### Disabled | ||
|
||
<Canvas> | ||
<Story id="mui-components-forms-autocomplete--disabled" /> | ||
</Canvas> | ||
|
||
#### Read-only | ||
|
||
<Canvas> | ||
<Story id="mui-components-forms-autocomplete--read-only" /> | ||
</Canvas> | ||
|
||
### Multi-Select | ||
|
||
The multi-Select variant allows users to select many values. | ||
|
||
#### Enabled | ||
|
||
<Canvas> | ||
<Story id="mui-components-forms-autocomplete--multiple" /> | ||
</Canvas> | ||
|
||
#### Disabled | ||
|
||
<Canvas> | ||
<Story id="mui-components-forms-autocomplete--multiple-disabled" /> | ||
</Canvas> | ||
|
||
#### Read-only | ||
|
||
<Canvas> | ||
<Story id="mui-components-forms-autocomplete--multiple-read-only" /> | ||
</Canvas> | ||
|
||
## Loading state | ||
|
||
The loading state is displayed when retrieving values from the server or when data is unavailable. | ||
|
||
<Canvas> | ||
<Story id="mui-components-forms-autocomplete--loading" /> | ||
</Canvas> | ||
|
||
## Custom Values | ||
|
||
Autocomplete also supports user-submitted values via the `isCustomValueAllowed` prop. | ||
|
||
<Canvas> | ||
<Story id="mui-components-forms-autocomplete--is-custom-value-allowed" /> | ||
</Canvas> |
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.
I'm assuming we won't have to use
grey[200]
with Design Tokens v2 right?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.
Yup. We don't have a token for it currently, but I'll be doing replacements with the new schema.