@contentful/f36-autocomplete 4.20.7 → 4.20.8

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/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import n, { useState, useCallback } from 'react';
1
+ import i, { useState, useCallback } from 'react';
2
2
  import { cx, css } from 'emotion';
3
3
  import { useCombobox } from 'downshift';
4
4
  import { mergeRefs } from '@contentful/f36-core';
@@ -11,7 +11,7 @@ import { Subheading, SectionHeading, Text } from '@contentful/f36-typography';
11
11
  import { getStringMatch } from '@contentful/f36-utils';
12
12
  import p from '@contentful/f36-tokens';
13
13
 
14
- var be=Object.defineProperty,xe=Object.defineProperties;var ve=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var X=(e,o,i)=>o in e?be(e,o,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[o]=i,g=(e,o)=>{for(var i in o||(o={}))U.call(o,i)&&X(e,i,o[i]);if(P)for(var i of P(o))W.call(o,i)&&X(e,i,o[i]);return e},h=(e,o)=>xe(e,ve(o));var q=(e,o)=>{var i={};for(var r in e)U.call(e,r)&&o.indexOf(r)<0&&(i[r]=e[r]);if(e!=null&&P)for(var r of P(e))o.indexOf(r)<0&&W.call(e,r)&&(i[r]=e[r]);return i};var S=e=>({autocomplete:css({position:"relative",width:"100%"}),combobox:css({position:"relative"}),inputField:css({paddingRight:p.spacingXl,textOverflow:"ellipsis",whiteSpace:"nowrap"}),toggleButton:css({position:"absolute",top:"1px",right:"1px",zIndex:1,padding:p.spacing2Xs,height:"38px"}),content:css({overflow:"auto",maxHeight:`${e}px`}),list:css({listStyle:"none",padding:`${p.spacingXs} 0`,margin:0}),groupTitle:css({padding:`${p.spacingXs} ${p.spacingM}`,lineHeight:p.lineHeightM}),noMatchesTitle:css({color:p.gray500,margin:`${p.spacingM} 0 ${p.spacingM} 0`}),item:css({display:"block",padding:`${p.spacingXs} ${p.spacingM}`,wordBreak:"break-word",whiteSpace:"break-spaces",cursor:"pointer",hyphens:"auto","&:focus, &:hover":{backgroundColor:p.gray100},"&:active":{backgroundColor:p.gray200}}),disabled:css({opacity:.5,pointerEvents:"none"}),highlighted:css({backgroundColor:p.gray100})});var M=e=>{let{items:o,elementStartIndex:i,highlightedIndex:r,getItemProps:I,renderItem:T,inputValue:b,listMaxHeight:A=180}=e,s=S(A);return n.createElement("ul",{className:s.list,"data-test-id":"cf-autocomplete-list"},o.map((m,H)=>{let c=i+H,k=I({item:m,index:c});return n.createElement(Text,h(g({},k),{as:"li",key:c,className:cx([s.item,r===c&&s.highlighted]),"data-test-id":`cf-autocomplete-list-item-${c}`}),T?T(m,b):typeof m=="string"?n.createElement(z,{item:m,inputValue:b}):m)}))};M.displayName="AutocompleteItems";function z({item:e,inputValue:o}){let{before:i,match:r,after:I}=getStringMatch(e,o);return n.createElement(n.Fragment,null,i,n.createElement("b",null,r),I)}z.displayName="HighlightedItem";function Le(e,o){let {id:i,className:r,clearAfterSelect:I=!1,closeAfterSelect:T=!0,defaultValue:b="",selectedItem:A,items:s,onInputValueChange:m,onSelectItem:H,renderItem:c,icon:k=n.createElement(ChevronDownIcon,{variant:"muted"}),itemToString:Q=t=>t,isInvalid:Y,isDisabled:R,isRequired:Z,isReadOnly:ee,noMatchesMessage:te="No matches found",placeholder:oe="Search",inputRef:ie,toggleRef:ne,listRef:se,listWidth:re="auto",listMaxHeight:pe=180,isGrouped:x=!1,isLoading:v=!1,usePortal:ae=!1,testId:le="cf-autocomplete"}=e,u=S(pe),[d,me]=useState(b),y=useCallback(t=>{me(t),m==null||m(t);},[m]),ue=useCallback(t=>{let a=t.target.value;y(a);},[y]),ce=C(x)?s.reduce((t,a)=>[...t,...a.options],[]):s,de=C(x)?s.every(t=>t.options.length===0):s.length===0,{getComboboxProps:ge,getInputProps:he,getItemProps:_,getMenuProps:fe,getToggleButtonProps:Ie,highlightedIndex:$,isOpen:B,toggleMenu:w}=useCombobox({items:ce,selectedItem:A,inputValue:d,itemToString:Q,onInputValueChange:({type:t,inputValue:a})=>{t!=="__input_change__"&&y(a);},onStateChange:({type:t,selectedItem:a})=>{switch(t){case useCombobox.stateChangeTypes.InputKeyDownEnter:case useCombobox.stateChangeTypes.ItemClick:a&&H(a),I&&y(""),T||w();break;}}}),F=he(),G=q(F,["aria-labelledby","id"]),ye=ge(),D=Ie(),N=fe(),L=0;return n.createElement("div",{"data-test-id":le,className:cx(u.autocomplete,r),ref:o},n.createElement(Popover,{usePortal:ae,isOpen:B,isFullWidth:re==="full",renderOnlyWhenOpen:!1,autoFocus:!1,id:N.id},n.createElement(Popover.Trigger,null,n.createElement("div",h(g({},ye),{className:u.combobox}),n.createElement(TextInput,h(g({className:u.inputField},G),{onFocus:()=>{B||w();},id:i,isInvalid:Y,isDisabled:R,isRequired:Z,isReadOnly:ee,ref:mergeRefs(G.ref,ie),testId:"cf-autocomplete-input",placeholder:oe,onChange:t=>{G.onChange(t),ue(t);}})),n.createElement(IconButton,h(g({},D),{ref:mergeRefs(D.ref,ne),"aria-label":d?"Clear":"Show list",className:u.toggleButton,variant:"transparent",icon:d?n.createElement(CloseIcon,{variant:"muted"}):k,onClick:()=>{d?y(""):w();},isDisabled:R,size:"small"})))),(s.length>0||d.length>0)&&n.createElement(Popover.Content,h(g({},N),{ref:mergeRefs(N.ref,se),className:u.content,testId:"cf-autocomplete-container"}),v&&[...Array(3)].map((t,a)=>n.createElement("div",{key:a,className:cx(u.item,u.disabled)},n.createElement(Ee,null))),!v&&de&&n.createElement("div",{className:u.item},n.createElement(Subheading,{className:u.noMatchesTitle},te)),!v&&C(x)&&s.map((t,a)=>{if(t.options.length<1)return;let Te=n.createElement("div",{key:a},n.createElement(SectionHeading,{key:a,"data-test-id":"cf-autocomplete-grouptitle",marginBottom:"none",className:u.groupTitle},t.groupTitle),n.createElement(M,{items:t.options,highlightedIndex:$,getItemProps:_,renderItem:c,inputValue:d,elementStartIndex:L}));return L+=t.options.length,Te}),!v&&!C(x)&&s.length>0&&n.createElement(M,{items:s,elementStartIndex:L,highlightedIndex:$,getItemProps:_,renderItem:c,inputValue:d}))))}var Ee=()=>n.createElement(Skeleton.Container,{svgHeight:16},n.createElement(Skeleton.BodyText,{numberOfLines:1}));function C(e,o){return e}var Ve=n.forwardRef(Le);
14
+ var xe=Object.defineProperty,ve=Object.defineProperties;var Pe=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var U=(e,o,n)=>o in e?xe(e,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[o]=n,c=(e,o)=>{for(var n in o||(o={}))W.call(o,n)&&U(e,n,o[n]);if(S)for(var n of S(o))q.call(o,n)&&U(e,n,o[n]);return e},d=(e,o)=>ve(e,Pe(o));var z=(e,o)=>{var n={};for(var r in e)W.call(e,r)&&o.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&S)for(var r of S(e))o.indexOf(r)<0&&q.call(e,r)&&(n[r]=e[r]);return n};var M=e=>({autocomplete:css({position:"relative",width:"100%"}),combobox:css({position:"relative"}),inputField:css({paddingRight:p.spacingXl,textOverflow:"ellipsis",whiteSpace:"nowrap"}),toggleButton:css({position:"absolute",top:"1px",right:"1px",zIndex:1,padding:p.spacing2Xs,height:"38px"}),content:css({overflow:"auto",maxHeight:`${e}px`}),list:css({listStyle:"none",padding:`${p.spacingXs} 0`,margin:0}),groupTitle:css({padding:`${p.spacingXs} ${p.spacingM}`,lineHeight:p.lineHeightM}),noMatchesTitle:css({color:p.gray500,margin:`${p.spacingM} 0 ${p.spacingM} 0`}),item:css({display:"block",padding:`${p.spacingXs} ${p.spacingM}`,wordBreak:"break-word",whiteSpace:"break-spaces",cursor:"pointer",hyphens:"auto","&:focus, &:hover":{backgroundColor:p.gray100},"&:active":{backgroundColor:p.gray200}}),disabled:css({opacity:.5,pointerEvents:"none"}),highlighted:css({backgroundColor:p.gray100}),hidden:css({display:"none"})});var C=e=>{let{items:o,elementStartIndex:n,highlightedIndex:r,getItemProps:I,renderItem:T,inputValue:b,listMaxHeight:H=180}=e,s=M(H);return i.createElement("ul",{className:s.list,"data-test-id":"cf-autocomplete-list"},o.map((u,k)=>{let g=n+k,w=I({item:u,index:g});return i.createElement(Text,d(c({},w),{as:"li",key:g,className:cx([s.item,r===g&&s.highlighted]),"data-test-id":`cf-autocomplete-list-item-${g}`}),T?T(u,b):typeof u=="string"?i.createElement(j,{item:u,inputValue:b}):u)}))};C.displayName="AutocompleteItems";function j({item:e,inputValue:o}){let{before:n,match:r,after:I}=getStringMatch(e,o);return i.createElement(i.Fragment,null,n,i.createElement("b",null,r),I)}j.displayName="HighlightedItem";function Ee(e,o){let {id:n,className:r,clearAfterSelect:I=!1,closeAfterSelect:T=!0,defaultValue:b="",selectedItem:H,items:s,onInputValueChange:u,onSelectItem:k,renderItem:g,icon:w=i.createElement(ChevronDownIcon,{variant:"muted"}),itemToString:Q=t=>t,isInvalid:Y,isDisabled:R,isRequired:Z,isReadOnly:ee,showEmptyList:te,noMatchesMessage:oe="No matches found",placeholder:ie="Search",inputRef:ne,toggleRef:se,listRef:re,listWidth:pe="auto",listMaxHeight:ae=180,isGrouped:x=!1,isLoading:v=!1,usePortal:le=!1,testId:me="cf-autocomplete"}=e,m=M(ae),[h,ue]=useState(b),y=useCallback(t=>{ue(t),u==null||u(t);},[u]),ce=useCallback(t=>{let a=t.target.value;y(a);},[y]),de=A(x)?s.reduce((t,a)=>[...t,...a.options],[]):s,ge=A(x)?s.every(t=>t.options.length===0):s.length===0,{getComboboxProps:he,getInputProps:fe,getItemProps:$,getMenuProps:Ie,getToggleButtonProps:ye,highlightedIndex:B,isOpen:D,toggleMenu:N}=useCombobox({items:de,selectedItem:H,inputValue:h,itemToString:Q,onInputValueChange:({type:t,inputValue:a})=>{t!=="__input_change__"&&y(a);},onStateChange:({type:t,selectedItem:a})=>{switch(t){case useCombobox.stateChangeTypes.InputKeyDownEnter:case useCombobox.stateChangeTypes.ItemClick:a&&k(a),I&&y(""),T||N();break;}}}),X=fe(),G=z(X,["aria-labelledby","id"]),Te=he(),F=ye(),P=Ie(),L=0;return i.createElement("div",{"data-test-id":me,className:cx(m.autocomplete,r),ref:o},i.createElement(Popover,{usePortal:le,isOpen:D,isFullWidth:pe==="full",renderOnlyWhenOpen:!1,autoFocus:!1,id:P.id},i.createElement(Popover.Trigger,null,i.createElement("div",d(c({},Te),{className:m.combobox}),i.createElement(TextInput,d(c({className:m.inputField},G),{onFocus:()=>{D||N();},id:n,isInvalid:Y,isDisabled:R,isRequired:Z,isReadOnly:ee,ref:mergeRefs(G.ref,ne),testId:"cf-autocomplete-input",placeholder:ie,onChange:t=>{G.onChange(t),ce(t);}})),i.createElement(IconButton,d(c({},F),{ref:mergeRefs(F.ref,se),"aria-label":h?"Clear":"Show list",className:m.toggleButton,variant:"transparent",icon:h?i.createElement(CloseIcon,{variant:"muted"}):w,onClick:()=>{h?y(""):N();},isDisabled:R,size:"small"})))),s.length>0||h.length>0||te?i.createElement(Popover.Content,d(c({},P),{ref:mergeRefs(P.ref,re),className:m.content,testId:"cf-autocomplete-container"}),v&&[...Array(3)].map((t,a)=>i.createElement("div",{key:a,className:cx(m.item,m.disabled)},i.createElement(Ve,null))),!v&&ge&&i.createElement("div",{className:m.item},i.createElement(Subheading,{className:m.noMatchesTitle},oe)),!v&&A(x)&&s.map((t,a)=>{if(t.options.length<1)return;let be=i.createElement("div",{key:a},i.createElement(SectionHeading,{key:a,"data-test-id":"cf-autocomplete-grouptitle",marginBottom:"none",className:m.groupTitle},t.groupTitle),i.createElement(C,{items:t.options,highlightedIndex:B,getItemProps:$,renderItem:g,inputValue:h,elementStartIndex:L}));return L+=t.options.length,be}),!v&&!A(x)&&s.length>0&&i.createElement(C,{items:s,elementStartIndex:L,highlightedIndex:B,getItemProps:$,renderItem:g,inputValue:h})):i.createElement("div",d(c({},P),{className:cx(m.hidden)}))))}var Ve=()=>i.createElement(Skeleton.Container,{svgHeight:16},i.createElement(Skeleton.BodyText,{numberOfLines:1}));function A(e,o){return e}var Oe=i.forwardRef(Ee);
15
15
 
16
- export { Ve as Autocomplete };
16
+ export { Oe as Autocomplete };
17
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Autocomplete.tsx","../../src/AutocompleteItems.tsx","../../src/Autocomplete.styles.ts"],"names":["React","useCallback","useState","cx","useCombobox","mergeRefs","IconButton","TextInput","CloseIcon","ChevronDownIcon","Skeleton","Popover","Subheading","SectionHeading","getStringMatch","Text","css","tokens","getAutocompleteStyles","listMaxHeight","AutocompleteItems","props","items","elementStartIndex","highlightedIndex","getItemProps","renderItem","inputValue","styles","item","index","itemIndex","itemProps","__spreadProps","__spreadValues","HighlightedItem","before","match","after","_Autocomplete","ref","id","className","clearAfterSelect","closeAfterSelect","defaultValue","selectedItem","onInputValueChange","onSelectItem","icon","itemToString","isInvalid","isDisabled","isRequired","isReadOnly","noMatchesMessage","placeholder","inputRef","toggleRef","listRef","listWidth","isGrouped","isLoading","usePortal","testId","setInputValue","handleInputValueChange","value","handleNativeChangeEvent","event","flattenItems","isUsingGroups","acc","group","isShowingNoMatches","getComboboxProps","getInputProps","getMenuProps","getToggleButtonProps","isOpen","toggleMenu","type","_a","_labelledby","_inputId","inputProps","__objRest","comboboxProps","toggleProps","menuProps","_","ListItemLoadingState","render","Autocomplete"],"mappings":"qlBAAA,OAAOA,GAAS,eAAAC,EAAa,YAAAC,OAAgB,QAC7C,OAAS,MAAAC,MAAU,UACnB,OAAS,eAAAC,MAAmB,YAE5B,OACE,aAAAC,MAGK,uBACP,OAAS,cAAAC,OAAkB,yBAC3B,OAAS,aAAAC,OAAsC,wBAC/C,OAAS,aAAAC,GAAW,mBAAAC,OAAuB,wBAC3C,OAAS,YAAAC,MAAgB,2BACzB,OAAS,WAAAC,MAAe,0BACxB,OAAS,cAAAC,GAAY,kBAAAC,OAAsB,6BCd3C,OAA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EACPV,EACAvC,EACuC,CACvC,OAAOuC,CACT,CAOO,IAAMgC,GAAe7F,EAAM,WAAWuC,EAAa","sourcesContent":["import React, { useCallback, useState } from 'react';\nimport { cx } from 'emotion';\nimport { useCombobox } from 'downshift';\n\nimport {\n mergeRefs,\n type CommonProps,\n type ExpandProps,\n} from '@contentful/f36-core';\nimport { IconButton } from '@contentful/f36-button';\nimport { TextInput, type TextInputProps } from '@contentful/f36-forms';\nimport { CloseIcon, ChevronDownIcon } from '@contentful/f36-icons';\nimport { Skeleton } from '@contentful/f36-skeleton';\nimport { Popover } from '@contentful/f36-popover';\nimport { Subheading, SectionHeading } from '@contentful/f36-typography';\n\nimport { AutocompleteItems } from './AutocompleteItems';\nimport { getAutocompleteStyles } from './Autocomplete.styles';\n\nexport interface GenericGroupType<ItemType> {\n groupTitle: string;\n options: ItemType[];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface AutocompleteProps<ItemType>\n extends CommonProps,\n Pick<\n TextInputProps,\n | 'isDisabled'\n | 'isInvalid'\n | 'isReadOnly'\n | 'isRequired'\n | 'id'\n | 'defaultValue'\n > {\n /**\n * It’s an array of data to be used as \"options\" by the autocomplete component.\n * This can either be a plain list of items or a list of groups of items.\n */\n items: ItemType[] | GenericGroupType<ItemType>[];\n\n /**\n * Set a custom icon for the text input\n */\n icon?: React.ReactElement;\n\n /**\n * Tells if the item is a object with groups\n */\n isGrouped?: boolean;\n\n /**\n * Function called whenever the input value changes\n */\n onInputValueChange?: (value: string) => void;\n /**\n * This is the function that will be called when the user selects one of the \"options\" in the list.\n * The component will pass the selected \"item\" as an argument to the function..\n */\n onSelectItem: (item: ItemType) => void;\n\n /**\n * Applying the selectedItem property turns autocomplete into a controlled component.\n * Can be used to display e.g. previously selected element. If it is an object the itemToString function will apply to it.\n */\n selectedItem?: ItemType;\n\n /**\n * This is the function that will be called for each \"item\" passed in the `items` prop.\n * It receives the \"item\" and \"inputValue\" as arguments and returns a ReactNode.\n * The inputValue is passed in case you want to highlight the match on the render.\n */\n renderItem?: (item: ItemType, inputValue: string) => React.ReactNode;\n /**\n * When using objects as `items`, we recommend passing a function that tells Downshift how to extract a string\n * from those objetcs to be used as inputValue\n */\n itemToString?: (item: ItemType) => string;\n /**\n * If this is set to `true` the text input will be cleared after an item is selected\n * @default false\n */\n clearAfterSelect?: boolean;\n /**\n * If this is set to `false` the dropdown menu will stay open after selecting an item\n * @default true\n */\n closeAfterSelect?: boolean;\n /**\n * This is the value will be passed to the `placeholder` prop of the input.\n * @default \"Search\"\n */\n placeholder?: string;\n /**\n * A message that will be shown when it is not possible to find any option that matches the input value\n * @default \"No matches\"\n */\n noMatchesMessage?: string;\n /**\n * Use this prop to get a ref to the input element of the component\n */\n inputRef?: React.Ref<HTMLInputElement>;\n /**\n * Use this prop to get a ref to the toggle button of the component\n */\n toggleRef?: React.Ref<HTMLButtonElement>;\n /**\n * Use this prop to get a ref to the list of items of the component\n */\n listRef?: React.Ref<HTMLUListElement>;\n /**\n * It sets the width of the list\n * @default \"auto\"\n */\n listWidth?: 'auto' | 'full';\n /**\n * It sets the max-height, in pixels, of the list\n * The default value is the height of 5 single line items\n * @default 180\n */\n listMaxHeight?: number;\n /**\n * Sets the list to show its loading state\n * @default false\n */\n isLoading?: boolean;\n /**\n * Boolean to control whether or not to render the suggestions box in a React Portal.\n * Rendering content inside a Portal allows the suggestions box to escape the bounds\n * of its parent while still being positioned correctly.\n * Defaults to `false`\n */\n usePortal?: boolean;\n}\n\nfunction _Autocomplete<ItemType>(\n props: AutocompleteProps<ItemType>,\n ref: React.Ref<HTMLDivElement>,\n) {\n const {\n id,\n className,\n clearAfterSelect = false,\n closeAfterSelect = true,\n defaultValue = '',\n selectedItem,\n items,\n onInputValueChange,\n onSelectItem,\n renderItem,\n icon = <ChevronDownIcon variant=\"muted\" />,\n itemToString = (item: ItemType) => item as unknown as string,\n isInvalid,\n isDisabled,\n isRequired,\n isReadOnly,\n noMatchesMessage = 'No matches found',\n placeholder = 'Search',\n inputRef,\n toggleRef,\n listRef,\n listWidth = 'auto',\n listMaxHeight = 180,\n isGrouped = false,\n isLoading = false,\n usePortal = false,\n testId = 'cf-autocomplete',\n } = props;\n\n type GroupType = GenericGroupType<ItemType>;\n\n const styles = getAutocompleteStyles(listMaxHeight);\n\n const [inputValue, setInputValue] = useState(defaultValue);\n\n const handleInputValueChange = useCallback(\n (value: string) => {\n setInputValue(value);\n\n onInputValueChange?.(value);\n },\n [onInputValueChange],\n );\n\n // Handle manually to avoid a jumping cursor, see https://github.com/downshift-js/downshift/issues/1108#issuecomment-842407759\n const handleNativeChangeEvent = useCallback(\n (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n const value = event.target.value;\n handleInputValueChange(value);\n },\n [handleInputValueChange],\n );\n\n const flattenItems = isUsingGroups(isGrouped, items)\n ? items.reduce(\n (acc: ItemType[], group: GroupType) => [...acc, ...group.options],\n [],\n )\n : items;\n\n const isShowingNoMatches = isUsingGroups(isGrouped, items)\n ? items.every((group: GroupType) => group.options.length === 0)\n : items.length === 0;\n\n const {\n getComboboxProps,\n getInputProps,\n getItemProps,\n getMenuProps,\n getToggleButtonProps,\n highlightedIndex,\n isOpen,\n toggleMenu,\n } = useCombobox({\n items: flattenItems,\n selectedItem,\n inputValue,\n itemToString,\n onInputValueChange: ({ type, inputValue }) => {\n if (type !== '__input_change__') {\n handleInputValueChange(inputValue);\n }\n },\n onStateChange: ({ type, selectedItem }) => {\n switch (type) {\n case useCombobox.stateChangeTypes.InputKeyDownEnter:\n case useCombobox.stateChangeTypes.ItemClick:\n if (selectedItem) {\n onSelectItem(selectedItem);\n }\n if (clearAfterSelect) {\n handleInputValueChange('');\n }\n if (!closeAfterSelect) {\n toggleMenu();\n }\n break;\n default:\n break;\n }\n },\n });\n\n const {\n 'aria-labelledby': _labelledby,\n id: _inputId,\n ...inputProps\n } = getInputProps();\n const comboboxProps = getComboboxProps();\n const toggleProps = getToggleButtonProps();\n const menuProps = getMenuProps();\n let elementStartIndex = 0;\n\n return (\n <div\n data-test-id={testId}\n className={cx(styles.autocomplete, className)}\n ref={ref}\n >\n <Popover\n usePortal={usePortal}\n isOpen={isOpen}\n isFullWidth={listWidth === 'full'}\n renderOnlyWhenOpen={false}\n // This is necessary, otherwise the focus will change from the input to the Popover\n // and the user won't be able to type in the input\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={false}\n id={menuProps.id}\n >\n <Popover.Trigger>\n <div {...comboboxProps} className={styles.combobox}>\n <TextInput\n className={styles.inputField}\n {...inputProps}\n onFocus={() => {\n if (!isOpen) {\n toggleMenu();\n }\n }}\n id={id}\n isInvalid={isInvalid}\n isDisabled={isDisabled}\n isRequired={isRequired}\n isReadOnly={isReadOnly}\n ref={mergeRefs(inputProps.ref, inputRef)}\n testId=\"cf-autocomplete-input\"\n placeholder={placeholder}\n onChange={(event) => {\n inputProps.onChange(event);\n handleNativeChangeEvent(event);\n }}\n />\n <IconButton\n {...toggleProps}\n ref={mergeRefs(toggleProps.ref, toggleRef)}\n aria-label={inputValue ? 'Clear' : 'Show list'}\n className={styles.toggleButton}\n variant=\"transparent\"\n icon={inputValue ? <CloseIcon variant=\"muted\" /> : icon}\n onClick={() => {\n if (inputValue) {\n handleInputValueChange('');\n } else {\n toggleMenu();\n }\n }}\n isDisabled={isDisabled}\n size=\"small\"\n />\n </div>\n </Popover.Trigger>\n\n {(items.length > 0 || inputValue.length > 0) && (\n <Popover.Content\n {...menuProps}\n ref={mergeRefs(menuProps.ref, listRef)}\n className={styles.content}\n testId=\"cf-autocomplete-container\"\n >\n {isLoading &&\n [...Array(3)].map((_, index) => (\n <div key={index} className={cx(styles.item, styles.disabled)}>\n <ListItemLoadingState />\n </div>\n ))}\n\n {!isLoading && isShowingNoMatches && (\n <div className={styles.item}>\n <Subheading className={styles.noMatchesTitle}>\n {noMatchesMessage}\n </Subheading>\n </div>\n )}\n\n {!isLoading &&\n isUsingGroups(isGrouped, items) &&\n items.map((group: GroupType, index: number) => {\n if (group.options.length < 1) {\n return;\n }\n const render = (\n <div key={index}>\n <SectionHeading\n key={index}\n data-test-id=\"cf-autocomplete-grouptitle\"\n marginBottom=\"none\"\n className={styles.groupTitle}\n >\n {group.groupTitle}\n </SectionHeading>\n <AutocompleteItems<ItemType>\n items={group.options}\n highlightedIndex={highlightedIndex}\n getItemProps={getItemProps}\n renderItem={renderItem}\n inputValue={inputValue}\n elementStartIndex={elementStartIndex}\n />\n </div>\n );\n elementStartIndex += group.options.length;\n return render;\n })}\n\n {!isLoading &&\n !isUsingGroups(isGrouped, items) &&\n items.length > 0 && (\n <AutocompleteItems<ItemType>\n items={items}\n elementStartIndex={elementStartIndex}\n highlightedIndex={highlightedIndex}\n getItemProps={getItemProps}\n renderItem={renderItem}\n inputValue={inputValue}\n />\n )}\n </Popover.Content>\n )}\n </Popover>\n </div>\n );\n}\n\nconst ListItemLoadingState = () => {\n return (\n <Skeleton.Container svgHeight={16}>\n <Skeleton.BodyText numberOfLines={1} />\n </Skeleton.Container>\n );\n};\n\n// This is required to infer correct typings when differentiating groups and items\nfunction isUsingGroups<ItemType>(\n isGrouped: boolean,\n items: ItemType[] | GenericGroupType<ItemType>[],\n): items is GenericGroupType<ItemType>[] {\n return isGrouped;\n}\n\n/**\n * The Autocomplete is a component that will show a `TextInput` where a user can type any word which will be used\n * to filter a list of items. That list of filtered items will be shown to the user as possible options for the input.\n * Once one of the options is selected, that option becomes the value of the `TextInput`.\n */\nexport const Autocomplete = React.forwardRef(_Autocomplete) as <T>(\n props: ExpandProps<AutocompleteProps<T>> & {\n ref?: React.Ref<HTMLDivElement>;\n },\n) => ReturnType<typeof _Autocomplete>;\n","import React, { HTMLAttributes } from 'react';\nimport { cx } from 'emotion';\nimport { getStringMatch } from '@contentful/f36-utils';\nimport type { UseComboboxGetItemPropsOptions } from 'downshift';\nimport { Text } from '@contentful/f36-typography';\n\nimport { getAutocompleteStyles } from './Autocomplete.styles';\n\ninterface AutocompleteItemsProps<ItemType> {\n items: ItemType[];\n elementStartIndex: number;\n highlightedIndex: number;\n getItemProps: (\n options: UseComboboxGetItemPropsOptions<ItemType>,\n ) => HTMLAttributes<HTMLLIElement>;\n renderItem: (item: ItemType, inputValue: string) => React.ReactNode;\n inputValue: string;\n listMaxHeight?: number;\n}\n\nexport const AutocompleteItems = <ItemType,>(\n props: AutocompleteItemsProps<ItemType>,\n) => {\n const {\n items,\n elementStartIndex,\n highlightedIndex,\n getItemProps,\n renderItem,\n inputValue,\n listMaxHeight = 180,\n } = props;\n\n const styles = getAutocompleteStyles(listMaxHeight);\n\n return (\n <ul className={styles.list} data-test-id=\"cf-autocomplete-list\">\n {items.map((item: ItemType, index: number) => {\n const itemIndex = elementStartIndex + index;\n const itemProps = getItemProps({ item, index: itemIndex });\n return (\n <Text\n {...itemProps}\n as=\"li\"\n key={itemIndex}\n className={cx([\n styles.item,\n highlightedIndex === itemIndex && styles.highlighted,\n ])}\n data-test-id={`cf-autocomplete-list-item-${itemIndex}`}\n >\n {renderItem ? (\n renderItem(item, inputValue)\n ) : typeof item === 'string' ? (\n <HighlightedItem item={item} inputValue={inputValue} />\n ) : (\n item\n )}\n </Text>\n );\n })}\n </ul>\n );\n};\n\nAutocompleteItems.displayName = 'AutocompleteItems';\n\nfunction HighlightedItem({\n item,\n inputValue,\n}: {\n item: string;\n inputValue: string;\n}) {\n const { before, match, after } = getStringMatch(item, inputValue);\n\n return (\n <>\n {before}\n <b>{match}</b>\n {after}\n </>\n );\n}\n\nHighlightedItem.displayName = 'HighlightedItem';\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getAutocompleteStyles = (listMaxHeight: number) => ({\n autocomplete: css({\n position: 'relative',\n width: '100%',\n }),\n combobox: css({\n position: 'relative',\n }),\n inputField: css({\n paddingRight: tokens.spacingXl,\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n }),\n toggleButton: css({\n position: 'absolute',\n top: '1px',\n right: '1px',\n zIndex: 1,\n padding: tokens.spacing2Xs,\n height: '38px',\n }),\n content: css({\n overflow: 'auto',\n maxHeight: `${listMaxHeight}px`,\n }),\n list: css({\n listStyle: 'none',\n padding: `${tokens.spacingXs} 0`,\n margin: 0,\n }),\n groupTitle: css({\n padding: `${tokens.spacingXs} ${tokens.spacingM}`,\n lineHeight: tokens.lineHeightM,\n }),\n noMatchesTitle: css({\n color: tokens.gray500,\n margin: `${tokens.spacingM} 0 ${tokens.spacingM} 0`,\n }),\n item: css({\n display: 'block',\n padding: `${tokens.spacingXs} ${tokens.spacingM}`,\n wordBreak: 'break-word',\n whiteSpace: 'break-spaces',\n cursor: 'pointer',\n hyphens: 'auto',\n\n '&:focus, &:hover': {\n backgroundColor: tokens.gray100,\n },\n '&:active': {\n backgroundColor: tokens.gray200,\n },\n }),\n disabled: css({\n opacity: 0.5,\n pointerEvents: 'none',\n }),\n highlighted: css({\n backgroundColor: tokens.gray100,\n }),\n});\n"]}
1
+ {"version":3,"sources":["../../src/Autocomplete.tsx","../../src/AutocompleteItems.tsx","../../src/Autocomplete.styles.ts"],"names":["React","useCallback","useState","cx","useCombobox","mergeRefs","IconButton","TextInput","CloseIcon","ChevronDownIcon","Skeleton","Popover","Subheading","SectionHeading","getStringMatch","Text","css","tokens","getAutocompleteStyles","listMaxHeight","AutocompleteItems","props","items","elementStartIndex","highlightedIndex","getItemProps","renderItem","inputValue","styles","item","index","itemIndex","itemProps","__spreadProps","__spreadValues","HighlightedItem","before","match","after","_Autocomplete","ref","id","className","clearAfterSelect","closeAfterSelect","defaultValue","selectedItem","onInputValueChange","onSelectItem","icon","itemToString","isInvalid","isDisabled","isRequired","isReadOnly","showEmptyList","noMatchesMessage","placeholder","inputRef","toggleRef","listRef","listWidth","isGrouped","isLoading","usePortal","testId","setInputValue","handleInputValueChange","value","handleNativeChangeEvent","event","flattenItems","isUsingGroups","acc","group","isShowingNoMatches","getComboboxProps","getInputProps","getMenuProps","getToggleButtonProps","isOpen","toggleMenu","type","_a","_labelledby","_inputId","inputProps","__objRest","comboboxProps","toggleProps","menuProps","_","ListItemLoadingState","render","Autocomplete"],"mappings":"qlBAAA,OAAOA,GAAS,eAAAC,EAAa,YAAAC,OAAgB,QAC7C,OAAS,MAAAC,MAAU,UACnB,OAAS,eAAAC,MAAmB,YAE5B,OACE,aAAAC,MAGK,uBACP,OAAS,cAAAC,OAAkB,yBAC3B,OAAS,aAAAC,OAAsC,wBAC/C,OAAS,aAAAC,GAAW,mBAAAC,OAAuB,wBAC3C,OAAS,YAAAC,MAAgB,2BACzB,OAAS,WAAAC,MAAe,0BACxB,OAAS,cAAAC,GAAY,kBAAAC,OAAsB,6BCd3C,OAAOb,MAA+B,QACtC,OAAS,MAAAG,OAAU,UACnB,OAAS,kBAAAW,OAAsB,wBAE/B,OAAS,QAAAC,OAAY,6BCJrB,OAAS,OAAAC,MAAW,UACpB,OAAOC,MAAY,yBAEZ,IAAMC,EAAyBC,IAA2B,CAC/D,aAAcH,EAAI,CAChB,SAAU,WACV,MAAO,MACT,CAAC,EACD,SAAUA,EAAI,CACZ,SAAU,UACZ,CAAC,EACD,WAAYA,EAAI,CACd,aAAcC,EAAO,UACrB,aAAc,WACd,WAAY,QACd,CAAC,EACD,aAAcD,EAAI,CAChB,SAAU,WACV,IAAK,MACL,MAAO,MACP,OAAQ,EACR,QAASC,EAAO,WAChB,OAAQ,MACV,CAAC,EACD,QAASD,EAAI,CACX,SAAU,OACV,UAAW,GAAGG,KAChB,CAAC,EACD,KAAMH,EAAI,CACR,UAAW,OACX,QAAS,GAAGC,EAAO,cACnB,OAAQ,CACV,CAAC,EACD,WAAYD,EAAI,CACd,QAAS,GAAGC,EAAO,aAAaA,EAAO,WACvC,WAAYA,EAAO,WACrB,CAAC,EACD,eAAgBD,EAAI,CAClB,MAAOC,EAAO,QACd,OAAQ,GAAGA,EAAO,cAAcA,EAAO,YACzC,CAAC,EACD,KAAMD,EAAI,CACR,QAAS,QACT,QAAS,GAAGC,EAAO,aAAaA,EAAO,WACvC,UAAW,aACX,WAAY,e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AYC,EACZ,WAAYC,EACZ,kBAAmBJ,EACrB,CACF,EAEF,OAAAA,GAAqBmD,EAAM,QAAQ,OAC5BmB,EACT,CAAC,EAEF,CAAC9B,GACA,CAACS,EAAcV,EAAWxC,CAAK,GAC/BA,EAAM,OAAS,GACbtB,EAAA,cAACoB,EAAA,CACC,MAAOE,EACP,kBAAmBC,EACnB,iBAAkBC,EAClB,aAAcC,EACd,WAAYC,EACZ,WAAYC,EACd,CAEN,EAIA3B,EAAA,cAAC,MAAAiC,EAAAC,EAAA,GAAQwD,GAAR,CAAmB,UAAWvF,EAAGyB,EAAO,MAAM,GAAG,CAEtD,CACF,CAEJ,CAEA,IAAMgE,GAAuB,IAEzB5F,EAAA,cAACU,EAAS,UAAT,CAAmB,UAAW,IAC7BV,EAAA,cAACU,EAAS,SAAT,CAAkB,cAAe,EAAG,CACvC,EAKJ,SAAS8D,EACPV,EACAxC,EACuC,CACvC,OAAOwC,CACT,CAOO,IAAMgC,GAAe9F,EAAM,WAAWuC,EAAa","sourcesContent":["import React, { useCallback, useState } from 'react';\nimport { cx } from 'emotion';\nimport { useCombobox } from 'downshift';\n\nimport {\n mergeRefs,\n type CommonProps,\n type ExpandProps,\n} from '@contentful/f36-core';\nimport { IconButton } from '@contentful/f36-button';\nimport { TextInput, type TextInputProps } from '@contentful/f36-forms';\nimport { CloseIcon, ChevronDownIcon } from '@contentful/f36-icons';\nimport { Skeleton } from '@contentful/f36-skeleton';\nimport { Popover } from '@contentful/f36-popover';\nimport { Subheading, SectionHeading } from '@contentful/f36-typography';\n\nimport { AutocompleteItems } from './AutocompleteItems';\nimport { getAutocompleteStyles } from './Autocomplete.styles';\n\nexport interface GenericGroupType<ItemType> {\n groupTitle: string;\n options: ItemType[];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface AutocompleteProps<ItemType>\n extends CommonProps,\n Pick<\n TextInputProps,\n | 'isDisabled'\n | 'isInvalid'\n | 'isReadOnly'\n | 'isRequired'\n | 'id'\n | 'defaultValue'\n > {\n /**\n * It’s an array of data to be used as \"options\" by the autocomplete component.\n * This can either be a plain list of items or a list of groups of items.\n */\n items: ItemType[] | GenericGroupType<ItemType>[];\n\n /**\n * Set a custom icon for the text input\n */\n icon?: React.ReactElement;\n\n /**\n * Tells if the item is a object with groups\n */\n isGrouped?: boolean;\n\n /**\n * Function called whenever the input value changes\n */\n onInputValueChange?: (value: string) => void;\n /**\n * This is the function that will be called when the user selects one of the \"options\" in the list.\n * The component will pass the selected \"item\" as an argument to the function..\n */\n onSelectItem: (item: ItemType) => void;\n\n /**\n * Applying the selectedItem property turns autocomplete into a controlled component.\n * Can be used to display e.g. previously selected element. If it is an object the itemToString function will apply to it.\n */\n selectedItem?: ItemType;\n\n /**\n * This is the function that will be called for each \"item\" passed in the `items` prop.\n * It receives the \"item\" and \"inputValue\" as arguments and returns a ReactNode.\n * The inputValue is passed in case you want to highlight the match on the render.\n */\n renderItem?: (item: ItemType, inputValue: string) => React.ReactNode;\n /**\n * When using objects as `items`, we recommend passing a function that tells Downshift how to extract a string\n * from those objetcs to be used as inputValue\n */\n itemToString?: (item: ItemType) => string;\n /**\n * If this is set to `true` the text input will be cleared after an item is selected\n * @default false\n */\n clearAfterSelect?: boolean;\n /**\n * If this is set to `false` the dropdown menu will stay open after selecting an item\n * @default true\n */\n closeAfterSelect?: boolean;\n /**\n * This is the value will be passed to the `placeholder` prop of the input.\n * @default \"Search\"\n */\n placeholder?: string;\n /**\n * Defines if the list should be shown even if empty, when input is focused\n * @default false\n */\n showEmptyList?: boolean;\n /**\n * A message that will be shown when it is not possible to find any option that matches the input value\n * @default \"No matches\"\n */\n noMatchesMessage?: string;\n /**\n * Use this prop to get a ref to the input element of the component\n */\n inputRef?: React.Ref<HTMLInputElement>;\n /**\n * Use this prop to get a ref to the toggle button of the component\n */\n toggleRef?: React.Ref<HTMLButtonElement>;\n /**\n * Use this prop to get a ref to the list of items of the component\n */\n listRef?: React.Ref<HTMLUListElement>;\n /**\n * It sets the width of the list\n * @default \"auto\"\n */\n listWidth?: 'auto' | 'full';\n /**\n * It sets the max-height, in pixels, of the list\n * The default value is the height of 5 single line items\n * @default 180\n */\n listMaxHeight?: number;\n /**\n * Sets the list to show its loading state\n * @default false\n */\n isLoading?: boolean;\n /**\n * Boolean to control whether or not to render the suggestions box in a React Portal.\n * Rendering content inside a Portal allows the suggestions box to escape the bounds\n * of its parent while still being positioned correctly.\n * Defaults to `false`\n */\n usePortal?: boolean;\n}\n\nfunction _Autocomplete<ItemType>(\n props: AutocompleteProps<ItemType>,\n ref: React.Ref<HTMLDivElement>,\n) {\n const {\n id,\n className,\n clearAfterSelect = false,\n closeAfterSelect = true,\n defaultValue = '',\n selectedItem,\n items,\n onInputValueChange,\n onSelectItem,\n renderItem,\n icon = <ChevronDownIcon variant=\"muted\" />,\n itemToString = (item: ItemType) => item as unknown as string,\n isInvalid,\n isDisabled,\n isRequired,\n isReadOnly,\n showEmptyList,\n noMatchesMessage = 'No matches found',\n placeholder = 'Search',\n inputRef,\n toggleRef,\n listRef,\n listWidth = 'auto',\n listMaxHeight = 180,\n isGrouped = false,\n isLoading = false,\n usePortal = false,\n testId = 'cf-autocomplete',\n } = props;\n\n type GroupType = GenericGroupType<ItemType>;\n\n const styles = getAutocompleteStyles(listMaxHeight);\n\n const [inputValue, setInputValue] = useState(defaultValue);\n\n const handleInputValueChange = useCallback(\n (value: string) => {\n setInputValue(value);\n\n onInputValueChange?.(value);\n },\n [onInputValueChange],\n );\n\n // Handle manually to avoid a jumping cursor, see https://github.com/downshift-js/downshift/issues/1108#issuecomment-842407759\n const handleNativeChangeEvent = useCallback(\n (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n const value = event.target.value;\n handleInputValueChange(value);\n },\n [handleInputValueChange],\n );\n\n const flattenItems = isUsingGroups(isGrouped, items)\n ? items.reduce(\n (acc: ItemType[], group: GroupType) => [...acc, ...group.options],\n [],\n )\n : items;\n\n const isShowingNoMatches = isUsingGroups(isGrouped, items)\n ? items.every((group: GroupType) => group.options.length === 0)\n : items.length === 0;\n\n const {\n getComboboxProps,\n getInputProps,\n getItemProps,\n getMenuProps,\n getToggleButtonProps,\n highlightedIndex,\n isOpen,\n toggleMenu,\n } = useCombobox({\n items: flattenItems,\n selectedItem,\n inputValue,\n itemToString,\n onInputValueChange: ({ type, inputValue }) => {\n if (type !== '__input_change__') {\n handleInputValueChange(inputValue);\n }\n },\n onStateChange: ({ type, selectedItem }) => {\n switch (type) {\n case useCombobox.stateChangeTypes.InputKeyDownEnter:\n case useCombobox.stateChangeTypes.ItemClick:\n if (selectedItem) {\n onSelectItem(selectedItem);\n }\n if (clearAfterSelect) {\n handleInputValueChange('');\n }\n if (!closeAfterSelect) {\n toggleMenu();\n }\n break;\n default:\n break;\n }\n },\n });\n\n const {\n 'aria-labelledby': _labelledby,\n id: _inputId,\n ...inputProps\n } = getInputProps();\n const comboboxProps = getComboboxProps();\n const toggleProps = getToggleButtonProps();\n const menuProps = getMenuProps();\n let elementStartIndex = 0;\n\n return (\n <div\n data-test-id={testId}\n className={cx(styles.autocomplete, className)}\n ref={ref}\n >\n <Popover\n usePortal={usePortal}\n isOpen={isOpen}\n isFullWidth={listWidth === 'full'}\n renderOnlyWhenOpen={false}\n // This is necessary, otherwise the focus will change from the input to the Popover\n // and the user won't be able to type in the input\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={false}\n id={menuProps.id}\n >\n <Popover.Trigger>\n <div {...comboboxProps} className={styles.combobox}>\n <TextInput\n className={styles.inputField}\n {...inputProps}\n onFocus={() => {\n if (!isOpen) {\n toggleMenu();\n }\n }}\n id={id}\n isInvalid={isInvalid}\n isDisabled={isDisabled}\n isRequired={isRequired}\n isReadOnly={isReadOnly}\n ref={mergeRefs(inputProps.ref, inputRef)}\n testId=\"cf-autocomplete-input\"\n placeholder={placeholder}\n onChange={(event) => {\n inputProps.onChange(event);\n handleNativeChangeEvent(event);\n }}\n />\n <IconButton\n {...toggleProps}\n ref={mergeRefs(toggleProps.ref, toggleRef)}\n aria-label={inputValue ? 'Clear' : 'Show list'}\n className={styles.toggleButton}\n variant=\"transparent\"\n icon={inputValue ? <CloseIcon variant=\"muted\" /> : icon}\n onClick={() => {\n if (inputValue) {\n handleInputValueChange('');\n } else {\n toggleMenu();\n }\n }}\n isDisabled={isDisabled}\n size=\"small\"\n />\n </div>\n </Popover.Trigger>\n\n {items.length > 0 || inputValue.length > 0 || showEmptyList ? (\n <Popover.Content\n {...menuProps}\n ref={mergeRefs(menuProps.ref, listRef)}\n className={styles.content}\n testId=\"cf-autocomplete-container\"\n >\n {isLoading &&\n [...Array(3)].map((_, index) => (\n <div key={index} className={cx(styles.item, styles.disabled)}>\n <ListItemLoadingState />\n </div>\n ))}\n\n {!isLoading && isShowingNoMatches && (\n <div className={styles.item}>\n <Subheading className={styles.noMatchesTitle}>\n {noMatchesMessage}\n </Subheading>\n </div>\n )}\n\n {!isLoading &&\n isUsingGroups(isGrouped, items) &&\n items.map((group: GroupType, index: number) => {\n if (group.options.length < 1) {\n return;\n }\n const render = (\n <div key={index}>\n <SectionHeading\n key={index}\n data-test-id=\"cf-autocomplete-grouptitle\"\n marginBottom=\"none\"\n className={styles.groupTitle}\n >\n {group.groupTitle}\n </SectionHeading>\n <AutocompleteItems<ItemType>\n items={group.options}\n highlightedIndex={highlightedIndex}\n getItemProps={getItemProps}\n renderItem={renderItem}\n inputValue={inputValue}\n elementStartIndex={elementStartIndex}\n />\n </div>\n );\n elementStartIndex += group.options.length;\n return render;\n })}\n\n {!isLoading &&\n !isUsingGroups(isGrouped, items) &&\n items.length > 0 && (\n <AutocompleteItems<ItemType>\n items={items}\n elementStartIndex={elementStartIndex}\n highlightedIndex={highlightedIndex}\n getItemProps={getItemProps}\n renderItem={renderItem}\n inputValue={inputValue}\n />\n )}\n </Popover.Content>\n ) : (\n // We need to render an empty hidden div, so we can pass the menuProps or downshift will show a warning about it\n // https://github.com/downshift-js/downshift/issues/1167#issuecomment-1088022842\n <div {...menuProps} className={cx(styles.hidden)} />\n )}\n </Popover>\n </div>\n );\n}\n\nconst ListItemLoadingState = () => {\n return (\n <Skeleton.Container svgHeight={16}>\n <Skeleton.BodyText numberOfLines={1} />\n </Skeleton.Container>\n );\n};\n\n// This is required to infer correct typings when differentiating groups and items\nfunction isUsingGroups<ItemType>(\n isGrouped: boolean,\n items: ItemType[] | GenericGroupType<ItemType>[],\n): items is GenericGroupType<ItemType>[] {\n return isGrouped;\n}\n\n/**\n * The Autocomplete is a component that will show a `TextInput` where a user can type any word which will be used\n * to filter a list of items. That list of filtered items will be shown to the user as possible options for the input.\n * Once one of the options is selected, that option becomes the value of the `TextInput`.\n */\nexport const Autocomplete = React.forwardRef(_Autocomplete) as <T>(\n props: ExpandProps<AutocompleteProps<T>> & {\n ref?: React.Ref<HTMLDivElement>;\n },\n) => ReturnType<typeof _Autocomplete>;\n","import React, { HTMLAttributes } from 'react';\nimport { cx } from 'emotion';\nimport { getStringMatch } from '@contentful/f36-utils';\nimport type { UseComboboxGetItemPropsOptions } from 'downshift';\nimport { Text } from '@contentful/f36-typography';\n\nimport { getAutocompleteStyles } from './Autocomplete.styles';\n\ninterface AutocompleteItemsProps<ItemType> {\n items: ItemType[];\n elementStartIndex: number;\n highlightedIndex: number;\n getItemProps: (\n options: UseComboboxGetItemPropsOptions<ItemType>,\n ) => HTMLAttributes<HTMLLIElement>;\n renderItem: (item: ItemType, inputValue: string) => React.ReactNode;\n inputValue: string;\n listMaxHeight?: number;\n}\n\nexport const AutocompleteItems = <ItemType,>(\n props: AutocompleteItemsProps<ItemType>,\n) => {\n const {\n items,\n elementStartIndex,\n highlightedIndex,\n getItemProps,\n renderItem,\n inputValue,\n listMaxHeight = 180,\n } = props;\n\n const styles = getAutocompleteStyles(listMaxHeight);\n\n return (\n <ul className={styles.list} data-test-id=\"cf-autocomplete-list\">\n {items.map((item: ItemType, index: number) => {\n const itemIndex = elementStartIndex + index;\n const itemProps = getItemProps({ item, index: itemIndex });\n return (\n <Text\n {...itemProps}\n as=\"li\"\n key={itemIndex}\n className={cx([\n styles.item,\n highlightedIndex === itemIndex && styles.highlighted,\n ])}\n data-test-id={`cf-autocomplete-list-item-${itemIndex}`}\n >\n {renderItem ? (\n renderItem(item, inputValue)\n ) : typeof item === 'string' ? (\n <HighlightedItem item={item} inputValue={inputValue} />\n ) : (\n item\n )}\n </Text>\n );\n })}\n </ul>\n );\n};\n\nAutocompleteItems.displayName = 'AutocompleteItems';\n\nfunction HighlightedItem({\n item,\n inputValue,\n}: {\n item: string;\n inputValue: string;\n}) {\n const { before, match, after } = getStringMatch(item, inputValue);\n\n return (\n <>\n {before}\n <b>{match}</b>\n {after}\n </>\n );\n}\n\nHighlightedItem.displayName = 'HighlightedItem';\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getAutocompleteStyles = (listMaxHeight: number) => ({\n autocomplete: css({\n position: 'relative',\n width: '100%',\n }),\n combobox: css({\n position: 'relative',\n }),\n inputField: css({\n paddingRight: tokens.spacingXl,\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n }),\n toggleButton: css({\n position: 'absolute',\n top: '1px',\n right: '1px',\n zIndex: 1,\n padding: tokens.spacing2Xs,\n height: '38px',\n }),\n content: css({\n overflow: 'auto',\n maxHeight: `${listMaxHeight}px`,\n }),\n list: css({\n listStyle: 'none',\n padding: `${tokens.spacingXs} 0`,\n margin: 0,\n }),\n groupTitle: css({\n padding: `${tokens.spacingXs} ${tokens.spacingM}`,\n lineHeight: tokens.lineHeightM,\n }),\n noMatchesTitle: css({\n color: tokens.gray500,\n margin: `${tokens.spacingM} 0 ${tokens.spacingM} 0`,\n }),\n item: css({\n display: 'block',\n padding: `${tokens.spacingXs} ${tokens.spacingM}`,\n wordBreak: 'break-word',\n whiteSpace: 'break-spaces',\n cursor: 'pointer',\n hyphens: 'auto',\n\n '&:focus, &:hover': {\n backgroundColor: tokens.gray100,\n },\n '&:active': {\n backgroundColor: tokens.gray200,\n },\n }),\n disabled: css({\n opacity: 0.5,\n pointerEvents: 'none',\n }),\n highlighted: css({\n backgroundColor: tokens.gray100,\n }),\n hidden: css({\n display: 'none',\n }),\n});\n"]}
package/dist/index.d.ts CHANGED
@@ -60,6 +60,11 @@ interface AutocompleteProps<ItemType> extends CommonProps, Pick<TextInputProps,
60
60
  * @default "Search"
61
61
  */
62
62
  placeholder?: string;
63
+ /**
64
+ * Defines if the list should be shown even if empty, when input is focused
65
+ * @default false
66
+ */
67
+ showEmptyList?: boolean;
63
68
  /**
64
69
  * A message that will be shown when it is not possible to find any option that matches the input value
65
70
  * @default "No matches"
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var n = require('react');
5
+ var i = require('react');
6
6
  var emotion = require('emotion');
7
7
  var downshift = require('downshift');
8
8
  var f36Core = require('@contentful/f36-core');
@@ -17,10 +17,10 @@ var p = require('@contentful/f36-tokens');
17
17
 
18
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
19
 
20
- var n__default = /*#__PURE__*/_interopDefaultLegacy(n);
20
+ var i__default = /*#__PURE__*/_interopDefaultLegacy(i);
21
21
  var p__default = /*#__PURE__*/_interopDefaultLegacy(p);
22
22
 
23
- var be=Object.defineProperty,xe=Object.defineProperties;var ve=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var X=(e,o,i)=>o in e?be(e,o,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[o]=i,g=(e,o)=>{for(var i in o||(o={}))U.call(o,i)&&X(e,i,o[i]);if(P)for(var i of P(o))W.call(o,i)&&X(e,i,o[i]);return e},h=(e,o)=>xe(e,ve(o));var q=(e,o)=>{var i={};for(var r in e)U.call(e,r)&&o.indexOf(r)<0&&(i[r]=e[r]);if(e!=null&&P)for(var r of P(e))o.indexOf(r)<0&&W.call(e,r)&&(i[r]=e[r]);return i};var S=e=>({autocomplete:emotion.css({position:"relative",width:"100%"}),combobox:emotion.css({position:"relative"}),inputField:emotion.css({paddingRight:p__default["default"].spacingXl,textOverflow:"ellipsis",whiteSpace:"nowrap"}),toggleButton:emotion.css({position:"absolute",top:"1px",right:"1px",zIndex:1,padding:p__default["default"].spacing2Xs,height:"38px"}),content:emotion.css({overflow:"auto",maxHeight:`${e}px`}),list:emotion.css({listStyle:"none",padding:`${p__default["default"].spacingXs} 0`,margin:0}),groupTitle:emotion.css({padding:`${p__default["default"].spacingXs} ${p__default["default"].spacingM}`,lineHeight:p__default["default"].lineHeightM}),noMatchesTitle:emotion.css({color:p__default["default"].gray500,margin:`${p__default["default"].spacingM} 0 ${p__default["default"].spacingM} 0`}),item:emotion.css({display:"block",padding:`${p__default["default"].spacingXs} ${p__default["default"].spacingM}`,wordBreak:"break-word",whiteSpace:"break-spaces",cursor:"pointer",hyphens:"auto","&:focus, &:hover":{backgroundColor:p__default["default"].gray100},"&:active":{backgroundColor:p__default["default"].gray200}}),disabled:emotion.css({opacity:.5,pointerEvents:"none"}),highlighted:emotion.css({backgroundColor:p__default["default"].gray100})});var M=e=>{let{items:o,elementStartIndex:i,highlightedIndex:r,getItemProps:I,renderItem:T,inputValue:b,listMaxHeight:A=180}=e,s=S(A);return n__default["default"].createElement("ul",{className:s.list,"data-test-id":"cf-autocomplete-list"},o.map((m,H)=>{let c=i+H,k=I({item:m,index:c});return n__default["default"].createElement(f36Typography.Text,h(g({},k),{as:"li",key:c,className:emotion.cx([s.item,r===c&&s.highlighted]),"data-test-id":`cf-autocomplete-list-item-${c}`}),T?T(m,b):typeof m=="string"?n__default["default"].createElement(z,{item:m,inputValue:b}):m)}))};M.displayName="AutocompleteItems";function z({item:e,inputValue:o}){let{before:i,match:r,after:I}=f36Utils.getStringMatch(e,o);return n__default["default"].createElement(n__default["default"].Fragment,null,i,n__default["default"].createElement("b",null,r),I)}z.displayName="HighlightedItem";function Le(e,o){let {id:i,className:r,clearAfterSelect:I=!1,closeAfterSelect:T=!0,defaultValue:b="",selectedItem:A,items:s,onInputValueChange:m,onSelectItem:H,renderItem:c,icon:k=n__default["default"].createElement(f36Icons.ChevronDownIcon,{variant:"muted"}),itemToString:Q=t=>t,isInvalid:Y,isDisabled:R,isRequired:Z,isReadOnly:ee,noMatchesMessage:te="No matches found",placeholder:oe="Search",inputRef:ie,toggleRef:ne,listRef:se,listWidth:re="auto",listMaxHeight:pe=180,isGrouped:x=!1,isLoading:v=!1,usePortal:ae=!1,testId:le="cf-autocomplete"}=e,u=S(pe),[d,me]=n.useState(b),y=n.useCallback(t=>{me(t),m==null||m(t);},[m]),ue=n.useCallback(t=>{let a=t.target.value;y(a);},[y]),ce=C(x)?s.reduce((t,a)=>[...t,...a.options],[]):s,de=C(x)?s.every(t=>t.options.length===0):s.length===0,{getComboboxProps:ge,getInputProps:he,getItemProps:_,getMenuProps:fe,getToggleButtonProps:Ie,highlightedIndex:$,isOpen:B,toggleMenu:w}=downshift.useCombobox({items:ce,selectedItem:A,inputValue:d,itemToString:Q,onInputValueChange:({type:t,inputValue:a})=>{t!=="__input_change__"&&y(a);},onStateChange:({type:t,selectedItem:a})=>{switch(t){case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:case downshift.useCombobox.stateChangeTypes.ItemClick:a&&H(a),I&&y(""),T||w();break;}}}),F=he(),G=q(F,["aria-labelledby","id"]),ye=ge(),D=Ie(),N=fe(),L=0;return n__default["default"].createElement("div",{"data-test-id":le,className:emotion.cx(u.autocomplete,r),ref:o},n__default["default"].createElement(f36Popover.Popover,{usePortal:ae,isOpen:B,isFullWidth:re==="full",renderOnlyWhenOpen:!1,autoFocus:!1,id:N.id},n__default["default"].createElement(f36Popover.Popover.Trigger,null,n__default["default"].createElement("div",h(g({},ye),{className:u.combobox}),n__default["default"].createElement(f36Forms.TextInput,h(g({className:u.inputField},G),{onFocus:()=>{B||w();},id:i,isInvalid:Y,isDisabled:R,isRequired:Z,isReadOnly:ee,ref:f36Core.mergeRefs(G.ref,ie),testId:"cf-autocomplete-input",placeholder:oe,onChange:t=>{G.onChange(t),ue(t);}})),n__default["default"].createElement(f36Button.IconButton,h(g({},D),{ref:f36Core.mergeRefs(D.ref,ne),"aria-label":d?"Clear":"Show list",className:u.toggleButton,variant:"transparent",icon:d?n__default["default"].createElement(f36Icons.CloseIcon,{variant:"muted"}):k,onClick:()=>{d?y(""):w();},isDisabled:R,size:"small"})))),(s.length>0||d.length>0)&&n__default["default"].createElement(f36Popover.Popover.Content,h(g({},N),{ref:f36Core.mergeRefs(N.ref,se),className:u.content,testId:"cf-autocomplete-container"}),v&&[...Array(3)].map((t,a)=>n__default["default"].createElement("div",{key:a,className:emotion.cx(u.item,u.disabled)},n__default["default"].createElement(Ee,null))),!v&&de&&n__default["default"].createElement("div",{className:u.item},n__default["default"].createElement(f36Typography.Subheading,{className:u.noMatchesTitle},te)),!v&&C(x)&&s.map((t,a)=>{if(t.options.length<1)return;let Te=n__default["default"].createElement("div",{key:a},n__default["default"].createElement(f36Typography.SectionHeading,{key:a,"data-test-id":"cf-autocomplete-grouptitle",marginBottom:"none",className:u.groupTitle},t.groupTitle),n__default["default"].createElement(M,{items:t.options,highlightedIndex:$,getItemProps:_,renderItem:c,inputValue:d,elementStartIndex:L}));return L+=t.options.length,Te}),!v&&!C(x)&&s.length>0&&n__default["default"].createElement(M,{items:s,elementStartIndex:L,highlightedIndex:$,getItemProps:_,renderItem:c,inputValue:d}))))}var Ee=()=>n__default["default"].createElement(f36Skeleton.Skeleton.Container,{svgHeight:16},n__default["default"].createElement(f36Skeleton.Skeleton.BodyText,{numberOfLines:1}));function C(e,o){return e}var Ve=n__default["default"].forwardRef(Le);
23
+ var xe=Object.defineProperty,ve=Object.defineProperties;var Pe=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var U=(e,o,n)=>o in e?xe(e,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[o]=n,c=(e,o)=>{for(var n in o||(o={}))W.call(o,n)&&U(e,n,o[n]);if(S)for(var n of S(o))q.call(o,n)&&U(e,n,o[n]);return e},d=(e,o)=>ve(e,Pe(o));var z=(e,o)=>{var n={};for(var r in e)W.call(e,r)&&o.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&S)for(var r of S(e))o.indexOf(r)<0&&q.call(e,r)&&(n[r]=e[r]);return n};var M=e=>({autocomplete:emotion.css({position:"relative",width:"100%"}),combobox:emotion.css({position:"relative"}),inputField:emotion.css({paddingRight:p__default["default"].spacingXl,textOverflow:"ellipsis",whiteSpace:"nowrap"}),toggleButton:emotion.css({position:"absolute",top:"1px",right:"1px",zIndex:1,padding:p__default["default"].spacing2Xs,height:"38px"}),content:emotion.css({overflow:"auto",maxHeight:`${e}px`}),list:emotion.css({listStyle:"none",padding:`${p__default["default"].spacingXs} 0`,margin:0}),groupTitle:emotion.css({padding:`${p__default["default"].spacingXs} ${p__default["default"].spacingM}`,lineHeight:p__default["default"].lineHeightM}),noMatchesTitle:emotion.css({color:p__default["default"].gray500,margin:`${p__default["default"].spacingM} 0 ${p__default["default"].spacingM} 0`}),item:emotion.css({display:"block",padding:`${p__default["default"].spacingXs} ${p__default["default"].spacingM}`,wordBreak:"break-word",whiteSpace:"break-spaces",cursor:"pointer",hyphens:"auto","&:focus, &:hover":{backgroundColor:p__default["default"].gray100},"&:active":{backgroundColor:p__default["default"].gray200}}),disabled:emotion.css({opacity:.5,pointerEvents:"none"}),highlighted:emotion.css({backgroundColor:p__default["default"].gray100}),hidden:emotion.css({display:"none"})});var C=e=>{let{items:o,elementStartIndex:n,highlightedIndex:r,getItemProps:I,renderItem:T,inputValue:b,listMaxHeight:H=180}=e,s=M(H);return i__default["default"].createElement("ul",{className:s.list,"data-test-id":"cf-autocomplete-list"},o.map((u,k)=>{let g=n+k,w=I({item:u,index:g});return i__default["default"].createElement(f36Typography.Text,d(c({},w),{as:"li",key:g,className:emotion.cx([s.item,r===g&&s.highlighted]),"data-test-id":`cf-autocomplete-list-item-${g}`}),T?T(u,b):typeof u=="string"?i__default["default"].createElement(j,{item:u,inputValue:b}):u)}))};C.displayName="AutocompleteItems";function j({item:e,inputValue:o}){let{before:n,match:r,after:I}=f36Utils.getStringMatch(e,o);return i__default["default"].createElement(i__default["default"].Fragment,null,n,i__default["default"].createElement("b",null,r),I)}j.displayName="HighlightedItem";function Ee(e,o){let {id:n,className:r,clearAfterSelect:I=!1,closeAfterSelect:T=!0,defaultValue:b="",selectedItem:H,items:s,onInputValueChange:u,onSelectItem:k,renderItem:g,icon:w=i__default["default"].createElement(f36Icons.ChevronDownIcon,{variant:"muted"}),itemToString:Q=t=>t,isInvalid:Y,isDisabled:R,isRequired:Z,isReadOnly:ee,showEmptyList:te,noMatchesMessage:oe="No matches found",placeholder:ie="Search",inputRef:ne,toggleRef:se,listRef:re,listWidth:pe="auto",listMaxHeight:ae=180,isGrouped:x=!1,isLoading:v=!1,usePortal:le=!1,testId:me="cf-autocomplete"}=e,m=M(ae),[h,ue]=i.useState(b),y=i.useCallback(t=>{ue(t),u==null||u(t);},[u]),ce=i.useCallback(t=>{let a=t.target.value;y(a);},[y]),de=A(x)?s.reduce((t,a)=>[...t,...a.options],[]):s,ge=A(x)?s.every(t=>t.options.length===0):s.length===0,{getComboboxProps:he,getInputProps:fe,getItemProps:$,getMenuProps:Ie,getToggleButtonProps:ye,highlightedIndex:B,isOpen:D,toggleMenu:N}=downshift.useCombobox({items:de,selectedItem:H,inputValue:h,itemToString:Q,onInputValueChange:({type:t,inputValue:a})=>{t!=="__input_change__"&&y(a);},onStateChange:({type:t,selectedItem:a})=>{switch(t){case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:case downshift.useCombobox.stateChangeTypes.ItemClick:a&&k(a),I&&y(""),T||N();break;}}}),X=fe(),G=z(X,["aria-labelledby","id"]),Te=he(),F=ye(),P=Ie(),L=0;return i__default["default"].createElement("div",{"data-test-id":me,className:emotion.cx(m.autocomplete,r),ref:o},i__default["default"].createElement(f36Popover.Popover,{usePortal:le,isOpen:D,isFullWidth:pe==="full",renderOnlyWhenOpen:!1,autoFocus:!1,id:P.id},i__default["default"].createElement(f36Popover.Popover.Trigger,null,i__default["default"].createElement("div",d(c({},Te),{className:m.combobox}),i__default["default"].createElement(f36Forms.TextInput,d(c({className:m.inputField},G),{onFocus:()=>{D||N();},id:n,isInvalid:Y,isDisabled:R,isRequired:Z,isReadOnly:ee,ref:f36Core.mergeRefs(G.ref,ne),testId:"cf-autocomplete-input",placeholder:ie,onChange:t=>{G.onChange(t),ce(t);}})),i__default["default"].createElement(f36Button.IconButton,d(c({},F),{ref:f36Core.mergeRefs(F.ref,se),"aria-label":h?"Clear":"Show list",className:m.toggleButton,variant:"transparent",icon:h?i__default["default"].createElement(f36Icons.CloseIcon,{variant:"muted"}):w,onClick:()=>{h?y(""):N();},isDisabled:R,size:"small"})))),s.length>0||h.length>0||te?i__default["default"].createElement(f36Popover.Popover.Content,d(c({},P),{ref:f36Core.mergeRefs(P.ref,re),className:m.content,testId:"cf-autocomplete-container"}),v&&[...Array(3)].map((t,a)=>i__default["default"].createElement("div",{key:a,className:emotion.cx(m.item,m.disabled)},i__default["default"].createElement(Ve,null))),!v&&ge&&i__default["default"].createElement("div",{className:m.item},i__default["default"].createElement(f36Typography.Subheading,{className:m.noMatchesTitle},oe)),!v&&A(x)&&s.map((t,a)=>{if(t.options.length<1)return;let be=i__default["default"].createElement("div",{key:a},i__default["default"].createElement(f36Typography.SectionHeading,{key:a,"data-test-id":"cf-autocomplete-grouptitle",marginBottom:"none",className:m.groupTitle},t.groupTitle),i__default["default"].createElement(C,{items:t.options,highlightedIndex:B,getItemProps:$,renderItem:g,inputValue:h,elementStartIndex:L}));return L+=t.options.length,be}),!v&&!A(x)&&s.length>0&&i__default["default"].createElement(C,{items:s,elementStartIndex:L,highlightedIndex:B,getItemProps:$,renderItem:g,inputValue:h})):i__default["default"].createElement("div",d(c({},P),{className:emotion.cx(m.hidden)}))))}var Ve=()=>i__default["default"].createElement(f36Skeleton.Skeleton.Container,{svgHeight:16},i__default["default"].createElement(f36Skeleton.Skeleton.BodyText,{numberOfLines:1}));function A(e,o){return e}var Oe=i__default["default"].forwardRef(Ee);
24
24
 
25
- exports.Autocomplete = Ve;
25
+ exports.Autocomplete = Oe;
26
26
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Autocomplete.tsx","../src/AutocompleteItems.tsx","../src/Autocomplete.styles.ts"],"names":["React","useCallback","useState","cx","useCombobox","mergeRefs","IconButton","TextInput","CloseIcon","ChevronDownIcon","Skeleton","Popover","Subheading","SectionHeading","getStringMatch","Text","css","tokens","getAutocompleteStyles","listMaxHeight","AutocompleteItems","props","items","elementStartIndex","highlightedIndex","getItemProps","renderItem","inputValue","styles","item","index","itemIndex","itemProps","__spreadProps","__spreadValues","HighlightedItem","before","match","after","_Autocomplete","ref","id","className","clearAfterSelect","closeAfterSelect","defaultValue","selectedItem","onInputValueChange","onSelectItem","icon","itemToString","isInvalid","isDisabled","isRequired","isReadOnly","noMatchesMessage","placeholder","inputRef","toggleRef","listRef","listWidth","isGrouped","isLoading","usePortal","testId","setInputValue","handleInputValueChange","value","handleNativeChangeEvent","event","flattenItems","isUsingGroups","acc","group","isShowingNoMatches","getComboboxProps","getInputProps","getMenuProps","getToggleButtonProps","isOpen","toggleMenu","type","_a","_labelledby","_inputId","inputProps","__objRest","comboboxProps","toggleProps","menuProps","_","ListItemLoadingState","render","Autocomplete"],"mappings":"qlBAAA,OAAOA,GAAS,eAAAC,EAAa,YAAAC,OAAgB,QAC7C,OAAS,MAAAC,MAAU,UACnB,OAAS,eAAAC,MAAmB,YAE5B,OACE,aAAAC,MAGK,uBACP,OAAS,cAAAC,OAAkB,yBAC3B,OAAS,aAAAC,OAAsC,wBAC/C,OAAS,aAAAC,GAAW,mBAAAC,OAAuB,wBAC3C,OAAS,YAAAC,M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CAAmB,UAAW,IAC7BV,EAAA,cAACU,EAAS,SAAT,CAAkB,cAAe,EAAG,CACvC,EAKJ,SAAS6D,EACPV,EACAvC,EACuC,CACvC,OAAOuC,CACT,CAOO,IAAMgC,GAAe7F,EAAM,WAAWuC,EAAa","sourcesContent":["import React, { useCallback, useState } from 'react';\nimport { cx } from 'emotion';\nimport { useCombobox } from 'downshift';\n\nimport {\n mergeRefs,\n type CommonProps,\n type ExpandProps,\n} from '@contentful/f36-core';\nimport { IconButton } from '@contentful/f36-button';\nimport { TextInput, type TextInputProps } from '@contentful/f36-forms';\nimport { CloseIcon, ChevronDownIcon } from '@contentful/f36-icons';\nimport { Skeleton } from '@contentful/f36-skeleton';\nimport { Popover } from '@contentful/f36-popover';\nimport { Subheading, SectionHeading } from '@contentful/f36-typography';\n\nimport { AutocompleteItems } from './AutocompleteItems';\nimport { getAutocompleteStyles } from './Autocomplete.styles';\n\nexport interface GenericGroupType<ItemType> {\n groupTitle: string;\n options: ItemType[];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface AutocompleteProps<ItemType>\n extends CommonProps,\n Pick<\n TextInputProps,\n | 'isDisabled'\n | 'isInvalid'\n | 'isReadOnly'\n | 'isRequired'\n | 'id'\n | 'defaultValue'\n > {\n /**\n * It’s an array of data to be used as \"options\" by the autocomplete component.\n * This can either be a plain list of items or a list of groups of items.\n */\n items: ItemType[] | GenericGroupType<ItemType>[];\n\n /**\n * Set a custom icon for the text input\n */\n icon?: React.ReactElement;\n\n /**\n * Tells if the item is a object with groups\n */\n isGrouped?: boolean;\n\n /**\n * Function called whenever the input value changes\n */\n onInputValueChange?: (value: string) => void;\n /**\n * This is the function that will be called when the user selects one of the \"options\" in the list.\n * The component will pass the selected \"item\" as an argument to the function..\n */\n onSelectItem: (item: ItemType) => void;\n\n /**\n * Applying the selectedItem property turns autocomplete into a controlled component.\n * Can be used to display e.g. previously selected element. If it is an object the itemToString function will apply to it.\n */\n selectedItem?: ItemType;\n\n /**\n * This is the function that will be called for each \"item\" passed in the `items` prop.\n * It receives the \"item\" and \"inputValue\" as arguments and returns a ReactNode.\n * The inputValue is passed in case you want to highlight the match on the render.\n */\n renderItem?: (item: ItemType, inputValue: string) => React.ReactNode;\n /**\n * When using objects as `items`, we recommend passing a function that tells Downshift how to extract a string\n * from those objetcs to be used as inputValue\n */\n itemToString?: (item: ItemType) => string;\n /**\n * If this is set to `true` the text input will be cleared after an item is selected\n * @default false\n */\n clearAfterSelect?: boolean;\n /**\n * If this is set to `false` the dropdown menu will stay open after selecting an item\n * @default true\n */\n closeAfterSelect?: boolean;\n /**\n * This is the value will be passed to the `placeholder` prop of the input.\n * @default \"Search\"\n */\n placeholder?: string;\n /**\n * A message that will be shown when it is not possible to find any option that matches the input value\n * @default \"No matches\"\n */\n noMatchesMessage?: string;\n /**\n * Use this prop to get a ref to the input element of the component\n */\n inputRef?: React.Ref<HTMLInputElement>;\n /**\n * Use this prop to get a ref to the toggle button of the component\n */\n toggleRef?: React.Ref<HTMLButtonElement>;\n /**\n * Use this prop to get a ref to the list of items of the component\n */\n listRef?: React.Ref<HTMLUListElement>;\n /**\n * It sets the width of the list\n * @default \"auto\"\n */\n listWidth?: 'auto' | 'full';\n /**\n * It sets the max-height, in pixels, of the list\n * The default value is the height of 5 single line items\n * @default 180\n */\n listMaxHeight?: number;\n /**\n * Sets the list to show its loading state\n * @default false\n */\n isLoading?: boolean;\n /**\n * Boolean to control whether or not to render the suggestions box in a React Portal.\n * Rendering content inside a Portal allows the suggestions box to escape the bounds\n * of its parent while still being positioned correctly.\n * Defaults to `false`\n */\n usePortal?: boolean;\n}\n\nfunction _Autocomplete<ItemType>(\n props: AutocompleteProps<ItemType>,\n ref: React.Ref<HTMLDivElement>,\n) {\n const {\n id,\n className,\n clearAfterSelect = false,\n closeAfterSelect = true,\n defaultValue = '',\n selectedItem,\n items,\n onInputValueChange,\n onSelectItem,\n renderItem,\n icon = <ChevronDownIcon variant=\"muted\" />,\n itemToString = (item: ItemType) => item as unknown as string,\n isInvalid,\n isDisabled,\n isRequired,\n isReadOnly,\n noMatchesMessage = 'No matches found',\n placeholder = 'Search',\n inputRef,\n toggleRef,\n listRef,\n listWidth = 'auto',\n listMaxHeight = 180,\n isGrouped = false,\n isLoading = false,\n usePortal = false,\n testId = 'cf-autocomplete',\n } = props;\n\n type GroupType = GenericGroupType<ItemType>;\n\n const styles = getAutocompleteStyles(listMaxHeight);\n\n const [inputValue, setInputValue] = useState(defaultValue);\n\n const handleInputValueChange = useCallback(\n (value: string) => {\n setInputValue(value);\n\n onInputValueChange?.(value);\n },\n [onInputValueChange],\n );\n\n // Handle manually to avoid a jumping cursor, see https://github.com/downshift-js/downshift/issues/1108#issuecomment-842407759\n const handleNativeChangeEvent = useCallback(\n (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n const value = event.target.value;\n handleInputValueChange(value);\n },\n [handleInputValueChange],\n );\n\n const flattenItems = isUsingGroups(isGrouped, items)\n ? items.reduce(\n (acc: ItemType[], group: GroupType) => [...acc, ...group.options],\n [],\n )\n : items;\n\n const isShowingNoMatches = isUsingGroups(isGrouped, items)\n ? items.every((group: GroupType) => group.options.length === 0)\n : items.length === 0;\n\n const {\n getComboboxProps,\n getInputProps,\n getItemProps,\n getMenuProps,\n getToggleButtonProps,\n highlightedIndex,\n isOpen,\n toggleMenu,\n } = useCombobox({\n items: flattenItems,\n selectedItem,\n inputValue,\n itemToString,\n onInputValueChange: ({ type, inputValue }) => {\n if (type !== '__input_change__') {\n handleInputValueChange(inputValue);\n }\n },\n onStateChange: ({ type, selectedItem }) => {\n switch (type) {\n case useCombobox.stateChangeTypes.InputKeyDownEnter:\n case useCombobox.stateChangeTypes.ItemClick:\n if (selectedItem) {\n onSelectItem(selectedItem);\n }\n if (clearAfterSelect) {\n handleInputValueChange('');\n }\n if (!closeAfterSelect) {\n toggleMenu();\n }\n break;\n default:\n break;\n }\n },\n });\n\n const {\n 'aria-labelledby': _labelledby,\n id: _inputId,\n ...inputProps\n } = getInputProps();\n const comboboxProps = getComboboxProps();\n const toggleProps = getToggleButtonProps();\n const menuProps = getMenuProps();\n let elementStartIndex = 0;\n\n return (\n <div\n data-test-id={testId}\n className={cx(styles.autocomplete, className)}\n ref={ref}\n >\n <Popover\n usePortal={usePortal}\n isOpen={isOpen}\n isFullWidth={listWidth === 'full'}\n renderOnlyWhenOpen={false}\n // This is necessary, otherwise the focus will change from the input to the Popover\n // and the user won't be able to type in the input\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={false}\n id={menuProps.id}\n >\n <Popover.Trigger>\n <div {...comboboxProps} className={styles.combobox}>\n <TextInput\n className={styles.inputField}\n {...inputProps}\n onFocus={() => {\n if (!isOpen) {\n toggleMenu();\n }\n }}\n id={id}\n isInvalid={isInvalid}\n isDisabled={isDisabled}\n isRequired={isRequired}\n isReadOnly={isReadOnly}\n ref={mergeRefs(inputProps.ref, inputRef)}\n testId=\"cf-autocomplete-input\"\n placeholder={placeholder}\n onChange={(event) => {\n inputProps.onChange(event);\n handleNativeChangeEvent(event);\n }}\n />\n <IconButton\n {...toggleProps}\n ref={mergeRefs(toggleProps.ref, toggleRef)}\n aria-label={inputValue ? 'Clear' : 'Show list'}\n className={styles.toggleButton}\n variant=\"transparent\"\n icon={inputValue ? <CloseIcon variant=\"muted\" /> : icon}\n onClick={() => {\n if (inputValue) {\n handleInputValueChange('');\n } else {\n toggleMenu();\n }\n }}\n isDisabled={isDisabled}\n size=\"small\"\n />\n </div>\n </Popover.Trigger>\n\n {(items.length > 0 || inputValue.length > 0) && (\n <Popover.Content\n {...menuProps}\n ref={mergeRefs(menuProps.ref, listRef)}\n className={styles.content}\n testId=\"cf-autocomplete-container\"\n >\n {isLoading &&\n [...Array(3)].map((_, index) => (\n <div key={index} className={cx(styles.item, styles.disabled)}>\n <ListItemLoadingState />\n </div>\n ))}\n\n {!isLoading && isShowingNoMatches && (\n <div className={styles.item}>\n <Subheading className={styles.noMatchesTitle}>\n {noMatchesMessage}\n </Subheading>\n </div>\n )}\n\n {!isLoading &&\n isUsingGroups(isGrouped, items) &&\n items.map((group: GroupType, index: number) => {\n if (group.options.length < 1) {\n return;\n }\n const render = (\n <div key={index}>\n <SectionHeading\n key={index}\n data-test-id=\"cf-autocomplete-grouptitle\"\n marginBottom=\"none\"\n className={styles.groupTitle}\n >\n {group.groupTitle}\n </SectionHeading>\n <AutocompleteItems<ItemType>\n items={group.options}\n highlightedIndex={highlightedIndex}\n getItemProps={getItemProps}\n renderItem={renderItem}\n inputValue={inputValue}\n elementStartIndex={elementStartIndex}\n />\n </div>\n );\n elementStartIndex += group.options.length;\n return render;\n })}\n\n {!isLoading &&\n !isUsingGroups(isGrouped, items) &&\n items.length > 0 && (\n <AutocompleteItems<ItemType>\n items={items}\n elementStartIndex={elementStartIndex}\n highlightedIndex={highlightedIndex}\n getItemProps={getItemProps}\n renderItem={renderItem}\n inputValue={inputValue}\n />\n )}\n </Popover.Content>\n )}\n </Popover>\n </div>\n );\n}\n\nconst ListItemLoadingState = () => {\n return (\n <Skeleton.Container svgHeight={16}>\n <Skeleton.BodyText numberOfLines={1} />\n </Skeleton.Container>\n );\n};\n\n// This is required to infer correct typings when differentiating groups and items\nfunction isUsingGroups<ItemType>(\n isGrouped: boolean,\n items: ItemType[] | GenericGroupType<ItemType>[],\n): items is GenericGroupType<ItemType>[] {\n return isGrouped;\n}\n\n/**\n * The Autocomplete is a component that will show a `TextInput` where a user can type any word which will be used\n * to filter a list of items. That list of filtered items will be shown to the user as possible options for the input.\n * Once one of the options is selected, that option becomes the value of the `TextInput`.\n */\nexport const Autocomplete = React.forwardRef(_Autocomplete) as <T>(\n props: ExpandProps<AutocompleteProps<T>> & {\n ref?: React.Ref<HTMLDivElement>;\n },\n) => ReturnType<typeof _Autocomplete>;\n","import React, { HTMLAttributes } from 'react';\nimport { cx } from 'emotion';\nimport { getStringMatch } from '@contentful/f36-utils';\nimport type { UseComboboxGetItemPropsOptions } from 'downshift';\nimport { Text } from '@contentful/f36-typography';\n\nimport { getAutocompleteStyles } from './Autocomplete.styles';\n\ninterface AutocompleteItemsProps<ItemType> {\n items: ItemType[];\n elementStartIndex: number;\n highlightedIndex: number;\n getItemProps: (\n options: UseComboboxGetItemPropsOptions<ItemType>,\n ) => HTMLAttributes<HTMLLIElement>;\n renderItem: (item: ItemType, inputValue: string) => React.ReactNode;\n inputValue: string;\n listMaxHeight?: number;\n}\n\nexport const AutocompleteItems = <ItemType,>(\n props: AutocompleteItemsProps<ItemType>,\n) => {\n const {\n items,\n elementStartIndex,\n highlightedIndex,\n getItemProps,\n renderItem,\n inputValue,\n listMaxHeight = 180,\n } = props;\n\n const styles = getAutocompleteStyles(listMaxHeight);\n\n return (\n <ul className={styles.list} data-test-id=\"cf-autocomplete-list\">\n {items.map((item: ItemType, index: number) => {\n const itemIndex = elementStartIndex + index;\n const itemProps = getItemProps({ item, index: itemIndex });\n return (\n <Text\n {...itemProps}\n as=\"li\"\n key={itemIndex}\n className={cx([\n styles.item,\n highlightedIndex === itemIndex && styles.highlighted,\n ])}\n data-test-id={`cf-autocomplete-list-item-${itemIndex}`}\n >\n {renderItem ? (\n renderItem(item, inputValue)\n ) : typeof item === 'string' ? (\n <HighlightedItem item={item} inputValue={inputValue} />\n ) : (\n item\n )}\n </Text>\n );\n })}\n </ul>\n );\n};\n\nAutocompleteItems.displayName = 'AutocompleteItems';\n\nfunction HighlightedItem({\n item,\n inputValue,\n}: {\n item: string;\n inputValue: string;\n}) {\n const { before, match, after } = getStringMatch(item, inputValue);\n\n return (\n <>\n {before}\n <b>{match}</b>\n {after}\n </>\n );\n}\n\nHighlightedItem.displayName = 'HighlightedItem';\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getAutocompleteStyles = (listMaxHeight: number) => ({\n autocomplete: css({\n position: 'relative',\n width: '100%',\n }),\n combobox: css({\n position: 'relative',\n }),\n inputField: css({\n paddingRight: tokens.spacingXl,\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n }),\n toggleButton: css({\n position: 'absolute',\n top: '1px',\n right: '1px',\n zIndex: 1,\n padding: tokens.spacing2Xs,\n height: '38px',\n }),\n content: css({\n overflow: 'auto',\n maxHeight: `${listMaxHeight}px`,\n }),\n list: css({\n listStyle: 'none',\n padding: `${tokens.spacingXs} 0`,\n margin: 0,\n }),\n groupTitle: css({\n padding: `${tokens.spacingXs} ${tokens.spacingM}`,\n lineHeight: tokens.lineHeightM,\n }),\n noMatchesTitle: css({\n color: tokens.gray500,\n margin: `${tokens.spacingM} 0 ${tokens.spacingM} 0`,\n }),\n item: css({\n display: 'block',\n padding: `${tokens.spacingXs} ${tokens.spacingM}`,\n wordBreak: 'break-word',\n whiteSpace: 'break-spaces',\n cursor: 'pointer',\n hyphens: 'auto',\n\n '&:focus, &:hover': {\n backgroundColor: tokens.gray100,\n },\n '&:active': {\n backgroundColor: tokens.gray200,\n },\n }),\n disabled: css({\n opacity: 0.5,\n pointerEvents: 'none',\n }),\n highlighted: css({\n backgroundColor: tokens.gray100,\n }),\n});\n"]}
1
+ {"version":3,"sources":["../src/Autocomplete.tsx","../src/AutocompleteItems.tsx","../src/Autocomplete.styles.ts"],"names":["React","useCallback","useState","cx","useCombobox","mergeRefs","IconButton","TextInput","CloseIcon","ChevronDownIcon","Skeleton","Popover","Subheading","SectionHeading","getStringMatch","Text","css","tokens","getAutocompleteStyles","listMaxHeight","AutocompleteItems","props","items","elementStartIndex","highlightedIndex","getItemProps","renderItem","inputValue","styles","item","index","itemIndex","itemProps","__spreadProps","__spreadValues","HighlightedItem","before","match","after","_Autocomplete","ref","id","className","clearAfterSelect","closeAfterSelect","defaultValue","selectedItem","onInputValueChange","onSelectItem","icon","itemToString","isInvalid","isDisabled","isRequired","isReadOnly","showEmptyList","noMatchesMessage","placeholder","inputRef","toggleRef","listRef","listWidth","isGrouped","isLoading","usePortal","testId","setInputValue","handleInputValueChange","value","handleNativeChangeEvent","event","flattenItems","isUsingGroups","acc","group","isShowingNoMatches","getComboboxProps","getInputProps","getMenuProps","getToggleButtonProps","isOpen","toggleMenu","type","_a","_labelledby","_inputId","inputProps","__objRest","comboboxProps","toggleProps","menuProps","_","ListItemLoadingState","render","Autocomplete"],"mappings":"qlBAAA,OAAOA,GAAS,eAAAC,EAAa,YAAAC,OAAgB,QAC7C,OAAS,MAAAC,MAAU,UACnB,OAAS,eAAAC,MAAmB,YAE5B,OACE,aAAAC,MAGK,uBACP,OAAS,cAAAC,OAAkB,yBAC3B,OAAS,aAAAC,OAAsC,wBAC/C,OAAS,aAAAC,GAAW,mBAAAC,OAAuB,wBAC3C,OAAS,YAAAC,MAAgB,2BACzB,OAAS,WAAAC,MAAe,0BACxB,OAAS,cAAAC,GAAY,kBAAAC,OAAsB,6BCd3C,OAAOb,MAA+B,QACtC,OAAS,MAAAG,OAAU,UACnB,OAAS,kBAAAW,OAAsB,wBAE/B,OAAS,QAAAC,OAAY,6BCJrB,OAAS,OAAAC,MAAW,UACpB,OAAOC,MAAY,yBAEZ,IAAMC,EAAyBC,IAA2B,CAC/D,aAAcH,EAAI,CAChB,SAAU,WACV,MAAO,MACT,CAAC,EACD,SAAUA,EAAI,CACZ,SAAU,UACZ,CAAC,EACD,WAAYA,EAAI,CACd,aAAcC,EAAO,UACrB,aAAc,WACd,WAAY,QACd,CAAC,EACD,aAAcD,EAAI,CAChB,SAAU,WACV,IAAK,MACL,MAAO,MACP,OAAQ,EACR,QAASC,EAAO,WAChB,OAAQ,MACV,CAAC,EACD,QAASD,EAAI,CACX,SAAU,OACV,UAAW,GAAGG,KAChB,CAAC,EACD,KAAMH,EAAI,CACR,UAAW,OACX,QAAS,GAAGC,EAAO,cACnB,OAAQ,CACV,CAAC,EACD,WAAYD,EAAI,CACd,QAAS,GAAGC,EAAO,aAAaA,EAAO,WACvC,WAAYA,EAAO,WACrB,CAAC,EACD,eAAgBD,EAAI,CAClB,MAAOC,EAAO,QACd,OAAQ,GAAGA,EAAO,cAAcA,EAAO,YACzC,CAAC,EACD,KA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,EACA1E,EAAA,cAACoB,EAAA,CACC,MAAOsD,EAAM,QACb,iBAAkBlD,EAClB,aAAcC,EACd,WAAYC,EACZ,WAAYC,EACZ,kBAAmBJ,EACrB,CACF,EAEF,OAAAA,GAAqBmD,EAAM,QAAQ,OAC5BmB,EACT,CAAC,EAEF,CAAC9B,GACA,CAACS,EAAcV,EAAWxC,CAAK,GAC/BA,EAAM,OAAS,GACbtB,EAAA,cAACoB,EAAA,CACC,MAAOE,EACP,kBAAmBC,EACnB,iBAAkBC,EAClB,aAAcC,EACd,WAAYC,EACZ,WAAYC,EACd,CAEN,EAIA3B,EAAA,cAAC,MAAAiC,EAAAC,EAAA,GAAQwD,GAAR,CAAmB,UAAWvF,EAAGyB,EAAO,MAAM,GAAG,CAEtD,CACF,CAEJ,CAEA,IAAMgE,GAAuB,IAEzB5F,EAAA,cAACU,EAAS,UAAT,CAAmB,UAAW,IAC7BV,EAAA,cAACU,EAAS,SAAT,CAAkB,cAAe,EAAG,CACvC,EAKJ,SAAS8D,EACPV,EACAxC,EACuC,CACvC,OAAOwC,CACT,CAOO,IAAMgC,GAAe9F,EAAM,WAAWuC,EAAa","sourcesContent":["import React, { useCallback, useState } from 'react';\nimport { cx } from 'emotion';\nimport { useCombobox } from 'downshift';\n\nimport {\n mergeRefs,\n type CommonProps,\n type ExpandProps,\n} from '@contentful/f36-core';\nimport { IconButton } from '@contentful/f36-button';\nimport { TextInput, type TextInputProps } from '@contentful/f36-forms';\nimport { CloseIcon, ChevronDownIcon } from '@contentful/f36-icons';\nimport { Skeleton } from '@contentful/f36-skeleton';\nimport { Popover } from '@contentful/f36-popover';\nimport { Subheading, SectionHeading } from '@contentful/f36-typography';\n\nimport { AutocompleteItems } from './AutocompleteItems';\nimport { getAutocompleteStyles } from './Autocomplete.styles';\n\nexport interface GenericGroupType<ItemType> {\n groupTitle: string;\n options: ItemType[];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface AutocompleteProps<ItemType>\n extends CommonProps,\n Pick<\n TextInputProps,\n | 'isDisabled'\n | 'isInvalid'\n | 'isReadOnly'\n | 'isRequired'\n | 'id'\n | 'defaultValue'\n > {\n /**\n * It’s an array of data to be used as \"options\" by the autocomplete component.\n * This can either be a plain list of items or a list of groups of items.\n */\n items: ItemType[] | GenericGroupType<ItemType>[];\n\n /**\n * Set a custom icon for the text input\n */\n icon?: React.ReactElement;\n\n /**\n * Tells if the item is a object with groups\n */\n isGrouped?: boolean;\n\n /**\n * Function called whenever the input value changes\n */\n onInputValueChange?: (value: string) => void;\n /**\n * This is the function that will be called when the user selects one of the \"options\" in the list.\n * The component will pass the selected \"item\" as an argument to the function..\n */\n onSelectItem: (item: ItemType) => void;\n\n /**\n * Applying the selectedItem property turns autocomplete into a controlled component.\n * Can be used to display e.g. previously selected element. If it is an object the itemToString function will apply to it.\n */\n selectedItem?: ItemType;\n\n /**\n * This is the function that will be called for each \"item\" passed in the `items` prop.\n * It receives the \"item\" and \"inputValue\" as arguments and returns a ReactNode.\n * The inputValue is passed in case you want to highlight the match on the render.\n */\n renderItem?: (item: ItemType, inputValue: string) => React.ReactNode;\n /**\n * When using objects as `items`, we recommend passing a function that tells Downshift how to extract a string\n * from those objetcs to be used as inputValue\n */\n itemToString?: (item: ItemType) => string;\n /**\n * If this is set to `true` the text input will be cleared after an item is selected\n * @default false\n */\n clearAfterSelect?: boolean;\n /**\n * If this is set to `false` the dropdown menu will stay open after selecting an item\n * @default true\n */\n closeAfterSelect?: boolean;\n /**\n * This is the value will be passed to the `placeholder` prop of the input.\n * @default \"Search\"\n */\n placeholder?: string;\n /**\n * Defines if the list should be shown even if empty, when input is focused\n * @default false\n */\n showEmptyList?: boolean;\n /**\n * A message that will be shown when it is not possible to find any option that matches the input value\n * @default \"No matches\"\n */\n noMatchesMessage?: string;\n /**\n * Use this prop to get a ref to the input element of the component\n */\n inputRef?: React.Ref<HTMLInputElement>;\n /**\n * Use this prop to get a ref to the toggle button of the component\n */\n toggleRef?: React.Ref<HTMLButtonElement>;\n /**\n * Use this prop to get a ref to the list of items of the component\n */\n listRef?: React.Ref<HTMLUListElement>;\n /**\n * It sets the width of the list\n * @default \"auto\"\n */\n listWidth?: 'auto' | 'full';\n /**\n * It sets the max-height, in pixels, of the list\n * The default value is the height of 5 single line items\n * @default 180\n */\n listMaxHeight?: number;\n /**\n * Sets the list to show its loading state\n * @default false\n */\n isLoading?: boolean;\n /**\n * Boolean to control whether or not to render the suggestions box in a React Portal.\n * Rendering content inside a Portal allows the suggestions box to escape the bounds\n * of its parent while still being positioned correctly.\n * Defaults to `false`\n */\n usePortal?: boolean;\n}\n\nfunction _Autocomplete<ItemType>(\n props: AutocompleteProps<ItemType>,\n ref: React.Ref<HTMLDivElement>,\n) {\n const {\n id,\n className,\n clearAfterSelect = false,\n closeAfterSelect = true,\n defaultValue = '',\n selectedItem,\n items,\n onInputValueChange,\n onSelectItem,\n renderItem,\n icon = <ChevronDownIcon variant=\"muted\" />,\n itemToString = (item: ItemType) => item as unknown as string,\n isInvalid,\n isDisabled,\n isRequired,\n isReadOnly,\n showEmptyList,\n noMatchesMessage = 'No matches found',\n placeholder = 'Search',\n inputRef,\n toggleRef,\n listRef,\n listWidth = 'auto',\n listMaxHeight = 180,\n isGrouped = false,\n isLoading = false,\n usePortal = false,\n testId = 'cf-autocomplete',\n } = props;\n\n type GroupType = GenericGroupType<ItemType>;\n\n const styles = getAutocompleteStyles(listMaxHeight);\n\n const [inputValue, setInputValue] = useState(defaultValue);\n\n const handleInputValueChange = useCallback(\n (value: string) => {\n setInputValue(value);\n\n onInputValueChange?.(value);\n },\n [onInputValueChange],\n );\n\n // Handle manually to avoid a jumping cursor, see https://github.com/downshift-js/downshift/issues/1108#issuecomment-842407759\n const handleNativeChangeEvent = useCallback(\n (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n const value = event.target.value;\n handleInputValueChange(value);\n },\n [handleInputValueChange],\n );\n\n const flattenItems = isUsingGroups(isGrouped, items)\n ? items.reduce(\n (acc: ItemType[], group: GroupType) => [...acc, ...group.options],\n [],\n )\n : items;\n\n const isShowingNoMatches = isUsingGroups(isGrouped, items)\n ? items.every((group: GroupType) => group.options.length === 0)\n : items.length === 0;\n\n const {\n getComboboxProps,\n getInputProps,\n getItemProps,\n getMenuProps,\n getToggleButtonProps,\n highlightedIndex,\n isOpen,\n toggleMenu,\n } = useCombobox({\n items: flattenItems,\n selectedItem,\n inputValue,\n itemToString,\n onInputValueChange: ({ type, inputValue }) => {\n if (type !== '__input_change__') {\n handleInputValueChange(inputValue);\n }\n },\n onStateChange: ({ type, selectedItem }) => {\n switch (type) {\n case useCombobox.stateChangeTypes.InputKeyDownEnter:\n case useCombobox.stateChangeTypes.ItemClick:\n if (selectedItem) {\n onSelectItem(selectedItem);\n }\n if (clearAfterSelect) {\n handleInputValueChange('');\n }\n if (!closeAfterSelect) {\n toggleMenu();\n }\n break;\n default:\n break;\n }\n },\n });\n\n const {\n 'aria-labelledby': _labelledby,\n id: _inputId,\n ...inputProps\n } = getInputProps();\n const comboboxProps = getComboboxProps();\n const toggleProps = getToggleButtonProps();\n const menuProps = getMenuProps();\n let elementStartIndex = 0;\n\n return (\n <div\n data-test-id={testId}\n className={cx(styles.autocomplete, className)}\n ref={ref}\n >\n <Popover\n usePortal={usePortal}\n isOpen={isOpen}\n isFullWidth={listWidth === 'full'}\n renderOnlyWhenOpen={false}\n // This is necessary, otherwise the focus will change from the input to the Popover\n // and the user won't be able to type in the input\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={false}\n id={menuProps.id}\n >\n <Popover.Trigger>\n <div {...comboboxProps} className={styles.combobox}>\n <TextInput\n className={styles.inputField}\n {...inputProps}\n onFocus={() => {\n if (!isOpen) {\n toggleMenu();\n }\n }}\n id={id}\n isInvalid={isInvalid}\n isDisabled={isDisabled}\n isRequired={isRequired}\n isReadOnly={isReadOnly}\n ref={mergeRefs(inputProps.ref, inputRef)}\n testId=\"cf-autocomplete-input\"\n placeholder={placeholder}\n onChange={(event) => {\n inputProps.onChange(event);\n handleNativeChangeEvent(event);\n }}\n />\n <IconButton\n {...toggleProps}\n ref={mergeRefs(toggleProps.ref, toggleRef)}\n aria-label={inputValue ? 'Clear' : 'Show list'}\n className={styles.toggleButton}\n variant=\"transparent\"\n icon={inputValue ? <CloseIcon variant=\"muted\" /> : icon}\n onClick={() => {\n if (inputValue) {\n handleInputValueChange('');\n } else {\n toggleMenu();\n }\n }}\n isDisabled={isDisabled}\n size=\"small\"\n />\n </div>\n </Popover.Trigger>\n\n {items.length > 0 || inputValue.length > 0 || showEmptyList ? (\n <Popover.Content\n {...menuProps}\n ref={mergeRefs(menuProps.ref, listRef)}\n className={styles.content}\n testId=\"cf-autocomplete-container\"\n >\n {isLoading &&\n [...Array(3)].map((_, index) => (\n <div key={index} className={cx(styles.item, styles.disabled)}>\n <ListItemLoadingState />\n </div>\n ))}\n\n {!isLoading && isShowingNoMatches && (\n <div className={styles.item}>\n <Subheading className={styles.noMatchesTitle}>\n {noMatchesMessage}\n </Subheading>\n </div>\n )}\n\n {!isLoading &&\n isUsingGroups(isGrouped, items) &&\n items.map((group: GroupType, index: number) => {\n if (group.options.length < 1) {\n return;\n }\n const render = (\n <div key={index}>\n <SectionHeading\n key={index}\n data-test-id=\"cf-autocomplete-grouptitle\"\n marginBottom=\"none\"\n className={styles.groupTitle}\n >\n {group.groupTitle}\n </SectionHeading>\n <AutocompleteItems<ItemType>\n items={group.options}\n highlightedIndex={highlightedIndex}\n getItemProps={getItemProps}\n renderItem={renderItem}\n inputValue={inputValue}\n elementStartIndex={elementStartIndex}\n />\n </div>\n );\n elementStartIndex += group.options.length;\n return render;\n })}\n\n {!isLoading &&\n !isUsingGroups(isGrouped, items) &&\n items.length > 0 && (\n <AutocompleteItems<ItemType>\n items={items}\n elementStartIndex={elementStartIndex}\n highlightedIndex={highlightedIndex}\n getItemProps={getItemProps}\n renderItem={renderItem}\n inputValue={inputValue}\n />\n )}\n </Popover.Content>\n ) : (\n // We need to render an empty hidden div, so we can pass the menuProps or downshift will show a warning about it\n // https://github.com/downshift-js/downshift/issues/1167#issuecomment-1088022842\n <div {...menuProps} className={cx(styles.hidden)} />\n )}\n </Popover>\n </div>\n );\n}\n\nconst ListItemLoadingState = () => {\n return (\n <Skeleton.Container svgHeight={16}>\n <Skeleton.BodyText numberOfLines={1} />\n </Skeleton.Container>\n );\n};\n\n// This is required to infer correct typings when differentiating groups and items\nfunction isUsingGroups<ItemType>(\n isGrouped: boolean,\n items: ItemType[] | GenericGroupType<ItemType>[],\n): items is GenericGroupType<ItemType>[] {\n return isGrouped;\n}\n\n/**\n * The Autocomplete is a component that will show a `TextInput` where a user can type any word which will be used\n * to filter a list of items. That list of filtered items will be shown to the user as possible options for the input.\n * Once one of the options is selected, that option becomes the value of the `TextInput`.\n */\nexport const Autocomplete = React.forwardRef(_Autocomplete) as <T>(\n props: ExpandProps<AutocompleteProps<T>> & {\n ref?: React.Ref<HTMLDivElement>;\n },\n) => ReturnType<typeof _Autocomplete>;\n","import React, { HTMLAttributes } from 'react';\nimport { cx } from 'emotion';\nimport { getStringMatch } from '@contentful/f36-utils';\nimport type { UseComboboxGetItemPropsOptions } from 'downshift';\nimport { Text } from '@contentful/f36-typography';\n\nimport { getAutocompleteStyles } from './Autocomplete.styles';\n\ninterface AutocompleteItemsProps<ItemType> {\n items: ItemType[];\n elementStartIndex: number;\n highlightedIndex: number;\n getItemProps: (\n options: UseComboboxGetItemPropsOptions<ItemType>,\n ) => HTMLAttributes<HTMLLIElement>;\n renderItem: (item: ItemType, inputValue: string) => React.ReactNode;\n inputValue: string;\n listMaxHeight?: number;\n}\n\nexport const AutocompleteItems = <ItemType,>(\n props: AutocompleteItemsProps<ItemType>,\n) => {\n const {\n items,\n elementStartIndex,\n highlightedIndex,\n getItemProps,\n renderItem,\n inputValue,\n listMaxHeight = 180,\n } = props;\n\n const styles = getAutocompleteStyles(listMaxHeight);\n\n return (\n <ul className={styles.list} data-test-id=\"cf-autocomplete-list\">\n {items.map((item: ItemType, index: number) => {\n const itemIndex = elementStartIndex + index;\n const itemProps = getItemProps({ item, index: itemIndex });\n return (\n <Text\n {...itemProps}\n as=\"li\"\n key={itemIndex}\n className={cx([\n styles.item,\n highlightedIndex === itemIndex && styles.highlighted,\n ])}\n data-test-id={`cf-autocomplete-list-item-${itemIndex}`}\n >\n {renderItem ? (\n renderItem(item, inputValue)\n ) : typeof item === 'string' ? (\n <HighlightedItem item={item} inputValue={inputValue} />\n ) : (\n item\n )}\n </Text>\n );\n })}\n </ul>\n );\n};\n\nAutocompleteItems.displayName = 'AutocompleteItems';\n\nfunction HighlightedItem({\n item,\n inputValue,\n}: {\n item: string;\n inputValue: string;\n}) {\n const { before, match, after } = getStringMatch(item, inputValue);\n\n return (\n <>\n {before}\n <b>{match}</b>\n {after}\n </>\n );\n}\n\nHighlightedItem.displayName = 'HighlightedItem';\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getAutocompleteStyles = (listMaxHeight: number) => ({\n autocomplete: css({\n position: 'relative',\n width: '100%',\n }),\n combobox: css({\n position: 'relative',\n }),\n inputField: css({\n paddingRight: tokens.spacingXl,\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n }),\n toggleButton: css({\n position: 'absolute',\n top: '1px',\n right: '1px',\n zIndex: 1,\n padding: tokens.spacing2Xs,\n height: '38px',\n }),\n content: css({\n overflow: 'auto',\n maxHeight: `${listMaxHeight}px`,\n }),\n list: css({\n listStyle: 'none',\n padding: `${tokens.spacingXs} 0`,\n margin: 0,\n }),\n groupTitle: css({\n padding: `${tokens.spacingXs} ${tokens.spacingM}`,\n lineHeight: tokens.lineHeightM,\n }),\n noMatchesTitle: css({\n color: tokens.gray500,\n margin: `${tokens.spacingM} 0 ${tokens.spacingM} 0`,\n }),\n item: css({\n display: 'block',\n padding: `${tokens.spacingXs} ${tokens.spacingM}`,\n wordBreak: 'break-word',\n whiteSpace: 'break-spaces',\n cursor: 'pointer',\n hyphens: 'auto',\n\n '&:focus, &:hover': {\n backgroundColor: tokens.gray100,\n },\n '&:active': {\n backgroundColor: tokens.gray200,\n },\n }),\n disabled: css({\n opacity: 0.5,\n pointerEvents: 'none',\n }),\n highlighted: css({\n backgroundColor: tokens.gray100,\n }),\n hidden: css({\n display: 'none',\n }),\n});\n"]}
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@contentful/f36-autocomplete",
3
- "version": "4.20.7",
3
+ "version": "4.20.8",
4
4
  "description": "Forma 36: Autocomplete component",
5
5
  "scripts": {
6
6
  "build": "tsup"
7
7
  },
8
8
  "dependencies": {
9
- "@contentful/f36-button": "^4.20.7",
10
- "@contentful/f36-core": "^4.20.7",
11
- "@contentful/f36-forms": "^4.20.7",
12
- "@contentful/f36-icons": "^4.20.7",
13
- "@contentful/f36-popover": "^4.20.7",
14
- "@contentful/f36-skeleton": "^4.20.7",
9
+ "@contentful/f36-button": "^4.20.8",
10
+ "@contentful/f36-core": "^4.20.8",
11
+ "@contentful/f36-forms": "^4.20.8",
12
+ "@contentful/f36-icons": "^4.20.8",
13
+ "@contentful/f36-popover": "^4.20.8",
14
+ "@contentful/f36-skeleton": "^4.20.8",
15
15
  "@contentful/f36-tokens": "^4.0.1",
16
- "@contentful/f36-typography": "^4.20.7",
17
- "@contentful/f36-utils": "^4.20.7",
18
- "downshift": "^6.1.7",
16
+ "@contentful/f36-typography": "^4.20.8",
17
+ "@contentful/f36-utils": "^4.20.8",
18
+ "downshift": "^6.1.12",
19
19
  "emotion": "^10.0.17"
20
20
  },
21
21
  "peerDependencies": {
package/CHANGELOG.md DELETED
@@ -1,711 +0,0 @@
1
- # Change Log
2
-
3
- ## 4.20.7
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [[`b7fff9c22`](https://github.com/contentful/forma-36/commit/b7fff9c22430713e6971d9c66e29b95226d7aa7a)]:
8
- - @contentful/f36-forms@4.20.7
9
- - @contentful/f36-button@4.20.7
10
- - @contentful/f36-icons@4.20.7
11
- - @contentful/f36-popover@4.20.7
12
- - @contentful/f36-skeleton@4.20.7
13
- - @contentful/f36-typography@4.20.7
14
- - @contentful/f36-utils@4.20.7
15
- - @contentful/f36-core@4.20.7
16
-
17
- ## 4.20.6
18
-
19
- ### Patch Changes
20
-
21
- - Updated dependencies [[`05bdd10f`](https://github.com/contentful/forma-36/commit/05bdd10f5ea6fae41cacb0f4fd3db0bdd65422e9)]:
22
- - @contentful/f36-icons@4.20.6
23
- - @contentful/f36-button@4.20.6
24
- - @contentful/f36-forms@4.20.6
25
- - @contentful/f36-popover@4.20.6
26
- - @contentful/f36-skeleton@4.20.6
27
- - @contentful/f36-typography@4.20.6
28
- - @contentful/f36-utils@4.20.6
29
- - @contentful/f36-core@4.20.6
30
-
31
- ## 4.20.5
32
-
33
- ### Patch Changes
34
-
35
- - Updated dependencies []:
36
- - @contentful/f36-button@4.20.5
37
- - @contentful/f36-forms@4.20.5
38
- - @contentful/f36-icons@4.20.5
39
- - @contentful/f36-popover@4.20.5
40
- - @contentful/f36-skeleton@4.20.5
41
- - @contentful/f36-typography@4.20.5
42
- - @contentful/f36-utils@4.20.5
43
- - @contentful/f36-core@4.20.5
44
-
45
- ## 4.20.4
46
-
47
- ### Patch Changes
48
-
49
- - Updated dependencies []:
50
- - @contentful/f36-button@4.20.4
51
- - @contentful/f36-forms@4.20.4
52
- - @contentful/f36-icons@4.20.4
53
- - @contentful/f36-popover@4.20.4
54
- - @contentful/f36-skeleton@4.20.4
55
- - @contentful/f36-typography@4.20.4
56
- - @contentful/f36-utils@4.20.4
57
- - @contentful/f36-core@4.20.4
58
-
59
- ## 4.20.3
60
-
61
- ### Patch Changes
62
-
63
- - Updated dependencies [[`d3c27ab8`](https://github.com/contentful/forma-36/commit/d3c27ab830ec9c2cc096e8be33da496c2dc284ea)]:
64
- - @contentful/f36-core@4.20.3
65
- - @contentful/f36-button@4.20.3
66
- - @contentful/f36-forms@4.20.3
67
- - @contentful/f36-icons@4.20.3
68
- - @contentful/f36-popover@4.20.3
69
- - @contentful/f36-skeleton@4.20.3
70
- - @contentful/f36-typography@4.20.3
71
- - @contentful/f36-utils@4.20.3
72
-
73
- ## 4.20.2
74
-
75
- ### Patch Changes
76
-
77
- - Updated dependencies []:
78
- - @contentful/f36-button@4.20.2
79
- - @contentful/f36-forms@4.20.2
80
- - @contentful/f36-icons@4.20.2
81
- - @contentful/f36-popover@4.20.2
82
- - @contentful/f36-skeleton@4.20.2
83
- - @contentful/f36-typography@4.20.2
84
- - @contentful/f36-utils@4.20.2
85
- - @contentful/f36-core@4.20.2
86
-
87
- ## 4.20.1
88
-
89
- ### Patch Changes
90
-
91
- - Updated dependencies []:
92
- - @contentful/f36-button@4.20.1
93
- - @contentful/f36-forms@4.20.1
94
- - @contentful/f36-icons@4.20.1
95
- - @contentful/f36-popover@4.20.1
96
- - @contentful/f36-skeleton@4.20.1
97
- - @contentful/f36-typography@4.20.1
98
- - @contentful/f36-utils@4.20.1
99
- - @contentful/f36-core@4.20.1
100
-
101
- ## 4.20.0
102
-
103
- ### Patch Changes
104
-
105
- - Updated dependencies []:
106
- - @contentful/f36-button@4.20.0
107
- - @contentful/f36-forms@4.20.0
108
- - @contentful/f36-icons@4.20.0
109
- - @contentful/f36-popover@4.20.0
110
- - @contentful/f36-skeleton@4.20.0
111
- - @contentful/f36-typography@4.20.0
112
- - @contentful/f36-utils@4.20.0
113
- - @contentful/f36-core@4.20.0
114
-
115
- ## 4.19.2
116
-
117
- ### Patch Changes
118
-
119
- - Updated dependencies [[`9647d295`](https://github.com/contentful/forma-36/commit/9647d295763c6518fe6d381d79a53524ac104d92)]:
120
- - @contentful/f36-typography@4.19.2
121
- - @contentful/f36-button@4.19.2
122
- - @contentful/f36-forms@4.19.2
123
- - @contentful/f36-icons@4.19.2
124
- - @contentful/f36-popover@4.19.2
125
- - @contentful/f36-skeleton@4.19.2
126
- - @contentful/f36-utils@4.19.2
127
- - @contentful/f36-core@4.19.2
128
-
129
- ## 4.19.1
130
-
131
- ### Patch Changes
132
-
133
- - [#2209](https://github.com/contentful/forma-36/pull/2209) [`42f0c321`](https://github.com/contentful/forma-36/commit/42f0c3218965137191842f492fe5dbf4bd10784c) Thanks [@denkristoffer](https://github.com/denkristoffer)! - build: build ESM to JS file - legacy output
134
- fix(notification): use type imports
135
- - Updated dependencies [[`42f0c321`](https://github.com/contentful/forma-36/commit/42f0c3218965137191842f492fe5dbf4bd10784c)]:
136
- - @contentful/f36-button@4.19.1
137
- - @contentful/f36-forms@4.19.1
138
- - @contentful/f36-icons@4.19.1
139
- - @contentful/f36-popover@4.19.1
140
- - @contentful/f36-skeleton@4.19.1
141
- - @contentful/f36-typography@4.19.1
142
- - @contentful/f36-utils@4.19.1
143
- - @contentful/f36-core@4.19.1
144
-
145
- ## 4.19.0
146
-
147
- ### Patch Changes
148
-
149
- - Updated dependencies []:
150
- - @contentful/f36-button@4.19.0
151
- - @contentful/f36-forms@4.19.0
152
- - @contentful/f36-icons@4.19.0
153
- - @contentful/f36-popover@4.19.0
154
- - @contentful/f36-skeleton@4.19.0
155
- - @contentful/f36-typography@4.19.0
156
- - @contentful/f36-utils@4.19.0
157
- - @contentful/f36-core@4.19.0
158
-
159
- ## 4.18.0
160
-
161
- ### Patch Changes
162
-
163
- - Updated dependencies []:
164
- - @contentful/f36-button@4.18.0
165
- - @contentful/f36-forms@4.18.0
166
- - @contentful/f36-icons@4.18.0
167
- - @contentful/f36-popover@4.18.0
168
- - @contentful/f36-skeleton@4.18.0
169
- - @contentful/f36-typography@4.18.0
170
- - @contentful/f36-utils@4.18.0
171
- - @contentful/f36-core@4.18.0
172
-
173
- ## 4.17.0
174
-
175
- ### Patch Changes
176
-
177
- - Updated dependencies [[`71baf762`](https://github.com/contentful/forma-36/commit/71baf762bc3635730f496dab4113975984878736)]:
178
- - @contentful/f36-skeleton@4.17.0
179
- - @contentful/f36-button@4.17.0
180
- - @contentful/f36-forms@4.17.0
181
- - @contentful/f36-icons@4.17.0
182
- - @contentful/f36-popover@4.17.0
183
- - @contentful/f36-typography@4.17.0
184
- - @contentful/f36-utils@4.17.0
185
- - @contentful/f36-core@4.17.0
186
-
187
- ## 4.16.0
188
-
189
- ### Patch Changes
190
-
191
- - Updated dependencies []:
192
- - @contentful/f36-button@4.16.0
193
- - @contentful/f36-forms@4.16.0
194
- - @contentful/f36-icons@4.16.0
195
- - @contentful/f36-popover@4.16.0
196
- - @contentful/f36-skeleton@4.16.0
197
- - @contentful/f36-typography@4.16.0
198
- - @contentful/f36-utils@4.16.0
199
- - @contentful/f36-core@4.16.0
200
-
201
- ## 4.15.1
202
-
203
- ### Patch Changes
204
-
205
- - [#2165](https://github.com/contentful/forma-36/pull/2165) [`5582f33c`](https://github.com/contentful/forma-36/commit/5582f33c0674850a30cc2a1792aad72fa219f7de) Thanks [@loweisz](https://github.com/loweisz)! - fix(autocomplete): hide list component when when items and search value are empty
206
-
207
- - Updated dependencies []:
208
- - @contentful/f36-button@4.15.1
209
- - @contentful/f36-forms@4.15.1
210
- - @contentful/f36-icons@4.15.1
211
- - @contentful/f36-popover@4.15.1
212
- - @contentful/f36-skeleton@4.15.1
213
- - @contentful/f36-typography@4.15.1
214
- - @contentful/f36-utils@4.15.1
215
- - @contentful/f36-core@4.15.1
216
-
217
- ## 4.15.0
218
-
219
- ### Patch Changes
220
-
221
- - Updated dependencies []:
222
- - @contentful/f36-button@4.15.0
223
- - @contentful/f36-forms@4.15.0
224
- - @contentful/f36-icons@4.15.0
225
- - @contentful/f36-popover@4.15.0
226
- - @contentful/f36-skeleton@4.15.0
227
- - @contentful/f36-typography@4.15.0
228
- - @contentful/f36-utils@4.15.0
229
- - @contentful/f36-core@4.15.0
230
-
231
- ## 4.14.0
232
-
233
- ### Patch Changes
234
-
235
- - Updated dependencies []:
236
- - @contentful/f36-button@4.14.0
237
- - @contentful/f36-forms@4.14.0
238
- - @contentful/f36-icons@4.14.0
239
- - @contentful/f36-popover@4.14.0
240
- - @contentful/f36-skeleton@4.14.0
241
- - @contentful/f36-typography@4.14.0
242
- - @contentful/f36-utils@4.14.0
243
- - @contentful/f36-core@4.14.0
244
-
245
- ## 4.13.0
246
-
247
- ### Patch Changes
248
-
249
- - Updated dependencies []:
250
- - @contentful/f36-button@4.13.0
251
- - @contentful/f36-forms@4.13.0
252
- - @contentful/f36-icons@4.13.0
253
- - @contentful/f36-popover@4.13.0
254
- - @contentful/f36-skeleton@4.13.0
255
- - @contentful/f36-typography@4.13.0
256
- - @contentful/f36-utils@4.13.0
257
- - @contentful/f36-core@4.13.0
258
-
259
- ## 4.12.0
260
-
261
- ### Patch Changes
262
-
263
- - Updated dependencies []:
264
- - @contentful/f36-button@4.12.0
265
- - @contentful/f36-forms@4.12.0
266
- - @contentful/f36-icons@4.12.0
267
- - @contentful/f36-popover@4.12.0
268
- - @contentful/f36-skeleton@4.12.0
269
- - @contentful/f36-typography@4.12.0
270
- - @contentful/f36-utils@4.12.0
271
- - @contentful/f36-core@4.12.0
272
-
273
- ## 4.11.0
274
-
275
- ### Minor Changes
276
-
277
- - [#2116](https://github.com/contentful/forma-36/pull/2116) [`7efcc111`](https://github.com/contentful/forma-36/commit/7efcc111878fd22085f9717dc4d708b721fc20f3) Thanks [@mshaaban0](https://github.com/mshaaban0)! - feat: allow passing custom icons to autocomplete
278
-
279
- ### Patch Changes
280
-
281
- - Updated dependencies []:
282
- - @contentful/f36-button@4.11.0
283
- - @contentful/f36-forms@4.11.0
284
- - @contentful/f36-icons@4.11.0
285
- - @contentful/f36-popover@4.11.0
286
- - @contentful/f36-skeleton@4.11.0
287
- - @contentful/f36-typography@4.11.0
288
- - @contentful/f36-utils@4.11.0
289
- - @contentful/f36-core@4.11.0
290
-
291
- ## 4.11.0-beta.0
292
-
293
- ### Minor Changes
294
-
295
- - [#2116](https://github.com/contentful/forma-36/pull/2116) [`7efcc111`](https://github.com/contentful/forma-36/commit/7efcc111878fd22085f9717dc4d708b721fc20f3) Thanks [@mshaaban0](https://github.com/mshaaban0)! - feat: allow passing custom icons to autocomplete
296
-
297
- ### Patch Changes
298
-
299
- - Updated dependencies []:
300
- - @contentful/f36-button@4.11.0-beta.0
301
- - @contentful/f36-forms@4.11.0-beta.0
302
- - @contentful/f36-icons@4.11.0-beta.0
303
- - @contentful/f36-popover@4.11.0-beta.0
304
- - @contentful/f36-skeleton@4.11.0-beta.0
305
- - @contentful/f36-typography@4.11.0-beta.0
306
- - @contentful/f36-utils@4.11.0-beta.0
307
- - @contentful/f36-core@4.11.0-beta.0
308
-
309
- ## 4.10.5
310
-
311
- ### Patch Changes
312
-
313
- - Updated dependencies [[`32cac8e8`](https://github.com/contentful/forma-36/commit/32cac8e8bdeedfe29b36bc6025eec11607c93da8)]:
314
- - @contentful/f36-icons@4.10.5
315
- - @contentful/f36-popover@4.10.5
316
- - @contentful/f36-button@4.10.5
317
- - @contentful/f36-forms@4.10.5
318
- - @contentful/f36-skeleton@4.10.5
319
- - @contentful/f36-typography@4.10.5
320
- - @contentful/f36-utils@4.10.5
321
- - @contentful/f36-core@4.10.5
322
-
323
- ## 4.10.4
324
-
325
- ### Patch Changes
326
-
327
- - [#2093](https://github.com/contentful/forma-36/pull/2093) [`52cce145`](https://github.com/contentful/forma-36/commit/52cce145fa2d7d2a4d9a7ff9591beca862317799) Thanks [@Lelith](https://github.com/Lelith)! - Enable controlling the dropdown menu open and close state after select with new property "closeAfterSelect"
328
-
329
- - Updated dependencies []:
330
- - @contentful/f36-button@4.10.4
331
- - @contentful/f36-forms@4.10.4
332
- - @contentful/f36-icons@4.10.4
333
- - @contentful/f36-popover@4.10.4
334
- - @contentful/f36-skeleton@4.10.4
335
- - @contentful/f36-typography@4.10.4
336
- - @contentful/f36-utils@4.10.4
337
- - @contentful/f36-core@4.10.4
338
-
339
- ## 4.10.3
340
-
341
- ### Patch Changes
342
-
343
- - Updated dependencies [[`1bc834c6`](https://github.com/contentful/forma-36/commit/1bc834c65097e5b253b7bc69a96a16121b4e7cc4)]:
344
- - @contentful/f36-popover@4.10.3
345
- - @contentful/f36-button@4.10.3
346
- - @contentful/f36-forms@4.10.3
347
- - @contentful/f36-icons@4.10.3
348
- - @contentful/f36-skeleton@4.10.3
349
- - @contentful/f36-typography@4.10.3
350
- - @contentful/f36-utils@4.10.3
351
- - @contentful/f36-core@4.10.3
352
-
353
- ## 4.10.2
354
-
355
- ### Patch Changes
356
-
357
- - Updated dependencies []:
358
- - @contentful/f36-button@4.10.2
359
- - @contentful/f36-forms@4.10.2
360
- - @contentful/f36-icons@4.10.2
361
- - @contentful/f36-popover@4.10.2
362
- - @contentful/f36-skeleton@4.10.2
363
- - @contentful/f36-typography@4.10.2
364
- - @contentful/f36-utils@4.10.2
365
- - @contentful/f36-core@4.10.2
366
-
367
- ## 4.10.1
368
-
369
- ### Patch Changes
370
-
371
- - Updated dependencies []:
372
- - @contentful/f36-button@4.10.1
373
- - @contentful/f36-forms@4.10.1
374
- - @contentful/f36-icons@4.10.1
375
- - @contentful/f36-popover@4.10.1
376
- - @contentful/f36-skeleton@4.10.1
377
- - @contentful/f36-typography@4.10.1
378
- - @contentful/f36-utils@4.10.1
379
- - @contentful/f36-core@4.10.1
380
-
381
- ## 4.10.0
382
-
383
- ### Patch Changes
384
-
385
- - Updated dependencies [[`20d73e7c`](https://github.com/contentful/forma-36/commit/20d73e7c8247ee789fdfde58882682808bf761ae)]:
386
- - @contentful/f36-button@4.10.0
387
- - @contentful/f36-forms@4.10.0
388
- - @contentful/f36-icons@4.10.0
389
- - @contentful/f36-popover@4.10.0
390
- - @contentful/f36-skeleton@4.10.0
391
- - @contentful/f36-typography@4.10.0
392
- - @contentful/f36-utils@4.10.0
393
- - @contentful/f36-core@4.10.0
394
-
395
- ## 4.9.0
396
-
397
- ### Minor Changes
398
-
399
- - [#2055](https://github.com/contentful/forma-36/pull/2055) [`910dafc9`](https://github.com/contentful/forma-36/commit/910dafc9ba4a1acc9133d2ee89e7a1fad879e932) Thanks [@Lelith](https://github.com/Lelith)! - Enable Autocomplete as a controlled input by using selectedItem property
400
-
401
- ### Patch Changes
402
-
403
- - Updated dependencies []:
404
- - @contentful/f36-button@4.9.0
405
- - @contentful/f36-forms@4.9.0
406
- - @contentful/f36-icons@4.9.0
407
- - @contentful/f36-popover@4.9.0
408
- - @contentful/f36-skeleton@4.9.0
409
- - @contentful/f36-typography@4.9.0
410
- - @contentful/f36-utils@4.9.0
411
- - @contentful/f36-core@4.9.0
412
-
413
- ## 4.8.2
414
-
415
- ### Patch Changes
416
-
417
- - Updated dependencies []:
418
- - @contentful/f36-button@4.8.2
419
- - @contentful/f36-forms@4.8.2
420
- - @contentful/f36-icons@4.8.2
421
- - @contentful/f36-popover@4.8.2
422
- - @contentful/f36-skeleton@4.8.2
423
- - @contentful/f36-typography@4.8.2
424
- - @contentful/f36-utils@4.8.2
425
- - @contentful/f36-core@4.8.2
426
-
427
- ## 4.8.1
428
-
429
- ### Patch Changes
430
-
431
- - Updated dependencies [[`7afca5e6`](https://github.com/contentful/forma-36/commit/7afca5e6f9d89b1f187fc48ab8e8fd39366f110b)]:
432
- - @contentful/f36-typography@4.8.1
433
- - @contentful/f36-button@4.8.1
434
- - @contentful/f36-forms@4.8.1
435
- - @contentful/f36-icons@4.8.1
436
- - @contentful/f36-popover@4.8.1
437
- - @contentful/f36-skeleton@4.8.1
438
- - @contentful/f36-utils@4.8.1
439
- - @contentful/f36-core@4.8.1
440
-
441
- ## 4.8.0
442
-
443
- ### Patch Changes
444
-
445
- - [#2008](https://github.com/contentful/forma-36/pull/2008) [`1a941fd9`](https://github.com/contentful/forma-36/commit/1a941fd99757e49bb30e0e32eab19bc680f66597) Thanks [@massao](https://github.com/massao)! - Fix issue with types being generated wrongly
446
-
447
- - Updated dependencies [[`1a941fd9`](https://github.com/contentful/forma-36/commit/1a941fd99757e49bb30e0e32eab19bc680f66597)]:
448
- - @contentful/f36-skeleton@4.8.0
449
- - @contentful/f36-button@4.8.0
450
- - @contentful/f36-forms@4.8.0
451
- - @contentful/f36-icons@4.8.0
452
- - @contentful/f36-popover@4.8.0
453
- - @contentful/f36-typography@4.8.0
454
- - @contentful/f36-utils@4.8.0
455
- - @contentful/f36-core@4.8.0
456
-
457
- ## 4.7.0
458
-
459
- ### Patch Changes
460
-
461
- - Updated dependencies [[`e50b8945`](https://github.com/contentful/forma-36/commit/e50b8945faef7323187e1bd9a2a9cbfcbae2e405)]:
462
- - @contentful/f36-core@4.7.0
463
- - @contentful/f36-button@4.7.0
464
- - @contentful/f36-forms@4.7.0
465
- - @contentful/f36-icons@4.7.0
466
- - @contentful/f36-popover@4.7.0
467
- - @contentful/f36-skeleton@4.7.0
468
- - @contentful/f36-typography@4.7.0
469
- - @contentful/f36-utils@4.7.0
470
-
471
- ## 4.6.2
472
-
473
- ### Patch Changes
474
-
475
- - Updated dependencies []:
476
- - @contentful/f36-button@4.6.2
477
- - @contentful/f36-forms@4.6.2
478
- - @contentful/f36-icons@4.6.2
479
- - @contentful/f36-popover@4.6.2
480
- - @contentful/f36-skeleton@4.6.2
481
- - @contentful/f36-typography@4.6.2
482
- - @contentful/f36-utils@4.6.2
483
- - @contentful/f36-core@4.6.2
484
-
485
- ## 4.6.1
486
-
487
- ### Patch Changes
488
-
489
- - Updated dependencies []:
490
- - @contentful/f36-button@4.6.1
491
- - @contentful/f36-forms@4.6.1
492
- - @contentful/f36-icons@4.6.1
493
- - @contentful/f36-popover@4.6.1
494
- - @contentful/f36-skeleton@4.6.1
495
- - @contentful/f36-typography@4.6.1
496
- - @contentful/f36-utils@4.6.1
497
- - @contentful/f36-core@4.6.1
498
-
499
- ## 4.6.0
500
-
501
- ### Patch Changes
502
-
503
- - Updated dependencies []:
504
- - @contentful/f36-button@4.6.0
505
- - @contentful/f36-forms@4.6.0
506
- - @contentful/f36-icons@4.6.0
507
- - @contentful/f36-popover@4.6.0
508
- - @contentful/f36-skeleton@4.6.0
509
- - @contentful/f36-typography@4.6.0
510
- - @contentful/f36-utils@4.6.0
511
- - @contentful/f36-core@4.6.0
512
-
513
- ## 4.5.0
514
-
515
- ### Patch Changes
516
-
517
- - Updated dependencies [[`d841d7cb`](https://github.com/contentful/forma-36/commit/d841d7cbf74b20192028591197bc42df3d2ebc2e)]:
518
- - @contentful/f36-utils@4.5.0
519
- - @contentful/f36-button@4.5.0
520
- - @contentful/f36-forms@4.5.0
521
- - @contentful/f36-icons@4.5.0
522
- - @contentful/f36-popover@4.5.0
523
- - @contentful/f36-skeleton@4.5.0
524
- - @contentful/f36-typography@4.5.0
525
- - @contentful/f36-core@4.5.0
526
-
527
- ## 4.4.1
528
-
529
- ### Patch Changes
530
-
531
- - Updated dependencies []:
532
- - @contentful/f36-button@4.4.1
533
- - @contentful/f36-forms@4.4.1
534
- - @contentful/f36-icons@4.4.1
535
- - @contentful/f36-popover@4.4.1
536
- - @contentful/f36-skeleton@4.4.1
537
- - @contentful/f36-typography@4.4.1
538
- - @contentful/f36-utils@4.4.1
539
- - @contentful/f36-core@4.4.1
540
-
541
- ## 4.4.0
542
-
543
- ### Patch Changes
544
-
545
- - Updated dependencies [[`a9459709`](https://github.com/contentful/forma-36/commit/a945970959bc7e9478bec822bb775a513c6aa0fe)]:
546
- - @contentful/f36-core@4.4.0
547
- - @contentful/f36-button@4.4.0
548
- - @contentful/f36-forms@4.4.0
549
- - @contentful/f36-icons@4.4.0
550
- - @contentful/f36-popover@4.4.0
551
- - @contentful/f36-skeleton@4.4.0
552
- - @contentful/f36-typography@4.4.0
553
- - @contentful/f36-utils@4.4.0
554
-
555
- ## 4.3.11
556
-
557
- ### Patch Changes
558
-
559
- - Updated dependencies [[`edd15d01`](https://github.com/contentful/forma-36/commit/edd15d016be65430e4a1ceb6c617a7b8bdb98585)]:
560
- - @contentful/f36-forms@4.3.11
561
- - @contentful/f36-button@4.3.11
562
- - @contentful/f36-icons@4.3.11
563
- - @contentful/f36-popover@4.3.11
564
- - @contentful/f36-skeleton@4.3.11
565
- - @contentful/f36-typography@4.3.11
566
- - @contentful/f36-utils@4.3.11
567
- - @contentful/f36-core@4.3.11
568
-
569
- ## 4.3.10
570
-
571
- ### Patch Changes
572
-
573
- - [#1969](https://github.com/contentful/forma-36/pull/1969) [`0c5a4b60`](https://github.com/contentful/forma-36/commit/0c5a4b60f8df76e1f75d98b7ea28dd0fd6307fc3) Thanks [@denkristoffer](https://github.com/denkristoffer)! - don't put cursor to the end on every change event
574
-
575
- - Updated dependencies [[`0c5a4b60`](https://github.com/contentful/forma-36/commit/0c5a4b60f8df76e1f75d98b7ea28dd0fd6307fc3)]:
576
- - @contentful/f36-forms@4.3.10
577
- - @contentful/f36-button@4.3.10
578
- - @contentful/f36-icons@4.3.10
579
- - @contentful/f36-popover@4.3.10
580
- - @contentful/f36-skeleton@4.3.10
581
- - @contentful/f36-typography@4.3.10
582
- - @contentful/f36-utils@4.3.10
583
- - @contentful/f36-core@4.3.10
584
-
585
- ## 4.3.9
586
-
587
- ### Patch Changes
588
-
589
- - [#1953](https://github.com/contentful/forma-36/pull/1953) [`df985087`](https://github.com/contentful/forma-36/commit/df98508780f63754e29df09d4f6239bdc84982a8) Thanks [@massao](https://github.com/massao)! - bump packages versions to have consistent versioning
590
-
591
- - Updated dependencies [[`df985087`](https://github.com/contentful/forma-36/commit/df98508780f63754e29df09d4f6239bdc84982a8)]:
592
- - @contentful/f36-button@4.3.9
593
- - @contentful/f36-forms@4.3.9
594
- - @contentful/f36-icons@4.3.9
595
- - @contentful/f36-popover@4.3.9
596
- - @contentful/f36-skeleton@4.3.9
597
- - @contentful/f36-typography@4.3.9
598
- - @contentful/f36-core@4.3.9
599
- - @contentful/f36-utils@4.3.9
600
-
601
- ## [4.2.11](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.10...@contentful/f36-autocomplete@4.2.11) (2022-03-14)
602
-
603
- **Note:** Version bump only for package @contentful/f36-autocomplete
604
-
605
- ## [4.2.10](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.9...@contentful/f36-autocomplete@4.2.10) (2022-03-10)
606
-
607
- **Note:** Version bump only for package @contentful/f36-autocomplete
608
-
609
- ## [4.2.9](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.8...@contentful/f36-autocomplete@4.2.9) (2022-03-09)
610
-
611
- **Note:** Version bump only for package @contentful/f36-autocomplete
612
-
613
- ## [4.2.8](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.7...@contentful/f36-autocomplete@4.2.8) (2022-03-09)
614
-
615
- **Note:** Version bump only for package @contentful/f36-autocomplete
616
-
617
- ## [4.2.7](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.6...@contentful/f36-autocomplete@4.2.7) (2022-03-03)
618
-
619
- ### Bug Fixes
620
-
621
- - migrate links from master to main ([#1923](https://github.com/contentful/forma-36/issues/1923)) ([607301d](https://github.com/contentful/forma-36/commit/607301d57a2e83190d2aa298120ddb8493e8c429))
622
-
623
- ## [4.2.6](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.5...@contentful/f36-autocomplete@4.2.6) (2022-03-02)
624
-
625
- **Note:** Version bump only for package @contentful/f36-autocomplete
626
-
627
- ## [4.2.5](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.4...@contentful/f36-autocomplete@4.2.5) (2022-03-01)
628
-
629
- ### Bug Fixes
630
-
631
- - autocomplete method documentation ([#1914](https://github.com/contentful/forma-36/issues/1914)) ([0596bd7](https://github.com/contentful/forma-36/commit/0596bd7e86398f4a15cac7e8e5a5943ca6c61fe0))
632
-
633
- ## [4.2.4](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.3...@contentful/f36-autocomplete@4.2.4) (2022-02-22)
634
-
635
- **Note:** Version bump only for package @contentful/f36-autocomplete
636
-
637
- ## [4.2.3](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.2...@contentful/f36-autocomplete@4.2.3) (2022-02-22)
638
-
639
- **Note:** Version bump only for package @contentful/f36-autocomplete
640
-
641
- ## [4.2.2](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.1...@contentful/f36-autocomplete@4.2.2) (2022-02-17)
642
-
643
- **Note:** Version bump only for package @contentful/f36-autocomplete
644
-
645
- ## [4.2.1](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.2.0...@contentful/f36-autocomplete@4.2.1) (2022-02-09)
646
-
647
- **Note:** Version bump only for package @contentful/f36-autocomplete
648
-
649
- # [4.2.0](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.11...@contentful/f36-autocomplete@4.2.0) (2022-02-09)
650
-
651
- ### Features
652
-
653
- - by default render Popover only when it's open ([#1873](https://github.com/contentful/forma-36/issues/1873)) ([48a511b](https://github.com/contentful/forma-36/commit/48a511bc48c17d3e4bf0cbfb8d16da8c3cbc29b2))
654
-
655
- ## [4.1.11](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.10...@contentful/f36-autocomplete@4.1.11) (2022-02-07)
656
-
657
- **Note:** Version bump only for package @contentful/f36-autocomplete
658
-
659
- ## [4.1.10](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.9...@contentful/f36-autocomplete@4.1.10) (2022-02-07)
660
-
661
- **Note:** Version bump only for package @contentful/f36-autocomplete
662
-
663
- ## [4.1.9](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.8...@contentful/f36-autocomplete@4.1.9) (2022-02-07)
664
-
665
- **Note:** Version bump only for package @contentful/f36-autocomplete
666
-
667
- ## [4.1.8](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.7...@contentful/f36-autocomplete@4.1.8) (2022-02-02)
668
-
669
- **Note:** Version bump only for package @contentful/f36-autocomplete
670
-
671
- ## [4.1.7](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.6...@contentful/f36-autocomplete@4.1.7) (2022-01-31)
672
-
673
- **Note:** Version bump only for package @contentful/f36-autocomplete
674
-
675
- ## [4.1.6](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.5...@contentful/f36-autocomplete@4.1.6) (2022-01-31)
676
-
677
- **Note:** Version bump only for package @contentful/f36-autocomplete
678
-
679
- ## [4.1.5](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.4...@contentful/f36-autocomplete@4.1.5) (2022-01-28)
680
-
681
- **Note:** Version bump only for package @contentful/f36-autocomplete
682
-
683
- ## [4.1.4](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.3...@contentful/f36-autocomplete@4.1.4) (2022-01-26)
684
-
685
- **Note:** Version bump only for package @contentful/f36-autocomplete
686
-
687
- ## [4.1.3](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.2...@contentful/f36-autocomplete@4.1.3) (2022-01-25)
688
-
689
- **Note:** Version bump only for package @contentful/f36-autocomplete
690
-
691
- ## [4.1.2](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.1...@contentful/f36-autocomplete@4.1.2) (2022-01-19)
692
-
693
- **Note:** Version bump only for package @contentful/f36-autocomplete
694
-
695
- ## [4.1.1](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.1.0...@contentful/f36-autocomplete@4.1.1) (2022-01-19)
696
-
697
- **Note:** Version bump only for package @contentful/f36-autocomplete
698
-
699
- # [4.1.0](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.0.2...@contentful/f36-autocomplete@4.1.0) (2022-01-13)
700
-
701
- ### Features
702
-
703
- - implement props list redesign [BAU-535](<[#1756](https://github.com/contentful/forma-36/issues/1756)>) ([21c57e7](https://github.com/contentful/forma-36/commit/21c57e72008b75990d03af4e7500edc1c7f3d26d))
704
-
705
- ## [4.0.2](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.0.1...@contentful/f36-autocomplete@4.0.2) (2022-01-12)
706
-
707
- **Note:** Version bump only for package @contentful/f36-autocomplete
708
-
709
- ## [4.0.1](https://github.com/contentful/forma-36/compare/@contentful/f36-autocomplete@4.0.0...@contentful/f36-autocomplete@4.0.1) (2022-01-11)
710
-
711
- **Note:** Version bump only for package @contentful/f36-autocomplete