@chayns-components/core 5.0.0-beta.487 → 5.0.0-beta.488
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.
|
@@ -82,10 +82,8 @@ const ComboBox = _ref => {
|
|
|
82
82
|
* This function sets the external selected item
|
|
83
83
|
*/
|
|
84
84
|
useEffect(() => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
setIsAnimating(false);
|
|
88
|
-
}
|
|
85
|
+
setIsAnimating(false);
|
|
86
|
+
setItem(selectedItem);
|
|
89
87
|
}, [selectedItem]);
|
|
90
88
|
const placeholderImageUrl = useMemo(() => {
|
|
91
89
|
if (selectedItem) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboBox.js","names":["getDevice","React","useCallback","useEffect","useMemo","useRef","useState","ComboBoxDirection","calculateContentHeight","calculateContentWidth","Icon","ComboBoxItem","StyledComboBox","StyledComboBoxHeader","StyledComboBoxIconWrapper","StyledComboBoxPlaceholder","StyledComboBoxPlaceholderImage","StyledMotionComboBoxBody","ComboBox","_ref","direction","BOTTOM","isDisabled","list","maxHeight","onSelect","placeholder","selectedItem","shouldShowRoundImage","item","setItem","isAnimating","setIsAnimating","minWidth","setMinWidth","height","setHeight","ref","browser","isMobile","chayns","env","handleClick","event","current","contains","target","document","addEventListener","removeEventListener","handleSetSelectedItem","itemToSelect","isAtLeastOneItemWithImageGiven","some","_ref2","imageUrl","textArray","map","_ref3","text","push","placeholderImageUrl","undefined","placeholderText","handleHeaderClick","prevState","comboBoxBody","items","_ref4","suffixElement","value","createElement","isSelected","key","animate","opacity","style","TOP","transform","$browser","name","$height","initial","$maxHeight","$minWidth","$direction","transition","duration","onClick","$isOpen","$isMobile","$isDisabled","src","icons","displayName"],"sources":["../../../src/components/combobox/ComboBox.tsx"],"sourcesContent":["import { getDevice } from 'chayns-api';\nimport React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n} from 'react';\nimport { ComboBoxDirection } from '../../types/comboBox';\nimport { calculateContentHeight, calculateContentWidth } from '../../utils/calculate';\nimport Icon from '../icon/Icon';\nimport ComboBoxItem from './combobox-item/ComboBoxItem';\nimport {\n StyledComboBox,\n StyledComboBoxHeader,\n StyledComboBoxIconWrapper,\n StyledComboBoxPlaceholder,\n StyledComboBoxPlaceholderImage,\n StyledMotionComboBoxBody,\n} from './ComboBox.styles';\n\nexport interface IComboBoxItem {\n imageUrl?: string;\n suffixElement?: ReactNode;\n text: string;\n value: string | number;\n}\n\nexport type ComboBoxProps = {\n /**\n * The direction in which the combobox should open.\n */\n direction?: ComboBoxDirection;\n /**\n * Whether the combobox should be disabled.\n */\n isDisabled?: boolean;\n /**\n * The list of the items that should be displayed.\n */\n list: IComboBoxItem[];\n /**\n * The maximum height of the combobox content.\n */\n maxHeight?: CSSProperties['maxHeight'];\n /**\n * Function that should be executed when an item is selected.\n */\n onSelect?: (comboboxItem: IComboBoxItem) => void;\n /**\n * A text that should be displayed when no item is selected.\n */\n placeholder: string;\n /**\n * An item that should be preselected.\n */\n selectedItem?: IComboBoxItem;\n /**\n * If true, the images of the items are displayed in a round shape.\n */\n shouldShowRoundImage?: boolean;\n};\n\nconst ComboBox: FC<ComboBoxProps> = ({\n direction = ComboBoxDirection.BOTTOM,\n isDisabled = false,\n list,\n maxHeight = '300px',\n onSelect,\n placeholder,\n selectedItem,\n shouldShowRoundImage,\n}) => {\n const [item, setItem] = useState<IComboBoxItem>();\n const [isAnimating, setIsAnimating] = useState(false);\n const [minWidth, setMinWidth] = useState(0);\n const [height, setHeight] = useState(0);\n\n const ref = useRef<HTMLDivElement>(null);\n\n const { browser } = getDevice();\n\n const { isMobile } = chayns.env;\n\n const handleClick = useCallback(\n (event: MouseEvent) => {\n if (ref.current && !ref.current.contains(event.target as Node)) {\n setIsAnimating(false);\n }\n },\n [ref],\n );\n\n /**\n * This function adds an event listener to the document to close the combobox when the user clicks outside of it\n */\n useEffect(() => {\n document.addEventListener('click', handleClick);\n\n return () => {\n document.removeEventListener('click', handleClick);\n };\n }, [handleClick, ref]);\n\n /**\n * This function sets the selected item\n */\n const handleSetSelectedItem = useCallback(\n (itemToSelect: IComboBoxItem) => {\n setItem(itemToSelect);\n setIsAnimating(false);\n\n if (onSelect) {\n onSelect(itemToSelect);\n }\n },\n [onSelect],\n );\n\n /**\n * This function calculates the greatest width\n */\n useEffect(() => {\n const isAtLeastOneItemWithImageGiven = list.some(({ imageUrl }) => imageUrl);\n\n const textArray = list.map(({ text }) => text);\n\n setHeight(calculateContentHeight(textArray));\n\n textArray.push(placeholder);\n\n // 45px = padding left + padding right + border left + border right + arrow icon width + arrow icon margin left\n // 32px = image width + flex gap\n setMinWidth(calculateContentWidth(list) + 45 + (isAtLeastOneItemWithImageGiven ? 32 : 0));\n }, [list, placeholder]);\n\n /**\n * This function sets the external selected item\n */\n useEffect(() => {\n if (selectedItem) {\n setItem(selectedItem);\n setIsAnimating(false);\n }\n }, [selectedItem]);\n\n const placeholderImageUrl = useMemo(() => {\n if (selectedItem) {\n return selectedItem.imageUrl;\n }\n\n if (item) {\n return item.imageUrl;\n }\n\n return undefined;\n }, [item, selectedItem]);\n\n /**\n * This function resets the placeholder\n */\n const placeholderText = useMemo(() => {\n let text = placeholder;\n\n if (selectedItem) {\n text = selectedItem.text;\n } else if (item) {\n text = item.text;\n }\n\n return text;\n }, [item, placeholder, selectedItem]);\n\n /**\n * This function opens the content of the combobox\n */\n const handleHeaderClick = useCallback(() => {\n if (!isDisabled) {\n setIsAnimating((prevState) => !prevState);\n }\n }, [isDisabled]);\n\n const comboBoxBody = useMemo(() => {\n const items = list.map(({ imageUrl, suffixElement, text, value }) => (\n <ComboBoxItem\n imageUrl={imageUrl}\n isSelected={selectedItem ? value === selectedItem.value : false}\n key={value}\n onSelect={handleSetSelectedItem}\n shouldShowRoundImage={shouldShowRoundImage}\n suffixElement={suffixElement}\n text={text}\n value={value}\n />\n ));\n\n const animate = isAnimating\n ? { height: 'fit-content', opacity: 1 }\n : { height: 0, opacity: 0 };\n\n const style =\n direction === ComboBoxDirection.TOP ? { transform: 'translateY(-100%)' } : undefined;\n\n return (\n <StyledMotionComboBoxBody\n $browser={browser?.name}\n animate={animate}\n $height={height}\n initial={{ height: 0, opacity: 0 }}\n $maxHeight={maxHeight}\n $minWidth={minWidth}\n style={style}\n $direction={direction}\n transition={{ duration: 0.2 }}\n >\n {items}\n </StyledMotionComboBoxBody>\n );\n }, [\n browser?.name,\n direction,\n handleSetSelectedItem,\n height,\n isAnimating,\n list,\n maxHeight,\n minWidth,\n selectedItem,\n shouldShowRoundImage,\n ]);\n\n return useMemo(\n () => (\n <StyledComboBox ref={ref}>\n {direction === ComboBoxDirection.TOP && comboBoxBody}\n <StyledComboBoxHeader\n $direction={direction}\n $minWidth={minWidth}\n onClick={handleHeaderClick}\n $isOpen={isAnimating}\n $isMobile={isMobile}\n $isDisabled={isDisabled}\n >\n <StyledComboBoxPlaceholder>\n {placeholderImageUrl && (\n <StyledComboBoxPlaceholderImage\n src={placeholderImageUrl}\n shouldShowRoundImage={shouldShowRoundImage}\n />\n )}\n {placeholderText}\n </StyledComboBoxPlaceholder>\n <StyledComboBoxIconWrapper>\n <Icon icons={['fa fa-chevron-down']} />\n </StyledComboBoxIconWrapper>\n </StyledComboBoxHeader>\n {direction === ComboBoxDirection.BOTTOM && comboBoxBody}\n </StyledComboBox>\n ),\n [\n comboBoxBody,\n direction,\n handleHeaderClick,\n isAnimating,\n isDisabled,\n isMobile,\n minWidth,\n placeholderImageUrl,\n placeholderText,\n shouldShowRoundImage,\n ],\n );\n};\n\nComboBox.displayName = 'ComboBox';\n\nexport default ComboBox;\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,YAAY;AACtC,OAAOC,KAAK,IAERC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QAGL,OAAO;AACd,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,sBAA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AS,EAAEnD,QAAS;IACpBuD,OAAO,EAAExB,iBAAkB;IAC3ByB,OAAO,EAAE1D,WAAY;IACrB2D,SAAS,EAAEnD,QAAS;IACpBoD,WAAW,EAAErE;EAAW,gBAExBrB,KAAA,CAAAsE,aAAA,CAACxD,yBAAyB,QACrB8C,mBAAmB,iBAChB5D,KAAA,CAAAsE,aAAA,CAACvD,8BAA8B;IAC3B4E,GAAG,EAAE/B,mBAAoB;IACzBjC,oBAAoB,EAAEA;EAAqB,CAC9C,CACJ,EACAmC,eACsB,CAAC,eAC5B9D,KAAA,CAAAsE,aAAA,CAACzD,yBAAyB,qBACtBb,KAAA,CAAAsE,aAAA,CAAC7D,IAAI;IAACmF,KAAK,EAAE,CAAC,oBAAoB;EAAE,CAAE,CACf,CACT,CAAC,EACtBzE,SAAS,KAAKb,iBAAiB,CAACc,MAAM,IAAI6C,YAC/B,CACnB,EACD,CACIA,YAAY,EACZ9C,SAAS,EACT4C,iBAAiB,EACjBjC,WAAW,EACXT,UAAU,EACViB,QAAQ,EACRN,QAAQ,EACR4B,mBAAmB,EACnBE,eAAe,EACfnC,oBAAoB,CAE5B,CAAC;AACL,CAAC;AAEDV,QAAQ,CAAC4E,WAAW,GAAG,UAAU;AAEjC,eAAe5E,QAAQ"}
|
|
1
|
+
{"version":3,"file":"ComboBox.js","names":["getDevice","React","useCallback","useEffect","useMemo","useRef","useState","ComboBoxDirection","calculateContentHeight","calculateContentWidth","Icon","ComboBoxItem","StyledComboBox","StyledComboBoxHeader","StyledComboBoxIconWrapper","StyledComboBoxPlaceholder","StyledComboBoxPlaceholderImage","StyledMotionComboBoxBody","ComboBox","_ref","direction","BOTTOM","isDisabled","list","maxHeight","onSelect","placeholder","selectedItem","shouldShowRoundImage","item","setItem","isAnimating","setIsAnimating","minWidth","setMinWidth","height","setHeight","ref","browser","isMobile","chayns","env","handleClick","event","current","contains","target","document","addEventListener","removeEventListener","handleSetSelectedItem","itemToSelect","isAtLeastOneItemWithImageGiven","some","_ref2","imageUrl","textArray","map","_ref3","text","push","placeholderImageUrl","undefined","placeholderText","handleHeaderClick","prevState","comboBoxBody","items","_ref4","suffixElement","value","createElement","isSelected","key","animate","opacity","style","TOP","transform","$browser","name","$height","initial","$maxHeight","$minWidth","$direction","transition","duration","onClick","$isOpen","$isMobile","$isDisabled","src","icons","displayName"],"sources":["../../../src/components/combobox/ComboBox.tsx"],"sourcesContent":["import { getDevice } from 'chayns-api';\nimport React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n} from 'react';\nimport { ComboBoxDirection } from '../../types/comboBox';\nimport { calculateContentHeight, calculateContentWidth } from '../../utils/calculate';\nimport Icon from '../icon/Icon';\nimport ComboBoxItem from './combobox-item/ComboBoxItem';\nimport {\n StyledComboBox,\n StyledComboBoxHeader,\n StyledComboBoxIconWrapper,\n StyledComboBoxPlaceholder,\n StyledComboBoxPlaceholderImage,\n StyledMotionComboBoxBody,\n} from './ComboBox.styles';\n\nexport interface IComboBoxItem {\n imageUrl?: string;\n suffixElement?: ReactNode;\n text: string;\n value: string | number;\n}\n\nexport type ComboBoxProps = {\n /**\n * The direction in which the combobox should open.\n */\n direction?: ComboBoxDirection;\n /**\n * Whether the combobox should be disabled.\n */\n isDisabled?: boolean;\n /**\n * The list of the items that should be displayed.\n */\n list: IComboBoxItem[];\n /**\n * The maximum height of the combobox content.\n */\n maxHeight?: CSSProperties['maxHeight'];\n /**\n * Function that should be executed when an item is selected.\n */\n onSelect?: (comboboxItem: IComboBoxItem) => void;\n /**\n * A text that should be displayed when no item is selected.\n */\n placeholder: string;\n /**\n * An item that should be preselected.\n */\n selectedItem?: IComboBoxItem;\n /**\n * If true, the images of the items are displayed in a round shape.\n */\n shouldShowRoundImage?: boolean;\n};\n\nconst ComboBox: FC<ComboBoxProps> = ({\n direction = ComboBoxDirection.BOTTOM,\n isDisabled = false,\n list,\n maxHeight = '300px',\n onSelect,\n placeholder,\n selectedItem,\n shouldShowRoundImage,\n}) => {\n const [item, setItem] = useState<IComboBoxItem>();\n const [isAnimating, setIsAnimating] = useState(false);\n const [minWidth, setMinWidth] = useState(0);\n const [height, setHeight] = useState(0);\n\n const ref = useRef<HTMLDivElement>(null);\n\n const { browser } = getDevice();\n\n const { isMobile } = chayns.env;\n\n const handleClick = useCallback(\n (event: MouseEvent) => {\n if (ref.current && !ref.current.contains(event.target as Node)) {\n setIsAnimating(false);\n }\n },\n [ref],\n );\n\n /**\n * This function adds an event listener to the document to close the combobox when the user clicks outside of it\n */\n useEffect(() => {\n document.addEventListener('click', handleClick);\n\n return () => {\n document.removeEventListener('click', handleClick);\n };\n }, [handleClick, ref]);\n\n /**\n * This function sets the selected item\n */\n const handleSetSelectedItem = useCallback(\n (itemToSelect: IComboBoxItem) => {\n setItem(itemToSelect);\n setIsAnimating(false);\n\n if (onSelect) {\n onSelect(itemToSelect);\n }\n },\n [onSelect],\n );\n\n /**\n * This function calculates the greatest width\n */\n useEffect(() => {\n const isAtLeastOneItemWithImageGiven = list.some(({ imageUrl }) => imageUrl);\n\n const textArray = list.map(({ text }) => text);\n\n setHeight(calculateContentHeight(textArray));\n\n textArray.push(placeholder);\n\n // 45px = padding left + padding right + border left + border right + arrow icon width + arrow icon margin left\n // 32px = image width + flex gap\n setMinWidth(calculateContentWidth(list) + 45 + (isAtLeastOneItemWithImageGiven ? 32 : 0));\n }, [list, placeholder]);\n\n /**\n * This function sets the external selected item\n */\n useEffect(() => {\n setIsAnimating(false);\n setItem(selectedItem);\n }, [selectedItem]);\n\n const placeholderImageUrl = useMemo(() => {\n if (selectedItem) {\n return selectedItem.imageUrl;\n }\n\n if (item) {\n return item.imageUrl;\n }\n\n return undefined;\n }, [item, selectedItem]);\n\n /**\n * This function resets the placeholder\n */\n const placeholderText = useMemo(() => {\n let text = placeholder;\n\n if (selectedItem) {\n text = selectedItem.text;\n } else if (item) {\n text = item.text;\n }\n\n return text;\n }, [item, placeholder, selectedItem]);\n\n /**\n * This function opens the content of the combobox\n */\n const handleHeaderClick = useCallback(() => {\n if (!isDisabled) {\n setIsAnimating((prevState) => !prevState);\n }\n }, [isDisabled]);\n\n const comboBoxBody = useMemo(() => {\n const items = list.map(({ imageUrl, suffixElement, text, value }) => (\n <ComboBoxItem\n imageUrl={imageUrl}\n isSelected={selectedItem ? value === selectedItem.value : false}\n key={value}\n onSelect={handleSetSelectedItem}\n shouldShowRoundImage={shouldShowRoundImage}\n suffixElement={suffixElement}\n text={text}\n value={value}\n />\n ));\n\n const animate = isAnimating\n ? { height: 'fit-content', opacity: 1 }\n : { height: 0, opacity: 0 };\n\n const style =\n direction === ComboBoxDirection.TOP ? { transform: 'translateY(-100%)' } : undefined;\n\n return (\n <StyledMotionComboBoxBody\n $browser={browser?.name}\n animate={animate}\n $height={height}\n initial={{ height: 0, opacity: 0 }}\n $maxHeight={maxHeight}\n $minWidth={minWidth}\n style={style}\n $direction={direction}\n transition={{ duration: 0.2 }}\n >\n {items}\n </StyledMotionComboBoxBody>\n );\n }, [\n browser?.name,\n direction,\n handleSetSelectedItem,\n height,\n isAnimating,\n list,\n maxHeight,\n minWidth,\n selectedItem,\n shouldShowRoundImage,\n ]);\n\n return useMemo(\n () => (\n <StyledComboBox ref={ref}>\n {direction === ComboBoxDirection.TOP && comboBoxBody}\n <StyledComboBoxHeader\n $direction={direction}\n $minWidth={minWidth}\n onClick={handleHeaderClick}\n $isOpen={isAnimating}\n $isMobile={isMobile}\n $isDisabled={isDisabled}\n >\n <StyledComboBoxPlaceholder>\n {placeholderImageUrl && (\n <StyledComboBoxPlaceholderImage\n src={placeholderImageUrl}\n shouldShowRoundImage={shouldShowRoundImage}\n />\n )}\n {placeholderText}\n </StyledComboBoxPlaceholder>\n <StyledComboBoxIconWrapper>\n <Icon icons={['fa fa-chevron-down']} />\n </StyledComboBoxIconWrapper>\n </StyledComboBoxHeader>\n {direction === ComboBoxDirection.BOTTOM && comboBoxBody}\n </StyledComboBox>\n ),\n [\n comboBoxBody,\n direction,\n handleHeaderClick,\n isAnimating,\n isDisabled,\n isMobile,\n minWidth,\n placeholderImageUrl,\n placeholderText,\n shouldShowRoundImage,\n ],\n );\n};\n\nComboBox.displayName = 'ComboBox';\n\nexport default ComboBox;\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,YAAY;AACtC,OAAOC,KAAK,IAERC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QAGL,OAAO;AACd,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,sBAAsB,EAAEC,qBAAqB,QAAQ,uBAAuB;AACrF,OAAOC,IAAI,MAAM,cAAc;AAC/B,OAAOC,YAAY,MAAM,8BAA8B;AACvD,SACIC,cAAc,EACdC,oBAAoB,EACpBC,yBAAyB,EACzBC,yBAAyB,EACzBC,8BAA8B,EAC9BC,wBAAwB,QACrB,mBAAmB;AA4C1B,MAAMC,QAA2B,GAAGC,IAAA,IAS9B;EAAA,IAT+B;IACjCC,SAAS,GAAGb,iBAAiB,CAACc,MAAM;IACpCC,UAAU,GAAG,KAAK;IAClBC,IAAI;IACJC,SAAS,GAAG,OAAO;IACnBC,QAAQ;IACRC,WAAW;IACXC,YAAY;IACZC;EACJ,CAAC,GAAAT,IAAA;EACG,MAAM,CAACU,IAAI,EAAEC,OAAO,CAAC,GAAGxB,QAAQ,CAAgB,CAAC;EACjD,MAAM,CAACyB,WAAW,EAAEC,cAAc,CAAC,GAAG1B,QAAQ,CAAC,KAAK,CAAC;EACrD,MAAM,CAAC2B,QAAQ,EAAEC,WAAW,CAAC,GAAG5B,QAAQ,CAAC,CAAC,CAAC;EAC3C,MAAM,CAAC6B,MAAM,EAAEC,SAAS,CAAC,GAAG9B,QAAQ,CAAC,CAAC,CAAC;EAEvC,MAAM+B,GAAG,GAAGhC,MAAM,CAAiB,IAAI,CAAC;EAExC,MAAM;IAAEiC;EAAQ,CAAC,GAAGtC,SAAS,CAAC,CAAC;EAE/B,MAAM;IAAEuC;EAAS,CAAC,GAAGC,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
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@babel/preset-env": "^7.23.9",
|
|
46
46
|
"@babel/preset-react": "^7.23.3",
|
|
47
47
|
"@babel/preset-typescript": "^7.23.3",
|
|
48
|
-
"@types/react": "^18.2.
|
|
48
|
+
"@types/react": "^18.2.60",
|
|
49
49
|
"@types/react-dom": "^18.2.19",
|
|
50
50
|
"@types/styled-components": "^5.1.34",
|
|
51
51
|
"@types/uuid": "^9.0.8",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"publishConfig": {
|
|
74
74
|
"access": "public"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "6840671c95ab92f3f23b682ef0ec54fd9067a139"
|
|
77
77
|
}
|