Skip to content

Commit 21d3261

Browse files
authored
update(console): support job failed reason, add new copy & text component (#2472)
1 parent f033f77 commit 21d3261

File tree

17 files changed

+157
-50
lines changed

17 files changed

+157
-50
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react'
2+
import Copy from 'react-copy-to-clipboard'
3+
import IconFont from '../IconFont'
4+
import Button from '../Button'
5+
6+
export interface ICopyToClipboardProps {
7+
content: string
8+
children?: React.ReactNode
9+
}
10+
11+
function CopyToClipboard({
12+
content,
13+
children,
14+
}: ICopyToClipboardProps): React.FunctionComponentElement<ICopyToClipboardProps> {
15+
const [copied, setCopied] = React.useState(false)
16+
17+
return (
18+
<Copy
19+
text={content}
20+
onCopy={() => {
21+
setCopied(true)
22+
}}
23+
>
24+
<Button as='link' kind='tertiary'>
25+
{typeof children === 'function' ? children(copied) : children}
26+
</Button>
27+
</Copy>
28+
)
29+
}
30+
31+
function IconCopy(props: ICopyToClipboardProps) {
32+
return (
33+
<CopyToClipboard {...props}>
34+
{(copied: boolean) => <IconFont type={copied ? 'check' : 'copy'} style={{ marginLeft: '5px' }} />}
35+
</CopyToClipboard>
36+
)
37+
}
38+
39+
export { IconCopy }
40+
41+
export default React.memo<ICopyToClipboardProps>(CopyToClipboard)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './CopyToClipboard'
2+
export { default as CopyToClipboard } from './CopyToClipboard'

console/packages/starwhale-ui/src/IconFont/fonts/iconfont.css

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@font-face {
22
font-family: "iconfont"; /* Project id 3410006 */
3-
src: url('iconfont.woff2?t=1688023288848') format('woff2'),
4-
url('iconfont.woff?t=1688023288848') format('woff'),
5-
url('iconfont.ttf?t=1688023288848') format('truetype');
3+
src: url('iconfont.woff2?t=1688627096806') format('woff2'),
4+
url('iconfont.woff?t=1688627096806') format('woff'),
5+
url('iconfont.ttf?t=1688627096806') format('truetype');
66
}
77

88
.iconfont {
@@ -13,6 +13,14 @@
1313
-moz-osx-font-smoothing: grayscale;
1414
}
1515

16+
.icon-a-copylink:before {
17+
content: "\e66f";
18+
}
19+
20+
.icon-copy:before {
21+
content: "\e670";
22+
}
23+
1624
.icon-global2:before {
1725
content: "\e66e";
1826
}

console/packages/starwhale-ui/src/IconFont/fonts/iconfont.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

console/packages/starwhale-ui/src/IconFont/fonts/iconfont.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
"css_prefix_text": "icon-",
66
"description": "",
77
"glyphs": [
8+
{
9+
"icon_id": "36317040",
10+
"name": "copy link",
11+
"font_class": "a-copylink",
12+
"unicode": "e66f",
13+
"unicode_decimal": 58991
14+
},
15+
{
16+
"icon_id": "36317041",
17+
"name": "copy",
18+
"font_class": "copy",
19+
"unicode": "e670",
20+
"unicode_decimal": 58992
21+
},
822
{
923
"icon_id": "36161167",
1024
"name": "global2",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:546784e4ea093fe91ad86af067cd673730db4fb78bf7879a5df25a4d34bbc23a
3-
size 20276
2+
oid sha256:091baf54f607f257ab2e6b1e701bb8b8e576710d8d261eed78781b906c92a433
3+
size 20776
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:1853237c23ff096172c6a897e49d906d85b848bb505b4ba73a869dd12253c563
3-
size 11684
2+
oid sha256:2ba650f46fe20e13547d996d808704bd2005554ec8b1ead89f2774bef673dcc3
3+
size 11972
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:f607da82f46c7e738be095e3a3273eb9771cbb115ef22461935a61a0626a2ec7
3-
size 9732
2+
oid sha256:ac49aed478de2396faa7eb029ec3bbaebe267ba29393c0170bb2b3a75336bf77
3+
size 9996

console/packages/starwhale-ui/src/IconFont/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export type IconTypesT =
113113
| 'top2'
114114
| 'time'
115115
| 'global2'
116+
| 'copy'
117+
| 'a-copylink'
116118

117119
interface IIconFontProps {
118120
style?: React.CSSProperties
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react'
2+
import { Tooltip } from '../Tooltip'
3+
import { IconCopy } from '../Copy'
4+
import { themedUseStyletron } from '../theme/styletron'
5+
6+
export interface ITextProps {
7+
children?: React.ReactNode
8+
size?: 'small' | 'medium' | 'large' | 'xlarge'
9+
style?: React.CSSProperties
10+
tooltip?: React.ReactNode
11+
content?: string
12+
maxWidth?: string
13+
}
14+
15+
const fontSizeMap: { [k in Exclude<ITextProps['size'], undefined>]: string } = {
16+
small: '12px',
17+
medium: '14px',
18+
large: '16px',
19+
xlarge: '20px',
20+
}
21+
22+
function Text({ children, style, size = 'medium', tooltip = '', content = '', maxWidth = '200px' }: ITextProps) {
23+
const [css] = themedUseStyletron()
24+
25+
let Component = (
26+
<span
27+
style={style}
28+
className={css({
29+
fontSize: fontSizeMap[size],
30+
WebkitLineClamp: 1,
31+
display: 'inline-block',
32+
overflow: 'hidden',
33+
textOverflow: 'ellipsis',
34+
verticalAlign: 'middle',
35+
maxWidth,
36+
})}
37+
>
38+
{children ?? content}
39+
</span>
40+
)
41+
42+
if (tooltip) {
43+
Component = (
44+
<Tooltip content={tooltip} showArrow placement='top'>
45+
{Component}
46+
</Tooltip>
47+
)
48+
}
49+
50+
return (
51+
<>
52+
{Component}
53+
{content && <IconCopy content={content} />}
54+
</>
55+
)
56+
}
57+
58+
function MonoText({ children, style, ...props }: ITextProps) {
59+
return (
60+
<Text {...props} style={{ ...style, fontFamily: 'Roboto Mono' }}>
61+
{children}
62+
</Text>
63+
)
64+
}
65+
66+
export { MonoText }
67+
export default Text

0 commit comments

Comments
 (0)