Skip to content

Commit

Permalink
Merge pull request #82 from catenax-ng/feature/CPLP-3502/StaticTableC…
Browse files Browse the repository at this point in the history
…opyIcon
  • Loading branch information
oyo authored Jan 11, 2024
2 parents cdfee9a + 3a794aa commit b75db80
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.1.16

- Add copy icon functionality in static table row

## 2.1.15

- Add tooltip hint in stepper and make stepper responsive
Expand Down
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ npm/npmjs/-/strip-final-newline/3.0.0, MIT, approved, clearlydefined
npm/npmjs/-/strip-indent/3.0.0, MIT, approved, clearlydefined
npm/npmjs/-/strip-json-comments/3.1.1, MIT, approved, clearlydefined
npm/npmjs/-/style-inject/0.3.0, MIT, approved, clearlydefined
npm/npmjs/-/style-loader/3.3.3, MIT, approved, clearlydefined
npm/npmjs/-/style-loader/3.3.3, MIT, approved, #12669
npm/npmjs/-/stylehacks/5.1.1, MIT, approved, clearlydefined
npm/npmjs/-/stylis/4.2.0, MIT, approved, #8409
npm/npmjs/-/supports-color/5.5.0, MIT, approved, clearlydefined
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@catena-x/portal-shared-components",
"version": "2.1.15",
"version": "2.1.16",
"description": "Catena-X Portal Shared Components",
"author": "Catena-X Contributors",
"license": "Apache-2.0",
Expand Down
1 change: 1 addition & 0 deletions src/components/basic/StaticTable/StaticTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Table.args = {
},
{
icon: true,
copyValue: 'test',
inputValue: 'row1 col2',
isValid: (value) => console.log('Checking Validation', value),
errorMessage: 'Please enter valid value.',
Expand Down
44 changes: 40 additions & 4 deletions src/components/basic/StaticTable/VerticalTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
********************************************************************************/

import { useState } from 'react'
import { Typography, Link } from '@mui/material'
import { Typography, Link, Box } from '@mui/material'
import EditIcon from '@mui/icons-material/Edit'
import HelpOutlineIcon from '@mui/icons-material/HelpOutline'
import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'
import ContentCopyIcon from '@mui/icons-material/ContentCopy'
import CloseIcon from '@mui/icons-material/Close'
import type { TableType } from './types'
import { Input } from '../Input'
Expand All @@ -35,6 +36,7 @@ export const VerticalTable = ({
data: TableType
handleEdit?: (inputValue: string) => void
}) => {
const [copied, setCopied] = useState<string>('')
const [inputField, setInputField] = useState<{
row: unknown
column: unknown
Expand Down Expand Up @@ -103,6 +105,8 @@ export const VerticalTable = ({
)
}

const renderTextvalue = (text: string | undefined) => text ?? ''

return (
<table
style={{ width: '100%', borderCollapse: 'collapse' }}
Expand Down Expand Up @@ -144,8 +148,8 @@ export const VerticalTable = ({
>
<div style={{ display: 'flex', alignItems: 'center' }}>
{inputField &&
inputField.row === r &&
inputField.column === c ? (
inputField.row === r &&
inputField.column === c ? (
renderInputField(r, c)
) : (
<Link
Expand All @@ -168,13 +172,45 @@ export const VerticalTable = ({
</Typography>
</Link>
)}
{data?.edit?.[r]?.[c].copyValue &&
(
c !== 0 &&
<Box
sx={{
cursor: 'pointer',
display: 'flex',
color: copied === data?.edit?.[r]?.[c].copyValue ? '#00cc00' : '#eeeeee',
':hover': {
color: copied === data?.edit?.[r]?.[c].copyValue ? '#00cc00' : '#cccccc',
},
}}
onClick={() => {
void (async () => {
const value = renderTextvalue(data?.edit?.[r]?.[c].copyValue?.toString())
await navigator.clipboard.writeText(value)
setCopied(value)
setTimeout(() => {
setCopied('')
}, 1000)
})()
}}
>
<ContentCopyIcon
sx={{
fontSize: '18px',
marginLeft: '10px',
}}
/>
</Box>
)
}
{data?.edit?.[r]?.[c].icon &&
!inputField &&
(c === 0 ? (
<Tooltips
color="dark"
tooltipPlacement="bottom-start"
tooltipText={data?.edit?.[r][c].inputValue ?? ''}
tooltipText={renderTextvalue(data?.edit?.[r][c].inputValue)}
>
<HelpOutlineIcon
sx={{
Expand Down
1 change: 1 addition & 0 deletions src/components/basic/StaticTable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface TableType {
edit?: Array<
Array<{
icon: boolean
copyValue?: string
inputValue?: string
clickableLink?: string
isValid?: (value: string) => unknown
Expand Down

0 comments on commit b75db80

Please sign in to comment.