@contentful/f36-autocomplete 4.15.1 → 4.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,47 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.18.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @contentful/f36-button@4.18.0
9
+ - @contentful/f36-forms@4.18.0
10
+ - @contentful/f36-icons@4.18.0
11
+ - @contentful/f36-popover@4.18.0
12
+ - @contentful/f36-skeleton@4.18.0
13
+ - @contentful/f36-typography@4.18.0
14
+ - @contentful/f36-utils@4.18.0
15
+ - @contentful/f36-core@4.18.0
16
+
17
+ ## 4.17.0
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [[`71baf762`](https://github.com/contentful/forma-36/commit/71baf762bc3635730f496dab4113975984878736)]:
22
+ - @contentful/f36-skeleton@4.17.0
23
+ - @contentful/f36-button@4.17.0
24
+ - @contentful/f36-forms@4.17.0
25
+ - @contentful/f36-icons@4.17.0
26
+ - @contentful/f36-popover@4.17.0
27
+ - @contentful/f36-typography@4.17.0
28
+ - @contentful/f36-utils@4.17.0
29
+ - @contentful/f36-core@4.17.0
30
+
31
+ ## 4.16.0
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies []:
36
+ - @contentful/f36-button@4.16.0
37
+ - @contentful/f36-forms@4.16.0
38
+ - @contentful/f36-icons@4.16.0
39
+ - @contentful/f36-popover@4.16.0
40
+ - @contentful/f36-skeleton@4.16.0
41
+ - @contentful/f36-typography@4.16.0
42
+ - @contentful/f36-utils@4.16.0
43
+ - @contentful/f36-core@4.16.0
44
+
3
45
  ## 4.15.1
4
46
 
5
47
  ### Patch Changes
@@ -1,11 +1,12 @@
1
- import React from "react";
2
- import { CommonProps } from "@contentful/f36-core";
3
- import { TextInputProps } from "@contentful/f36-forms";
1
+ import React from 'react';
2
+ import { CommonProps } from '@contentful/f36-core';
3
+ import { TextInputProps } from '@contentful/f36-forms';
4
+
4
5
  interface GenericGroupType<ItemType> {
5
6
  groupTitle: string;
6
7
  options: ItemType[];
7
8
  }
8
- export interface AutocompleteProps<ItemType> extends CommonProps, Pick<TextInputProps, 'isDisabled' | 'isInvalid' | 'isReadOnly' | 'isRequired' | 'id' | 'defaultValue'> {
9
+ interface AutocompleteProps<ItemType> extends CommonProps, Pick<TextInputProps, 'isDisabled' | 'isInvalid' | 'isReadOnly' | 'isRequired' | 'id' | 'defaultValue'> {
9
10
  /**
10
11
  * It’s an array of data to be used as "options" by the autocomplete component.
11
12
  * This can either be a plain list of items or a list of groups of items.
@@ -106,8 +107,8 @@ declare function _Autocomplete<ItemType>(props: AutocompleteProps<ItemType>, ref
106
107
  * to filter a list of items. That list of filtered items will be shown to the user as possible options for the input.
107
108
  * Once one of the options is selected, that option becomes the value of the `TextInput`.
108
109
  */
109
- export const Autocomplete: <T>(props: AutocompleteProps<T> & {
110
+ declare const Autocomplete: <T>(props: AutocompleteProps<T> & {
110
111
  ref?: React.Ref<HTMLDivElement>;
111
112
  }) => ReturnType<typeof _Autocomplete>;
112
113
 
113
- //# sourceMappingURL=types.d.ts.map
114
+ export { Autocomplete, AutocompleteProps };
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var n = require('react');
6
+ var emotion = require('emotion');
7
+ var downshift = require('downshift');
8
+ var f36Core = require('@contentful/f36-core');
9
+ var f36Button = require('@contentful/f36-button');
10
+ var f36Forms = require('@contentful/f36-forms');
11
+ var f36Icons = require('@contentful/f36-icons');
12
+ var f36Skeleton = require('@contentful/f36-skeleton');
13
+ var f36Popover = require('@contentful/f36-popover');
14
+ var f36Typography = require('@contentful/f36-typography');
15
+ var f36Utils = require('@contentful/f36-utils');
16
+ var p = require('@contentful/f36-tokens');
17
+
18
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
+
20
+ var n__default = /*#__PURE__*/_interopDefaultLegacy(n);
21
+ var p__default = /*#__PURE__*/_interopDefaultLegacy(p);
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);
24
+
25
+ exports.Autocomplete = Ve;
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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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,EACP,kBAAmBC,EACnB,iBAAkBC,EAClB,aAAcC,EACd,WAAYC,EACZ,WAAYC,EACd,CAEN,CAEJ,CACF,CAEJ,CAEA,IAAMgE,GAAuB,IAEzB3F,EAAA,cAACU,EAAS,UAAT,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"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,17 @@
1
+ import n, { useState, useCallback } from 'react';
2
+ import { cx, css } from 'emotion';
3
+ import { useCombobox } from 'downshift';
4
+ import { mergeRefs } from '@contentful/f36-core';
5
+ import { IconButton } from '@contentful/f36-button';
6
+ import { TextInput } from '@contentful/f36-forms';
7
+ import { ChevronDownIcon, CloseIcon } from '@contentful/f36-icons';
8
+ import { Skeleton } from '@contentful/f36-skeleton';
9
+ import { Popover } from '@contentful/f36-popover';
10
+ import { Subheading, SectionHeading, Text } from '@contentful/f36-typography';
11
+ import { getStringMatch } from '@contentful/f36-utils';
12
+ import p from '@contentful/f36-tokens';
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);
15
+
16
+ export { Ve as Autocomplete };
17
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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,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,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,IACb1E,EAAA,cAAC,OAAI,UAAW4B,EAAO,MACrB5B,EAAA,cAACY,GAAA,CAAW,UAAWgB,EAAO,gBAC3B2B,EACH,CACF,EAGD,CAACO,GACAS,EAAcV,EAAWvC,CAAK,GAC9BA,EAAM,IAAI,CAACmD,EAAkB3C,IAAkB,CAC7C,GAAI2C,EAAM,QAAQ,OAAS,EACzB,OAEF,IAAMmB,GACJ5F,EAAA,cAAC,OAAI,IAAK8B,GACR9B,EAAA,cAACa,GAAA,CACC,IAAKiB,EACL,eAAa,6BACb,aAAa,OACb,UAAWF,EAAO,YAEjB6C,EAAM,UACT,EACAzE,EAAA,cAACoB,EAAA,CACC,MAAOqD,EAAM,QACb,iBAAkBjD,EAClB,aAAcC,EACd,WAAYC,EACZ,WAAYC,EACZ,kBAAmBJ,EACrB,CACF,EAEF,OAAAA,GAAqBkD,EAAM,QAAQ,OAC5BmB,EACT,CAAC,EAEF,CAAC9B,GACA,CAACS,EAAcV,EAAWvC,CAAK,GAC/BA,EAAM,OAAS,GACbtB,EAAA,cAACoB,EAAA,CACC,MAAOE,EACP,kBAAmBC,EACnB,iBAAkBC,EAClB,aAAcC,EACd,WAAYC,EACZ,WAAYC,EACd,CAEN,CAEJ,CACF,CAEJ,CAEA,IAAMgE,GAAuB,IAEzB3F,EAAA,cAACU,EAAS,UAAT,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"]}
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@contentful/f36-autocomplete",
3
- "version": "4.15.1",
3
+ "version": "4.18.0",
4
4
  "description": "Forma 36: Autocomplete component",
5
5
  "scripts": {
6
- "build": "parcel build"
6
+ "build": "tsup"
7
7
  },
8
8
  "dependencies": {
9
9
  "@babel/runtime": "^7.6.2",
10
- "@contentful/f36-button": "^4.15.1",
11
- "@contentful/f36-core": "^4.15.1",
12
- "@contentful/f36-forms": "^4.15.1",
13
- "@contentful/f36-icons": "^4.15.1",
14
- "@contentful/f36-popover": "^4.15.1",
15
- "@contentful/f36-skeleton": "^4.15.1",
10
+ "@contentful/f36-button": "^4.18.0",
11
+ "@contentful/f36-core": "^4.18.0",
12
+ "@contentful/f36-forms": "^4.18.0",
13
+ "@contentful/f36-icons": "^4.18.0",
14
+ "@contentful/f36-popover": "^4.18.0",
15
+ "@contentful/f36-skeleton": "^4.18.0",
16
16
  "@contentful/f36-tokens": "^4.0.1",
17
- "@contentful/f36-typography": "^4.15.1",
18
- "@contentful/f36-utils": "^4.15.1",
17
+ "@contentful/f36-typography": "^4.18.0",
18
+ "@contentful/f36-utils": "^4.18.0",
19
19
  "downshift": "^6.1.7",
20
20
  "emotion": "^10.0.17"
21
21
  },
@@ -26,9 +26,9 @@
26
26
  "files": [
27
27
  "dist"
28
28
  ],
29
- "main": "dist/main.js",
30
- "module": "dist/module.js",
31
- "types": "dist/types.d.ts",
29
+ "main": "dist/index.js",
30
+ "module": "dist/index.mjs",
31
+ "types": "dist/index.d.ts",
32
32
  "source": "src/index.ts",
33
33
  "sideEffects": false,
34
34
  "browserslist": "extends @contentful/browserslist-config",
package/dist/main.js DELETED
@@ -1,292 +0,0 @@
1
- var $hVoOH$emotion = require("emotion");
2
- var $hVoOH$react = require("react");
3
- var $hVoOH$downshift = require("downshift");
4
- var $hVoOH$contentfulf36core = require("@contentful/f36-core");
5
- var $hVoOH$contentfulf36button = require("@contentful/f36-button");
6
- var $hVoOH$contentfulf36forms = require("@contentful/f36-forms");
7
- var $hVoOH$contentfulf36icons = require("@contentful/f36-icons");
8
- var $hVoOH$contentfulf36skeleton = require("@contentful/f36-skeleton");
9
- var $hVoOH$contentfulf36popover = require("@contentful/f36-popover");
10
- var $hVoOH$contentfulf36typography = require("@contentful/f36-typography");
11
- var $hVoOH$contentfulf36utils = require("@contentful/f36-utils");
12
- var $hVoOH$contentfulf36tokens = require("@contentful/f36-tokens");
13
-
14
- function $parcel$export(e, n, v, s) {
15
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
16
- }
17
- function $parcel$interopDefault(a) {
18
- return a && a.__esModule ? a.default : a;
19
- }
20
-
21
- $parcel$export(module.exports, "Autocomplete", () => $56e6e764f18116b7$export$2f2b9559550c7bbc);
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
- const $e938248654439d1d$export$71b73d9f7d678746 = (listMaxHeight)=>({
39
- autocomplete: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
40
- name: "1jke4yk",
41
- styles: "position:relative;width:100%;"
42
- }),
43
- combobox: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
44
- name: "79elbk",
45
- styles: "position:relative;"
46
- }),
47
- inputField: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
48
- paddingRight: (0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).spacingXl,
49
- textOverflow: "ellipsis",
50
- whiteSpace: "nowrap"
51
- }),
52
- toggleButton: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
53
- position: "absolute",
54
- top: "1px",
55
- right: "1px",
56
- zIndex: 1,
57
- padding: (0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).spacing2Xs,
58
- height: "38px"
59
- }),
60
- content: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
61
- overflow: "auto",
62
- maxHeight: `${listMaxHeight}px`
63
- }),
64
- list: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
65
- listStyle: "none",
66
- padding: `${(0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).spacingXs} 0`,
67
- margin: 0
68
- }),
69
- groupTitle: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
70
- padding: `${(0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).spacingXs} ${(0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).spacingM}`,
71
- lineHeight: (0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).lineHeightM
72
- }),
73
- noMatchesTitle: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
74
- color: (0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).gray500,
75
- margin: `${(0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).spacingM} 0 ${(0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).spacingM} 0`
76
- }),
77
- item: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
78
- display: "block",
79
- padding: `${(0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).spacingXs} ${(0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).spacingM}`,
80
- wordBreak: "break-word",
81
- whiteSpace: "break-spaces",
82
- cursor: "pointer",
83
- hyphens: "auto",
84
- "&:focus, &:hover": {
85
- backgroundColor: (0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).gray100
86
- },
87
- "&:active": {
88
- backgroundColor: (0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).gray200
89
- }
90
- }),
91
- disabled: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
92
- name: "1e07izz",
93
- styles: "opacity:0.5;pointer-events:none;"
94
- }),
95
- highlighted: /*#__PURE__*/ (0, $hVoOH$emotion.css)({
96
- backgroundColor: (0, ($parcel$interopDefault($hVoOH$contentfulf36tokens))).gray100
97
- })
98
- });
99
-
100
-
101
- const $26b30f0765231b47$export$4db5c29873bb228f = (props)=>{
102
- const { items: items , elementStartIndex: elementStartIndex , highlightedIndex: highlightedIndex , getItemProps: getItemProps , renderItem: renderItem , inputValue: inputValue , listMaxHeight: listMaxHeight = 180 } = props;
103
- const styles = (0, $e938248654439d1d$export$71b73d9f7d678746)(listMaxHeight);
104
- return /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement("ul", {
105
- className: styles.list,
106
- "data-test-id": "cf-autocomplete-list"
107
- }, items.map((item, index)=>{
108
- const itemIndex = elementStartIndex + index;
109
- const itemProps = getItemProps({
110
- item: item,
111
- index: itemIndex
112
- });
113
- return /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36typography.Text), {
114
- ...itemProps,
115
- as: "li",
116
- key: itemIndex,
117
- className: (0, $hVoOH$emotion.cx)([
118
- styles.item,
119
- highlightedIndex === itemIndex && styles.highlighted
120
- ]),
121
- "data-test-id": `cf-autocomplete-list-item-${itemIndex}`
122
- }, renderItem ? renderItem(item, inputValue) : typeof item === "string" ? /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement($26b30f0765231b47$var$HighlightedItem, {
123
- item: item,
124
- inputValue: inputValue
125
- }) : item);
126
- }));
127
- };
128
- $26b30f0765231b47$export$4db5c29873bb228f.displayName = "AutocompleteItems";
129
- function $26b30f0765231b47$var$HighlightedItem({ item: item , inputValue: inputValue }) {
130
- const { before: before , match: match , after: after } = (0, $hVoOH$contentfulf36utils.getStringMatch)(item, inputValue);
131
- return /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, ($parcel$interopDefault($hVoOH$react))).Fragment, null, before, /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement("b", null, match), after);
132
- }
133
- $26b30f0765231b47$var$HighlightedItem.displayName = "HighlightedItem";
134
-
135
-
136
-
137
- function $56e6e764f18116b7$var$_Autocomplete(props, ref) {
138
- const { id: id , className: className , clearAfterSelect: clearAfterSelect = false , closeAfterSelect: closeAfterSelect = true , defaultValue: defaultValue = "" , selectedItem: selectedItem1 , items: items , onInputValueChange: onInputValueChange , onSelectItem: onSelectItem , renderItem: renderItem , icon: icon = /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36icons.ChevronDownIcon), {
139
- variant: "muted"
140
- }) , itemToString: itemToString = (item)=>item , isInvalid: isInvalid , isDisabled: isDisabled , isRequired: isRequired , isReadOnly: isReadOnly , noMatchesMessage: noMatchesMessage = "No matches found" , placeholder: placeholder = "Search" , inputRef: inputRef , toggleRef: toggleRef , listRef: listRef , listWidth: listWidth = "auto" , listMaxHeight: listMaxHeight = 180 , isGrouped: isGrouped = false , isLoading: isLoading = false , usePortal: usePortal = false , testId: testId = "cf-autocomplete" } = props;
141
- const styles = (0, $e938248654439d1d$export$71b73d9f7d678746)(listMaxHeight);
142
- const [inputValue1, setInputValue] = (0, $hVoOH$react.useState)(defaultValue);
143
- const handleInputValueChange = (0, $hVoOH$react.useCallback)((value)=>{
144
- setInputValue(value);
145
- onInputValueChange === null || onInputValueChange === void 0 ? void 0 : onInputValueChange(value);
146
- }, [
147
- onInputValueChange
148
- ]); // Handle manually to avoid a jumping cursor, see https://github.com/downshift-js/downshift/issues/1108#issuecomment-842407759
149
- const handleNativeChangeEvent = (0, $hVoOH$react.useCallback)((event)=>{
150
- const value = event.target.value;
151
- handleInputValueChange(value);
152
- }, [
153
- handleInputValueChange
154
- ]);
155
- const flattenItems = $56e6e764f18116b7$var$isUsingGroups(isGrouped, items) ? items.reduce((acc, group)=>[
156
- ...acc,
157
- ...group.options
158
- ], []) : items;
159
- const isShowingNoMatches = $56e6e764f18116b7$var$isUsingGroups(isGrouped, items) ? items.every((group)=>group.options.length === 0) : items.length === 0;
160
- const { getComboboxProps: getComboboxProps , getInputProps: getInputProps , getItemProps: getItemProps , getMenuProps: getMenuProps , getToggleButtonProps: getToggleButtonProps , highlightedIndex: highlightedIndex , isOpen: isOpen , toggleMenu: toggleMenu } = (0, $hVoOH$downshift.useCombobox)({
161
- items: flattenItems,
162
- selectedItem: selectedItem1,
163
- inputValue: inputValue1,
164
- itemToString: itemToString,
165
- onInputValueChange: ({ type: type , inputValue: inputValue })=>{
166
- if (type !== "__input_change__") handleInputValueChange(inputValue);
167
- },
168
- onStateChange: ({ type: type , selectedItem: selectedItem })=>{
169
- switch(type){
170
- case (0, $hVoOH$downshift.useCombobox).stateChangeTypes.InputKeyDownEnter:
171
- case (0, $hVoOH$downshift.useCombobox).stateChangeTypes.ItemClick:
172
- if (selectedItem) onSelectItem(selectedItem);
173
- if (clearAfterSelect) handleInputValueChange("");
174
- if (!closeAfterSelect) toggleMenu();
175
- break;
176
- default:
177
- break;
178
- }
179
- }
180
- });
181
- const { "aria-labelledby": _labelledby , id: _inputId , ...inputProps } = getInputProps();
182
- const comboboxProps = getComboboxProps();
183
- const toggleProps = getToggleButtonProps();
184
- const menuProps = getMenuProps();
185
- let elementStartIndex = 0;
186
- return /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement("div", {
187
- "data-test-id": testId,
188
- className: (0, $hVoOH$emotion.cx)(styles.autocomplete, className),
189
- ref: ref
190
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36popover.Popover), {
191
- usePortal: usePortal,
192
- isOpen: isOpen,
193
- isFullWidth: listWidth === "full",
194
- renderOnlyWhenOpen: false,
195
- // and the user won't be able to type in the input
196
- // eslint-disable-next-line jsx-a11y/no-autofocus
197
- autoFocus: false,
198
- id: menuProps.id
199
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36popover.Popover).Trigger, null, /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement("div", {
200
- ...comboboxProps,
201
- className: styles.combobox
202
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36forms.TextInput), {
203
- className: styles.inputField,
204
- ...inputProps,
205
- onFocus: ()=>{
206
- if (!isOpen) toggleMenu();
207
- },
208
- id: id,
209
- isInvalid: isInvalid,
210
- isDisabled: isDisabled,
211
- isRequired: isRequired,
212
- isReadOnly: isReadOnly,
213
- ref: (0, $hVoOH$contentfulf36core.mergeRefs)(inputProps.ref, inputRef),
214
- testId: "cf-autocomplete-input",
215
- placeholder: placeholder,
216
- onChange: (event)=>{
217
- inputProps.onChange(event);
218
- handleNativeChangeEvent(event);
219
- }
220
- }), /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36button.IconButton), {
221
- ...toggleProps,
222
- ref: (0, $hVoOH$contentfulf36core.mergeRefs)(toggleProps.ref, toggleRef),
223
- "aria-label": inputValue1 ? "Clear" : "Show list",
224
- className: styles.toggleButton,
225
- variant: "transparent",
226
- icon: inputValue1 ? /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36icons.CloseIcon), {
227
- variant: "muted"
228
- }) : icon,
229
- onClick: ()=>{
230
- if (inputValue1) handleInputValueChange("");
231
- else toggleMenu();
232
- },
233
- isDisabled: isDisabled,
234
- size: "small"
235
- }))), (items.length > 0 || inputValue1.length > 0) && /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36popover.Popover).Content, {
236
- ...menuProps,
237
- ref: (0, $hVoOH$contentfulf36core.mergeRefs)(menuProps.ref, listRef),
238
- className: styles.content,
239
- testId: "cf-autocomplete-container"
240
- }, isLoading && [
241
- ...Array(3)
242
- ].map((_, index)=>/*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement("div", {
243
- key: index,
244
- className: (0, $hVoOH$emotion.cx)(styles.item, styles.disabled)
245
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement($56e6e764f18116b7$var$ListItemLoadingState, null))), !isLoading && isShowingNoMatches && /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement("div", {
246
- className: styles.item
247
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36typography.Subheading), {
248
- className: styles.noMatchesTitle
249
- }, noMatchesMessage)), !isLoading && $56e6e764f18116b7$var$isUsingGroups(isGrouped, items) && items.map((group, index)=>{
250
- if (group.options.length < 1) return;
251
- const render = /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement("div", {
252
- key: index
253
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36typography.SectionHeading), {
254
- key: index,
255
- "data-test-id": "cf-autocomplete-grouptitle",
256
- marginBottom: "none",
257
- className: styles.groupTitle
258
- }, group.groupTitle), /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $26b30f0765231b47$export$4db5c29873bb228f), {
259
- items: group.options,
260
- highlightedIndex: highlightedIndex,
261
- getItemProps: getItemProps,
262
- renderItem: renderItem,
263
- inputValue: inputValue1,
264
- elementStartIndex: elementStartIndex
265
- }));
266
- elementStartIndex += group.options.length;
267
- return render;
268
- }), !isLoading && !$56e6e764f18116b7$var$isUsingGroups(isGrouped, items) && items.length > 0 && /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $26b30f0765231b47$export$4db5c29873bb228f), {
269
- items: items,
270
- elementStartIndex: elementStartIndex,
271
- highlightedIndex: highlightedIndex,
272
- getItemProps: getItemProps,
273
- renderItem: renderItem,
274
- inputValue: inputValue1
275
- }))));
276
- }
277
- const $56e6e764f18116b7$var$ListItemLoadingState = ()=>{
278
- return /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36skeleton.SkeletonContainer), {
279
- svgHeight: 16
280
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).createElement((0, $hVoOH$contentfulf36skeleton.SkeletonBodyText), {
281
- numberOfLines: 1
282
- }));
283
- }; // This is required to infer correct typings when differentiating groups and items
284
- function $56e6e764f18116b7$var$isUsingGroups(isGrouped, items) {
285
- return isGrouped;
286
- }
287
- const $56e6e764f18116b7$export$2f2b9559550c7bbc = /*#__PURE__*/ (0, ($parcel$interopDefault($hVoOH$react))).forwardRef($56e6e764f18116b7$var$_Autocomplete);
288
-
289
-
290
-
291
-
292
- //# sourceMappingURL=main.js.map
package/dist/main.js.map DELETED
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;A;;;;;;;;;;A;;;;A;;AGGO,MAAMoB,yCAAqB,GAAG,CAAC+B,aAAD,GAA4B,CAAA;QAC/DoD,YAAY,EAAA,aAAE,CAAA,CAAA,GAAA,kBAAdA,CAAAA,CAAAA;YAAc,IAAA,EAAA,SAAA;YAAA,MAAA,EAAA,+BAAA;SAAA,CADiD;QAK/DC,QAAQ,EAAA,aAAE,CAAA,CAAA,GAAA,kBAAVA,CAAAA,CAAAA;YAAU,IAAA,EAAA,QAAA;YAAA,MAAA,EAAA,oBAAA;SAAA,CALqD;QAQ/DC,UAAU,EAAA,aAAE,CAAA,CAAA,GAAA,kBAAA,CAAA,CAAI;YACd+B,YAAY,EAAED,CAAAA,GAAAA,oDAAM,CAAA,CAACE,SADP;YAEdC,YAAY,EAAE,UAFA;YAGdC,UAAU,EAAE,QAAZA;SAHU,CARmD;QAa/DhC,YAAY,EAAA,aAAE,CAAA,CAAA,GAAA,kBAAA,CAAA,CAAI;YAChBiC,QAAQ,EAAE,UADM;YAEhBC,GAAG,EAAE,KAFW;YAGhBC,KAAK,EAAE,KAHS;YAIhBC,MAAM,EAAE,CA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W7C,MAAM,CAAC7C,UAAR;WAETyD,KAAK,CAACzD,UAAP,CACtB,gBACoB,0DAAC,CAAA,GAAA,yCAAiB,CAAA;YAChB,KAAA,EAAOyD,KAAK,CAACxD,OAAP;YACN,gBAAA,EAAkBiE,gBAAD;YACjB,YAAA,EAAcH,YAAD;YACb,UAAA,EAAYlD,UAAD;YACX,UAAA,EAAYC,WAAD;YACX,iBAAA,EAAmBkE,iBAAD;UANxC,CAVgB,AAkBhB;QAEgBA,iBAAiB,IAAIvB,KAAK,CAACxD,OAAN,CAAc2D,MAAnC,CAAAoB;QACA,OAAOa,MAAP,CAAA;KAzBF,CAFF,EA8BC,CAAC/D,SAAD,IACC,CAACwB,mCAAa,CAAC/C,SAAD,EAAYH,KAAZ,CADf,IAECA,KAAK,CAACwD,MAAN,GAAe,CAFhB,kBAGG,0DAAC,CAAA,GAAA,yCAAiB,CAAA;QAChB,KAAA,EAAOxD,KAAD;QACN,iBAAA,EAAmB4E,iBAAD;QAClB,gBAAA,EAAkBd,gBAAD;QACjB,YAAA,EAAcH,YAAD;QACb,UAAA,EAAYlD,UAAD;QACX,UAAA,EAAYC,WAAD;MATjB,CApDJ,CAkER,CA9HE,CA+HF;CAEC;AAED,MAAMgF,0CAAoB,GAAG,IAAM;IACjC,qBACE,0DAAC,CAAA,GAAA,8CAAD,CAAA;QAAmB,SAAA,EAAW,EAAD;qBAC3B,0DAAC,CAAA,GAAA,6CAAD,CAAA;QAAkB,aAAA,EAAe,CAAD;MAAtC,CAFE,CAGF;CAJA,A,EAQA,kFAFC;AAGD,SAASxC,mCAAa,CACpB/C,SADF,EAEEH,KAFF,EAGyC;IACvC,OAAOG,SAAP,CAAA;CACD;AAOM,MAAM7B,yCAAY,iBAAGE,CAAAA,GAAAA,sCAAK,CAAA,CAACmH,UAAN,CAAiB/D,mCAAjB,CAAA,AAArB,AACsC;;ADrZ7C","sources":["packages/components/autocomplete/src/index.ts","packages/components/autocomplete/src/Autocomplete.tsx","packages/components/autocomplete/src/AutocompleteItems.tsx","packages/components/autocomplete/src/Autocomplete.styles.ts"],"sourcesContent":["export { Autocomplete } from './Autocomplete';\nexport type { AutocompleteProps } from './Autocomplete';\n","import React, { useCallback, useState } from 'react';\nimport { cx } from 'emotion';\nimport { useCombobox } from 'downshift';\n\nimport { mergeRefs } from '@contentful/f36-core';\nimport type { CommonProps, ExpandProps } from '@contentful/f36-core';\nimport { IconButton } from '@contentful/f36-button';\nimport { TextInput } from '@contentful/f36-forms';\nimport type { TextInputProps } from '@contentful/f36-forms';\nimport { CloseIcon, ChevronDownIcon } from '@contentful/f36-icons';\nimport { SkeletonContainer, SkeletonBodyText } 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 <SkeletonContainer svgHeight={16}>\n <SkeletonBodyText numberOfLines={1} />\n </SkeletonContainer>\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';\n\nimport { getStringMatch } from '@contentful/f36-utils';\nimport { Text } from '@contentful/f36-typography';\nimport { getAutocompleteStyles } from './Autocomplete.styles';\nimport type { UseComboboxGetItemPropsOptions } from 'downshift';\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"],"names":["Autocomplete","AutocompleteProps","React","useCallback","useState","useCombobox","mergeRefs","CommonProps","ExpandProps","IconButton","TextInput","TextInputProps","CloseIcon","ChevronDownIcon","SkeletonContainer","SkeletonBodyText","Popover","Subheading","SectionHeading","AutocompleteItems","getAutocompleteStyles","GenericGroupType","groupTitle","options","ItemType","Pick","items","icon","ReactElement","isGrouped","onInputValueChange","value","onSelectItem","item","selectedItem","renderItem","inputValue","ReactNode","itemToString","clearAfterSelect","closeAfterSelect","placeholder","noMatchesMessage","inputRef","Ref","HTMLInputElement","toggleRef","HTMLButtonElement","listRef","HTMLUListElement","listWidth","listMaxHeight","isLoading","usePortal","_Autocomplete","props","ref","HTMLDivElement","id","className","defaultValue","isInvalid","isDisabled","isRequired","isReadOnly","testId","GroupType","styles","setInputValue","handleInputValueChange","handleNativeChangeEvent","event","ChangeEvent","HTMLTextAreaElement","target","flattenItems","isUsingGroups","reduce","acc","group","isShowingNoMatches","every","length","getComboboxProps","getInputProps","getItemProps","getMenuProps","getToggleButtonProps","highlightedIndex","isOpen","toggleMenu","type","onStateChange","stateChangeTypes","InputKeyDownEnter","ItemClick","_labelledby","_inputId","inputProps","comboboxProps","toggleProps","menuProps","elementStartIndex","autocomplete","combobox","inputField","onChange","toggleButton","content","Array","map","_","index","disabled","noMatchesTitle","render","ListItemLoadingState","forwardRef","T","ReturnType","HTMLAttributes","getStringMatch","Text","UseComboboxGetItemPropsOptions","AutocompleteItemsProps","HTMLLIElement","list","itemIndex","itemProps","highlighted","displayName","HighlightedItem","before","match","after","tokens","paddingRight","spacingXl","textOverflow","whiteSpace","position","top","right","zIndex","padding","spacing2Xs","height","overflow","maxHeight","listStyle","spacingXs","margin","spacingM","lineHeight","lineHeightM","color","gray500","display","wordBreak","cursor","hyphens","backgroundColor","gray100","gray200"],"version":3,"file":"main.js.map"}
package/dist/module.js DELETED
@@ -1,285 +0,0 @@
1
- import {cx as $7oe8x$cx, css as $7oe8x$css} from "emotion";
2
- import $7oe8x$react, {useState as $7oe8x$useState, useCallback as $7oe8x$useCallback} from "react";
3
- import {useCombobox as $7oe8x$useCombobox} from "downshift";
4
- import {mergeRefs as $7oe8x$mergeRefs} from "@contentful/f36-core";
5
- import {IconButton as $7oe8x$IconButton} from "@contentful/f36-button";
6
- import {TextInput as $7oe8x$TextInput} from "@contentful/f36-forms";
7
- import {ChevronDownIcon as $7oe8x$ChevronDownIcon, CloseIcon as $7oe8x$CloseIcon} from "@contentful/f36-icons";
8
- import {SkeletonContainer as $7oe8x$SkeletonContainer, SkeletonBodyText as $7oe8x$SkeletonBodyText} from "@contentful/f36-skeleton";
9
- import {Popover as $7oe8x$Popover} from "@contentful/f36-popover";
10
- import {Subheading as $7oe8x$Subheading, SectionHeading as $7oe8x$SectionHeading, Text as $7oe8x$Text} from "@contentful/f36-typography";
11
- import {getStringMatch as $7oe8x$getStringMatch} from "@contentful/f36-utils";
12
- import $7oe8x$contentfulf36tokens from "@contentful/f36-tokens";
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
- const $b76be67e84921f58$export$71b73d9f7d678746 = (listMaxHeight)=>({
31
- autocomplete: /*#__PURE__*/ (0, $7oe8x$css)({
32
- name: "1jke4yk",
33
- styles: "position:relative;width:100%;"
34
- }),
35
- combobox: /*#__PURE__*/ (0, $7oe8x$css)({
36
- name: "79elbk",
37
- styles: "position:relative;"
38
- }),
39
- inputField: /*#__PURE__*/ (0, $7oe8x$css)({
40
- paddingRight: (0, $7oe8x$contentfulf36tokens).spacingXl,
41
- textOverflow: "ellipsis",
42
- whiteSpace: "nowrap"
43
- }),
44
- toggleButton: /*#__PURE__*/ (0, $7oe8x$css)({
45
- position: "absolute",
46
- top: "1px",
47
- right: "1px",
48
- zIndex: 1,
49
- padding: (0, $7oe8x$contentfulf36tokens).spacing2Xs,
50
- height: "38px"
51
- }),
52
- content: /*#__PURE__*/ (0, $7oe8x$css)({
53
- overflow: "auto",
54
- maxHeight: `${listMaxHeight}px`
55
- }),
56
- list: /*#__PURE__*/ (0, $7oe8x$css)({
57
- listStyle: "none",
58
- padding: `${(0, $7oe8x$contentfulf36tokens).spacingXs} 0`,
59
- margin: 0
60
- }),
61
- groupTitle: /*#__PURE__*/ (0, $7oe8x$css)({
62
- padding: `${(0, $7oe8x$contentfulf36tokens).spacingXs} ${(0, $7oe8x$contentfulf36tokens).spacingM}`,
63
- lineHeight: (0, $7oe8x$contentfulf36tokens).lineHeightM
64
- }),
65
- noMatchesTitle: /*#__PURE__*/ (0, $7oe8x$css)({
66
- color: (0, $7oe8x$contentfulf36tokens).gray500,
67
- margin: `${(0, $7oe8x$contentfulf36tokens).spacingM} 0 ${(0, $7oe8x$contentfulf36tokens).spacingM} 0`
68
- }),
69
- item: /*#__PURE__*/ (0, $7oe8x$css)({
70
- display: "block",
71
- padding: `${(0, $7oe8x$contentfulf36tokens).spacingXs} ${(0, $7oe8x$contentfulf36tokens).spacingM}`,
72
- wordBreak: "break-word",
73
- whiteSpace: "break-spaces",
74
- cursor: "pointer",
75
- hyphens: "auto",
76
- "&:focus, &:hover": {
77
- backgroundColor: (0, $7oe8x$contentfulf36tokens).gray100
78
- },
79
- "&:active": {
80
- backgroundColor: (0, $7oe8x$contentfulf36tokens).gray200
81
- }
82
- }),
83
- disabled: /*#__PURE__*/ (0, $7oe8x$css)({
84
- name: "1e07izz",
85
- styles: "opacity:0.5;pointer-events:none;"
86
- }),
87
- highlighted: /*#__PURE__*/ (0, $7oe8x$css)({
88
- backgroundColor: (0, $7oe8x$contentfulf36tokens).gray100
89
- })
90
- });
91
-
92
-
93
- const $641c6dc49f14cfd8$export$4db5c29873bb228f = (props)=>{
94
- const { items: items , elementStartIndex: elementStartIndex , highlightedIndex: highlightedIndex , getItemProps: getItemProps , renderItem: renderItem , inputValue: inputValue , listMaxHeight: listMaxHeight = 180 } = props;
95
- const styles = (0, $b76be67e84921f58$export$71b73d9f7d678746)(listMaxHeight);
96
- return /*#__PURE__*/ (0, $7oe8x$react).createElement("ul", {
97
- className: styles.list,
98
- "data-test-id": "cf-autocomplete-list"
99
- }, items.map((item, index)=>{
100
- const itemIndex = elementStartIndex + index;
101
- const itemProps = getItemProps({
102
- item: item,
103
- index: itemIndex
104
- });
105
- return /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$Text), {
106
- ...itemProps,
107
- as: "li",
108
- key: itemIndex,
109
- className: (0, $7oe8x$cx)([
110
- styles.item,
111
- highlightedIndex === itemIndex && styles.highlighted
112
- ]),
113
- "data-test-id": `cf-autocomplete-list-item-${itemIndex}`
114
- }, renderItem ? renderItem(item, inputValue) : typeof item === "string" ? /*#__PURE__*/ (0, $7oe8x$react).createElement($641c6dc49f14cfd8$var$HighlightedItem, {
115
- item: item,
116
- inputValue: inputValue
117
- }) : item);
118
- }));
119
- };
120
- $641c6dc49f14cfd8$export$4db5c29873bb228f.displayName = "AutocompleteItems";
121
- function $641c6dc49f14cfd8$var$HighlightedItem({ item: item , inputValue: inputValue }) {
122
- const { before: before , match: match , after: after } = (0, $7oe8x$getStringMatch)(item, inputValue);
123
- return /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$react).Fragment, null, before, /*#__PURE__*/ (0, $7oe8x$react).createElement("b", null, match), after);
124
- }
125
- $641c6dc49f14cfd8$var$HighlightedItem.displayName = "HighlightedItem";
126
-
127
-
128
-
129
- function $7cd5ba9838c72bf9$var$_Autocomplete(props, ref) {
130
- const { id: id , className: className , clearAfterSelect: clearAfterSelect = false , closeAfterSelect: closeAfterSelect = true , defaultValue: defaultValue = "" , selectedItem: selectedItem1 , items: items , onInputValueChange: onInputValueChange , onSelectItem: onSelectItem , renderItem: renderItem , icon: icon = /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$ChevronDownIcon), {
131
- variant: "muted"
132
- }) , itemToString: itemToString = (item)=>item , isInvalid: isInvalid , isDisabled: isDisabled , isRequired: isRequired , isReadOnly: isReadOnly , noMatchesMessage: noMatchesMessage = "No matches found" , placeholder: placeholder = "Search" , inputRef: inputRef , toggleRef: toggleRef , listRef: listRef , listWidth: listWidth = "auto" , listMaxHeight: listMaxHeight = 180 , isGrouped: isGrouped = false , isLoading: isLoading = false , usePortal: usePortal = false , testId: testId = "cf-autocomplete" } = props;
133
- const styles = (0, $b76be67e84921f58$export$71b73d9f7d678746)(listMaxHeight);
134
- const [inputValue1, setInputValue] = (0, $7oe8x$useState)(defaultValue);
135
- const handleInputValueChange = (0, $7oe8x$useCallback)((value)=>{
136
- setInputValue(value);
137
- onInputValueChange === null || onInputValueChange === void 0 ? void 0 : onInputValueChange(value);
138
- }, [
139
- onInputValueChange
140
- ]); // Handle manually to avoid a jumping cursor, see https://github.com/downshift-js/downshift/issues/1108#issuecomment-842407759
141
- const handleNativeChangeEvent = (0, $7oe8x$useCallback)((event)=>{
142
- const value = event.target.value;
143
- handleInputValueChange(value);
144
- }, [
145
- handleInputValueChange
146
- ]);
147
- const flattenItems = $7cd5ba9838c72bf9$var$isUsingGroups(isGrouped, items) ? items.reduce((acc, group)=>[
148
- ...acc,
149
- ...group.options
150
- ], []) : items;
151
- const isShowingNoMatches = $7cd5ba9838c72bf9$var$isUsingGroups(isGrouped, items) ? items.every((group)=>group.options.length === 0) : items.length === 0;
152
- const { getComboboxProps: getComboboxProps , getInputProps: getInputProps , getItemProps: getItemProps , getMenuProps: getMenuProps , getToggleButtonProps: getToggleButtonProps , highlightedIndex: highlightedIndex , isOpen: isOpen , toggleMenu: toggleMenu } = (0, $7oe8x$useCombobox)({
153
- items: flattenItems,
154
- selectedItem: selectedItem1,
155
- inputValue: inputValue1,
156
- itemToString: itemToString,
157
- onInputValueChange: ({ type: type , inputValue: inputValue })=>{
158
- if (type !== "__input_change__") handleInputValueChange(inputValue);
159
- },
160
- onStateChange: ({ type: type , selectedItem: selectedItem })=>{
161
- switch(type){
162
- case (0, $7oe8x$useCombobox).stateChangeTypes.InputKeyDownEnter:
163
- case (0, $7oe8x$useCombobox).stateChangeTypes.ItemClick:
164
- if (selectedItem) onSelectItem(selectedItem);
165
- if (clearAfterSelect) handleInputValueChange("");
166
- if (!closeAfterSelect) toggleMenu();
167
- break;
168
- default:
169
- break;
170
- }
171
- }
172
- });
173
- const { "aria-labelledby": _labelledby , id: _inputId , ...inputProps } = getInputProps();
174
- const comboboxProps = getComboboxProps();
175
- const toggleProps = getToggleButtonProps();
176
- const menuProps = getMenuProps();
177
- let elementStartIndex = 0;
178
- return /*#__PURE__*/ (0, $7oe8x$react).createElement("div", {
179
- "data-test-id": testId,
180
- className: (0, $7oe8x$cx)(styles.autocomplete, className),
181
- ref: ref
182
- }, /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$Popover), {
183
- usePortal: usePortal,
184
- isOpen: isOpen,
185
- isFullWidth: listWidth === "full",
186
- renderOnlyWhenOpen: false,
187
- // and the user won't be able to type in the input
188
- // eslint-disable-next-line jsx-a11y/no-autofocus
189
- autoFocus: false,
190
- id: menuProps.id
191
- }, /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$Popover).Trigger, null, /*#__PURE__*/ (0, $7oe8x$react).createElement("div", {
192
- ...comboboxProps,
193
- className: styles.combobox
194
- }, /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$TextInput), {
195
- className: styles.inputField,
196
- ...inputProps,
197
- onFocus: ()=>{
198
- if (!isOpen) toggleMenu();
199
- },
200
- id: id,
201
- isInvalid: isInvalid,
202
- isDisabled: isDisabled,
203
- isRequired: isRequired,
204
- isReadOnly: isReadOnly,
205
- ref: (0, $7oe8x$mergeRefs)(inputProps.ref, inputRef),
206
- testId: "cf-autocomplete-input",
207
- placeholder: placeholder,
208
- onChange: (event)=>{
209
- inputProps.onChange(event);
210
- handleNativeChangeEvent(event);
211
- }
212
- }), /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$IconButton), {
213
- ...toggleProps,
214
- ref: (0, $7oe8x$mergeRefs)(toggleProps.ref, toggleRef),
215
- "aria-label": inputValue1 ? "Clear" : "Show list",
216
- className: styles.toggleButton,
217
- variant: "transparent",
218
- icon: inputValue1 ? /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$CloseIcon), {
219
- variant: "muted"
220
- }) : icon,
221
- onClick: ()=>{
222
- if (inputValue1) handleInputValueChange("");
223
- else toggleMenu();
224
- },
225
- isDisabled: isDisabled,
226
- size: "small"
227
- }))), (items.length > 0 || inputValue1.length > 0) && /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$Popover).Content, {
228
- ...menuProps,
229
- ref: (0, $7oe8x$mergeRefs)(menuProps.ref, listRef),
230
- className: styles.content,
231
- testId: "cf-autocomplete-container"
232
- }, isLoading && [
233
- ...Array(3)
234
- ].map((_, index)=>/*#__PURE__*/ (0, $7oe8x$react).createElement("div", {
235
- key: index,
236
- className: (0, $7oe8x$cx)(styles.item, styles.disabled)
237
- }, /*#__PURE__*/ (0, $7oe8x$react).createElement($7cd5ba9838c72bf9$var$ListItemLoadingState, null))), !isLoading && isShowingNoMatches && /*#__PURE__*/ (0, $7oe8x$react).createElement("div", {
238
- className: styles.item
239
- }, /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$Subheading), {
240
- className: styles.noMatchesTitle
241
- }, noMatchesMessage)), !isLoading && $7cd5ba9838c72bf9$var$isUsingGroups(isGrouped, items) && items.map((group, index)=>{
242
- if (group.options.length < 1) return;
243
- const render = /*#__PURE__*/ (0, $7oe8x$react).createElement("div", {
244
- key: index
245
- }, /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$SectionHeading), {
246
- key: index,
247
- "data-test-id": "cf-autocomplete-grouptitle",
248
- marginBottom: "none",
249
- className: styles.groupTitle
250
- }, group.groupTitle), /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $641c6dc49f14cfd8$export$4db5c29873bb228f), {
251
- items: group.options,
252
- highlightedIndex: highlightedIndex,
253
- getItemProps: getItemProps,
254
- renderItem: renderItem,
255
- inputValue: inputValue1,
256
- elementStartIndex: elementStartIndex
257
- }));
258
- elementStartIndex += group.options.length;
259
- return render;
260
- }), !isLoading && !$7cd5ba9838c72bf9$var$isUsingGroups(isGrouped, items) && items.length > 0 && /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $641c6dc49f14cfd8$export$4db5c29873bb228f), {
261
- items: items,
262
- elementStartIndex: elementStartIndex,
263
- highlightedIndex: highlightedIndex,
264
- getItemProps: getItemProps,
265
- renderItem: renderItem,
266
- inputValue: inputValue1
267
- }))));
268
- }
269
- const $7cd5ba9838c72bf9$var$ListItemLoadingState = ()=>{
270
- return /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$SkeletonContainer), {
271
- svgHeight: 16
272
- }, /*#__PURE__*/ (0, $7oe8x$react).createElement((0, $7oe8x$SkeletonBodyText), {
273
- numberOfLines: 1
274
- }));
275
- }; // This is required to infer correct typings when differentiating groups and items
276
- function $7cd5ba9838c72bf9$var$isUsingGroups(isGrouped, items) {
277
- return isGrouped;
278
- }
279
- const $7cd5ba9838c72bf9$export$2f2b9559550c7bbc = /*#__PURE__*/ (0, $7oe8x$react).forwardRef($7cd5ba9838c72bf9$var$_Autocomplete);
280
-
281
-
282
-
283
-
284
- export {$7cd5ba9838c72bf9$export$2f2b9559550c7bbc as Autocomplete};
285
- //# sourceMappingURL=module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;;A;;;;;;;;;;A;;;;A;;AGGO,MAAMoB,yCAAqB,GAAG,CAAC+B,aAAD,GAA4B,CAAA;QAC/DoD,YAAY,EAAA,aAAE,CAAA,CAAA,GAAA,UAAdA,CAAAA,CAAAA;YAAc,IAAA,EAAA,SAAA;YAAA,MAAA,EAAA,+BAAA;SAAA,CADiD;QAK/DC,QAAQ,EAAA,aAAE,CAAA,CAAA,GAAA,UAAVA,CAAAA,CAAAA;YAAU,IAAA,EAAA,QAAA;YAAA,MAAA,EAAA,oBAAA;SAAA,CALqD;QAQ/DC,UAAU,EAAA,aAAE,CAAA,CAAA,GAAA,UAAA,CAAA,CAAI;YACd+B,YAAY,EAAED,CAAAA,GAAAA,0BAAM,CAAA,CAACE,SADP;YAEdC,YAAY,EAAE,UAFA;YAGdC,UAAU,EAAE,QAAZA;SAHU,CARmD;QAa/DhC,YAAY,EAAA,aAAE,CAAA,CAAA,GAAA,UAAA,CAAA,CAAI;YAChBiC,QAAQ,EAAE,UADM;YAEhBC,GAAG,EAAE,KAFW;YAGhBC,KAAK,EAAE,KAHS;YAIhBC,MAAM,EAAE,CAJQ;YAKhBC,OAAO,EAAET,CAAAA,GAAAA,0BAAM,CAAA,CAACU,UALA;YAMhBC,MAAM,EAAE,MAARA;SANY,CAbiD;QAqB/DtC,OAAO,EAAA,aAAE,CAAA,CAAA,GAAA,UAAA,CAAA,CAAI;YACXuC,QAAQ,EAAE,MADC;YAEXC,SAAS,EAAG,CAAA,EAAEjG,aAAc,CAA5BiG,EAAAA,CAAAA;SAFO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VgB,AAkBhB;QAEgBA,iBAAiB,IAAIvB,KAAK,CAACxD,OAAN,CAAc2D,MAAnC,CAAAoB;QACA,OAAOa,MAAP,CAAA;KAzBF,CAFF,EA8BC,CAAC/D,SAAD,IACC,CAACwB,mCAAa,CAAC/C,SAAD,EAAYH,KAAZ,CADf,IAECA,KAAK,CAACwD,MAAN,GAAe,CAFhB,kBAGG,gCAAC,CAAA,GAAA,yCAAiB,CAAA;QAChB,KAAA,EAAOxD,KAAD;QACN,iBAAA,EAAmB4E,iBAAD;QAClB,gBAAA,EAAkBd,gBAAD;QACjB,YAAA,EAAcH,YAAD;QACb,UAAA,EAAYlD,UAAD;QACX,UAAA,EAAYC,WAAD;MATjB,CApDJ,CAkER,CA9HE,CA+HF;CAEC;AAED,MAAMgF,0CAAoB,GAAG,IAAM;IACjC,qBACE,gCAAC,CAAA,GAAA,wBAAD,CAAA;QAAmB,SAAA,EAAW,EAAD;qBAC3B,gCAAC,CAAA,GAAA,uBAAD,CAAA;QAAkB,aAAA,EAAe,CAAD;MAAtC,CAFE,CAGF;CAJA,A,EAQA,kFAFC;AAGD,SAASxC,mCAAa,CACpB/C,SADF,EAEEH,KAFF,EAGyC;IACvC,OAAOG,SAAP,CAAA;CACD;AAOM,MAAM7B,yCAAY,iBAAGE,CAAAA,GAAAA,YAAK,CAAA,CAACmH,UAAN,CAAiB/D,mCAAjB,CAAA,AAArB,AACsC;;ADrZ7C","sources":["packages/components/autocomplete/src/index.ts","packages/components/autocomplete/src/Autocomplete.tsx","packages/components/autocomplete/src/AutocompleteItems.tsx","packages/components/autocomplete/src/Autocomplete.styles.ts"],"sourcesContent":["export { Autocomplete } from './Autocomplete';\nexport type { AutocompleteProps } from './Autocomplete';\n","import React, { useCallback, useState } from 'react';\nimport { cx } from 'emotion';\nimport { useCombobox } from 'downshift';\n\nimport { mergeRefs } from '@contentful/f36-core';\nimport type { CommonProps, ExpandProps } from '@contentful/f36-core';\nimport { IconButton } from '@contentful/f36-button';\nimport { TextInput } from '@contentful/f36-forms';\nimport type { TextInputProps } from '@contentful/f36-forms';\nimport { CloseIcon, ChevronDownIcon } from '@contentful/f36-icons';\nimport { SkeletonContainer, SkeletonBodyText } 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 <SkeletonContainer svgHeight={16}>\n <SkeletonBodyText numberOfLines={1} />\n </SkeletonContainer>\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';\n\nimport { getStringMatch } from '@contentful/f36-utils';\nimport { Text } from '@contentful/f36-typography';\nimport { getAutocompleteStyles } from './Autocomplete.styles';\nimport type { UseComboboxGetItemPropsOptions } from 'downshift';\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"],"names":["Autocomplete","AutocompleteProps","React","useCallback","useState","useCombobox","mergeRefs","CommonProps","ExpandProps","IconButton","TextInput","TextInputProps","CloseIcon","ChevronDownIcon","SkeletonContainer","SkeletonBodyText","Popover","Subheading","SectionHeading","AutocompleteItems","getAutocompleteStyles","GenericGroupType","groupTitle","options","ItemType","Pick","items","icon","ReactElement","isGrouped","onInputValueChange","value","onSelectItem","item","selectedItem","renderItem","inputValue","ReactNode","itemToString","clearAfterSelect","closeAfterSelect","placeholder","noMatchesMessage","inputRef","Ref","HTMLInputElement","toggleRef","HTMLButtonElement","listRef","HTMLUListElement","listWidth","listMaxHeight","isLoading","usePortal","_Autocomplete","props","ref","HTMLDivElement","id","className","defaultValue","isInvalid","isDisabled","isRequired","isReadOnly","testId","GroupType","styles","setInputValue","handleInputValueChange","handleNativeChangeEvent","event","ChangeEvent","HTMLTextAreaElement","target","flattenItems","isUsingGroups","reduce","acc","group","isShowingNoMatches","every","length","getComboboxProps","getInputProps","getItemProps","getMenuProps","getToggleButtonProps","highlightedIndex","isOpen","toggleMenu","type","onStateChange","stateChangeTypes","InputKeyDownEnter","ItemClick","_labelledby","_inputId","inputProps","comboboxProps","toggleProps","menuProps","elementStartIndex","autocomplete","combobox","inputField","onChange","toggleButton","content","Array","map","_","index","disabled","noMatchesTitle","render","ListItemLoadingState","forwardRef","T","ReturnType","HTMLAttributes","getStringMatch","Text","UseComboboxGetItemPropsOptions","AutocompleteItemsProps","HTMLLIElement","list","itemIndex","itemProps","highlighted","displayName","HighlightedItem","before","match","after","tokens","paddingRight","spacingXl","textOverflow","whiteSpace","position","top","right","zIndex","padding","spacing2Xs","height","overflow","maxHeight","listStyle","spacingXs","margin","spacingM","lineHeight","lineHeightM","color","gray500","display","wordBreak","cursor","hyphens","backgroundColor","gray100","gray200"],"version":3,"file":"module.js.map"}
@@ -1 +0,0 @@
1
- {"mappings":";;;AEiBA,2BAAkC,QAAQ;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,QAAQ,EAAE,CAAC;CACrB;AAGD,mCAAmC,QAAQ,CACzC,SAAQ,WAAW,EACjB,IAAI,CACF,cAAc,EACZ,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,IAAI,GACJ,cAAc,CACjB;IACH;;;OAGG;IACH,KAAK,EAAE,QAAQ,EAAE,GAAG,iBAAiB,QAAQ,CAAC,EAAE,CAAC;IAEjD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,YAAY,CAAC;IAE1B;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C;;;OAGG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IAEvC;;;OAGG;IACH,YAAY,CAAC,EAAE,QAAQ,CAAC;IAExB;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,KAAK,MAAM,SAAS,CAAC;IACrE;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,MAAM,CAAC;IAC1C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACvC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACzC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACtC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,+BAAuB,QAAQ,EAC7B,KAAK,EAAE,kBAAkB,QAAQ,CAAC,EAClC,GAAG,EAAE,MAAM,GAAG,CAAC,cAAc,CAAC,eAqP/B;AAkBD;;;;GAIG;AACH,OAAO,MAAM;UAEH,MAAM,GAAG,CAAC,cAAc,CAAC;MAE9B,WAAW,oBAAoB,CAAC,CAAC","sources":["packages/components/autocomplete/src/src/Autocomplete.styles.ts","packages/components/autocomplete/src/src/AutocompleteItems.tsx","packages/components/autocomplete/src/src/Autocomplete.tsx","packages/components/autocomplete/src/src/index.ts","packages/components/autocomplete/src/index.ts"],"sourcesContent":[null,null,null,null,"export { Autocomplete } from './Autocomplete';\nexport type { AutocompleteProps } from './Autocomplete';\n"],"names":[],"version":3,"file":"types.d.ts.map"}