@okta/odyssey-react-mui 1.23.0 → 1.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/dist/Autocomplete.js +2 -0
- package/dist/Autocomplete.js.map +1 -1
- package/dist/Banner.js +6 -2
- package/dist/Banner.js.map +1 -1
- package/dist/Callout.js +6 -2
- package/dist/Callout.js.map +1 -1
- package/dist/ContrastModeProvider.js +86 -0
- package/dist/ContrastModeProvider.js.map +1 -0
- package/dist/FieldHint.js +20 -6
- package/dist/FieldHint.js.map +1 -1
- package/dist/Link.js.map +1 -1
- package/dist/OdysseyProvider.js +40 -20
- package/dist/OdysseyProvider.js.map +1 -1
- package/dist/Stack.js +32 -0
- package/dist/Stack.js.map +1 -0
- package/dist/Tag.js +64 -22
- package/dist/Tag.js.map +1 -1
- package/dist/Typography.js +27 -6
- package/dist/Typography.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.scss +8 -4
- package/dist/labs/datePickerTheme.js +3 -6
- package/dist/labs/datePickerTheme.js.map +1 -1
- package/dist/src/Autocomplete.d.ts +7 -1
- package/dist/src/Autocomplete.d.ts.map +1 -1
- package/dist/src/Banner.d.ts +16 -12
- package/dist/src/Banner.d.ts.map +1 -1
- package/dist/src/Callout.d.ts +9 -9
- package/dist/src/Callout.d.ts.map +1 -1
- package/dist/src/ContrastModeProvider.d.ts +34 -0
- package/dist/src/ContrastModeProvider.d.ts.map +1 -0
- package/dist/src/FieldHint.d.ts.map +1 -1
- package/dist/src/Link.d.ts +3 -1
- package/dist/src/Link.d.ts.map +1 -1
- package/dist/src/OdysseyProvider.d.ts +5 -3
- package/dist/src/OdysseyProvider.d.ts.map +1 -1
- package/dist/src/Stack.d.ts +33 -0
- package/dist/src/Stack.d.ts.map +1 -0
- package/dist/src/Tag.d.ts.map +1 -1
- package/dist/src/Typography.d.ts +3 -2
- package/dist/src/Typography.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/labs/datePickerTheme.d.ts.map +1 -1
- package/dist/src/theme/components.d.ts.map +1 -1
- package/dist/src/theme/palette.d.ts.map +1 -1
- package/dist/src/theme/palette.types.d.ts +2 -0
- package/dist/src/theme/palette.types.d.ts.map +1 -1
- package/dist/theme/components.js +345 -287
- package/dist/theme/components.js.map +1 -1
- package/dist/theme/palette.js +2 -1
- package/dist/theme/palette.js.map +1 -1
- package/dist/theme/palette.types.js.map +1 -1
- package/dist/tsconfig.production.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/Autocomplete.tsx +13 -0
- package/src/Banner.tsx +29 -14
- package/src/Callout.tsx +18 -11
- package/src/ContrastModeProvider.tsx +131 -0
- package/src/FieldHint.tsx +28 -4
- package/src/Link.tsx +3 -1
- package/src/OdysseyProvider.tsx +54 -27
- package/src/Stack.tsx +56 -0
- package/src/Tag.tsx +65 -21
- package/src/Typography.test.tsx +26 -0
- package/src/Typography.tsx +38 -6
- package/src/index.ts +4 -0
- package/src/labs/datePickerTheme.tsx +2 -6
- package/src/theme/components.tsx +371 -293
- package/src/theme/palette.ts +2 -1
- package/src/theme/palette.types.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,37 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.24.1](https://github.com/okta/odyssey/compare/v1.24.0...v1.24.1) (2024-10-04)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **odyssey-react-mui:** add back margin removed in error ([e36cb89](https://github.com/okta/odyssey/commit/e36cb89d20daf7eb68cbc58d8391ea7cf512b281))
|
|
11
|
+
- **odyssey-react-mui:** add back no children styling ([2a07fa3](https://github.com/okta/odyssey/commit/2a07fa37130d48206939aa94c42add4a3f105157))
|
|
12
|
+
- **odyssey-react-mui:** add back size and full width styling ([11552fd](https://github.com/okta/odyssey/commit/11552fd7818d232535eb89c86d04c3ccc15896b3))
|
|
13
|
+
- **odyssey-react-mui:** fix margin start ([478e20e](https://github.com/okta/odyssey/commit/478e20ef320ee26c1fd96e93a1dabb7131808d6f))
|
|
14
|
+
- **odyssey-storybook:** add back floatingAction styles ([0b84954](https://github.com/okta/odyssey/commit/0b8495484de11e35e2959c2e3b6dba80394b6a3e))
|
|
15
|
+
|
|
16
|
+
## [1.24.0](https://github.com/okta/odyssey/compare/v1.20.0...v1.24.0) (2024-10-01)
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
- add additional action button and menu slot to table ([#2334](https://github.com/okta/odyssey/issues/2334)) ([52b3f38](https://github.com/okta/odyssey/commit/52b3f3832adc442e0219be16fe8a4d96cf100a4e))
|
|
21
|
+
- adds a generic top nav component ([#2296](https://github.com/okta/odyssey/issues/2296)) ([6f3165f](https://github.com/okta/odyssey/commit/6f3165f9fd4a1d1743c975b72132d4ec186d09bb))
|
|
22
|
+
- adds new Shadow DOM export with better naming ([#2338](https://github.com/okta/odyssey/issues/2338)) ([0997e36](https://github.com/okta/odyssey/commit/0997e36afd4d241f5b3960528aff2865fb6d6ac3))
|
|
23
|
+
- automatically scroll to the first isSelected SideNavItem ([#2325](https://github.com/okta/odyssey/issues/2325)) ([52ce441](https://github.com/okta/odyssey/commit/52ce44137ffe5601cfa6044782a21afb5449167e))
|
|
24
|
+
- Misc Odyssey updates ([#2326](https://github.com/okta/odyssey/issues/2326)) ([84fcef3](https://github.com/okta/odyssey/commit/84fcef346841f0a125995a61b80958499343e7e1))
|
|
25
|
+
- **odyssey-react-mui:** add overline typography variant ([#2349](https://github.com/okta/odyssey/issues/2349)) ([4530f69](https://github.com/okta/odyssey/commit/4530f699dffc11117f366ca26826e7ca51f4f296))
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
- Add missing props to Storybook ([#2313](https://github.com/okta/odyssey/issues/2313)) ([bbf96a2](https://github.com/okta/odyssey/commit/bbf96a257160b922c0ebc31b1c5dec1fe31c35b4))
|
|
30
|
+
- fixes translations not working with TypeScript ([#2354](https://github.com/okta/odyssey/issues/2354)) ([37653ee](https://github.com/okta/odyssey/commit/37653ee47c2fab8b54dec26efd5115f6633c2977))
|
|
31
|
+
- **odyssey-design-tokens:** using correct weights in SB ([#2363](https://github.com/okta/odyssey/issues/2363)) ([2dfa614](https://github.com/okta/odyssey/commit/2dfa614cd4c09d71d8624be690ae788e134a74ba))
|
|
32
|
+
- **odyssey-react-mui:** Add min-heights to keep correct heights ([#2324](https://github.com/okta/odyssey/issues/2324)) ([40d5a50](https://github.com/okta/odyssey/commit/40d5a5070ebfab1b650066e91b451c0ef4b3f2d8))
|
|
33
|
+
- remove invalid pseudo element from theme overrides ([#2310](https://github.com/okta/odyssey/issues/2310)) ([fea0793](https://github.com/okta/odyssey/commit/fea0793acf0800494270a87e4e5d65129942b99e))
|
|
34
|
+
- select multioption not rendering text when you use an options object ([#2323](https://github.com/okta/odyssey/issues/2323)) ([4bafbb9](https://github.com/okta/odyssey/commit/4bafbb99e03e52ad572fba9049013c058c75da38))
|
|
35
|
+
- Update Test Selector types and improve functionality ([#2333](https://github.com/okta/odyssey/issues/2333)) ([7039009](https://github.com/okta/odyssey/commit/703900947861dfb36b8996414130a8db3414ccfa))
|
|
36
|
+
|
|
6
37
|
## [1.23.0](https://github.com/okta/odyssey/compare/v1.19.0...v1.23.0) (2024-09-19)
|
|
7
38
|
|
|
8
39
|
### Features
|
package/dist/Autocomplete.js
CHANGED
|
@@ -58,6 +58,7 @@ const Autocomplete = ({
|
|
|
58
58
|
defaultValue,
|
|
59
59
|
errorMessage,
|
|
60
60
|
errorMessageList,
|
|
61
|
+
getOptionLabel,
|
|
61
62
|
hasMultipleChoices,
|
|
62
63
|
id: idOverride,
|
|
63
64
|
inputValue,
|
|
@@ -275,6 +276,7 @@ const Autocomplete = ({
|
|
|
275
276
|
disabled: isDisabled,
|
|
276
277
|
freeSolo: isCustomValueAllowed,
|
|
277
278
|
filterSelectedOptions: true,
|
|
279
|
+
getOptionLabel: getOptionLabel,
|
|
278
280
|
id: idOverride,
|
|
279
281
|
fullWidth: isFullWidth,
|
|
280
282
|
loading: isLoading,
|
package/dist/Autocomplete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autocomplete.js","names":["createContext","forwardRef","memo","useCallback","useContext","useEffect","useMemo","useRef","useState","styled","VariableSizeList","useTranslation","Field","ComponentControlledState","useInputValues","getControlState","jsx","_jsx","createElement","_createElement","AutocompleteTestSelector","accessibleText","errorMessage","hint","label","children","list","listItem","elementSelector","method","options","role","isControlledElement","ListboxContainer","div","Autocomplete","ariaDescribedBy","defaultValue","errorMessageList","hasMultipleChoices","id","idOverride","inputValue","isCustomValueAllowed","isDisabled","isFullWidth","isLoading","isOptional","isReadOnly","isVirtualized","isVirtualizedProp","HintLinkComponent","name","nameOverride","noOptionsText","onBlur","onChange","onChangeProp","onInputChange","onInputChangeProp","onFocus","value","getIsOptionEqualToValue","testId","translate","t","controlledStateRef","controlledValue","uncontrolledValue","Boolean","defaultValueProp","undefined","valueProps","controlState","current","inputValueProp","CONTROLLED","renderInput","InputLabelProps","InputProps","params","fieldType","hasVisibleLabel","htmlFor","renderFieldComponent","errorMessageElementId","labelElementId","_InputBase","inputProps","required","Row","data","index","setItemSize","style","rowRef","firstChild","firstElementChild","height","clientHeight","baseOption","key","props","styles","ref","OuterListboxContext","OuterListboxElementType","outerProps","useResetCache","length","resetCacheRef","resetAfterIndex","ListboxComponent","listHeight","setListHeight","other","itemData","flatMap","item","concat","sizeMap","getListBoxHeight","COMBINED_LISTBOX_PADDING","OVERSCAN_ROW_COUNT","itemsHeightCalculated","map","_","reduce","prevItemHeight","nextItemHeight","gridRef","size","getItemSize","Provider","innerElementType","itemCount","itemSize","width","outerElementType","overscanCount","event","reason","details","_Autocomplete","clearText","closeText","disableCloseOnSelect","disabled","freeSolo","filterSelectedOptions","fullWidth","loading","multiple","openText","readOnly","isOptionEqualToValue","MemoizedAutocomplete","displayName"],"sources":["../src/Autocomplete.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n Autocomplete as MuiAutocomplete,\n AutocompleteProps as MuiAutocompleteProps,\n InputBase,\n UseAutocompleteProps,\n AutocompleteValue,\n AutocompleteRenderInputParams,\n} from \"@mui/material\";\nimport {\n createContext,\n forwardRef,\n HTMLAttributes,\n memo,\n ReactElement,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport styled from \"@emotion/styled\";\nimport { VariableSizeList, ListChildComponentProps } from \"react-window\";\nimport { useTranslation } from \"react-i18next\";\n\nimport { Field } from \"./Field\";\nimport { FieldComponentProps } from \"./FieldComponentProps\";\nimport type { HtmlProps } from \"./HtmlProps\";\nimport {\n ComponentControlledState,\n useInputValues,\n getControlState,\n} from \"./inputUtils\";\nimport { TestSelector } from \"./test-selectors\";\n\nexport const AutocompleteTestSelector = {\n accessibleText: {\n errorMessage: \"errorMessage\",\n hint: \"description\",\n label: \"label\",\n },\n children: {\n list: {\n children: {\n listItem: {\n elementSelector: {\n method: \"ByRole\",\n options: {\n label: \"name\",\n },\n role: \"option\",\n },\n },\n },\n isControlledElement: true,\n },\n },\n elementSelector: {\n method: \"ByRole\",\n options: {\n label: \"name\",\n },\n role: \"combobox\",\n },\n} as const satisfies TestSelector;\n\ntype SetItemSize = (size: number) => void;\n\nexport type AutocompleteProps<\n OptionType,\n HasMultipleChoices extends boolean | undefined,\n IsCustomValueAllowed extends boolean | undefined,\n> = {\n /**\n * The default value. Use when the component is not controlled.\n */\n defaultValue?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"defaultValue\"];\n /**\n * Enables multiple choice selection\n */\n hasMultipleChoices?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"multiple\"];\n /**\n * The value for the input\n */\n inputValue?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"inputValue\"];\n /**\n * Allows the input of custom values\n */\n isCustomValueAllowed?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"freeSolo\"];\n /**\n * Disables the Autocomplete input\n */\n isDisabled?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"disabled\"];\n /**\n * Displays a loading indicator\n */\n isLoading?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"loading\"];\n /**\n * Makes the Autocomplete input read-only\n */\n isReadOnly?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"readOnly\"];\n /**\n * The label text for the autocomplete input\n */\n label: string;\n /**\n * The text to display when no options are available\n *\n * default: \"No Options\"\n */\n noOptionsText?: string;\n /**\n * Callback fired when the autocomplete loses focus.\n */\n onBlur?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onBlur\"];\n /**\n * Callback fired when a selection is made.\n */\n onChange?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onChange\"];\n /**\n * Callback fired when the textbox receives typed characters.\n */\n onInputChange?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onInputChange\"];\n /**\n * Callback fired when the autocomplete gains focus.\n */\n onFocus?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onFocus\"];\n /**\n * The options for the Autocomplete input\n */\n options: ReadonlyArray<OptionType>;\n /**\n * The value of the Autocomplete input\n */\n value?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"value\"];\n\n /**\n * Used to determine if the option represents the given value. Uses strict equality by default if none provided.\n * Both arguments need to be handled, an option can only match with one value.\n * option: the option to test\n * value: the value to test against\n *\n * You will need to implement this function if your `option` items are objects.\n */\n getIsOptionEqualToValue?: (option: OptionType, value: OptionType) => boolean;\n\n /**\n * If this component is required to display a virtualized list of options,\n * then this value needs to be set to true.\n * It is recommended if you're options are on the order of 10's of hundreds or more.\n */\n isVirtualized?: boolean;\n} & Pick<\n FieldComponentProps,\n | \"errorMessage\"\n | \"errorMessageList\"\n | \"hint\"\n | \"HintLinkComponent\"\n | \"id\"\n | \"isFullWidth\"\n | \"isOptional\"\n | \"name\"\n> &\n Pick<HtmlProps, \"ariaDescribedBy\" | \"testId\" | \"translate\">;\n\nconst ListboxContainer = styled.div`\n width: 100%;\n height: 100%;\n`;\n\nconst Autocomplete = <\n OptionType,\n HasMultipleChoices extends boolean | undefined,\n IsCustomValueAllowed extends boolean | undefined,\n>({\n ariaDescribedBy,\n defaultValue,\n errorMessage,\n errorMessageList,\n hasMultipleChoices,\n id: idOverride,\n inputValue,\n isCustomValueAllowed,\n isDisabled,\n isFullWidth = false,\n isLoading,\n isOptional = false,\n isReadOnly,\n isVirtualized: isVirtualizedProp = false,\n hint,\n HintLinkComponent,\n label,\n name: nameOverride,\n noOptionsText,\n onBlur,\n onChange: onChangeProp,\n onInputChange: onInputChangeProp,\n onFocus,\n options,\n value,\n getIsOptionEqualToValue,\n testId,\n translate,\n}: AutocompleteProps<OptionType, HasMultipleChoices, IsCustomValueAllowed>) => {\n const { t } = useTranslation();\n const controlledStateRef = useRef(\n getControlState({\n controlledValue: value,\n uncontrolledValue: defaultValue,\n }),\n );\n\n const isVirtualized = useRef(Boolean(isVirtualizedProp));\n\n const defaultValueProp = useMemo<\n | AutocompleteValue<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >\n | undefined\n >(() => {\n if (hasMultipleChoices) {\n if (value === undefined) {\n return defaultValue;\n }\n return [] as AutocompleteValue<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >;\n }\n return value === undefined ? defaultValue : undefined;\n }, [defaultValue, hasMultipleChoices, value]);\n\n const valueProps = useInputValues({\n defaultValue: defaultValueProp,\n value: value,\n controlState: controlledStateRef.current,\n });\n\n const inputValueProp = useMemo(() => {\n if (controlledStateRef.current === ComponentControlledState.CONTROLLED) {\n return { inputValue };\n }\n return undefined;\n }, [inputValue]);\n\n const renderInput = useCallback(\n ({\n InputLabelProps,\n InputProps,\n ...params\n }: AutocompleteRenderInputParams) => (\n <Field\n ariaDescribedBy={ariaDescribedBy}\n errorMessage={errorMessage}\n errorMessageList={errorMessageList}\n fieldType=\"single\"\n hasVisibleLabel\n //@ts-expect-error htmlFor does not exist ont he InputLabelProps for autocomplete\n id={InputLabelProps.htmlFor}\n isFullWidth={isFullWidth}\n hint={hint}\n HintLinkComponent={HintLinkComponent}\n label={label}\n isOptional={isOptional}\n renderFieldComponent={({\n ariaDescribedBy,\n id,\n errorMessageElementId,\n labelElementId,\n }) => (\n <InputBase\n {...params}\n {...InputProps}\n inputProps={{\n ...params.inputProps,\n \"aria-errormessage\": errorMessageElementId,\n \"aria-labelledby\": labelElementId,\n \"data-se\": testId,\n }}\n aria-describedby={ariaDescribedBy}\n id={id}\n name={nameOverride ?? id}\n required={!isOptional}\n />\n )}\n />\n ),\n [\n ariaDescribedBy,\n errorMessage,\n errorMessageList,\n hint,\n HintLinkComponent,\n isFullWidth,\n isOptional,\n label,\n nameOverride,\n testId,\n ],\n );\n\n const Row = ({\n data,\n index,\n setItemSize,\n style,\n }: ListChildComponentProps & { setItemSize: SetItemSize }) => {\n const rowRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (rowRef.current) {\n /**\n * Checking for child height to workaround a bug where the clientHeight of the row isn't updated correctly\n * @see here if you need to know more: https://github.com/bvaughn/react-window/issues/582#issuecomment-1883074908\n */\n const firstChild = rowRef.current.firstElementChild;\n const height = firstChild\n ? firstChild.clientHeight\n : rowRef.current.clientHeight;\n\n setItemSize(height);\n }\n }, [index, rowRef, setItemSize]);\n\n const baseOption = data[index];\n const { key, props } = baseOption;\n\n /**\n * react-window calculates the absolute positions of the list items, via an inline style, so\n * we need to add it to each list item that is being rendered in the viewable list window.\n * @see here if you need to know more: https://github.com/bvaughn/react-window?tab=readme-ov-file#why-is-my-list-blank-when-i-scroll\n */\n const styles = useMemo(\n () => ({\n ...style,\n height: \"auto\",\n }),\n [style],\n );\n\n return (\n <div ref={rowRef}>\n <li {...props} key={key} style={styles} />\n </div>\n );\n };\n\n const OuterListboxContext = createContext({});\n\n const OuterListboxElementType = forwardRef<HTMLDivElement>((props, ref) => {\n const outerProps = useContext(OuterListboxContext);\n return <div ref={ref} {...props} {...outerProps} />;\n });\n\n const useResetCache = (length: number) => {\n const resetCacheRef = useRef<VariableSizeList>(null);\n useEffect(() => {\n if (resetCacheRef.current) {\n resetCacheRef.current.resetAfterIndex(0, true);\n }\n }, [length]);\n return resetCacheRef;\n };\n\n const ListboxComponent = forwardRef<\n HTMLDivElement,\n HTMLAttributes<HTMLElement>\n >(function (props, ref) {\n const [listHeight, setListHeight] = useState(0);\n\n const { children, ...other } = props;\n const itemData: ReactElement[] = (children as ReactElement[]).flatMap(\n (item: ReactElement & { children?: ReactElement[] }) =>\n [item].concat(item.children || []),\n );\n\n const sizeMap = useRef<number[]>([]);\n\n const getListBoxHeight = useCallback(() => {\n // 8px of padding top/bottom applied by MUI\n const COMBINED_LISTBOX_PADDING = 16;\n\n if (itemData.length > OVERSCAN_ROW_COUNT) {\n // has a max-height of 40vh set in CSS. This is only set because height needs to be a number\n return 99999;\n } else {\n const itemsHeightCalculated = itemData\n .map((_, index) => sizeMap.current[index] || 0)\n .reduce(\n (prevItemHeight, nextItemHeight) => prevItemHeight + nextItemHeight,\n 0,\n );\n return COMBINED_LISTBOX_PADDING + itemsHeightCalculated;\n }\n }, [itemData, sizeMap]);\n\n useEffect(() => {\n if (sizeMap.current.length && itemData.length) {\n setListHeight(getListBoxHeight());\n }\n }, [getListBoxHeight, itemData, sizeMap]);\n\n // The number of items (rows or columns) to render outside of the visible area for performance and scrolling reasons\n const OVERSCAN_ROW_COUNT = 8;\n\n const gridRef = useResetCache(itemData.length);\n\n const setItemSize = useCallback<SetItemSize>(\n (size) => {\n gridRef?.current?.resetAfterIndex(0, true);\n sizeMap.current = sizeMap.current.concat(size);\n },\n [gridRef, sizeMap],\n );\n const getItemSize = useCallback(\n // using 45px as a sane default here to avoid a lot of content shift on repaint\n (index: number) => sizeMap.current[index] || 45,\n [sizeMap],\n );\n\n return (\n <ListboxContainer ref={ref}>\n <OuterListboxContext.Provider value={other}>\n <VariableSizeList\n innerElementType=\"ul\"\n itemData={itemData}\n itemCount={itemData.length}\n itemSize={getItemSize}\n height={listHeight}\n width=\"100%\"\n ref={gridRef}\n outerElementType={OuterListboxElementType}\n overscanCount={OVERSCAN_ROW_COUNT}\n >\n {({ data, index, style }) => (\n <Row\n data={data}\n index={index}\n style={style}\n setItemSize={setItemSize}\n />\n )}\n </VariableSizeList>\n </OuterListboxContext.Provider>\n </ListboxContainer>\n );\n });\n\n const onChange = useCallback<\n NonNullable<\n UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onChange\"]\n >\n >(\n (event, value, reason, details) => {\n onChangeProp?.(event, value, reason, details);\n },\n [onChangeProp],\n );\n\n const onInputChange = useCallback<\n NonNullable<\n UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onInputChange\"]\n >\n >(\n (event, value, reason) => {\n onInputChangeProp?.(event, value, reason);\n },\n [onInputChangeProp],\n );\n\n return (\n <MuiAutocomplete\n {...valueProps}\n {...inputValueProp}\n // conditionally provide the ListboxComponent if this needs to be virtualized\n {...(isVirtualized.current && {\n ListboxComponent,\n })}\n // AutoComplete is wrapped in a div within MUI which does not get the disabled attr. So this aria-disabled gets set in the div\n aria-disabled={isDisabled}\n clearText={t(\"clear.text\")}\n closeText={t(\"close.text\")}\n disableCloseOnSelect={hasMultipleChoices}\n disabled={isDisabled}\n freeSolo={isCustomValueAllowed}\n filterSelectedOptions={true}\n id={idOverride}\n fullWidth={isFullWidth}\n loading={isLoading}\n multiple={hasMultipleChoices}\n noOptionsText={noOptionsText}\n onBlur={onBlur}\n onChange={onChange}\n onInputChange={onInputChange}\n onFocus={onFocus}\n openText={t(\"open.text\")}\n options={options}\n readOnly={isReadOnly}\n renderInput={renderInput}\n isOptionEqualToValue={getIsOptionEqualToValue}\n translate={translate}\n />\n );\n};\n\n// Need the `typeof Autocomplete` because generics don't get passed through\nconst MemoizedAutocomplete = memo(Autocomplete) as typeof Autocomplete;\n// @ts-expect-error displayName is expected to not be on `typeof Autocomplete`\nMemoizedAutocomplete.displayName = \"Autocomplete\";\n\nexport { MemoizedAutocomplete as Autocomplete };\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAUA,SACEA,aAAa,EACbC,UAAU,EAEVC,IAAI,EAEJC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,OAAOC,MAAM,MAAM,iBAAiB;AACpC,SAASC,gBAAgB,QAAiC,cAAc;AACxE,SAASC,cAAc,QAAQ,eAAe;AAAC,SAEtCC,KAAK;AAAA,SAIZC,wBAAwB,EACxB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IACxBlF,iBAAiB,GAAGiF,KAAK,EAAE/E,KAAK,EAAEgF,MAAM,CAAC;EAC3C,CAAC,EACD,CAAClF,iBAAiB,CACpB,CAAC;EAED,OACE1C,IAAA,CAAA8H,aAAA;IAAA,GACMvE,UAAU;IAAA,GACVG,cAAc;IAAA,IAEb1B,aAAa,CAACyB,OAAO,IAAI;MAC5BsC;IACF,CAAC;IAED,iBAAepE,UAAW;IAC1BoG,SAAS,EAAE/E,CAAC,CAAC,YAAY,CAAE;IAC3BgF,SAAS,EAAEhF,CAAC,CAAC,YAAY,CAAE;IAC3BiF,oBAAoB,EAAE3G,kBAAmB;IACzC4G,QAAQ,EAAEvG,UAAW;IACrBwG,QAAQ,EAAEzG,oBAAqB;IAC/B0G,qBAAqB,EAAE,IAAK;IAC5B7G,EAAE,EAAEC,UAAW;IACf6G,SAAS,EAAEzG,WAAY;IACvB0G,OAAO,EAAEzG,SAAU;IACnB0G,QAAQ,EAAEjH,kBAAmB;IAC7Be,aAAa,EAAEA,aAAc;IAC7BC,MAAM,EAAEA,MAAO;IACfC,QAAQ,EAAEA,QAAS;IACnBE,aAAa,EAAEA,aAAc;IAC7BE,OAAO,EAAEA,OAAQ;IACjB6F,QAAQ,EAAExF,CAAC,CAAC,WAAW,CAAE;IACzBnC,OAAO,EAAEA,OAAQ;IACjB4H,QAAQ,EAAE1G,UAAW;IACrB6B,WAAW,EAAEA,WAAY;IACzB8E,oBAAoB,EAAE7F,uBAAwB;IAC9CE,SAAS,EAAEA;EAAU,CACtB,CAAC;AAEN,CAAC;AAGD,MAAM4F,oBAAoB,GAAG1J,IAAI,CAACiC,YAAY,CAAwB;AAEtEyH,oBAAoB,CAACC,WAAW,GAAG,cAAc;AAEjD,SAASD,oBAAoB,IAAIzH,YAAY"}
|
|
1
|
+
{"version":3,"file":"Autocomplete.js","names":["createContext","forwardRef","memo","useCallback","useContext","useEffect","useMemo","useRef","useState","styled","VariableSizeList","useTranslation","Field","ComponentControlledState","useInputValues","getControlState","jsx","_jsx","createElement","_createElement","AutocompleteTestSelector","accessibleText","errorMessage","hint","label","children","list","listItem","elementSelector","method","options","role","isControlledElement","ListboxContainer","div","Autocomplete","ariaDescribedBy","defaultValue","errorMessageList","getOptionLabel","hasMultipleChoices","id","idOverride","inputValue","isCustomValueAllowed","isDisabled","isFullWidth","isLoading","isOptional","isReadOnly","isVirtualized","isVirtualizedProp","HintLinkComponent","name","nameOverride","noOptionsText","onBlur","onChange","onChangeProp","onInputChange","onInputChangeProp","onFocus","value","getIsOptionEqualToValue","testId","translate","t","controlledStateRef","controlledValue","uncontrolledValue","Boolean","defaultValueProp","undefined","valueProps","controlState","current","inputValueProp","CONTROLLED","renderInput","InputLabelProps","InputProps","params","fieldType","hasVisibleLabel","htmlFor","renderFieldComponent","errorMessageElementId","labelElementId","_InputBase","inputProps","required","Row","data","index","setItemSize","style","rowRef","firstChild","firstElementChild","height","clientHeight","baseOption","key","props","styles","ref","OuterListboxContext","OuterListboxElementType","outerProps","useResetCache","length","resetCacheRef","resetAfterIndex","ListboxComponent","listHeight","setListHeight","other","itemData","flatMap","item","concat","sizeMap","getListBoxHeight","COMBINED_LISTBOX_PADDING","OVERSCAN_ROW_COUNT","itemsHeightCalculated","map","_","reduce","prevItemHeight","nextItemHeight","gridRef","size","getItemSize","Provider","innerElementType","itemCount","itemSize","width","outerElementType","overscanCount","event","reason","details","_Autocomplete","clearText","closeText","disableCloseOnSelect","disabled","freeSolo","filterSelectedOptions","fullWidth","loading","multiple","openText","readOnly","isOptionEqualToValue","MemoizedAutocomplete","displayName"],"sources":["../src/Autocomplete.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n Autocomplete as MuiAutocomplete,\n AutocompleteProps as MuiAutocompleteProps,\n InputBase,\n UseAutocompleteProps,\n AutocompleteValue,\n AutocompleteRenderInputParams,\n} from \"@mui/material\";\nimport {\n createContext,\n forwardRef,\n HTMLAttributes,\n memo,\n ReactElement,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport styled from \"@emotion/styled\";\nimport { VariableSizeList, ListChildComponentProps } from \"react-window\";\nimport { useTranslation } from \"react-i18next\";\n\nimport { Field } from \"./Field\";\nimport { FieldComponentProps } from \"./FieldComponentProps\";\nimport type { HtmlProps } from \"./HtmlProps\";\nimport {\n ComponentControlledState,\n useInputValues,\n getControlState,\n} from \"./inputUtils\";\nimport { TestSelector } from \"./test-selectors\";\n\nexport const AutocompleteTestSelector = {\n accessibleText: {\n errorMessage: \"errorMessage\",\n hint: \"description\",\n label: \"label\",\n },\n children: {\n list: {\n children: {\n listItem: {\n elementSelector: {\n method: \"ByRole\",\n options: {\n label: \"name\",\n },\n role: \"option\",\n },\n },\n },\n isControlledElement: true,\n },\n },\n elementSelector: {\n method: \"ByRole\",\n options: {\n label: \"name\",\n },\n role: \"combobox\",\n },\n} as const satisfies TestSelector;\n\ntype SetItemSize = (size: number) => void;\n\nexport type AutocompleteProps<\n OptionType,\n HasMultipleChoices extends boolean | undefined,\n IsCustomValueAllowed extends boolean | undefined,\n> = {\n /**\n * The default value. Use when the component is not controlled.\n */\n defaultValue?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"defaultValue\"];\n /**\n * Used to determine the string value for a given option. It's used to fill the input (and the list box options if renderOption is not provided). If used in free solo mode, it must accept both the type of the options and a string.\n *\n * `function(option: Value) => string`\n */\n getOptionLabel?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"getOptionLabel\"];\n /**\n * Enables multiple choice selection\n */\n hasMultipleChoices?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"multiple\"];\n /**\n * The value for the input\n */\n inputValue?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"inputValue\"];\n /**\n * Allows the input of custom values\n */\n isCustomValueAllowed?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"freeSolo\"];\n /**\n * Disables the Autocomplete input\n */\n isDisabled?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"disabled\"];\n /**\n * Displays a loading indicator\n */\n isLoading?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"loading\"];\n /**\n * Makes the Autocomplete input read-only\n */\n isReadOnly?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"readOnly\"];\n /**\n * The label text for the autocomplete input\n */\n label: string;\n /**\n * The text to display when no options are available\n *\n * default: \"No Options\"\n */\n noOptionsText?: string;\n /**\n * Callback fired when the autocomplete loses focus.\n */\n onBlur?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onBlur\"];\n /**\n * Callback fired when a selection is made.\n */\n onChange?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onChange\"];\n /**\n * Callback fired when the textbox receives typed characters.\n */\n onInputChange?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onInputChange\"];\n /**\n * Callback fired when the autocomplete gains focus.\n */\n onFocus?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onFocus\"];\n /**\n * The options for the Autocomplete input\n */\n options: ReadonlyArray<OptionType>;\n /**\n * The value of the Autocomplete input\n */\n value?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"value\"];\n\n /**\n * Used to determine if the option represents the given value. Uses strict equality by default if none provided.\n * Both arguments need to be handled, an option can only match with one value.\n * option: the option to test\n * value: the value to test against\n *\n * You will need to implement this function if your `option` items are objects.\n */\n getIsOptionEqualToValue?: (option: OptionType, value: OptionType) => boolean;\n\n /**\n * If this component is required to display a virtualized list of options,\n * then this value needs to be set to true.\n * It is recommended if you're options are on the order of 10's of hundreds or more.\n */\n isVirtualized?: boolean;\n} & Pick<\n FieldComponentProps,\n | \"errorMessage\"\n | \"errorMessageList\"\n | \"hint\"\n | \"HintLinkComponent\"\n | \"id\"\n | \"isFullWidth\"\n | \"isOptional\"\n | \"name\"\n> &\n Pick<HtmlProps, \"ariaDescribedBy\" | \"testId\" | \"translate\">;\n\nconst ListboxContainer = styled.div`\n width: 100%;\n height: 100%;\n`;\n\nconst Autocomplete = <\n OptionType,\n HasMultipleChoices extends boolean | undefined,\n IsCustomValueAllowed extends boolean | undefined,\n>({\n ariaDescribedBy,\n defaultValue,\n errorMessage,\n errorMessageList,\n getOptionLabel,\n hasMultipleChoices,\n id: idOverride,\n inputValue,\n isCustomValueAllowed,\n isDisabled,\n isFullWidth = false,\n isLoading,\n isOptional = false,\n isReadOnly,\n isVirtualized: isVirtualizedProp = false,\n hint,\n HintLinkComponent,\n label,\n name: nameOverride,\n noOptionsText,\n onBlur,\n onChange: onChangeProp,\n onInputChange: onInputChangeProp,\n onFocus,\n options,\n value,\n getIsOptionEqualToValue,\n testId,\n translate,\n}: AutocompleteProps<OptionType, HasMultipleChoices, IsCustomValueAllowed>) => {\n const { t } = useTranslation();\n const controlledStateRef = useRef(\n getControlState({\n controlledValue: value,\n uncontrolledValue: defaultValue,\n }),\n );\n\n const isVirtualized = useRef(Boolean(isVirtualizedProp));\n\n const defaultValueProp = useMemo<\n | AutocompleteValue<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >\n | undefined\n >(() => {\n if (hasMultipleChoices) {\n if (value === undefined) {\n return defaultValue;\n }\n return [] as AutocompleteValue<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >;\n }\n return value === undefined ? defaultValue : undefined;\n }, [defaultValue, hasMultipleChoices, value]);\n\n const valueProps = useInputValues({\n defaultValue: defaultValueProp,\n value: value,\n controlState: controlledStateRef.current,\n });\n\n const inputValueProp = useMemo(() => {\n if (controlledStateRef.current === ComponentControlledState.CONTROLLED) {\n return { inputValue };\n }\n return undefined;\n }, [inputValue]);\n\n const renderInput = useCallback(\n ({\n InputLabelProps,\n InputProps,\n ...params\n }: AutocompleteRenderInputParams) => (\n <Field\n ariaDescribedBy={ariaDescribedBy}\n errorMessage={errorMessage}\n errorMessageList={errorMessageList}\n fieldType=\"single\"\n hasVisibleLabel\n //@ts-expect-error htmlFor does not exist ont he InputLabelProps for autocomplete\n id={InputLabelProps.htmlFor}\n isFullWidth={isFullWidth}\n hint={hint}\n HintLinkComponent={HintLinkComponent}\n label={label}\n isOptional={isOptional}\n renderFieldComponent={({\n ariaDescribedBy,\n id,\n errorMessageElementId,\n labelElementId,\n }) => (\n <InputBase\n {...params}\n {...InputProps}\n inputProps={{\n ...params.inputProps,\n \"aria-errormessage\": errorMessageElementId,\n \"aria-labelledby\": labelElementId,\n \"data-se\": testId,\n }}\n aria-describedby={ariaDescribedBy}\n id={id}\n name={nameOverride ?? id}\n required={!isOptional}\n />\n )}\n />\n ),\n [\n ariaDescribedBy,\n errorMessage,\n errorMessageList,\n hint,\n HintLinkComponent,\n isFullWidth,\n isOptional,\n label,\n nameOverride,\n testId,\n ],\n );\n\n const Row = ({\n data,\n index,\n setItemSize,\n style,\n }: ListChildComponentProps & { setItemSize: SetItemSize }) => {\n const rowRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (rowRef.current) {\n /**\n * Checking for child height to workaround a bug where the clientHeight of the row isn't updated correctly\n * @see here if you need to know more: https://github.com/bvaughn/react-window/issues/582#issuecomment-1883074908\n */\n const firstChild = rowRef.current.firstElementChild;\n const height = firstChild\n ? firstChild.clientHeight\n : rowRef.current.clientHeight;\n\n setItemSize(height);\n }\n }, [index, rowRef, setItemSize]);\n\n const baseOption = data[index];\n const { key, props } = baseOption;\n\n /**\n * react-window calculates the absolute positions of the list items, via an inline style, so\n * we need to add it to each list item that is being rendered in the viewable list window.\n * @see here if you need to know more: https://github.com/bvaughn/react-window?tab=readme-ov-file#why-is-my-list-blank-when-i-scroll\n */\n const styles = useMemo(\n () => ({\n ...style,\n height: \"auto\",\n }),\n [style],\n );\n\n return (\n <div ref={rowRef}>\n <li {...props} key={key} style={styles} />\n </div>\n );\n };\n\n const OuterListboxContext = createContext({});\n\n const OuterListboxElementType = forwardRef<HTMLDivElement>((props, ref) => {\n const outerProps = useContext(OuterListboxContext);\n return <div ref={ref} {...props} {...outerProps} />;\n });\n\n const useResetCache = (length: number) => {\n const resetCacheRef = useRef<VariableSizeList>(null);\n useEffect(() => {\n if (resetCacheRef.current) {\n resetCacheRef.current.resetAfterIndex(0, true);\n }\n }, [length]);\n return resetCacheRef;\n };\n\n const ListboxComponent = forwardRef<\n HTMLDivElement,\n HTMLAttributes<HTMLElement>\n >(function (props, ref) {\n const [listHeight, setListHeight] = useState(0);\n\n const { children, ...other } = props;\n const itemData: ReactElement[] = (children as ReactElement[]).flatMap(\n (item: ReactElement & { children?: ReactElement[] }) =>\n [item].concat(item.children || []),\n );\n\n const sizeMap = useRef<number[]>([]);\n\n const getListBoxHeight = useCallback(() => {\n // 8px of padding top/bottom applied by MUI\n const COMBINED_LISTBOX_PADDING = 16;\n\n if (itemData.length > OVERSCAN_ROW_COUNT) {\n // has a max-height of 40vh set in CSS. This is only set because height needs to be a number\n return 99999;\n } else {\n const itemsHeightCalculated = itemData\n .map((_, index) => sizeMap.current[index] || 0)\n .reduce(\n (prevItemHeight, nextItemHeight) => prevItemHeight + nextItemHeight,\n 0,\n );\n return COMBINED_LISTBOX_PADDING + itemsHeightCalculated;\n }\n }, [itemData, sizeMap]);\n\n useEffect(() => {\n if (sizeMap.current.length && itemData.length) {\n setListHeight(getListBoxHeight());\n }\n }, [getListBoxHeight, itemData, sizeMap]);\n\n // The number of items (rows or columns) to render outside of the visible area for performance and scrolling reasons\n const OVERSCAN_ROW_COUNT = 8;\n\n const gridRef = useResetCache(itemData.length);\n\n const setItemSize = useCallback<SetItemSize>(\n (size) => {\n gridRef?.current?.resetAfterIndex(0, true);\n sizeMap.current = sizeMap.current.concat(size);\n },\n [gridRef, sizeMap],\n );\n const getItemSize = useCallback(\n // using 45px as a sane default here to avoid a lot of content shift on repaint\n (index: number) => sizeMap.current[index] || 45,\n [sizeMap],\n );\n\n return (\n <ListboxContainer ref={ref}>\n <OuterListboxContext.Provider value={other}>\n <VariableSizeList\n innerElementType=\"ul\"\n itemData={itemData}\n itemCount={itemData.length}\n itemSize={getItemSize}\n height={listHeight}\n width=\"100%\"\n ref={gridRef}\n outerElementType={OuterListboxElementType}\n overscanCount={OVERSCAN_ROW_COUNT}\n >\n {({ data, index, style }) => (\n <Row\n data={data}\n index={index}\n style={style}\n setItemSize={setItemSize}\n />\n )}\n </VariableSizeList>\n </OuterListboxContext.Provider>\n </ListboxContainer>\n );\n });\n\n const onChange = useCallback<\n NonNullable<\n UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onChange\"]\n >\n >(\n (event, value, reason, details) => {\n onChangeProp?.(event, value, reason, details);\n },\n [onChangeProp],\n );\n\n const onInputChange = useCallback<\n NonNullable<\n UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onInputChange\"]\n >\n >(\n (event, value, reason) => {\n onInputChangeProp?.(event, value, reason);\n },\n [onInputChangeProp],\n );\n\n return (\n <MuiAutocomplete\n {...valueProps}\n {...inputValueProp}\n // conditionally provide the ListboxComponent if this needs to be virtualized\n {...(isVirtualized.current && {\n ListboxComponent,\n })}\n // AutoComplete is wrapped in a div within MUI which does not get the disabled attr. So this aria-disabled gets set in the div\n aria-disabled={isDisabled}\n clearText={t(\"clear.text\")}\n closeText={t(\"close.text\")}\n disableCloseOnSelect={hasMultipleChoices}\n disabled={isDisabled}\n freeSolo={isCustomValueAllowed}\n filterSelectedOptions={true}\n getOptionLabel={getOptionLabel}\n id={idOverride}\n fullWidth={isFullWidth}\n loading={isLoading}\n multiple={hasMultipleChoices}\n noOptionsText={noOptionsText}\n onBlur={onBlur}\n onChange={onChange}\n onInputChange={onInputChange}\n onFocus={onFocus}\n openText={t(\"open.text\")}\n options={options}\n readOnly={isReadOnly}\n renderInput={renderInput}\n isOptionEqualToValue={getIsOptionEqualToValue}\n translate={translate}\n />\n );\n};\n\n// Need the `typeof Autocomplete` because generics don't get passed through\nconst MemoizedAutocomplete = memo(Autocomplete) as typeof Autocomplete;\n// @ts-expect-error displayName is expected to not be on `typeof Autocomplete`\nMemoizedAutocomplete.displayName = \"Autocomplete\";\n\nexport { MemoizedAutocomplete as Autocomplete };\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAUA,SACEA,aAAa,EACbC,UAAU,EAEVC,IAAI,EAEJC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,OAAOC,MAAM,MAAM,iBAAiB;AACpC,SAASC,gBAAgB,QAAiC,cAAc;AACxE,SAASC,cAAc,QAAQ,eAAe;AAAC,SAEtCC,KAAK;AAAA,SAIZC,wBAAwB,EACxBC,cAAc,EACdC,eAAe;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,aAAA,IAAAC,cAAA;AAIjB,OAAO,MAAMC,wBAAwB,GAAG;EACtCC,cAAc,EAAE;IACdC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,CAAA+H,aAAA;IAAA,GACMvE,UAAU;IAAA,GACVG,cAAc;IAAA,IAEb1B,aAAa,CAACyB,OAAO,IAAI;MAC5BsC;IACF,CAAC;IAED,iBAAepE,UAAW;IAC1BoG,SAAS,EAAE/E,CAAC,CAAC,YAAY,CAAE;IAC3BgF,SAAS,EAAEhF,CAAC,CAAC,YAAY,CAAE;IAC3BiF,oBAAoB,EAAE3G,kBAAmB;IACzC4G,QAAQ,EAAEvG,UAAW;IACrBwG,QAAQ,EAAEzG,oBAAqB;IAC/B0G,qBAAqB,EAAE,IAAK;IAC5B/G,cAAc,EAAEA,cAAe;IAC/BE,EAAE,EAAEC,UAAW;IACf6G,SAAS,EAAEzG,WAAY;IACvB0G,OAAO,EAAEzG,SAAU;IACnB0G,QAAQ,EAAEjH,kBAAmB;IAC7Be,aAAa,EAAEA,aAAc;IAC7BC,MAAM,EAAEA,MAAO;IACfC,QAAQ,EAAEA,QAAS;IACnBE,aAAa,EAAEA,aAAc;IAC7BE,OAAO,EAAEA,OAAQ;IACjB6F,QAAQ,EAAExF,CAAC,CAAC,WAAW,CAAE;IACzBpC,OAAO,EAAEA,OAAQ;IACjB6H,QAAQ,EAAE1G,UAAW;IACrB6B,WAAW,EAAEA,WAAY;IACzB8E,oBAAoB,EAAE7F,uBAAwB;IAC9CE,SAAS,EAAEA;EAAU,CACtB,CAAC;AAEN,CAAC;AAGD,MAAM4F,oBAAoB,GAAG3J,IAAI,CAACiC,YAAY,CAAwB;AAEtE0H,oBAAoB,CAACC,WAAW,GAAG,cAAc;AAEjD,SAASD,oBAAoB,IAAI1H,YAAY"}
|
package/dist/Banner.js
CHANGED
|
@@ -21,8 +21,10 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
21
21
|
export const bannerRoleValues = ["status", "alert"];
|
|
22
22
|
export const bannerSeverityValues = ["success", "info", "warning", "error"];
|
|
23
23
|
const Banner = ({
|
|
24
|
-
|
|
24
|
+
linkRel,
|
|
25
|
+
linkTarget,
|
|
25
26
|
linkText,
|
|
27
|
+
linkUrl,
|
|
26
28
|
onClose,
|
|
27
29
|
role,
|
|
28
30
|
severity,
|
|
@@ -47,8 +49,10 @@ const Banner = ({
|
|
|
47
49
|
children: text
|
|
48
50
|
}), linkUrl && _jsx(Link, {
|
|
49
51
|
href: linkUrl,
|
|
50
|
-
|
|
52
|
+
rel: linkRel,
|
|
53
|
+
target: linkTarget,
|
|
51
54
|
translate: translate,
|
|
55
|
+
variant: "monochrome",
|
|
52
56
|
children: linkText
|
|
53
57
|
})]
|
|
54
58
|
});
|
package/dist/Banner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Banner.js","names":["memo","useTranslation","Link","ScreenReaderText","jsx","_jsx","jsxs","_jsxs","bannerRoleValues","bannerSeverityValues","Banner","
|
|
1
|
+
{"version":3,"file":"Banner.js","names":["memo","useTranslation","Link","ScreenReaderText","jsx","_jsx","jsxs","_jsxs","bannerRoleValues","bannerSeverityValues","Banner","linkRel","linkTarget","linkText","linkUrl","onClose","role","severity","text","testId","translate","t","_Alert","variant","children","_AlertTitle","href","rel","target","MemoizedBanner","displayName"],"sources":["../src/Banner.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { memo } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { Alert, AlertColor, AlertTitle, AlertProps } from \"@mui/material\";\n\nimport type { HtmlProps } from \"./HtmlProps\";\nimport { Link, LinkProps } from \"./Link\";\nimport { ScreenReaderText } from \"./ScreenReaderText\";\n\nexport const bannerRoleValues = [\"status\", \"alert\"] as const;\nexport const bannerSeverityValues: AlertColor[] = [\n \"success\",\n \"info\",\n \"warning\",\n \"error\",\n];\n\nexport type BannerProps = {\n /**\n * The function that's fired when the user clicks the close button. If undefined,\n * the close button will not be shown.\n */\n onClose?: AlertProps[\"onClose\"];\n /**\n * Sets the ARIA role of the alert\n * (\"status\" for something that dynamically updates, \"alert\" for errors, null for something\n * unchanging)\n */\n role?: (typeof bannerRoleValues)[number];\n /**\n * Determine the color and icon of the alert\n */\n severity: (typeof bannerSeverityValues)[number];\n /**\n * The text content of the alert\n */\n text: string;\n} & Pick<HtmlProps, \"testId\" | \"translate\"> &\n (\n | {\n linkRel?: LinkProps[\"rel\"];\n linkTarget?: LinkProps[\"target\"];\n linkText: string;\n /**\n * If defined, the Banner will include a link to the URL\n */\n linkUrl: LinkProps[\"href\"];\n }\n | {\n linkRel?: never;\n linkTarget?: never;\n linkText?: never;\n linkUrl?: never;\n }\n );\n\nconst Banner = ({\n linkRel,\n linkTarget,\n linkText,\n linkUrl,\n onClose,\n role,\n severity,\n text,\n testId,\n translate,\n}: BannerProps) => {\n const { t } = useTranslation();\n\n return (\n <Alert\n data-se={testId}\n onClose={onClose}\n role={role}\n severity={severity}\n variant=\"banner\"\n >\n <ScreenReaderText translate={translate}>\n {t(`severity.${severity}`)}\n </ScreenReaderText>\n <AlertTitle translate={translate}>{text}</AlertTitle>\n {linkUrl && (\n <Link\n href={linkUrl}\n rel={linkRel}\n target={linkTarget}\n translate={translate}\n variant=\"monochrome\"\n >\n {linkText}\n </Link>\n )}\n </Alert>\n );\n};\n\nconst MemoizedBanner = memo(Banner);\nMemoizedBanner.displayName = \"Banner\";\n\nexport { MemoizedBanner as Banner };\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,QAAQ,OAAO;AAC5B,SAASC,cAAc,QAAQ,eAAe;AAAC,SAItCC,IAAI;AAAA,SACJ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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _Alert from "@mui/material/Alert";
|
|
2
|
-
import _Link from "@mui/material/Link";
|
|
3
2
|
import _Box from "@mui/material/Box";
|
|
4
3
|
import _AlertTitle from "@mui/material/AlertTitle";
|
|
5
4
|
/*!
|
|
@@ -17,6 +16,7 @@ import _AlertTitle from "@mui/material/AlertTitle";
|
|
|
17
16
|
import styled from "@emotion/styled";
|
|
18
17
|
import { memo } from "react";
|
|
19
18
|
import { useTranslation } from "react-i18next";
|
|
19
|
+
import { Link } from "./Link.js";
|
|
20
20
|
import { useOdysseyDesignTokens } from "./OdysseyDesignTokensContext.js";
|
|
21
21
|
import { Paragraph } from "./Typography.js";
|
|
22
22
|
import { useUniqueId } from "./useUniqueId.js";
|
|
@@ -59,6 +59,8 @@ const ContentContainer = styled("div", {
|
|
|
59
59
|
}));
|
|
60
60
|
const Callout = ({
|
|
61
61
|
children,
|
|
62
|
+
linkRel,
|
|
63
|
+
linkTarget,
|
|
62
64
|
linkText,
|
|
63
65
|
linkUrl,
|
|
64
66
|
role,
|
|
@@ -93,8 +95,10 @@ const Callout = ({
|
|
|
93
95
|
}), text && _jsx(Paragraph, {
|
|
94
96
|
children: text
|
|
95
97
|
}), linkUrl && _jsx(_Box, {
|
|
96
|
-
children: _jsx(
|
|
98
|
+
children: _jsx(Link, {
|
|
97
99
|
href: linkUrl,
|
|
100
|
+
rel: linkRel,
|
|
101
|
+
target: linkTarget,
|
|
98
102
|
variant: "monochrome",
|
|
99
103
|
children: linkText
|
|
100
104
|
})
|
package/dist/Callout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Callout.js","names":["styled","memo","useTranslation","useOdysseyDesignTokens","Paragraph","useUniqueId","jsx","_jsx","jsxs","_jsxs","CalloutTestSelector","accessibleText","text","title","children","link","elementSelector","method","options","linkText","role","calloutRoleValues","calloutSeverityValues","ContentContainer","shouldForwardProp","prop","odysseyDesignTokens","marginBlockStart","Spacing4","Callout","linkUrl","severity","testId","translate","t","titleId","_Alert","variant","_AlertTitle","id","_Box","component","
|
|
1
|
+
{"version":3,"file":"Callout.js","names":["styled","memo","useTranslation","Link","useOdysseyDesignTokens","Paragraph","useUniqueId","jsx","_jsx","jsxs","_jsxs","CalloutTestSelector","accessibleText","text","title","children","link","elementSelector","method","options","linkText","role","calloutRoleValues","calloutSeverityValues","ContentContainer","shouldForwardProp","prop","odysseyDesignTokens","marginBlockStart","Spacing4","Callout","linkRel","linkTarget","linkUrl","severity","testId","translate","t","titleId","_Alert","variant","_AlertTitle","id","_Box","component","href","rel","target","MemoizedCallout","displayName"],"sources":["../src/Callout.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport styled from \"@emotion/styled\";\nimport { Alert, AlertTitle, Box } from \"@mui/material\";\nimport { memo, ReactNode } from \"react\";\nimport { useTranslation } from \"react-i18next\";\n\nimport type { HtmlProps } from \"./HtmlProps\";\nimport { Link, LinkProps } from \"./Link\";\nimport {\n DesignTokens,\n useOdysseyDesignTokens,\n} from \"./OdysseyDesignTokensContext\";\nimport { type TestSelector } from \"./test-selectors\";\nimport { Paragraph } from \"./Typography\";\nimport { useUniqueId } from \"./useUniqueId\";\n\nexport const CalloutTestSelector = {\n accessibleText: {\n text: \"description\",\n title: \"label\",\n },\n children: {\n link: {\n elementSelector: {\n method: \"ByRole\",\n options: {\n linkText: \"name\",\n },\n role: \"link\",\n },\n },\n },\n elementSelector: {\n method: \"ByRole\",\n options: {\n title: \"name\",\n },\n role: [\"alert\", \"status\"],\n },\n} as const satisfies TestSelector;\n\nexport const calloutRoleValues = [\"status\", \"alert\"] as const;\nexport const calloutSeverityValues = [\n \"success\",\n \"info\",\n \"warning\",\n \"error\",\n] as const;\n\nexport type CalloutProps = {\n /**\n * Used to optionally pass a text list to the component\n */\n children?: ReactNode;\n /**\n * Sets the ARIA role of the Callout\n * (\"status\" for something that dynamically updates, \"alert\" for errors, null for something\n * unchanging)\n */\n role?: (typeof calloutRoleValues)[number];\n /**\n * Determine the color and icon of the Callout\n */\n severity: (typeof calloutSeverityValues)[number];\n /**\n * The text content of the Callout\n */\n text?: string;\n /**\n * The title of the Callout\n */\n title?: string;\n} & (\n | {\n children?: never;\n text: string;\n }\n | {\n children: ReactNode;\n text?: never;\n }\n) &\n (\n | {\n linkRel?: LinkProps[\"rel\"];\n linkTarget?: LinkProps[\"target\"];\n linkText: string;\n /**\n * If defined, the Callout will include a link to the URL\n */\n linkUrl: LinkProps[\"href\"];\n }\n | {\n linkRel?: never;\n linkTarget?: never;\n linkUrl?: never;\n linkText?: never;\n }\n ) &\n Pick<HtmlProps, \"testId\" | \"translate\">;\n\nconst ContentContainer = styled(\"div\", {\n shouldForwardProp: (prop) => prop !== \"odysseyDesignTokens\",\n})(({ odysseyDesignTokens }: { odysseyDesignTokens: DesignTokens }) => ({\n \"& > * + *\": {\n marginBlockStart: odysseyDesignTokens.Spacing4,\n },\n}));\n\nconst Callout = ({\n children,\n linkRel,\n linkTarget,\n linkText,\n linkUrl,\n role,\n severity,\n testId,\n text,\n title,\n translate,\n}: CalloutProps) => {\n const { t } = useTranslation();\n const odysseyDesignTokens = useOdysseyDesignTokens();\n const titleId = useUniqueId();\n\n return (\n <Alert\n aria-label={t(`severity.${severity}`)}\n aria-labelledby={titleId}\n data-se={testId}\n role={role}\n severity={severity}\n variant=\"callout\"\n >\n {title && (\n <AlertTitle aria-hidden id={titleId} translate={translate}>\n {title}\n </AlertTitle>\n )}\n\n <ContentContainer odysseyDesignTokens={odysseyDesignTokens}>\n {children && <Box component=\"div\">{children}</Box>}\n {text && <Paragraph>{text}</Paragraph>}\n {linkUrl && (\n <Box>\n <Link\n href={linkUrl}\n rel={linkRel}\n target={linkTarget}\n variant=\"monochrome\"\n >\n {linkText}\n </Link>\n </Box>\n )}\n </ContentContainer>\n </Alert>\n );\n};\n\nconst MemoizedCallout = memo(Callout);\nMemoizedCallout.displayName = \"Callout\";\n\nexport { MemoizedCallout as Callout };\n"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,MAAM,MAAM,iBAAiB;AAEpC,SAASC,IAAI,QAAmB,OAAO;AACvC,SAASC,cAAc,QAAQ,eAAe;AAAC,SAGtCC,IAAI;AAAA,SAGXC,sBAAsB;AAAA,SAGfC,SAAS;AAAA,SACTC,WAAW;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAEpB,OAAO,MAAMC,mBAAmB,GAAG;EACjCC,cAAc,EAAE;IACdC,IAAI,EAAE,aAAa;IACnBC,KAAK,EAAE;EACT,CAAC;EACDC,QAAQ,EAAE;IACRC,IAAI,EAAE;MACJC,eAAe,EAAE;QACfC,MAAM,EAAE,QAAQ;QAChBC,OAAO,EAAE;UACPC,QAAQ,EAAE;QACZ,CAAC;QACDC,IAAI,EAAE;MACR;IACF;EACF,CAAC;EACDJ,eAAe,EAAE;IACfC,MAAM,EAAE,QAAQ;IAChBC,OAAO,EAAE;MACPL,KAAK,EAAE;IACT,CAAC;IACDO,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ;EAC1B;AACF,CAAiC;AAEjC,OAAO,MAAMC,iBAAiB,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAU;AAC7D,OAAO,MAAMC,qBAAqB,GAAG,CACnC,SAAS,EACT,MAAM,EACN,SAAS,EACT,OAAO,CACC;AAsDV,MAAMC,gBAAgB,GAAGxB,MAAM,CAAC,KAAK,EAAE;EACrCyB,iB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AAEZ,OAAQ;UACda,GAAG,EAAEf,OAAQ;UACbgB,MAAM,EAAEf,UAAW;UACnBQ,OAAO,EAAC,YAAY;UAAAzB,QAAA,EAEnBK;QAAQ,CACL;MAAC,CACJ,CACN;IAAA,CACe,CAAC;EAAA,CACd,CAAC;AAEZ,CAAC;AAED,MAAM4B,eAAe,GAAG/C,IAAI,CAAC6B,OAAO,CAAC;AACrCkB,eAAe,CAACC,WAAW,GAAG,SAAS;AAEvC,SAASD,eAAe,IAAIlB,OAAO"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
3
|
+
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
4
|
+
*
|
|
5
|
+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
6
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
8
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
9
|
+
*
|
|
10
|
+
* See the License for the specific language governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import React, { createContext, useContext, useRef, useLayoutEffect, useState, useMemo } from "react";
|
|
14
|
+
import { createTheme, ThemeProvider, useTheme } from "@mui/material/styles";
|
|
15
|
+
import * as Tokens from "@okta/odyssey-design-tokens";
|
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
const ContrastModeContext = createContext({
|
|
18
|
+
contrastMode: "highContrast",
|
|
19
|
+
parentBackgroundColor: ""
|
|
20
|
+
});
|
|
21
|
+
export const useContrastContext = () => useContext(ContrastModeContext);
|
|
22
|
+
const hexToRgb = hex => {
|
|
23
|
+
const bigint = parseInt(hex.slice(1), 16);
|
|
24
|
+
const r = bigint >> 16 & 255;
|
|
25
|
+
const g = bigint >> 8 & 255;
|
|
26
|
+
const b = bigint & 255;
|
|
27
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
28
|
+
};
|
|
29
|
+
export const useParentBackgroundColor = ref => {
|
|
30
|
+
const [backgroundColor, setBackgroundColor] = useState("");
|
|
31
|
+
const hueNeutral50Rgb = useMemo(() => hexToRgb(Tokens.HueNeutral50), []);
|
|
32
|
+
useLayoutEffect(() => {
|
|
33
|
+
if (ref.current) {
|
|
34
|
+
let element = ref.current;
|
|
35
|
+
while (element) {
|
|
36
|
+
const bgColor = window.getComputedStyle(element).backgroundColor;
|
|
37
|
+
if (bgColor !== "rgba(0, 0, 0, 0)" && bgColor !== "transparent") {
|
|
38
|
+
if (bgColor === hueNeutral50Rgb) {
|
|
39
|
+
setBackgroundColor(Tokens.HueNeutral50);
|
|
40
|
+
} else {
|
|
41
|
+
setBackgroundColor(bgColor);
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
element = element.parentElement;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, [ref, hueNeutral50Rgb]);
|
|
49
|
+
return backgroundColor;
|
|
50
|
+
};
|
|
51
|
+
export const ContrastModeProvider = ({
|
|
52
|
+
children,
|
|
53
|
+
contrastMode: explicitContrastMode
|
|
54
|
+
}) => {
|
|
55
|
+
const ref = useRef(null);
|
|
56
|
+
const parentBackgroundColor = useParentBackgroundColor(ref);
|
|
57
|
+
const [contrastMode, setContrastMode] = useState("highContrast");
|
|
58
|
+
useLayoutEffect(() => {
|
|
59
|
+
if (explicitContrastMode) {
|
|
60
|
+
setContrastMode(explicitContrastMode);
|
|
61
|
+
} else {
|
|
62
|
+
const isLowContrast = parentBackgroundColor === Tokens.HueNeutral50;
|
|
63
|
+
setContrastMode(isLowContrast ? "lowContrast" : "highContrast");
|
|
64
|
+
}
|
|
65
|
+
}, [parentBackgroundColor, explicitContrastMode]);
|
|
66
|
+
const contextValue = useMemo(() => ({
|
|
67
|
+
contrastMode,
|
|
68
|
+
parentBackgroundColor
|
|
69
|
+
}), [contrastMode, parentBackgroundColor]);
|
|
70
|
+
const existingTheme = useTheme();
|
|
71
|
+
const theme = useMemo(() => createTheme({
|
|
72
|
+
...existingTheme,
|
|
73
|
+
odysseyContrastMode: contrastMode
|
|
74
|
+
}), [existingTheme, contrastMode]);
|
|
75
|
+
return _jsx("div", {
|
|
76
|
+
ref: ref,
|
|
77
|
+
children: _jsx(ContrastModeContext.Provider, {
|
|
78
|
+
value: contextValue,
|
|
79
|
+
children: _jsx(ThemeProvider, {
|
|
80
|
+
theme: theme,
|
|
81
|
+
children: children
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=ContrastModeProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContrastModeProvider.js","names":["React","createContext","useContext","useRef","useLayoutEffect","useState","useMemo","createTheme","ThemeProvider","useTheme","Tokens","jsx","_jsx","ContrastModeContext","contrastMode","parentBackgroundColor","useContrastContext","hexToRgb","hex","bigint","parseInt","slice","r","g","b","useParentBackgroundColor","ref","backgroundColor","setBackgroundColor","hueNeutral50Rgb","HueNeutral50","current","element","bgColor","window","getComputedStyle","parentElement","ContrastModeProvider","children","explicitContrastMode","setContrastMode","isLowContrast","contextValue","existingTheme","theme","odysseyContrastMode","Provider","value"],"sources":["../src/ContrastModeProvider.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport React, {\n createContext,\n useContext,\n useRef,\n useLayoutEffect,\n useState,\n useMemo,\n ReactNode,\n} from \"react\";\nimport { createTheme, ThemeProvider, useTheme } from \"@mui/material/styles\";\nimport * as Tokens from \"@okta/odyssey-design-tokens\";\n\ndeclare module \"@mui/material/styles\" {\n interface Theme {\n odysseyContrastMode: ContrastMode;\n }\n interface ThemeOptions {\n odysseyContrastMode?: ContrastMode;\n }\n}\n\nexport type ContrastMode = \"lowContrast\" | \"highContrast\";\n\nexport type ContrastModeContextType = {\n contrastMode: ContrastMode;\n parentBackgroundColor: string;\n};\n\nconst ContrastModeContext = createContext<ContrastModeContextType>({\n contrastMode: \"highContrast\",\n parentBackgroundColor: \"\",\n});\n\nexport const useContrastContext = () => useContext(ContrastModeContext);\n\nconst hexToRgb = (hex: string): string => {\n const bigint = parseInt(hex.slice(1), 16);\n const r = (bigint >> 16) & 255;\n const g = (bigint >> 8) & 255;\n const b = bigint & 255;\n return `rgb(${r}, ${g}, ${b})`;\n};\n\nexport const useParentBackgroundColor = (ref: React.RefObject<HTMLElement>) => {\n const [backgroundColor, setBackgroundColor] = useState(\"\");\n\n const hueNeutral50Rgb = useMemo(() => hexToRgb(Tokens.HueNeutral50), []);\n\n useLayoutEffect(() => {\n if (ref.current) {\n let element: HTMLElement | null = ref.current;\n while (element) {\n const bgColor = window.getComputedStyle(element).backgroundColor;\n\n if (bgColor !== \"rgba(0, 0, 0, 0)\" && bgColor !== \"transparent\") {\n if (bgColor === hueNeutral50Rgb) {\n setBackgroundColor(Tokens.HueNeutral50);\n } else {\n setBackgroundColor(bgColor);\n }\n break;\n }\n element = element.parentElement;\n }\n }\n }, [ref, hueNeutral50Rgb]);\n\n return backgroundColor;\n};\n\ntype ContrastModeProviderProps = {\n children: ReactNode;\n contrastMode?: ContrastMode;\n};\n\nexport const ContrastModeProvider = ({\n children,\n contrastMode: explicitContrastMode,\n}: ContrastModeProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const parentBackgroundColor = useParentBackgroundColor(ref);\n const [contrastMode, setContrastMode] =\n useState<ContrastMode>(\"highContrast\");\n\n useLayoutEffect(() => {\n if (explicitContrastMode) {\n setContrastMode(explicitContrastMode);\n } else {\n const isLowContrast = parentBackgroundColor === Tokens.HueNeutral50;\n setContrastMode(isLowContrast ? \"lowContrast\" : \"highContrast\");\n }\n }, [parentBackgroundColor, explicitContrastMode]);\n\n const contextValue = useMemo<ContrastModeContextType>(\n () => ({\n contrastMode,\n parentBackgroundColor,\n }),\n [contrastMode, parentBackgroundColor],\n );\n\n const existingTheme = useTheme();\n const theme = useMemo(\n () =>\n createTheme({\n ...existingTheme,\n odysseyContrastMode: contrastMode,\n }),\n [existingTheme, contrastMode],\n );\n\n return (\n <div ref={ref}>\n <ContrastModeContext.Provider value={contextValue}>\n <ThemeProvider theme={theme}>{children}</ThemeProvider>\n </ContrastModeContext.Provider>\n </div>\n );\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IACVC,aAAa,EACbC,UAAU,EACVC,MAAM,EACNC,eAAe,EACfC,QAAQ,EACRC,OAAO,QAEF,OAAO;AACd,SAASC,WAAW,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,sBAAsB;AAC3E,OAAO,KAAKC,MAAM,MAAM,6BAA6B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAkBtD,MAAMC,mBAAmB,GAAGZ,aAAa,CAA0B;EACjEa,YAAY,EAAE,cAAc;EAC5BC,qBAAqB,EAAE;AACzB,CAAC,CAAC;AAEF,OAAO,MAAMC,kBAAkB,GAAGA,CAAA,KAAMd,UAAU,CAACW,mBAAmB,CAAC;AAEvE,MAAMI,QAAQ,GAAIC,GAAW,IAAa;EACxC,MAAMC,MAAM,GAAGC,QAAQ,CAACF,GAAG,CAACG,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;EACzC,MAAMC,CAAC,GAAIH,MAAM,IAAI,EAAE,GAAI,GAAG;EAC9B,MAAMI,CAAC,G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Ac,CAAC;EAExCD,eAAe,CAAC,MAAM;IACpB,IAAImC,oBAAoB,EAAE;MACxBC,eAAe,CAACD,oBAAoB,CAAC;IACvC,CAAC,MAAM;MACL,MAAME,aAAa,GAAG1B,qBAAqB,KAAKL,MAAM,CAACoB,YAAY;MACnEU,eAAe,CAACC,aAAa,GAAG,aAAa,GAAG,cAAc,CAAC;IACjE;EACF,CAAC,EAAE,CAAC1B,qBAAqB,EAAEwB,oBAAoB,CAAC,CAAC;EAEjD,MAAMG,YAAY,GAAGpC,OAAO,CAC1B,OAAO;IACLQ,YAAY;IACZC;EACF,CAAC,CAAC,EACF,CAACD,YAAY,EAAEC,qBAAqB,CACtC,CAAC;EAED,MAAM4B,aAAa,GAAGlC,QAAQ,CAAC,CAAC;EAChC,MAAMmC,KAAK,GAAGtC,OAAO,CACnB,MACEC,WAAW,CAAC;IACV,GAAGoC,aAAa;IAChBE,mBAAmB,EAAE/B;EACvB,CAAC,CAAC,EACJ,CAAC6B,aAAa,EAAE7B,YAAY,CAC9B,CAAC;EAED,OACEF,IAAA;IAAKc,GAAG,EAAEA,GAAI;IAAAY,QAAA,EACZ1B,IAAA,CAACC,mBAAmB,CAACiC,QAAQ;MAACC,KAAK,EAAEL,YAAa;MAAAJ,QAAA,EAChD1B,IAAA,CAACJ,aAAa;QAACoC,KAAK,EAAEA,KAAM;QAAAN,QAAA,EAAEA;MAAQ,CAAgB;IAAC,CAC3B;EAAC,CAC5B,CAAC;AAEV,CAAC"}
|
package/dist/FieldHint.js
CHANGED
|
@@ -12,9 +12,23 @@ import _FormHelperText from "@mui/material/FormHelperText";
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { memo } from "react";
|
|
15
|
+
import styled from "@emotion/styled";
|
|
16
|
+
import { useOdysseyDesignTokens } from "./OdysseyDesignTokensContext.js";
|
|
15
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
const HintLinkContainer = styled.span(({
|
|
19
|
+
odysseyDesignTokens
|
|
20
|
+
}) => ({
|
|
21
|
+
a: {
|
|
22
|
+
color: odysseyDesignTokens.TypographyColorBody,
|
|
23
|
+
textDecoration: "underline",
|
|
24
|
+
"&:visited": {
|
|
25
|
+
color: odysseyDesignTokens.TypographyColorBody
|
|
26
|
+
},
|
|
27
|
+
"&:hover": {
|
|
28
|
+
color: odysseyDesignTokens.TypographyColorSubordinate
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
18
32
|
const FieldHint = ({
|
|
19
33
|
id,
|
|
20
34
|
LinkComponent,
|
|
@@ -22,14 +36,14 @@ const FieldHint = ({
|
|
|
22
36
|
text,
|
|
23
37
|
translate
|
|
24
38
|
}) => {
|
|
39
|
+
const odysseyDesignTokens = useOdysseyDesignTokens();
|
|
25
40
|
return _jsxs(_FormHelperText, {
|
|
26
41
|
"data-se": testId,
|
|
27
42
|
id: id,
|
|
28
43
|
translate: translate,
|
|
29
|
-
children: [text, LinkComponent &&
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
})
|
|
44
|
+
children: [text, LinkComponent && _jsxs(HintLinkContainer, {
|
|
45
|
+
odysseyDesignTokens: odysseyDesignTokens,
|
|
46
|
+
children: [" ", LinkComponent]
|
|
33
47
|
})]
|
|
34
48
|
});
|
|
35
49
|
};
|
package/dist/FieldHint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldHint.js","names":["memo","jsxs","_jsxs","
|
|
1
|
+
{"version":3,"file":"FieldHint.js","names":["memo","styled","useOdysseyDesignTokens","jsxs","_jsxs","HintLinkContainer","span","odysseyDesignTokens","a","color","TypographyColorBody","textDecoration","TypographyColorSubordinate","FieldHint","id","LinkComponent","testId","text","translate","_FormHelperText","children","MemoizedFieldHint","displayName"],"sources":["../src/FieldHint.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { memo } from \"react\";\nimport styled from \"@emotion/styled\";\nimport { FormHelperText } from \"@mui/material\";\n\nimport { FieldComponentProps } from \"./FieldComponentProps\";\nimport type { HtmlProps } from \"./HtmlProps\";\nimport {\n useOdysseyDesignTokens,\n DesignTokens,\n} from \"./OdysseyDesignTokensContext\";\n\nconst HintLinkContainer = styled.span<{ odysseyDesignTokens: DesignTokens }>(\n ({ odysseyDesignTokens }) => ({\n a: {\n color: odysseyDesignTokens.TypographyColorBody,\n textDecoration: \"underline\",\n\n \"&:visited\": {\n color: odysseyDesignTokens.TypographyColorBody,\n },\n\n \"&:hover\": {\n color: odysseyDesignTokens.TypographyColorSubordinate,\n },\n },\n }),\n);\n\nexport type FieldHintProps = {\n LinkComponent?: FieldComponentProps[\"HintLinkComponent\"];\n id?: string;\n text: string;\n} & Pick<HtmlProps, \"testId\" | \"translate\">;\n\nconst FieldHint = ({\n id,\n LinkComponent,\n testId,\n text,\n translate,\n}: FieldHintProps) => {\n const odysseyDesignTokens = useOdysseyDesignTokens();\n\n return (\n <FormHelperText data-se={testId} id={id} translate={translate}>\n {text}\n {LinkComponent && (\n <HintLinkContainer odysseyDesignTokens={odysseyDesignTokens}>\n {\" \"}\n {LinkComponent}\n </HintLinkContainer>\n )}\n </FormHelperText>\n );\n};\n\nconst MemoizedFieldHint = memo(FieldHint);\nMemoizedFieldHint.displayName = \"FieldHint\";\n\nexport { MemoizedFieldHint as FieldHint };\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,QAAQ,OAAO;AAC5B,OAAOC,MAAM,MAAM,iBAAiB;AAAC,SAMnCC,sBAAsB;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAIxB,MAAMC,iBAAiB,GAAGJ,MAAM,CAACK,IAAI,CACnC,CAAC;EAAEC;AAAoB,CAAC,MAAM;EAC5BC,CAAC,EAAE;IACDC,KAAK,EAAEF,mBAAmB,CAACG,mBAAmB;IAC9CC,cAAc,EAAE,WAAW;IAE3B,WAAW,EAAE;MACXF,KAAK,EAAEF,mBAAmB,CAACG;IAC7B,CAAC;IAED,SAAS,EAAE;MACTD,KAAK,EAAEF,mBAAmB,CAACK;IAC7B;EACF;AACF,CAAC,CACH,CAAC;AAQD,MAAMC,SAAS,GAAGA,CAAC;EACjBC,EAAE;EACFC,aAAa;EACbC,MAAM;EACNC,IAAI;EACJC;AACc,CAAC,KAAK;EACpB,MAAMX,mBAAmB,GAAGL,sBAAsB,CAAC,CAAC;EAEpD,OACEE,KAAA,CAAAe,eAAA;IAAgB,WAASH,MAAO;IAACF,EAAE,EAAEA,EAAG;IAACI,SAAS,EAAEA,SAAU;IAAAE,QAAA,GAC3DH,IAAI,EACJF,aAAa,IACZX,KAAA,CAACC,iBAAiB;MAACE,mBAAmB,EAAEA,mBAAoB;MAAAa,QAAA,GACzD,GAAG,EACHL,aAAa;IAAA,CACG,CACpB;EAAA,CACa,CAAC;AAErB,CAAC;AAED,MAAMM,iBAAiB,GAAGrB,IAAI,CAACa,SAAS,CAAC;AACzCQ,iBAAiB,CAACC,WAAW,GAAG,WAAW;AAE3C,SAASD,iBAAiB,IAAIR,SAAS"}
|
package/dist/Link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.js","names":["memo","useImperativeHandle","useRef","ExternalLinkIcon","jsx","_jsx","jsxs","_jsxs","linkVariantValues","Link","ariaLabel","children","href","icon","linkRef","rel","target","testId","translate","variant","onClick","localLinkRef","focus","current","_Link","ref","className","role","MemoizedLink","displayName"],"sources":["../src/Link.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { memo, ReactElement, useImperativeHandle, useRef } from \"react\";\nimport { ExternalLinkIcon } from \"./icons.generated\";\nimport type { HtmlProps } from \"./HtmlProps\";\nimport { FocusHandle } from \"./inputUtils\";\n\nimport { Link as MuiLink, LinkProps as MuiLinkProps } from \"@mui/material\";\n\nexport const linkVariantValues = [\"default\", \"monochrome\"] as const;\n\nexport type LinkProps = {\n /**\n * The content within the Link\n */\n children: React.ReactNode;\n /**\n * The Link destination\n */\n href: string;\n /**\n * An optional Icon component at the start of the Link\n */\n icon?: ReactElement;\n /**\n * The ref forwarded to the TextField\n */\n linkRef?: React.RefObject<FocusHandle>;\n /**\n * The click event handler for the Link\n */\n onClick?: MuiLinkProps[\"onClick\"];\n /**\n * The
|
|
1
|
+
{"version":3,"file":"Link.js","names":["memo","useImperativeHandle","useRef","ExternalLinkIcon","jsx","_jsx","jsxs","_jsxs","linkVariantValues","Link","ariaLabel","children","href","icon","linkRef","rel","target","testId","translate","variant","onClick","localLinkRef","focus","current","_Link","ref","className","role","MemoizedLink","displayName"],"sources":["../src/Link.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { memo, ReactElement, useImperativeHandle, useRef } from \"react\";\nimport { ExternalLinkIcon } from \"./icons.generated\";\nimport type { HtmlProps } from \"./HtmlProps\";\nimport { FocusHandle } from \"./inputUtils\";\n\nimport { Link as MuiLink, LinkProps as MuiLinkProps } from \"@mui/material\";\n\nexport const linkVariantValues = [\"default\", \"monochrome\"] as const;\n\nexport type LinkProps = {\n /**\n * The content within the Link\n */\n children: React.ReactNode;\n /**\n * The Link destination\n */\n href: string;\n /**\n * An optional Icon component at the start of the Link\n */\n icon?: ReactElement;\n /**\n * The ref forwarded to the TextField\n */\n linkRef?: React.RefObject<FocusHandle>;\n /**\n * The click event handler for the Link\n */\n onClick?: MuiLinkProps[\"onClick\"];\n /**\n * The rel attribute defines the relationship between a linked resource and the current document\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel\n */\n rel?: string;\n /**\n * The HTML `target` attribute for the Link\n */\n target?:\n | \"_self\"\n | \"_blank\"\n | \"_parent\"\n | \"_top\"\n | (string & NonNullable<unknown>);\n /**\n * The visual presentation of the Link (default or monochrome)\n */\n variant?: (typeof linkVariantValues)[number];\n} & Pick<HtmlProps, \"ariaLabel\" | \"testId\" | \"translate\">;\n\nconst Link = ({\n ariaLabel,\n children,\n href,\n icon,\n linkRef,\n rel,\n target,\n testId,\n translate,\n variant,\n onClick,\n}: LinkProps) => {\n const localLinkRef = useRef<HTMLAnchorElement>(null);\n useImperativeHandle(\n linkRef,\n () => {\n return {\n focus: () => {\n localLinkRef.current?.focus();\n },\n };\n },\n [],\n );\n\n return (\n <MuiLink\n aria-label={ariaLabel}\n data-se={testId}\n href={href}\n ref={localLinkRef}\n rel={rel}\n target={target}\n translate={translate}\n variant={variant}\n onClick={onClick}\n >\n {icon && <span className=\"Link-icon\">{icon}</span>}\n\n {children}\n\n {target === \"_blank\" && (\n <span className=\"Link-indicator\" role=\"presentation\">\n <ExternalLinkIcon />\n </span>\n )}\n </MuiLink>\n );\n};\n\nconst MemoizedLink = memo(Link);\n\nMemoizedLink.displayName = \"Link\";\n\nexport { MemoizedLink as Link };\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,EAAgBC,mBAAmB,EAAEC,MAAM,QAAQ,OAAO;AAAC,SAC/DC,gBAAgB;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAMzB,OAAO,MAAMC,iBAAiB,GAAG,CAAC,SAAS,EAAE,YAAY,CAAU;AA4CnE,MAAMC,IAAI,GAAGA,CAAC;EACZC,SAAS;EACTC,QAAQ;EACRC,IAAI;EACJC,IAAI;EACJC,OAAO;EACPC,GAAG;EACHC,MAAM;EACNC,MAAM;EACNC,SAAS;EACTC,OAAO;EACPC;AACS,CAAC,KAAK;EACf,MAAMC,YAAY,GAAGnB,MAAM,CAAoB,IAAI,CAAC;EACpDD,mBAAmB,CACjBa,OAAO,EACP,MAAM;IACJ,OAAO;MACLQ,KAAK,EAAEA,CAAA,KAAM;QACXD,YAAY,CAACE,OAAO,EAAED,KAAK,CAAC,CAAC;MAC/B;IACF,CAAC;EACH,CAAC,EACD,EACF,CAAC;EAED,OACEf,KAAA,CAAAiB,KAAA;IACE,cAAYd,SAAU;IACtB,WAASO,MAAO;IAChBL,IAAI,EAAEA,IAAK;IACXa,GAAG,EAAEJ,YAAa;IAClBN,GAAG,EAAEA,GAAI;IACTC,MAAM,EAAEA,MAAO;IACfE,SAAS,EAAEA,SAAU;IACrBC,OAAO,EAAEA,OAAQ;IACjBC,OAAO,EAAEA,OAAQ;IAAAT,QAAA,GAEhBE,IAAI,IAAIR,IAAA;MAAMqB,SAAS,EAAC,WAAW;MAAAf,QAAA,EAAEE;IAAI,CAAO,CAAC,EAEjDF,QAAQ,EAERK,MAAM,KAAK,QAAQ,IAClBX,IAAA;MAAMqB,SAAS,EAAC,gBAAgB;MAACC,IAAI,EAAC,cAAc;MAAAhB,QAAA,EAClDN,IAAA,CAACF,gBAAgB,IAAE;IAAC,CAChB,CACP;EAAA,CACM,CAAC;AAEd,CAAC;AAED,MAAMyB,YAAY,GAAG5B,IAAI,CAACS,IAAI,CAAC;AAE/BmB,YAAY,CAACC,WAAW,GAAG,MAAM;AAEjC,SAASD,YAAY,IAAInB,IAAI"}
|
package/dist/OdysseyProvider.js
CHANGED
|
@@ -11,15 +11,16 @@ import _ScopedCssBaseline from "@mui/material/ScopedCssBaseline";
|
|
|
11
11
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { memo } from "react";
|
|
14
|
+
import { memo, useMemo } from "react";
|
|
15
15
|
import { OdysseyCacheProvider } from "./OdysseyCacheProvider.js";
|
|
16
16
|
import { OdysseyThemeProvider } from "./OdysseyThemeProvider.js";
|
|
17
17
|
import { OdysseyTranslationProvider } from "./OdysseyTranslationProvider.js";
|
|
18
|
+
import { ContrastModeProvider, useContrastContext } from "./ContrastModeProvider.js";
|
|
18
19
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
20
|
const scopedCssBaselineStyles = {
|
|
20
21
|
height: "inherit"
|
|
21
22
|
};
|
|
22
|
-
const
|
|
23
|
+
const OdysseyProviderInner = ({
|
|
23
24
|
children,
|
|
24
25
|
designTokensOverride,
|
|
25
26
|
emotionRoot,
|
|
@@ -31,26 +32,45 @@ const OdysseyProvider = ({
|
|
|
31
32
|
stylisPlugins,
|
|
32
33
|
themeOverride,
|
|
33
34
|
translationOverrides
|
|
34
|
-
}) =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
}) => {
|
|
36
|
+
const {
|
|
37
|
+
contrastMode
|
|
38
|
+
} = useContrastContext();
|
|
39
|
+
const memoizedThemeProps = useMemo(() => ({
|
|
40
|
+
...themeOverride,
|
|
41
|
+
odysseyContrastMode: contrastMode
|
|
42
|
+
}), [themeOverride, contrastMode]);
|
|
43
|
+
return _jsx(OdysseyCacheProvider, {
|
|
44
|
+
emotionRoot: emotionRoot,
|
|
45
|
+
emotionRootElement: emotionRootElement,
|
|
46
|
+
hasShadowDom: Boolean(shadowRootElement || shadowDomElement),
|
|
47
|
+
nonce: nonce,
|
|
48
|
+
stylisPlugins: stylisPlugins,
|
|
49
|
+
children: _jsx(OdysseyThemeProvider, {
|
|
50
|
+
designTokensOverride: designTokensOverride,
|
|
51
|
+
shadowDomElement: shadowDomElement,
|
|
52
|
+
shadowRootElement: shadowRootElement,
|
|
53
|
+
themeOverride: memoizedThemeProps,
|
|
54
|
+
children: _jsx(_ScopedCssBaseline, {
|
|
55
|
+
sx: scopedCssBaselineStyles,
|
|
56
|
+
children: _jsx(OdysseyTranslationProvider, {
|
|
57
|
+
languageCode: languageCode,
|
|
58
|
+
translationOverrides: translationOverrides,
|
|
59
|
+
children: children
|
|
60
|
+
})
|
|
50
61
|
})
|
|
51
62
|
})
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const OdysseyProvider = ({
|
|
66
|
+
contrastMode,
|
|
67
|
+
...providerProps
|
|
68
|
+
}) => _jsx(ContrastModeProvider, {
|
|
69
|
+
contrastMode: contrastMode,
|
|
70
|
+
children: _jsx(OdysseyProviderInner, {
|
|
71
|
+
...providerProps
|
|
52
72
|
})
|
|
53
73
|
});
|
|
54
|
-
const
|
|
55
|
-
export {
|
|
74
|
+
const MemoizedOdysseyProvider = memo(OdysseyProvider);
|
|
75
|
+
export { MemoizedOdysseyProvider as OdysseyProvider };
|
|
56
76
|
//# sourceMappingURL=OdysseyProvider.js.map
|