-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GUI Components: List component styling, add ListHeader (#3780)
- Loading branch information
1 parent
e813d2a
commit 550018e
Showing
8 changed files
with
257 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
portals-ui/packages/components/lib/components/list/list-header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import classNames from 'classnames'; | ||
import { SearchInput } from '@epam/uui'; | ||
import type { ListHeaderProps } from './types'; | ||
|
||
const ListHeader = (props: ListHeaderProps) => { | ||
const { | ||
className, | ||
style, | ||
title, | ||
controls, | ||
search, | ||
onSearch, | ||
searchPlaceholder, | ||
} = props; | ||
return ( | ||
<div className={classNames(className, 'divide-y')} style={style}> | ||
<b | ||
className="flex no-wrap px-6 py-4" | ||
style={{ color: 'var(--uui-text-secondary)' }}> | ||
{title} {controls ? <div className="ml-auto">{controls}</div> : null} | ||
</b> | ||
{onSearch ? ( | ||
<div className="px-6 py-2"> | ||
<SearchInput | ||
value={search} | ||
onValueChange={onSearch} | ||
placeholder={searchPlaceholder ?? 'Search'} | ||
debounceDelay={300} | ||
size="30" | ||
/> | ||
</div> | ||
) : null} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ListHeader; |
20 changes: 20 additions & 0 deletions
20
portals-ui/packages/components/lib/components/list/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { ReactNode } from 'react'; | ||
import type { CommonProps } from '../common.types'; | ||
|
||
export type ListProps<Item> = CommonProps & { | ||
data: Item[]; | ||
renderItem: (item: Item, index: number) => ReactNode | string; | ||
header?: ReactNode; | ||
footer?: ReactNode; | ||
virtualized?: boolean; | ||
itemKey?: keyof Item | ((item: Item, index: number) => string | number); | ||
}; | ||
|
||
export type ListHeaderProps = CommonProps & { | ||
title: string | ReactNode; | ||
logo?: string; | ||
search?: string; | ||
searchPlaceholder?: string; | ||
onSearch?: (search: string) => void; | ||
controls?: ReactNode; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import DummyComponent from './components/dummy-component'; | ||
import List from './components/list'; | ||
import List, { ListHeader } from './components/list'; | ||
import '@epam/uui-components/styles.css'; | ||
import '@epam/uui/styles.css'; | ||
import './style.css'; | ||
|
||
export { DummyComponent, List }; | ||
export { DummyComponent, List, ListHeader }; | ||
export * from './components/common.types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
@tailwind components; | ||
|
||
.list-container { | ||
box-shadow: var(--uui-shadow-level-1); | ||
border-radius: var(--uui-border-radius); | ||
} | ||
|
||
.list-footer-container, | ||
.list-header-container { | ||
box-shadow: var(--uui-shadow-level-1); | ||
} | ||
|
||
.list-footer-container { | ||
box-shadow: var(--uui-shadow-level-1); | ||
@apply h-12 flex justify-center items-center; | ||
} |
110 changes: 110 additions & 0 deletions
110
portals-ui/sites/ngs-portal/src/shared/highlight-text/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { useMemo } from 'react'; | ||
import type { CSSProperties } from 'react'; | ||
import classNames from 'classnames'; | ||
import type { CommonProps } from '@cloud-pipeline/components'; | ||
import './style.css'; | ||
|
||
export type HighlightedTextProps = CommonProps & { | ||
search?: string | undefined; | ||
children: string; | ||
highlightClassName?: string; | ||
highlightStyle?: CSSProperties; | ||
}; | ||
|
||
type HighlightPart = { | ||
part: string; | ||
highlight: boolean; | ||
}; | ||
|
||
const escapeRegExpCharacters = [ | ||
'.', | ||
'-', | ||
'+', | ||
'*', | ||
'?', | ||
'^', | ||
'$', | ||
'(', | ||
')', | ||
'[', | ||
']', | ||
'{', | ||
'}', | ||
]; | ||
|
||
function escapeRegExp( | ||
string: string, | ||
characters = escapeRegExpCharacters, | ||
): string { | ||
let result = string; | ||
characters.forEach((character) => { | ||
result = result.replace( | ||
new RegExp('\\' + character, 'g'), | ||
`\\${character}`, | ||
); | ||
}); | ||
return result; | ||
} | ||
|
||
export default function HighlightedText(props: HighlightedTextProps) { | ||
const { | ||
children: text, | ||
search = '', | ||
className, | ||
style, | ||
highlightClassName, | ||
highlightStyle, | ||
} = props; | ||
const parts = useMemo<HighlightPart[]>(() => { | ||
if (!search?.length) { | ||
return [ | ||
{ | ||
part: text, | ||
highlight: false, | ||
}, | ||
]; | ||
} | ||
const regExp = new RegExp(`${escapeRegExp(search)}`, 'ig'); | ||
let e = regExp.exec(text); | ||
let idx = 0; | ||
const result: HighlightPart[] = []; | ||
while (e) { | ||
result.push({ | ||
part: text.slice(idx, e.index), | ||
highlight: false, | ||
}); | ||
result.push({ | ||
part: e[0], | ||
highlight: true, | ||
}); | ||
idx = e.index + e[0].length; | ||
e = regExp.exec(text); | ||
} | ||
if (idx < text.length) { | ||
result.push({ | ||
part: text.slice(idx), | ||
highlight: false, | ||
}); | ||
} | ||
return result; | ||
}, [text, search]); | ||
return ( | ||
<span className={classNames(className, 'highlighted-text')} style={style}> | ||
{parts.map((part, idx) => ( | ||
<span | ||
key={`part-${idx}`} | ||
className={classNames( | ||
'm-0', | ||
'highlighted-text-part', | ||
highlightClassName, | ||
{ | ||
highlighted: part.highlight, | ||
}, | ||
)} | ||
style={part.highlight ? highlightStyle : undefined}> | ||
{part.part} | ||
</span> | ||
))} | ||
</span> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
portals-ui/sites/ngs-portal/src/shared/highlight-text/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@tailwind components; | ||
|
||
.highlighted-text .highlighted-text-part.highlighted { | ||
@apply bg-amber-200 dark:bg-amber-700/75; | ||
} |