-
Notifications
You must be signed in to change notification settings - Fork 31
add OpenShift LogSnippet #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
83d46d5
3af9de9
e63ddfa
3fcba6e
6ce785e
e510823
e659560
bae7d6c
9959299
b8327d4
3d000d5
8b7385c
fb101c3
96c265e
dc1ffa6
1850983
de4c55c
7689bd2
558893c
49a1255
5bbc8f4
1a34f9b
a2b1258
f6a1506
bc7cc0f
b21ccdf
9c8dbf8
588d44f
8f2074a
0d4e71c
ea38872
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,36 +1,57 @@ | ||||||
| import * as React from 'react'; | ||||||
| import { CodeBlock, CodeBlockCode, Flex, FlexItem, Text, TextVariants } from '@patternfly/react-core'; | ||||||
|
|
||||||
| import { CodeBlock, CodeBlockCode, Flex, FlexItem, FlexProps, Text, TextVariants } from '@patternfly/react-core'; | ||||||
| import clsx from 'clsx'; | ||||||
| import { createUseStyles } from 'react-jss' | ||||||
|
|
||||||
| export type BorderVariant = 'red' | 'green' | 'blue' | 'cyan' | 'gold' | 'orange' | 'purple' | ||||||
|
|
||||||
| export interface LogSnippetProps extends FlexProps { | ||||||
| /** Log snippet or code to be displayed */ | ||||||
| logSnippet?: string; | ||||||
| /** Message to appear above the log snippet */ | ||||||
| message: string | React.ReactNode; | ||||||
| /** Custom color for left border */ | ||||||
| leftBorderVariant?: BorderVariant | ||||||
| } | ||||||
|
|
||||||
| const useStyles = createUseStyles({ | ||||||
| logSnippet: { | ||||||
| borderLeft: '2px solid var(--pf-v5-global--danger-color--100)', | ||||||
| marginLeft: 'var(--pf-v5-global--spacer--sm)', | ||||||
| padding: 'var(--pf-v5-global--spacer--sm) 0 var(--pf-v5-global--spacer--sm) var(--pf-v5-global--spacer--sm)', | ||||||
| backgroundColor: 'var(--pf-v5-global--palette--black-100)' | ||||||
|
||||||
| }, | ||||||
| redBorder: { | ||||||
| borderLeft: 'var(--pf-v5-global--BorderWidth--md) solid var(--pf-v5-global--danger-color--100)', | ||||||
| }, | ||||||
| variantBorderColor: { | ||||||
| borderLeft: (props) => `var(--pf-v5-global--BorderWidth--md) solid var(--pf-v5-global--palette--${props.leftBorderVariant}-100)`, | ||||||
| }, | ||||||
| statusMessage: { | ||||||
| marginBottom:'var(--pf-v5-global--spacer--sm)', | ||||||
| }, | ||||||
| }); | ||||||
|
|
||||||
| export interface LogSnippetProps { | ||||||
| /** Log snippet or code to be displayed */ | ||||||
| logSnippet?: string; | ||||||
| /** Message to appear above the log snippet */ | ||||||
| message: string; | ||||||
| } | ||||||
|
|
||||||
| export const LogSnippet: React.FunctionComponent<LogSnippetProps> = ({ logSnippet, message }) => { | ||||||
| const classes = useStyles(); | ||||||
|
|
||||||
| return ( | ||||||
| <Flex direction={{ default: 'column' }} className={classes.logSnippet}> | ||||||
| <FlexItem> | ||||||
| export const LogSnippet: React.FunctionComponent<LogSnippetProps> = ({ logSnippet, message, leftBorderVariant, ...props }) => { | ||||||
| const classes = useStyles(props); | ||||||
|
|
||||||
| const displayMessage = () => { | ||||||
| if(typeof message === 'string') { | ||||||
| return ( | ||||||
| <Text component={TextVariants.p} className={classes.statusMessage}> | ||||||
| {message} | ||||||
| </Text> | ||||||
| ) | ||||||
| } else { | ||||||
| return message | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return ( | ||||||
| <Flex direction={{ default: 'column' }} className={clsx(classes.logSnippet, { [classes.redBorder]: leftBorderVariant }, { [classes.redBorder]: !props.leftBorderVariant })} {...props}> | ||||||
| <FlexItem> | ||||||
| { displayMessage() } | ||||||
|
||||||
| { displayMessage() } | |
| { typeof message === 'string' ? <Text component={TextVariants.p} className={classes.statusMessage}>{message}</Text> : message } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually use clsx with this. Is there a reason we aren't here? I think we should use a layout instead of the div and p below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought clsx was just for conditional rendering