@chayns-components/core 5.0.0-beta.396 → 5.0.0-beta.398
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/lib/components/accordion/Accordion.js +11 -5
- package/lib/components/accordion/Accordion.js.map +1 -1
- package/lib/components/combobox/ComboBox.styles.js +8 -13
- package/lib/components/combobox/ComboBox.styles.js.map +1 -1
- package/lib/components/combobox/combobox-item/ComboBoxItem.styles.js +3 -2
- package/lib/components/combobox/combobox-item/ComboBoxItem.styles.js.map +1 -1
- package/lib/components/search-box/SearchBox.d.ts +4 -0
- package/lib/components/search-box/SearchBox.js +72 -5
- package/lib/components/search-box/SearchBox.js.map +1 -1
- package/lib/components/search-box/search-box-item/SearchBoxItem.js +2 -1
- package/lib/components/search-box/search-box-item/SearchBoxItem.js.map +1 -1
- package/lib/components/search-box/search-box-item/SearchBoxItem.styles.js +11 -2
- package/lib/components/search-box/search-box-item/SearchBoxItem.styles.js.map +1 -1
- package/package.json +8 -8
|
@@ -53,6 +53,12 @@ const Accordion = _ref => {
|
|
|
53
53
|
const isInitialRenderRef = (0, _react.useRef)(true);
|
|
54
54
|
const isInGroup = typeof updateOpenAccordionUuid === 'function';
|
|
55
55
|
const isOpen = isInGroup ? openAccordionUuid === uuid : isAccordionOpen;
|
|
56
|
+
const onCloseRef = (0, _react.useRef)(onClose);
|
|
57
|
+
const onOpenRef = (0, _react.useRef)(onOpen);
|
|
58
|
+
(0, _react.useEffect)(() => {
|
|
59
|
+
onCloseRef.current = onClose;
|
|
60
|
+
onOpenRef.current = onOpen;
|
|
61
|
+
}, [onClose, onOpen]);
|
|
56
62
|
const handleHeadClick = (0, _react.useCallback)(() => {
|
|
57
63
|
if (isDisabled) {
|
|
58
64
|
return;
|
|
@@ -74,13 +80,13 @@ const Accordion = _ref => {
|
|
|
74
80
|
if (isInitialRenderRef.current) {
|
|
75
81
|
isInitialRenderRef.current = false;
|
|
76
82
|
} else if (isOpen) {
|
|
77
|
-
if (typeof
|
|
78
|
-
|
|
83
|
+
if (typeof onOpenRef.current === 'function') {
|
|
84
|
+
onOpenRef.current();
|
|
79
85
|
}
|
|
80
|
-
} else if (typeof
|
|
81
|
-
|
|
86
|
+
} else if (typeof onCloseRef.current === 'function') {
|
|
87
|
+
onCloseRef.current();
|
|
82
88
|
}
|
|
83
|
-
}, [isOpen
|
|
89
|
+
}, [isOpen]);
|
|
84
90
|
(0, _react.useEffect)(() => {
|
|
85
91
|
if (isDefaultOpen) {
|
|
86
92
|
if (typeof updateOpenAccordionUuid === 'function') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Accordion.js","names":["_framerMotion","require","_react","_interopRequireWildcard","_uuid","_AccordionBody","_interopRequireDefault","_AccordionGroup","_AccordionHead","_Accordion","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","AccordionContext","exports","React","createContext","isWrapped","Accordion","_ref","bodyMaxHeight","children","icon","isDefaultOpen","isDisabled","isFixed","isOpened","isTitleGreyed","onBodyScroll","onClose","onOpen","onSearchChange","rightElement","searchIcon","searchPlaceholder","shouldForceBackground","shouldHideBackground","title","titleElement","shouldRenderClosed","openAccordionUuid","updateOpenAccordionUuid","useContext","AccordionGroupContext","isParentWrapped","isAccordionOpen","setIsAccordionOpen","useState","uuid","useUuid","isInitialRenderRef","useRef","isInGroup","isOpen","handleHeadClick","useCallback","currentIsAccordionOpen","useEffect","current","shouldOnlyOpen","accordionContextProviderValue","useMemo","createElement","StyledAccordion","className","Provider","value","MotionConfig","transition","type","onClick","AnimatePresence","initial","maxHeight","onScroll","shouldHideBody","displayName","_default"],"sources":["../../../src/components/accordion/Accordion.tsx"],"sourcesContent":["import { AnimatePresence, MotionConfig } from 'framer-motion';\nimport React, {\n ChangeEventHandler,\n FC,\n ReactNode,\n UIEvent,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useUuid } from '../../hooks/uuid';\nimport AccordionBody from './accordion-body/AccordionBody';\nimport { AccordionGroupContext } from './accordion-group/AccordionGroup';\nimport AccordionHead from './accordion-head/AccordionHead';\nimport { StyledAccordion } from './Accordion.styles';\n\nexport const AccordionContext = React.createContext({ isWrapped: false });\n\nexport type AccordionProps = {\n /**\n * Maximum height of the accordion body element. This automatically makes the content of the\n * body element scrollable.\n */\n bodyMaxHeight?: number;\n /**\n * The content of the accordion body\n */\n children: ReactNode;\n /**\n * The icon that is displayed in front of the title\n */\n icon?: string;\n /**\n * This can be used to automatically expand the Accordion during the first render.\n */\n isDefaultOpen?: boolean;\n /**\n * This will disable the Accordion so that it cannot be opened and will gray out the title. Does not work with isOpened.\n */\n isDisabled?: boolean;\n /**\n * This can be used so that the Accordion cannot be opened or closed.\n * In addition, in this case the icon is exchanged to mark the Accordions.\n */\n isFixed?: boolean;\n /**\n * This can be used to open the Accordion from the outside.\n */\n isOpened?: boolean;\n /**\n * This will gray out the title of the Accordion to indicate hidden content, for example.\n */\n isTitleGreyed?: boolean;\n /**\n * This value must be set for nested Accordions. This adjusts the style of\n * the head and the padding of the content.\n */\n isWrapped?: boolean;\n /**\n * Function that is executed when the accordion body will be scrolled\n */\n onBodyScroll?: (event: UIEvent<HTMLDivElement>) => void;\n /**\n * Function that is executed when the accordion will be closed.\n */\n onClose?: VoidFunction;\n /**\n * Function that is executed when the accordion will be opened.\n */\n onOpen?: VoidFunction;\n /**\n * Function that is executed when the text of the search in the accordion\n * head changes. When this function is given, the search field is displayed\n * in the Accordion Head.\n */\n onSearchChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Content to be displayed on the right side in the head of the Accordion\n */\n rightElement?: ReactNode;\n /**\n * Icon to be displayed on the right side in the search input\n */\n searchIcon?: string[];\n /**\n * The placeholder to be used for the search\n */\n searchPlaceholder?: string;\n /**\n * This will force the background color of the accordion to be used even if it is closed and not hovered.\n */\n shouldForceBackground?: boolean;\n /**\n * This will hide the background color of the accordion\n */\n shouldHideBackground?: boolean;\n /**\n * Title of the Accordion displayed in the head\n */\n title: string;\n /**\n * Additional elements to be displayed in the header next to the title.\n */\n titleElement?: ReactNode;\n /**\n * This will render the Accordion closed on the first render.\n */\n shouldRenderClosed?: boolean;\n};\n\nconst Accordion: FC<AccordionProps> = ({\n bodyMaxHeight,\n children,\n icon,\n isDefaultOpen = false,\n isDisabled = false,\n isFixed = false,\n isOpened,\n isTitleGreyed = false,\n isWrapped = false,\n onBodyScroll,\n onClose,\n onOpen,\n onSearchChange,\n rightElement,\n searchIcon,\n searchPlaceholder,\n shouldForceBackground = false,\n shouldHideBackground = false,\n title,\n titleElement,\n shouldRenderClosed = false,\n}) => {\n const { openAccordionUuid, updateOpenAccordionUuid } = useContext(AccordionGroupContext);\n const { isWrapped: isParentWrapped } = useContext(AccordionContext);\n\n const [isAccordionOpen, setIsAccordionOpen] = useState<boolean>(isDefaultOpen ?? isOpened);\n\n const uuid = useUuid();\n\n const isInitialRenderRef = useRef(true);\n\n const isInGroup = typeof updateOpenAccordionUuid === 'function';\n\n const isOpen = isInGroup ? openAccordionUuid === uuid : isAccordionOpen;\n\n const handleHeadClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid);\n }\n\n setIsAccordionOpen((currentIsAccordionOpen) => !currentIsAccordionOpen);\n }, [isDisabled, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (isDisabled && isOpen) {\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid);\n }\n\n setIsAccordionOpen((currentIsAccordionOpen) => !currentIsAccordionOpen);\n }\n }, [isDisabled, isOpen, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (isInitialRenderRef.current) {\n isInitialRenderRef.current = false;\n } else if (isOpen) {\n if (typeof onOpen === 'function') {\n onOpen();\n }\n } else if (typeof onClose === 'function') {\n onClose();\n }\n }, [isOpen, onClose, onOpen]);\n\n useEffect(() => {\n if (isDefaultOpen) {\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid, { shouldOnlyOpen: true });\n } else {\n setIsAccordionOpen(true);\n }\n }\n }, [isDefaultOpen, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (typeof isOpened === 'boolean') {\n if (typeof updateOpenAccordionUuid === 'function' && isOpened) {\n updateOpenAccordionUuid(uuid);\n } else {\n setIsAccordionOpen(isOpened);\n }\n }\n }, [isOpened, updateOpenAccordionUuid, uuid]);\n\n const accordionContextProviderValue = useMemo(() => ({ isWrapped }), [isWrapped]);\n\n return (\n <StyledAccordion\n className=\"beta-chayns-accordion\"\n isOpen={isOpen}\n isParentWrapped={isParentWrapped}\n isWrapped={isWrapped}\n shouldForceBackground={shouldForceBackground}\n shouldHideBackground={shouldHideBackground}\n >\n <AccordionContext.Provider value={accordionContextProviderValue}>\n <MotionConfig transition={{ type: 'tween' }}>\n <AccordionHead\n icon={icon}\n isOpen={isOpen}\n isFixed={isFixed}\n isTitleGreyed={isTitleGreyed || isDisabled}\n isWrapped={isWrapped}\n onClick={handleHeadClick}\n onSearchChange={onSearchChange}\n rightElement={rightElement}\n searchIcon={searchIcon}\n searchPlaceholder={searchPlaceholder}\n title={title}\n titleElement={titleElement}\n />\n <AnimatePresence initial={false}>\n {(isOpen || shouldRenderClosed) && (\n <AccordionBody\n maxHeight={bodyMaxHeight}\n onScroll={onBodyScroll}\n shouldHideBody={shouldRenderClosed && !isOpen}\n >\n {children}\n </AccordionBody>\n )}\n </AnimatePresence>\n </MotionConfig>\n </AccordionContext.Provider>\n </StyledAccordion>\n );\n};\n\nAccordion.displayName = 'Accordion';\n\nexport default Accordion;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAYA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,c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,cAAc,EAAEA,cAAe;IAC/BC,YAAY,EAAEA,YAAa;IAC3BC,UAAU,EAAEA,UAAW;IACvBC,iBAAiB,EAAEA,iBAAkB;IACrCG,KAAK,EAAEA,KAAM;IACbC,YAAY,EAAEA;EAAa,CAC9B,CAAC,eACFvD,MAAA,CAAAU,OAAA,CAAAqE,aAAA,CAACjF,aAAA,CAAA0F,eAAe;IAACC,OAAO,EAAE;EAAM,GAC3B,CAACnB,MAAM,IAAId,kBAAkB,kBAC1BxD,MAAA,CAAAU,OAAA,CAAAqE,aAAA,CAAC5E,cAAA,CAAAO,OAAa;IACVgF,SAAS,EAAErD,aAAc;IACzBsD,QAAQ,EAAE9C,YAAa;IACvB+C,cAAc,EAAEpC,kBAAkB,IAAI,CAACc;EAAO,GAE7ChC,QACU,CAEN,CACP,CACS,CACd,CAAC;AAE1B,CAAC;AAEDH,SAAS,CAAC0D,WAAW,GAAG,WAAW;AAAC,IAAAC,QAAA,GAAA/D,OAAA,CAAArB,OAAA,GAErByB,SAAS"}
|
|
1
|
+
{"version":3,"file":"Accordion.js","names":["_framerMotion","require","_react","_interopRequireWildcard","_uuid","_AccordionBody","_interopRequireDefault","_AccordionGroup","_AccordionHead","_Accordion","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","AccordionContext","exports","React","createContext","isWrapped","Accordion","_ref","bodyMaxHeight","children","icon","isDefaultOpen","isDisabled","isFixed","isOpened","isTitleGreyed","onBodyScroll","onClose","onOpen","onSearchChange","rightElement","searchIcon","searchPlaceholder","shouldForceBackground","shouldHideBackground","title","titleElement","shouldRenderClosed","openAccordionUuid","updateOpenAccordionUuid","useContext","AccordionGroupContext","isParentWrapped","isAccordionOpen","setIsAccordionOpen","useState","uuid","useUuid","isInitialRenderRef","useRef","isInGroup","isOpen","onCloseRef","onOpenRef","useEffect","current","handleHeadClick","useCallback","currentIsAccordionOpen","shouldOnlyOpen","accordionContextProviderValue","useMemo","createElement","StyledAccordion","className","Provider","value","MotionConfig","transition","type","onClick","AnimatePresence","initial","maxHeight","onScroll","shouldHideBody","displayName","_default"],"sources":["../../../src/components/accordion/Accordion.tsx"],"sourcesContent":["import { AnimatePresence, MotionConfig } from 'framer-motion';\nimport React, {\n ChangeEventHandler,\n FC,\n ReactNode,\n UIEvent,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useUuid } from '../../hooks/uuid';\nimport AccordionBody from './accordion-body/AccordionBody';\nimport { AccordionGroupContext } from './accordion-group/AccordionGroup';\nimport AccordionHead from './accordion-head/AccordionHead';\nimport { StyledAccordion } from './Accordion.styles';\n\nexport const AccordionContext = React.createContext({ isWrapped: false });\n\nexport type AccordionProps = {\n /**\n * Maximum height of the accordion body element. This automatically makes the content of the\n * body element scrollable.\n */\n bodyMaxHeight?: number;\n /**\n * The content of the accordion body\n */\n children: ReactNode;\n /**\n * The icon that is displayed in front of the title\n */\n icon?: string;\n /**\n * This can be used to automatically expand the Accordion during the first render.\n */\n isDefaultOpen?: boolean;\n /**\n * This will disable the Accordion so that it cannot be opened and will gray out the title. Does not work with isOpened.\n */\n isDisabled?: boolean;\n /**\n * This can be used so that the Accordion cannot be opened or closed.\n * In addition, in this case the icon is exchanged to mark the Accordions.\n */\n isFixed?: boolean;\n /**\n * This can be used to open the Accordion from the outside.\n */\n isOpened?: boolean;\n /**\n * This will gray out the title of the Accordion to indicate hidden content, for example.\n */\n isTitleGreyed?: boolean;\n /**\n * This value must be set for nested Accordions. This adjusts the style of\n * the head and the padding of the content.\n */\n isWrapped?: boolean;\n /**\n * Function that is executed when the accordion body will be scrolled\n */\n onBodyScroll?: (event: UIEvent<HTMLDivElement>) => void;\n /**\n * Function that is executed when the accordion will be closed.\n */\n onClose?: VoidFunction;\n /**\n * Function that is executed when the accordion will be opened.\n */\n onOpen?: VoidFunction;\n /**\n * Function that is executed when the text of the search in the accordion\n * head changes. When this function is given, the search field is displayed\n * in the Accordion Head.\n */\n onSearchChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Content to be displayed on the right side in the head of the Accordion\n */\n rightElement?: ReactNode;\n /**\n * Icon to be displayed on the right side in the search input\n */\n searchIcon?: string[];\n /**\n * The placeholder to be used for the search\n */\n searchPlaceholder?: string;\n /**\n * This will force the background color of the accordion to be used even if it is closed and not hovered.\n */\n shouldForceBackground?: boolean;\n /**\n * This will hide the background color of the accordion\n */\n shouldHideBackground?: boolean;\n /**\n * Title of the Accordion displayed in the head\n */\n title: string;\n /**\n * Additional elements to be displayed in the header next to the title.\n */\n titleElement?: ReactNode;\n /**\n * This will render the Accordion closed on the first render.\n */\n shouldRenderClosed?: boolean;\n};\n\nconst Accordion: FC<AccordionProps> = ({\n bodyMaxHeight,\n children,\n icon,\n isDefaultOpen = false,\n isDisabled = false,\n isFixed = false,\n isOpened,\n isTitleGreyed = false,\n isWrapped = false,\n onBodyScroll,\n onClose,\n onOpen,\n onSearchChange,\n rightElement,\n searchIcon,\n searchPlaceholder,\n shouldForceBackground = false,\n shouldHideBackground = false,\n title,\n titleElement,\n shouldRenderClosed = false,\n}) => {\n const { openAccordionUuid, updateOpenAccordionUuid } = useContext(AccordionGroupContext);\n const { isWrapped: isParentWrapped } = useContext(AccordionContext);\n\n const [isAccordionOpen, setIsAccordionOpen] = useState<boolean>(isDefaultOpen ?? isOpened);\n\n const uuid = useUuid();\n\n const isInitialRenderRef = useRef(true);\n\n const isInGroup = typeof updateOpenAccordionUuid === 'function';\n\n const isOpen = isInGroup ? openAccordionUuid === uuid : isAccordionOpen;\n\n const onCloseRef = useRef(onClose);\n const onOpenRef = useRef(onOpen);\n\n useEffect(() => {\n onCloseRef.current = onClose;\n onOpenRef.current = onOpen;\n }, [onClose, onOpen]);\n\n const handleHeadClick = useCallback(() => {\n if (isDisabled) {\n return;\n }\n\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid);\n }\n\n setIsAccordionOpen((currentIsAccordionOpen) => !currentIsAccordionOpen);\n }, [isDisabled, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (isDisabled && isOpen) {\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid);\n }\n\n setIsAccordionOpen((currentIsAccordionOpen) => !currentIsAccordionOpen);\n }\n }, [isDisabled, isOpen, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (isInitialRenderRef.current) {\n isInitialRenderRef.current = false;\n } else if (isOpen) {\n if (typeof onOpenRef.current === 'function') {\n onOpenRef.current();\n }\n } else if (typeof onCloseRef.current === 'function') {\n onCloseRef.current();\n }\n }, [isOpen]);\n\n useEffect(() => {\n if (isDefaultOpen) {\n if (typeof updateOpenAccordionUuid === 'function') {\n updateOpenAccordionUuid(uuid, { shouldOnlyOpen: true });\n } else {\n setIsAccordionOpen(true);\n }\n }\n }, [isDefaultOpen, updateOpenAccordionUuid, uuid]);\n\n useEffect(() => {\n if (typeof isOpened === 'boolean') {\n if (typeof updateOpenAccordionUuid === 'function' && isOpened) {\n updateOpenAccordionUuid(uuid);\n } else {\n setIsAccordionOpen(isOpened);\n }\n }\n }, [isOpened, updateOpenAccordionUuid, uuid]);\n\n const accordionContextProviderValue = useMemo(() => ({ isWrapped }), [isWrapped]);\n\n return (\n <StyledAccordion\n className=\"beta-chayns-accordion\"\n isOpen={isOpen}\n isParentWrapped={isParentWrapped}\n isWrapped={isWrapped}\n shouldForceBackground={shouldForceBackground}\n shouldHideBackground={shouldHideBackground}\n >\n <AccordionContext.Provider value={accordionContextProviderValue}>\n <MotionConfig transition={{ type: 'tween' }}>\n <AccordionHead\n icon={icon}\n isOpen={isOpen}\n isFixed={isFixed}\n isTitleGreyed={isTitleGreyed || isDisabled}\n isWrapped={isWrapped}\n onClick={handleHeadClick}\n onSearchChange={onSearchChange}\n rightElement={rightElement}\n searchIcon={searchIcon}\n searchPlaceholder={searchPlaceholder}\n title={title}\n titleElement={titleElement}\n />\n <AnimatePresence initial={false}>\n {(isOpen || shouldRenderClosed) && (\n <AccordionBody\n maxHeight={bodyMaxHeight}\n onScroll={onBodyScroll}\n shouldHideBody={shouldRenderClosed && !isOpen}\n >\n {children}\n </AccordionBody>\n )}\n </AnimatePresence>\n </MotionConfig>\n </AccordionContext.Provider>\n </StyledAccordion>\n );\n};\n\nAccordion.displayName = 'Accordion';\n\nexport default Accordion;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAYA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAF,sBAAA,CAAAL,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AAAqD,SAAAK,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAX,wBAAAW,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,GAAA,CAAAJ,CAAA,UAAAG,CAAA,CAAAE,GAAA,CAAAL,CAAA,OAAAM,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAA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AC;AAE1B,CAAC;AAEDH,SAAS,CAAC4D,WAAW,GAAG,WAAW;AAAC,IAAAC,QAAA,GAAAjE,OAAA,CAAArB,OAAA,GAErByB,SAAS"}
|
|
@@ -48,6 +48,7 @@ const StyledComboBoxHeader = exports.StyledComboBoxHeader = _styledComponents.de
|
|
|
48
48
|
} = _ref5;
|
|
49
49
|
return minWidth;
|
|
50
50
|
}}px;
|
|
51
|
+
transition: background-color 0.2s ease-in-out;
|
|
51
52
|
|
|
52
53
|
${_ref6 => {
|
|
53
54
|
let {
|
|
@@ -76,7 +77,7 @@ const StyledComboBoxHeader = exports.StyledComboBoxHeader = _styledComponents.de
|
|
|
76
77
|
} = _ref7;
|
|
77
78
|
return !isMobile && !isDisabled && (0, _styledComponents.css)`
|
|
78
79
|
&:hover {
|
|
79
|
-
background-color: ${theme['secondary-
|
|
80
|
+
background-color: ${theme['secondary-102']};
|
|
80
81
|
}
|
|
81
82
|
`;
|
|
82
83
|
}}
|
|
@@ -120,7 +121,7 @@ const StyledMotionComboBoxBody = exports.StyledMotionComboBoxBody = (0, _styledC
|
|
|
120
121
|
let {
|
|
121
122
|
theme
|
|
122
123
|
} = _ref11;
|
|
123
|
-
return theme['
|
|
124
|
+
return theme['101'];
|
|
124
125
|
}};
|
|
125
126
|
display: flex;
|
|
126
127
|
position: absolute;
|
|
@@ -152,29 +153,23 @@ const StyledMotionComboBoxBody = exports.StyledMotionComboBoxBody = (0, _styledC
|
|
|
152
153
|
} = _ref15;
|
|
153
154
|
return height <= 300 ? 'hidden' : 'auto';
|
|
154
155
|
}};
|
|
155
|
-
|
|
156
|
+
|
|
157
|
+
${_ref16 => {
|
|
156
158
|
let {
|
|
159
|
+
direction,
|
|
157
160
|
theme
|
|
158
161
|
} = _ref16;
|
|
159
|
-
return theme['009-rgb'];
|
|
160
|
-
}}, 0.08)
|
|
161
|
-
inset;
|
|
162
|
-
|
|
163
|
-
${_ref17 => {
|
|
164
|
-
let {
|
|
165
|
-
direction
|
|
166
|
-
} = _ref17;
|
|
167
162
|
if (direction === _comboBox.ComboBoxDirection.BOTTOM) {
|
|
168
163
|
return (0, _styledComponents.css)`
|
|
169
164
|
border-bottom-left-radius: 3px;
|
|
170
165
|
border-bottom-right-radius: 3px;
|
|
171
|
-
|
|
166
|
+
box-shadow: 0 2px 8px 2px rgba(${theme['009-rgb']}, 0.15);
|
|
172
167
|
`;
|
|
173
168
|
}
|
|
174
169
|
return (0, _styledComponents.css)`
|
|
175
170
|
border-top-left-radius: 3px;
|
|
176
171
|
border-top-right-radius: 3px;
|
|
177
|
-
|
|
172
|
+
box-shadow: 0 -2px 8px 2px rgba(${theme['009-rgb']}, 0.15);
|
|
178
173
|
`;
|
|
179
174
|
}}
|
|
180
175
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboBox.styles.js","names":["_framerMotion","require","_styledComponents","_interopRequireWildcard","_comboBox","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","StyledComboBox","exports","styled","div","StyledComboBoxHeader","_ref","isDisabled","_ref2","theme","_ref3","_ref4","minWidth","_ref5","_ref6","isOpen","direction","ComboBoxDirection","BOTTOM","css","_ref7","isMobile","StyledComboBoxPlaceholder","_ref8","text","StyledComboBoxPlaceholderImage","img","_ref9","_ref10","shouldShowRoundImage","StyledComboBoxIconWrapper","StyledMotionComboBoxBody","motion","_ref11","_ref12","_ref13","_ref14","maxHeight","_ref15","height","_ref16"
|
|
1
|
+
{"version":3,"file":"ComboBox.styles.js","names":["_framerMotion","require","_styledComponents","_interopRequireWildcard","_comboBox","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","StyledComboBox","exports","styled","div","StyledComboBoxHeader","_ref","isDisabled","_ref2","theme","_ref3","_ref4","minWidth","_ref5","_ref6","isOpen","direction","ComboBoxDirection","BOTTOM","css","_ref7","isMobile","StyledComboBoxPlaceholder","_ref8","text","StyledComboBoxPlaceholderImage","img","_ref9","_ref10","shouldShowRoundImage","StyledComboBoxIconWrapper","StyledMotionComboBoxBody","motion","_ref11","_ref12","_ref13","_ref14","maxHeight","_ref15","height","_ref16"],"sources":["../../../src/components/combobox/ComboBox.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport type { CSSProperties } from 'react';\nimport styled, { css } from 'styled-components';\nimport { ComboBoxDirection } from '../../types/comboBox';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\nimport type { ComboBoxItemProps } from './combobox-item/ComboBoxItem';\n\nexport const StyledComboBox = styled.div`\n user-select: none;\n width: fit-content;\n`;\n\ntype StyledComboBoxHeaderProps = WithTheme<{\n isMobile: boolean;\n isOpen: boolean;\n minWidth: number;\n direction: ComboBoxDirection;\n isDisabled?: boolean;\n}>;\n\nexport const StyledComboBoxHeader = styled.div<StyledComboBoxHeaderProps>`\n display: flex;\n justify-content: space-between;\n border: 1px solid rgba(160, 160, 160, 0.3);\n padding: 4px 10px;\n cursor: ${({ isDisabled }) => (!isDisabled ? 'pointer' : 'not-allowed')};\n background: ${({ theme }: StyledComboBoxHeaderProps) => theme['001']};\n opacity: ${({ isDisabled }) => (isDisabled ? 0.5 : 1)};\n min-width: ${({ minWidth }) => minWidth}px;\n max-width: ${({ minWidth }) => minWidth}px;\n transition: background-color 0.2s ease-in-out;\n\n ${({ isOpen, direction }) => {\n if (isOpen) {\n return direction === ComboBoxDirection.BOTTOM\n ? css`\n border-top-left-radius: 3px;\n border-top-right-radius: 3px;\n `\n : css`\n border-bottom-left-radius: 3px;\n border-bottom-right-radius: 3px;\n `;\n }\n\n return css`\n border-radius: 3px;\n `;\n }}\n\n ${({ isMobile, isDisabled, theme }: StyledComboBoxHeaderProps) =>\n !isMobile &&\n !isDisabled &&\n css`\n &:hover {\n background-color: ${theme['secondary-102']};\n }\n `}\n`;\n\ntype StyledComboBoxPlaceholderProps = WithTheme<unknown>;\n\nexport const StyledComboBoxPlaceholder = styled.div<StyledComboBoxPlaceholderProps>`\n align-items: center;\n color: ${({ theme }: StyledComboBoxPlaceholderProps) => theme.text};\n display: flex;\n gap: 10px;\n`;\n\ntype StyledComboBoxPlaceholderImageProps = WithTheme<\n Pick<ComboBoxItemProps, 'shouldShowRoundImage'>\n>;\n\nexport const StyledComboBoxPlaceholderImage = styled.img<StyledComboBoxPlaceholderImageProps>`\n box-shadow: 0 0 0 1px\n rgba(${({ theme }: StyledComboBoxPlaceholderImageProps) => theme['009-rgb']}, 0.15);\n height: 22px;\n width: 22px;\n\n ${({ shouldShowRoundImage }) =>\n shouldShowRoundImage &&\n css`\n border-radius: 50%;\n `}\n`;\n\nexport const StyledComboBoxIconWrapper = styled.div`\n margin-left: 5px;\n`;\n\ntype StyledComboBoxBodyProps = WithTheme<{\n height: number;\n minWidth: number;\n maxHeight: CSSProperties['maxHeight'];\n direction: ComboBoxDirection;\n}>;\n\nexport const StyledMotionComboBoxBody = styled(motion.div)<StyledComboBoxBodyProps>`\n background: ${({ theme }: StyledComboBoxBodyProps) => theme['101']};\n display: flex;\n position: absolute;\n z-index: 4;\n flex-direction: column;\n border: 1px solid rgba(160, 160, 160, 0.3);\n cursor: pointer;\n min-width: ${({ minWidth }) => minWidth}px;\n max-width: ${({ minWidth }) => minWidth}px;\n max-height: ${({ maxHeight }) => maxHeight};\n overflow-y: ${({ height }) => (height <= 300 ? 'hidden' : 'auto')};\n\n ${({ direction, theme }) => {\n if (direction === ComboBoxDirection.BOTTOM) {\n return css`\n border-bottom-left-radius: 3px;\n border-bottom-right-radius: 3px;\n box-shadow: 0 2px 8px 2px rgba(${theme['009-rgb']}, 0.15);\n `;\n }\n\n return css`\n border-top-left-radius: 3px;\n border-top-right-radius: 3px;\n box-shadow: 0 -2px 8px 2px rgba(${theme['009-rgb']}, 0.15);\n `;\n }}\n\n &::-webkit-scrollbar {\n width: 5px;\n }\n\n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C;IAAEvB;EAAS,CAAC,GAAAuB,MAAA;EAAA,OAAKvB,QAAQ;AAAA,CAAC;AAC5C,kBAAkBwB,MAAA;EAAA,IAAC;IAAEC;EAAU,CAAC,GAAAD,MAAA;EAAA,OAAKC,SAAS;AAAA,CAAC;AAC/C,kBAAkBC,MAAA;EAAA,IAAC;IAAEC;EAAO,CAAC,GAAAD,MAAA;EAAA,OAAMC,MAAM,IAAI,GAAG,GAAG,QAAQ,GAAG,MAAM;AAAA,CAAE;AACtE;AACA,MAAMC,MAAA,IAA0B;EAAA,IAAzB;IAAExB,SAAS;IAAEP;EAAM,CAAC,GAAA+B,MAAA;EACnB,IAAIxB,SAAS,KAAKC,2BAAiB,CAACC,MAAM,EAAE;IACxC,OAAO,IAAAC,qBAAG,CAAC;AACvB;AACA;AACA,iDAAiDV,KAAK,CAAC,SAAS,CAAE;AAClE,aAAa;EACL;EAEA,OAAO,IAAAU,qBAAG,CAAC;AACnB;AACA;AACA,8CAA8CV,KAAK,CAAC,SAAS,CAAE;AAC/D,SAAS;AACL,CAAE;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC"}
|
|
@@ -14,7 +14,7 @@ const StyledComboBoxItem = exports.StyledComboBoxItem = _styledComponents.defaul
|
|
|
14
14
|
theme,
|
|
15
15
|
isSelected
|
|
16
16
|
} = _ref;
|
|
17
|
-
return isSelected && theme['secondary-
|
|
17
|
+
return isSelected && theme['secondary-103'];
|
|
18
18
|
}};
|
|
19
19
|
color: ${_ref2 => {
|
|
20
20
|
let {
|
|
@@ -25,6 +25,7 @@ const StyledComboBoxItem = exports.StyledComboBoxItem = _styledComponents.defaul
|
|
|
25
25
|
display: flex;
|
|
26
26
|
gap: 10px;
|
|
27
27
|
padding: 4px 10px;
|
|
28
|
+
transition: background-color 0.2s ease-in-out;
|
|
28
29
|
|
|
29
30
|
${_ref3 => {
|
|
30
31
|
let {
|
|
@@ -33,7 +34,7 @@ const StyledComboBoxItem = exports.StyledComboBoxItem = _styledComponents.defaul
|
|
|
33
34
|
} = _ref3;
|
|
34
35
|
return !isMobile && (0, _styledComponents.css)`
|
|
35
36
|
&:hover {
|
|
36
|
-
background-color: ${theme['secondary-
|
|
37
|
+
background-color: ${theme['secondary-102']};
|
|
37
38
|
}
|
|
38
39
|
`;
|
|
39
40
|
}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboBoxItem.styles.js","names":["_styledComponents","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","StyledComboBoxItem","exports","styled","div","_ref","theme","isSelected","_ref2","text","_ref3","isMobile","css","StyledComboBoxItemImage","img","_ref4","_ref5","shouldShowRoundImage"],"sources":["../../../../src/components/combobox/combobox-item/ComboBoxItem.styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport type { WithTheme } from '../../color-scheme-provider/ColorSchemeProvider';\nimport type { ComboBoxItemProps } from './ComboBoxItem';\n\ntype StyledComboBoxItemProps = WithTheme<{\n isMobile: boolean;\n isSelected: boolean;\n}>;\n\nexport const StyledComboBoxItem = styled.div<StyledComboBoxItemProps>`\n align-items: center;\n background-color: ${({ theme, isSelected }: StyledComboBoxItemProps) =>\n isSelected && theme['secondary-
|
|
1
|
+
{"version":3,"file":"ComboBoxItem.styles.js","names":["_styledComponents","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","StyledComboBoxItem","exports","styled","div","_ref","theme","isSelected","_ref2","text","_ref3","isMobile","css","StyledComboBoxItemImage","img","_ref4","_ref5","shouldShowRoundImage"],"sources":["../../../../src/components/combobox/combobox-item/ComboBoxItem.styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport type { WithTheme } from '../../color-scheme-provider/ColorSchemeProvider';\nimport type { ComboBoxItemProps } from './ComboBoxItem';\n\ntype StyledComboBoxItemProps = WithTheme<{\n isMobile: boolean;\n isSelected: boolean;\n}>;\n\nexport const StyledComboBoxItem = styled.div<StyledComboBoxItemProps>`\n align-items: center;\n background-color: ${({ theme, isSelected }: StyledComboBoxItemProps) =>\n isSelected && theme['secondary-103']};\n color: ${({ theme }: StyledComboBoxItemProps) => theme.text};\n display: flex;\n gap: 10px;\n padding: 4px 10px;\n transition: background-color 0.2s ease-in-out;\n\n ${({ isMobile, theme }: StyledComboBoxItemProps) =>\n !isMobile &&\n css`\n &:hover {\n background-color: ${theme['secondary-102']};\n }\n `}\n`;\n\ntype StyledComboBoxItemImageProps = WithTheme<Pick<ComboBoxItemProps, 'shouldShowRoundImage'>>;\n\nexport const StyledComboBoxItemImage = styled.img<StyledComboBoxItemImageProps>`\n box-shadow: 0 0 0 1px\n rgba(${({ theme }: StyledComboBoxItemImageProps) => theme['009-rgb']}, 0.15);\n height: 22px;\n width: 22px;\n\n ${({ shouldShowRoundImage }) =>\n shouldShowRoundImage &&\n css`\n border-radius: 50%;\n `}\n`;\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAgD,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,G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A,CAAAW,uBAAA,GAAGV,yBAAM,CAACW,GAAkC;AAChF;AACA,eAAeC,KAAA;EAAA,IAAC;IAAET;EAAoC,CAAC,GAAAS,KAAA;EAAA,OAAKT,KAAK,CAAC,SAAS,CAAC;AAAA,CAAC;AAC7E;AACA;AACA;AACA,MAAMU,KAAA;EAAA,IAAC;IAAEC;EAAqB,CAAC,GAAAD,KAAA;EAAA,OACvBC,oBAAoB,IACpB,IAAAL,qBAAG,CAAC;AACZ;AACA,SAAS;AAAA,CAAC;AACV,CAAC"}
|
|
@@ -25,6 +25,10 @@ export type SearchBoxProps = {
|
|
|
25
25
|
* Control the selected item. If you use this prop, make sure to update it when the user selects an item.
|
|
26
26
|
*/
|
|
27
27
|
selectedId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the full list of items should be displayed if the input is empty.
|
|
30
|
+
*/
|
|
31
|
+
shouldShowContentOnEmptyInput?: boolean;
|
|
28
32
|
};
|
|
29
33
|
declare const SearchBox: FC<SearchBoxProps>;
|
|
30
34
|
export default SearchBox;
|
|
@@ -21,13 +21,15 @@ const SearchBox = _ref => {
|
|
|
21
21
|
onChange,
|
|
22
22
|
onBlur,
|
|
23
23
|
onSelect,
|
|
24
|
-
selectedId
|
|
24
|
+
selectedId,
|
|
25
|
+
shouldShowContentOnEmptyInput = true
|
|
25
26
|
} = _ref;
|
|
26
27
|
const [matchingItems, setMatchingItems] = (0, _react.useState)([]);
|
|
27
28
|
const [value, setValue] = (0, _react.useState)('');
|
|
28
29
|
const [isAnimating, setIsAnimating] = (0, _react.useState)(false);
|
|
29
30
|
const [height, setHeight] = (0, _react.useState)(0);
|
|
30
31
|
const [width, setWidth] = (0, _react.useState)(0);
|
|
32
|
+
const [focusedIndex, setFocusedIndex] = (0, _react.useState)(null);
|
|
31
33
|
const boxRef = (0, _react.useRef)(null);
|
|
32
34
|
const contentRef = (0, _react.useRef)(null);
|
|
33
35
|
const inputRef = (0, _react.useRef)(null);
|
|
@@ -87,6 +89,19 @@ const SearchBox = _ref => {
|
|
|
87
89
|
}
|
|
88
90
|
}, [list, selectedId]);
|
|
89
91
|
|
|
92
|
+
/**
|
|
93
|
+
* This function sets the items on focus if shouldShowContentOnEmptyInput
|
|
94
|
+
*/
|
|
95
|
+
const handleFocus = (0, _react.useCallback)(() => {
|
|
96
|
+
if (shouldShowContentOnEmptyInput) {
|
|
97
|
+
setMatchingItems((0, _utils.searchList)({
|
|
98
|
+
items: list,
|
|
99
|
+
searchString: value
|
|
100
|
+
}));
|
|
101
|
+
setIsAnimating(true);
|
|
102
|
+
}
|
|
103
|
+
}, [list, shouldShowContentOnEmptyInput, value]);
|
|
104
|
+
|
|
90
105
|
/**
|
|
91
106
|
* This function handles changes of the input
|
|
92
107
|
*/
|
|
@@ -95,13 +110,17 @@ const SearchBox = _ref => {
|
|
|
95
110
|
items: list,
|
|
96
111
|
searchString: event.target.value
|
|
97
112
|
});
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
if (!shouldShowContentOnEmptyInput && !event.target.value) {
|
|
114
|
+
setMatchingItems([]);
|
|
115
|
+
} else {
|
|
116
|
+
setMatchingItems(searchedItems);
|
|
117
|
+
setIsAnimating(searchedItems.length !== 0);
|
|
118
|
+
}
|
|
100
119
|
setValue(event.target.value);
|
|
101
120
|
if (typeof onChange === 'function') {
|
|
102
121
|
onChange(event);
|
|
103
122
|
}
|
|
104
|
-
}, [list, onChange]);
|
|
123
|
+
}, [list, onChange, shouldShowContentOnEmptyInput]);
|
|
105
124
|
|
|
106
125
|
/**
|
|
107
126
|
* This function handles the blur event of the input
|
|
@@ -139,6 +158,53 @@ const SearchBox = _ref => {
|
|
|
139
158
|
});
|
|
140
159
|
return items;
|
|
141
160
|
}, [handleSelect, matchingItems]);
|
|
161
|
+
(0, _react.useEffect)(() => {
|
|
162
|
+
const handleKeyDown = e => {
|
|
163
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
164
|
+
e.preventDefault();
|
|
165
|
+
const children = contentRef.current?.children;
|
|
166
|
+
if (children && children.length > 0) {
|
|
167
|
+
const newIndex = focusedIndex !== null ? (focusedIndex + (e.key === 'ArrowUp' ? -1 : 1) + children.length) % children.length : 0;
|
|
168
|
+
if (focusedIndex !== null) {
|
|
169
|
+
const prevElement = children[focusedIndex];
|
|
170
|
+
prevElement.tabIndex = -1;
|
|
171
|
+
}
|
|
172
|
+
setFocusedIndex(newIndex);
|
|
173
|
+
const newElement = children[newIndex];
|
|
174
|
+
newElement.tabIndex = 0;
|
|
175
|
+
newElement.focus();
|
|
176
|
+
}
|
|
177
|
+
} else if (e.key === 'Enter' && focusedIndex !== null) {
|
|
178
|
+
const element = contentRef.current?.children[focusedIndex];
|
|
179
|
+
if (!element) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const {
|
|
183
|
+
id,
|
|
184
|
+
textContent
|
|
185
|
+
} = element;
|
|
186
|
+
handleSelect({
|
|
187
|
+
id: id.replace('search-box-item__', ''),
|
|
188
|
+
text: textContent ?? ''
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
193
|
+
return () => {
|
|
194
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
195
|
+
};
|
|
196
|
+
}, [focusedIndex, handleSelect]);
|
|
197
|
+
const handleKeyPress = (0, _react.useCallback)(event => {
|
|
198
|
+
if (event.keyCode === 27) {
|
|
199
|
+
setMatchingItems([]);
|
|
200
|
+
}
|
|
201
|
+
}, []);
|
|
202
|
+
(0, _react.useEffect)(() => {
|
|
203
|
+
document.addEventListener('keydown', handleKeyPress);
|
|
204
|
+
return () => {
|
|
205
|
+
document.addEventListener('keydown', handleKeyPress);
|
|
206
|
+
};
|
|
207
|
+
}, [handleKeyPress]);
|
|
142
208
|
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_SearchBox.StyledSearchBox, {
|
|
143
209
|
ref: boxRef
|
|
144
210
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -147,6 +213,7 @@ const SearchBox = _ref => {
|
|
|
147
213
|
ref: inputRef,
|
|
148
214
|
onChange: handleChange,
|
|
149
215
|
onBlur: handleBlur,
|
|
216
|
+
onFocus: handleFocus,
|
|
150
217
|
placeholder: placeholder,
|
|
151
218
|
value: value
|
|
152
219
|
})), /*#__PURE__*/_react.default.createElement(_framerMotion.AnimatePresence, {
|
|
@@ -172,7 +239,7 @@ const SearchBox = _ref => {
|
|
|
172
239
|
}
|
|
173
240
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
174
241
|
ref: contentRef
|
|
175
|
-
}, content)))), [content, handleBlur, handleChange, height, isAnimating, placeholder, value, width]);
|
|
242
|
+
}, content)))), [content, handleBlur, handleChange, handleFocus, height, isAnimating, placeholder, value, width]);
|
|
176
243
|
};
|
|
177
244
|
SearchBox.displayName = 'SearchBox';
|
|
178
245
|
var _default = exports.default = SearchBox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchBox.js","names":["_framerMotion","require","_react","_interopRequireWildcard","_calculate","_Input","_interopRequireDefault","_SearchBoxItem","_SearchBox","_utils","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","SearchBox","_ref","placeholder","list","onChange","onBlur","onSelect","selectedId","matchingItems","setMatchingItems","useState","value","setValue","isAnimating","setIsAnimating","height","setHeight","width","setWidth","boxRef","useRef","contentRef","inputRef","handleOutsideClick","useCallback","event","current","contains","target","useEffect","document","addEventListener","removeEventListener","textArray","map","_ref2","text","calculateContentHeight","input","getElementById","offsetWidth","selectedItem","find","_ref3","id","handleChange","searchedItems","searchList","items","searchString","length","handleBlur","handleSelect","item","content","useMemo","sort","b","localeCompare","forEach","_ref4","push","createElement","key","StyledSearchBox","ref","AnimatePresence","initial","StyledMotionSearchBoxBody","opacity","animate","transition","duration","type","displayName","_default","exports"],"sources":["../../../src/components/search-box/SearchBox.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n ChangeEvent,\n ChangeEventHandler,\n FC,\n FocusEvent,\n FocusEventHandler,\n ReactElement,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { calculateContentHeight } from '../../utils/calculate';\nimport Input from '../input/Input';\nimport SearchBoxItem from './search-box-item/SearchBoxItem';\nimport { StyledMotionSearchBoxBody, StyledSearchBox } from './SearchBox.styles';\nimport type { ISearchBoxItem } from './types';\nimport { searchList } from './utils';\n\nexport type SearchBoxProps = {\n /**\n * A list of items that can be searched.\n */\n list: ISearchBoxItem[];\n /**\n * The placeholder that should be displayed.\n */\n placeholder?: string;\n /**\n * Function to be executed when the input lost focus.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when the input is changed.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when an item is selected.\n */\n onSelect?: (item: ISearchBoxItem) => void;\n /**\n * Control the selected item. If you use this prop, make sure to update it when the user selects an item.\n */\n selectedId?: string;\n};\n\nconst SearchBox: FC<SearchBoxProps> = (\n {\n placeholder,\n list,\n onChange,\n onBlur,\n onSelect,\n selectedId\n }) => {\n const [matchingItems, setMatchingItems] = useState<ISearchBoxItem[]>([]);\n const [value, setValue] = useState('');\n const [isAnimating, setIsAnimating] = useState(false);\n const [height, setHeight] = useState<number>(0);\n const [width, setWidth] = useState(0);\n\n const boxRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n /**\n * This function closes the list of items\n */\n const handleOutsideClick = useCallback(\n (event: MouseEvent) => {\n if (boxRef.current && !boxRef.current.contains(event.target as Node)) {\n setIsAnimating(false);\n }\n },\n [boxRef]\n );\n\n /**\n * This hook listens for clicks\n */\n useEffect(() => {\n document.addEventListener('click', handleOutsideClick);\n\n return () => {\n document.removeEventListener('click', handleOutsideClick);\n };\n }, [handleOutsideClick, boxRef]);\n\n /**\n * This hook calculates the height\n */\n useEffect(() => {\n const textArray = list.map(({ text }) => text);\n\n setHeight(calculateContentHeight(textArray));\n }, [list, placeholder]);\n\n /**\n * This hook calculates the width\n */\n useEffect(() => {\n const input = document.getElementById('search_box_input');\n\n if (input) {\n setWidth(input.offsetWidth);\n }\n }, []);\n\n useEffect(() => {\n if (selectedId) {\n const selectedItem = list.find(({ id }) => id === selectedId);\n\n if (selectedItem) {\n setValue(selectedItem.text);\n }\n }\n }, [list, selectedId]);\n\n /**\n * This function handles changes of the input\n */\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const searchedItems = searchList({ items: list, searchString: event.target.value });\n\n setMatchingItems(searchedItems);\n setIsAnimating(searchedItems.length !== 0);\n setValue(event.target.value);\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n },\n [list, onChange]\n );\n\n /**\n * This function handles the blur event of the input\n */\n const handleBlur = useCallback(\n (event: FocusEvent<HTMLInputElement>) => {\n if (typeof onBlur === 'function') {\n onBlur(event);\n }\n },\n [onBlur]\n );\n\n /**\n * This function handles the item selection\n */\n const handleSelect = useCallback(\n (item: ISearchBoxItem) => {\n setValue(item.text);\n setIsAnimating(false);\n\n if (typeof onSelect === 'function') {\n onSelect(item);\n }\n },\n [onSelect]\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n matchingItems.sort((a, b) => a.text.localeCompare(b.text));\n\n matchingItems.forEach(({ id, text }) => {\n items.push(<SearchBoxItem key={id} text={text} id={id} onSelect={handleSelect}/>);\n });\n\n return items;\n }, [handleSelect, matchingItems]);\n\n return useMemo(\n () => (\n <StyledSearchBox ref={boxRef}>\n <div id=\"search_box_input\">\n <Input\n ref={inputRef}\n onChange={handleChange}\n onBlur={handleBlur}\n placeholder={placeholder}\n value={value}\n />\n </div>\n <AnimatePresence initial={false}>\n <StyledMotionSearchBoxBody\n key=\"content\"\n height={height}\n width={width}\n initial={{ height: 0, opacity: 0 }}\n animate={\n isAnimating\n ? { height: 'fit-content', opacity: 1 }\n : { height: 0, opacity: 0 }\n }\n transition={{\n duration: 0.2,\n type: 'tween',\n }}\n >\n <div ref={contentRef}>{content}</div>\n </StyledMotionSearchBoxBody>\n </AnimatePresence>\n </StyledSearchBox>\n ),\n [content, handleBlur, handleChange, height, isAnimating, placeholder, value, width]\n );\n};\n\nSearchBox.displayName = 'SearchBox';\n\nexport default SearchBox;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAaA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,cAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AAEA,IAAAQ,MAAA,GAAAR,OAAA;AAAqC,SAAAK,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAX,wBAAAW,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,GAAA,CAAAJ,CAAA,UAAAG,CAAA,CAAAE,GAAA,CAAAL,CAAA,OAAAM,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA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AAA,CAACtF,UAAA,CAAA4F,yBAAyB;IACtBL,GAAG,EAAC,SAAS;IACbhD,MAAM,EAAEA,MAAO;IACfE,KAAK,EAAEA,KAAM;IACbkD,OAAO,EAAE;MAAEpD,MAAM,EAAE,CAAC;MAAEsD,OAAO,EAAE;IAAE,CAAE;IACnCC,OAAO,EACHzD,WAAW,GACL;MAAEE,MAAM,EAAE,aAAa;MAAEsD,OAAO,EAAE;IAAE,CAAC,GACrC;MAAEtD,MAAM,EAAE,CAAC;MAAEsD,OAAO,EAAE;IAAE,CACjC;IACDE,UAAU,EAAE;MACRC,QAAQ,EAAE,GAAG;MACbC,IAAI,EAAE;IACV;EAAE,gBAEFvG,MAAA,CAAAU,OAAA,CAAAkF,aAAA;IAAKG,GAAG,EAAE5C;EAAW,GAAEiC,OAAa,CACb,CACd,CACJ,CACpB,EACD,CAACA,OAAO,EAAEH,UAAU,EAAEN,YAAY,EAAE9B,MAAM,EAAEF,WAAW,EAAEX,WAAW,EAAES,KAAK,EAAEM,KAAK,CACtF,CAAC;AACL,CAAC;AAEDjB,SAAS,CAAC0E,WAAW,GAAG,WAAW;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAhG,OAAA,GAErBoB,SAAS"}
|
|
1
|
+
{"version":3,"file":"SearchBox.js","names":["_framerMotion","require","_react","_interopRequireWildcard","_calculate","_Input","_interopRequireDefault","_SearchBoxItem","_SearchBox","_utils","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","SearchBox","_ref","placeholder","list","onChange","onBlur","onSelect","selectedId","shouldShowContentOnEmptyInput","matchingItems","setMatchingItems","useState","value","setValue","isAnimating","setIsAnimating","height","setHeight","width","setWidth","focusedIndex","setFocusedIndex","boxRef","useRef","contentRef","inputRef","handleOutsideClick","useCallback","event","current","contains","target","useEffect","document","addEventListener","removeEventListener","textArray","map","_ref2","text","calculateContentHeight","input","getElementById","offsetWidth","selectedItem","find","_ref3","id","handleFocus","searchList","items","searchString","handleChange","searchedItems","length","handleBlur","handleSelect","item","content","useMemo","sort","b","localeCompare","forEach","_ref4","push","createElement","key","handleKeyDown","preventDefault","children","newIndex","prevElement","tabIndex","newElement","focus","element","textContent","replace","handleKeyPress","keyCode","StyledSearchBox","ref","onFocus","AnimatePresence","initial","StyledMotionSearchBoxBody","opacity","animate","transition","duration","type","displayName","_default","exports"],"sources":["../../../src/components/search-box/SearchBox.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n ChangeEvent,\n ChangeEventHandler,\n FC,\n FocusEvent,\n FocusEventHandler,\n ReactElement,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { calculateContentHeight } from '../../utils/calculate';\nimport Input from '../input/Input';\nimport SearchBoxItem from './search-box-item/SearchBoxItem';\nimport { StyledMotionSearchBoxBody, StyledSearchBox } from './SearchBox.styles';\nimport type { ISearchBoxItem } from './types';\nimport { searchList } from './utils';\n\nexport type SearchBoxProps = {\n /**\n * A list of items that can be searched.\n */\n list: ISearchBoxItem[];\n /**\n * The placeholder that should be displayed.\n */\n placeholder?: string;\n /**\n * Function to be executed when the input lost focus.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when the input is changed.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when an item is selected.\n */\n onSelect?: (item: ISearchBoxItem) => void;\n /**\n * Control the selected item. If you use this prop, make sure to update it when the user selects an item.\n */\n selectedId?: string;\n /**\n * Whether the full list of items should be displayed if the input is empty.\n */\n shouldShowContentOnEmptyInput?: boolean;\n};\n\nconst SearchBox: FC<SearchBoxProps> = ({\n placeholder,\n list,\n onChange,\n onBlur,\n onSelect,\n selectedId,\n shouldShowContentOnEmptyInput = true,\n}) => {\n const [matchingItems, setMatchingItems] = useState<ISearchBoxItem[]>([]);\n const [value, setValue] = useState('');\n const [isAnimating, setIsAnimating] = useState(false);\n const [height, setHeight] = useState<number>(0);\n const [width, setWidth] = useState(0);\n const [focusedIndex, setFocusedIndex] = useState<number | null>(null);\n\n const boxRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n /**\n * This function closes the list of items\n */\n const handleOutsideClick = useCallback(\n (event: MouseEvent) => {\n if (boxRef.current && !boxRef.current.contains(event.target as Node)) {\n setIsAnimating(false);\n }\n },\n [boxRef]\n );\n\n /**\n * This hook listens for clicks\n */\n useEffect(() => {\n document.addEventListener('click', handleOutsideClick);\n\n return () => {\n document.removeEventListener('click', handleOutsideClick);\n };\n }, [handleOutsideClick, boxRef]);\n\n /**\n * This hook calculates the height\n */\n useEffect(() => {\n const textArray = list.map(({ text }) => text);\n\n setHeight(calculateContentHeight(textArray));\n }, [list, placeholder]);\n\n /**\n * This hook calculates the width\n */\n useEffect(() => {\n const input = document.getElementById('search_box_input');\n\n if (input) {\n setWidth(input.offsetWidth);\n }\n }, []);\n\n useEffect(() => {\n if (selectedId) {\n const selectedItem = list.find(({ id }) => id === selectedId);\n\n if (selectedItem) {\n setValue(selectedItem.text);\n }\n }\n }, [list, selectedId]);\n\n /**\n * This function sets the items on focus if shouldShowContentOnEmptyInput\n */\n const handleFocus = useCallback(() => {\n if (shouldShowContentOnEmptyInput) {\n setMatchingItems(searchList({ items: list, searchString: value }));\n setIsAnimating(true);\n }\n }, [list, shouldShowContentOnEmptyInput, value]);\n\n /**\n * This function handles changes of the input\n */\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const searchedItems = searchList({ items: list, searchString: event.target.value });\n\n if (!shouldShowContentOnEmptyInput && !event.target.value) {\n setMatchingItems([]);\n } else {\n setMatchingItems(searchedItems);\n setIsAnimating(searchedItems.length !== 0);\n }\n\n setValue(event.target.value);\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n },\n [list, onChange, shouldShowContentOnEmptyInput]\n );\n\n /**\n * This function handles the blur event of the input\n */\n const handleBlur = useCallback(\n (event: FocusEvent<HTMLInputElement>) => {\n if (typeof onBlur === 'function') {\n onBlur(event);\n }\n },\n [onBlur]\n );\n\n /**\n * This function handles the item selection\n */\n const handleSelect = useCallback(\n (item: ISearchBoxItem) => {\n setValue(item.text);\n setIsAnimating(false);\n\n if (typeof onSelect === 'function') {\n onSelect(item);\n }\n },\n [onSelect]\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n matchingItems.sort((a, b) => a.text.localeCompare(b.text));\n\n matchingItems.forEach(({ id, text }) => {\n items.push(<SearchBoxItem key={id} text={text} id={id} onSelect={handleSelect} />);\n });\n\n return items;\n }, [handleSelect, matchingItems]);\n\n useEffect(() => {\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {\n e.preventDefault();\n const children = contentRef.current?.children;\n if (children && children.length > 0) {\n const newIndex =\n focusedIndex !== null\n ? (focusedIndex + (e.key === 'ArrowUp' ? -1 : 1) + children.length) %\n children.length\n : 0;\n\n if (focusedIndex !== null) {\n const prevElement = children[focusedIndex] as HTMLDivElement;\n prevElement.tabIndex = -1;\n }\n\n setFocusedIndex(newIndex);\n\n const newElement = children[newIndex] as HTMLDivElement;\n newElement.tabIndex = 0;\n newElement.focus();\n }\n } else if (e.key === 'Enter' && focusedIndex !== null) {\n const element = contentRef.current?.children[focusedIndex];\n\n if (!element) {\n return;\n }\n\n const { id, textContent } = element;\n\n handleSelect({ id: id.replace('search-box-item__', ''), text: textContent ?? '' });\n }\n };\n\n document.addEventListener('keydown', handleKeyDown);\n\n return () => {\n document.removeEventListener('keydown', handleKeyDown);\n };\n }, [focusedIndex, handleSelect]);\n\n const handleKeyPress = useCallback((event: KeyboardEvent) => {\n if (event.keyCode === 27) {\n setMatchingItems([]);\n }\n }, []);\n\n useEffect(() => {\n document.addEventListener('keydown', handleKeyPress);\n\n return () => {\n document.addEventListener('keydown', handleKeyPress);\n };\n }, [handleKeyPress]);\n\n return useMemo(\n () => (\n <StyledSearchBox ref={boxRef}>\n <div id=\"search_box_input\">\n <Input\n ref={inputRef}\n onChange={handleChange}\n onBlur={handleBlur}\n onFocus={handleFocus}\n placeholder={placeholder}\n value={value}\n />\n </div>\n <AnimatePresence initial={false}>\n <StyledMotionSearchBoxBody\n key=\"content\"\n height={height}\n width={width}\n initial={{ height: 0, opacity: 0 }}\n animate={\n isAnimating\n ? { height: 'fit-content', opacity: 1 }\n : { height: 0, opacity: 0 }\n }\n transition={{\n duration: 0.2,\n type: 'tween',\n }}\n >\n <div ref={contentRef}>{content}</div>\n </StyledMotionSearchBoxBody>\n </AnimatePresence>\n </StyledSearchBox>\n ),\n [\n content,\n handleBlur,\n handleChange,\n handleFocus,\n height,\n isAnimating,\n placeholder,\n value,\n width,\n ]\n );\n};\n\nSearchBox.displayName = 'SearchBox';\n\nexport default SearchBox;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAaA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,cAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AAEA,IAAAQ,MAAA,GAAAR,OAAA;AAAqC,SAAAK,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAX,wBAAAW,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH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0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_SearchBoxItem.StyledSearchBoxItem, {
|
|
24
|
+
id: `search-box-item__${id}`,
|
|
24
25
|
onClick: handleClick
|
|
25
|
-
}, /*#__PURE__*/_react.default.createElement(_SearchBoxItem.StyledSearchBoxItemText, null, text)), [handleClick, text]);
|
|
26
|
+
}, /*#__PURE__*/_react.default.createElement(_SearchBoxItem.StyledSearchBoxItemText, null, text)), [handleClick, id, text]);
|
|
26
27
|
};
|
|
27
28
|
SearchBoxItem.displayName = 'SearchBoxItem';
|
|
28
29
|
var _default = exports.default = SearchBoxItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchBoxItem.js","names":["_react","_interopRequireWildcard","require","_SearchBoxItem","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","SearchBoxItem","_ref","id","text","onSelect","handleClick","useCallback","useMemo","createElement","StyledSearchBoxItem","onClick","StyledSearchBoxItemText","displayName","_default","exports"],"sources":["../../../../src/components/search-box/search-box-item/SearchBoxItem.tsx"],"sourcesContent":["import React, { FC, useCallback, useMemo } from 'react';\nimport type { ISearchBoxItem } from '../types';\nimport { StyledSearchBoxItem, StyledSearchBoxItemText } from './SearchBoxItem.styles';\n\nexport type SearchBoxItemProps = {\n onSelect: (item: ISearchBoxItem) => void;\n id: ISearchBoxItem['id'];\n text: ISearchBoxItem['text'];\n};\n\nconst SearchBoxItem: FC<SearchBoxItemProps> = ({ id, text, onSelect }) => {\n const handleClick = useCallback(() => {\n onSelect({ id, text });\n }, [id, onSelect, text]);\n\n return useMemo(\n () => (\n <StyledSearchBoxItem onClick={handleClick}>\n <StyledSearchBoxItemText>{text}</StyledSearchBoxItemText>\n </StyledSearchBoxItem>\n ),\n [handleClick, text]\n );\n};\n\nSearchBoxItem.displayName = 'SearchBoxItem';\n\nexport default SearchBoxItem;\n"],"mappings":";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EAAA,IAA3B;IAAEC,EAAE;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAAH,IAAA;EACjE,MAAMI,WAAW,GAAG,IAAAC,kBAAW,EAAC,MAAM;IAClCF,QAAQ,CAAC;MAAEF,EAAE;MAAEC;IAAK,CAAC,CAAC;EAC1B,CAAC,EAAE,CAACD,EAAE,EAAEE,QAAQ,EAAED,IAAI,CAAC,CAAC;EAExB,OAAO,IAAAI,cAAO,EACV,mBACIhC,MAAA,CAAAU,OAAA,CAAAuB,aAAA,CAAC9B,cAAA,CAAA+B,mBAAmB;
|
|
1
|
+
{"version":3,"file":"SearchBoxItem.js","names":["_react","_interopRequireWildcard","require","_SearchBoxItem","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","SearchBoxItem","_ref","id","text","onSelect","handleClick","useCallback","useMemo","createElement","StyledSearchBoxItem","onClick","StyledSearchBoxItemText","displayName","_default","exports"],"sources":["../../../../src/components/search-box/search-box-item/SearchBoxItem.tsx"],"sourcesContent":["import React, { FC, useCallback, useMemo } from 'react';\nimport type { ISearchBoxItem } from '../types';\nimport { StyledSearchBoxItem, StyledSearchBoxItemText } from './SearchBoxItem.styles';\n\nexport type SearchBoxItemProps = {\n onSelect: (item: ISearchBoxItem) => void;\n id: ISearchBoxItem['id'];\n text: ISearchBoxItem['text'];\n};\n\nconst SearchBoxItem: FC<SearchBoxItemProps> = ({ id, text, onSelect }) => {\n const handleClick = useCallback(() => {\n onSelect({ id, text });\n }, [id, onSelect, text]);\n\n return useMemo(\n () => (\n <StyledSearchBoxItem id={`search-box-item__${id}`} onClick={handleClick}>\n <StyledSearchBoxItemText>{text}</StyledSearchBoxItemText>\n </StyledSearchBoxItem>\n ),\n [handleClick, id, text]\n );\n};\n\nSearchBoxItem.displayName = 'SearchBoxItem';\n\nexport default SearchBoxItem;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,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;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAAH,IAAA;EACjE,MAAMI,WAAW,GAAG,IAAAC,kBAAW,EAAC,MAAM;IAClCF,QAAQ,CAAC;MAAEF,EAAE;MAAEC;IAAK,CAAC,CAAC;EAC1B,CAAC,EAAE,CAACD,EAAE,EAAEE,QAAQ,EAAED,IAAI,CAAC,CAAC;EAExB,OAAO,IAAAI,cAAO,EACV,mBACIhC,MAAA,CAAAU,OAAA,CAAAuB,aAAA,CAAC9B,cAAA,CAAA+B,mBAAmB;IAACP,EAAE,EAAG,oBAAmBA,EAAG,EAAE;IAACQ,OAAO,EAAEL;EAAY,gBACpE9B,MAAA,CAAAU,OAAA,CAAAuB,aAAA,CAAC9B,cAAA,CAAAiC,uBAAuB,QAAER,IAA8B,CACvC,CACxB,EACD,CAACE,WAAW,EAAEH,EAAE,EAAEC,IAAI,CAC1B,CAAC;AACL,CAAC;AAEDH,aAAa,CAACY,WAAW,GAAG,eAAe;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA7B,OAAA,GAE7Be,aAAa"}
|
|
@@ -13,14 +13,23 @@ const StyledSearchBoxItem = exports.StyledSearchBoxItem = _styledComponents.defa
|
|
|
13
13
|
theme
|
|
14
14
|
} = _ref;
|
|
15
15
|
return theme['secondary-103'];
|
|
16
|
+
}};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&:focus {
|
|
20
|
+
background: ${_ref2 => {
|
|
21
|
+
let {
|
|
22
|
+
theme
|
|
23
|
+
} = _ref2;
|
|
24
|
+
return theme['secondary-103'];
|
|
16
25
|
}};
|
|
17
26
|
}
|
|
18
27
|
`;
|
|
19
28
|
const StyledSearchBoxItemText = exports.StyledSearchBoxItemText = _styledComponents.default.p`
|
|
20
|
-
color: ${
|
|
29
|
+
color: ${_ref3 => {
|
|
21
30
|
let {
|
|
22
31
|
theme
|
|
23
|
-
} =
|
|
32
|
+
} = _ref3;
|
|
24
33
|
return theme.text;
|
|
25
34
|
}};
|
|
26
35
|
margin: 5px;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchBoxItem.styles.js","names":["_styledComponents","_interopRequireDefault","require","obj","__esModule","default","StyledSearchBoxItem","exports","styled","div","_ref","theme","StyledSearchBoxItemText","p","
|
|
1
|
+
{"version":3,"file":"SearchBoxItem.styles.js","names":["_styledComponents","_interopRequireDefault","require","obj","__esModule","default","StyledSearchBoxItem","exports","styled","div","_ref","theme","_ref2","StyledSearchBoxItemText","p","_ref3","text"],"sources":["../../../../src/components/search-box/search-box-item/SearchBoxItem.styles.ts"],"sourcesContent":["import styled from 'styled-components';\nimport type { WithTheme } from '../../color-scheme-provider/ColorSchemeProvider';\n\ntype StyledSearchBoxItemProps = WithTheme<unknown>;\nexport const StyledSearchBoxItem = styled.div<StyledSearchBoxItemProps>`\n &:hover {\n background: ${({ theme }: StyledSearchBoxItemProps) => theme['secondary-103']};\n }\n\n &:focus {\n background: ${({ theme }: StyledSearchBoxItemProps) => theme['secondary-103']};\n }\n`;\n\ntype StyledSearchBoxItemTextProps = WithTheme<unknown>;\n\nexport const StyledSearchBoxItemText = styled.p<StyledSearchBoxItemTextProps>`\n color: ${({ theme }: StyledSearchBoxItemTextProps) => theme.text};\n margin: 5px;\n`;\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAIhC,MAAMG,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,GAAGE,yBAAM,CAACC,GAA8B;AACxE;AACA,sBAAsBC,IAAA;EAAA,IAAC;IAAEC;EAAgC,CAAC,GAAAD,IAAA;EAAA,OAAKC,KAAK,CAAC,eAAe,CAAC;AAAA,CAAC;AACtF;AACA;AACA;AACA,sBAAsBC,KAAA;EAAA,IAAC;IAAED;EAAgC,CAAC,GAAAC,KAAA;EAAA,OAAKD,KAAK,CAAC,eAAe,CAAC;AAAA,CAAC;AACtF;AACA,CAAC;AAIM,MAAME,uBAAuB,GAAAN,OAAA,CAAAM,uBAAA,GAAGL,yBAAM,CAACM,CAAgC;AAC9E,aAAaC,KAAA;EAAA,IAAC;IAAEJ;EAAoC,CAAC,GAAAI,KAAA;EAAA,OAAKJ,KAAK,CAACK,IAAI;AAAA,CAAC;AACrE;AACA,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.398",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chayns",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@babel/cli": "^7.23.4",
|
|
37
37
|
"@babel/core": "^7.23.7",
|
|
38
|
-
"@babel/preset-env": "^7.23.
|
|
38
|
+
"@babel/preset-env": "^7.23.8",
|
|
39
39
|
"@babel/preset-react": "^7.23.3",
|
|
40
40
|
"@babel/preset-typescript": "^7.23.3",
|
|
41
|
-
"@types/react": "^18.2.
|
|
41
|
+
"@types/react": "^18.2.48",
|
|
42
42
|
"@types/react-dom": "^18.2.18",
|
|
43
43
|
"@types/styled-components": "^5.1.34",
|
|
44
44
|
"@types/uuid": "^9.0.7",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"lerna": "^8.0.2",
|
|
47
47
|
"react": "^18.2.0",
|
|
48
48
|
"react-dom": "^18.2.0",
|
|
49
|
-
"styled-components": "^6.1.
|
|
49
|
+
"styled-components": "^6.1.8",
|
|
50
50
|
"typescript": "^5.3.3"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
"@chayns/uac-service": "^0.0.46",
|
|
55
55
|
"@types/react-syntax-highlighter": "^15.5.11",
|
|
56
56
|
"babel-prettier-parser": "^0.10.8",
|
|
57
|
-
"chayns-api": "^1.0.
|
|
57
|
+
"chayns-api": "^1.0.45",
|
|
58
58
|
"clsx": "^2.1.0",
|
|
59
59
|
"date-fns": "^2.30.0",
|
|
60
|
-
"framer-motion": "^10.
|
|
61
|
-
"prettier": "^3.
|
|
60
|
+
"framer-motion": "^10.18.0",
|
|
61
|
+
"prettier": "^3.2.3",
|
|
62
62
|
"react-syntax-highlighter": "^15.5.0",
|
|
63
63
|
"uuid": "^9.0.1"
|
|
64
64
|
},
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "94bdafe2a185876107e107674aff56cb91a42a66"
|
|
74
74
|
}
|