diff --git a/packages/components/src/custom/Toolbar/index.ts b/packages/components/src/custom/Toolbar/index.ts new file mode 100644 index 000000000..1329bef9b --- /dev/null +++ b/packages/components/src/custom/Toolbar/index.ts @@ -0,0 +1 @@ +export * from './viewColumn'; diff --git a/packages/components/src/custom/Toolbar/viewColumn.tsx b/packages/components/src/custom/Toolbar/viewColumn.tsx new file mode 100644 index 000000000..7ebb47e31 --- /dev/null +++ b/packages/components/src/custom/Toolbar/viewColumn.tsx @@ -0,0 +1,108 @@ +import { IconButton, TextField, Tooltip } from '@layer5/sistent-components'; +import React, { useRef, useState } from 'react'; +import { + default as CloseIcon, + default as SearchIcon +} from '../../../../svg/src/icons/Search/searchIcon'; + +interface SearchBarProps { + onSearch: (searchText: string) => void; + style?: React.CSSProperties; + placeholder?: string; + onClear?: () => void; + expanded: boolean; + setExpanded: (expanded: boolean) => void; +} + +const SearchBar: React.FC = ({ placeholder, onClear, expanded, setExpanded }) => { + const [searchText, setSearchText] = useState(''); + const searchRef = useRef(null); + + const handleSearchChange = (event: React.ChangeEvent): void => { + setSearchText(event.target.value); + }; + + const handleClearIconClick = (): void => { + setSearchText(''); + setExpanded(false); + if (onClear) { + onClear(); + } + }; + + const handleSearchIconClick = (): void => { + if (expanded) { + setSearchText(''); + setExpanded(false); + } else { + setExpanded(true); + setTimeout(() => { + if (searchRef.current) { + searchRef.current.focus(); + } + }, 300); + } + }; + + //Todo: Need a width utility function + // const width = window.innerWidth; + // let searchWidth = "200px"; + // if (width <= 360) { + // searchWidth = "100px"; + // } + + return ( +
+ + + {expanded ? ( + + + + + + ) : ( + + + + + + )} +
+ ); +}; + +export default SearchBar; diff --git a/packages/svg/src/icons/Close/closeIcon.tsx b/packages/svg/src/icons/Close/closeIcon.tsx new file mode 100644 index 000000000..f81683ed1 --- /dev/null +++ b/packages/svg/src/icons/Close/closeIcon.tsx @@ -0,0 +1,19 @@ +import { FC } from 'react'; +import { IconProps } from '../types'; + +export const CloseIcon: FC = ({ width, height, ...props }) => { + return ( + + + + + ); +}; + +export default CloseIcon; diff --git a/packages/svg/src/icons/Close/index.ts b/packages/svg/src/icons/Close/index.ts new file mode 100644 index 000000000..36ec1a306 --- /dev/null +++ b/packages/svg/src/icons/Close/index.ts @@ -0,0 +1 @@ +export { default as CloseIcon } from './closeIcon'; diff --git a/packages/svg/src/icons/Search/intex.ts b/packages/svg/src/icons/Search/intex.ts new file mode 100644 index 000000000..c7ee78f09 --- /dev/null +++ b/packages/svg/src/icons/Search/intex.ts @@ -0,0 +1 @@ +export { default as SearchIcon } from './seacrhIcon'; diff --git a/packages/svg/src/icons/Search/seacrhIcon.tsx b/packages/svg/src/icons/Search/seacrhIcon.tsx new file mode 100644 index 000000000..3557d7bc3 --- /dev/null +++ b/packages/svg/src/icons/Search/seacrhIcon.tsx @@ -0,0 +1,18 @@ +import { FC } from 'react'; +import { IconProps } from '../types'; + +export const SearchIcon: FC = ({ width, height, ...props }) => { + return ( + + + + ); +}; + +export default SearchIcon;