Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
83d46d5
add OpenShift LogSnippet
InsaneZein Feb 8, 2024
3af9de9
fix layout; switch to pf variables
InsaneZein Feb 9, 2024
e63ddfa
add test
InsaneZein Feb 9, 2024
3fcba6e
pf variables and fix typos
InsaneZein Feb 13, 2024
6ce785e
fix snapshot
InsaneZein Feb 13, 2024
e510823
wip: add leftBorderVariant
InsaneZein Feb 15, 2024
e659560
fix dynamic styling
InsaneZein Feb 19, 2024
bae7d6c
update snapshot
InsaneZein Feb 19, 2024
9959299
remove old redborder class
InsaneZein Feb 19, 2024
b8327d4
update snapshot again
InsaneZein Feb 19, 2024
3d000d5
add types to createuseStyles
InsaneZein Feb 20, 2024
8b7385c
revert leftborder default to danger
InsaneZein Feb 20, 2024
fb101c3
Merge branch 'main' of github.com:patternfly/react-component-groups i…
InsaneZein Feb 20, 2024
96c265e
clean up code
InsaneZein Feb 20, 2024
dc1ffa6
add OpenShift LogSnippet
InsaneZein Feb 8, 2024
1850983
fix layout; switch to pf variables
InsaneZein Feb 9, 2024
de4c55c
add test
InsaneZein Feb 9, 2024
7689bd2
pf variables and fix typos
InsaneZein Feb 13, 2024
558893c
fix snapshot
InsaneZein Feb 13, 2024
49a1255
wip: add leftBorderVariant
InsaneZein Feb 15, 2024
5bbc8f4
fix dynamic styling
InsaneZein Feb 19, 2024
1a34f9b
update snapshot
InsaneZein Feb 19, 2024
a2b1258
remove old redborder class
InsaneZein Feb 19, 2024
f6a1506
update snapshot again
InsaneZein Feb 19, 2024
bc7cc0f
add types to createuseStyles
InsaneZein Feb 20, 2024
b21ccdf
revert leftborder default to danger
InsaneZein Feb 20, 2024
9c8dbf8
clean up code
InsaneZein Feb 20, 2024
588d44f
Merge branch 'add-logsnippet' of github.com:patternfly/react-componen…
InsaneZein Feb 20, 2024
8f2074a
more cleanup
InsaneZein Feb 20, 2024
0d4e71c
Merge branch 'main' of github.com:patternfly/react-component-groups i…
InsaneZein Feb 20, 2024
ea38872
feat(logsnippet): add log snippet
InsaneZein Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip: add leftBorderVariant
  • Loading branch information
InsaneZein committed Feb 15, 2024
commit e5108234b2c6fe3bc37d92cd1e0345bd5316435f
49 changes: 35 additions & 14 deletions packages/module/src/LogSnippet/LogSnippet.tsx
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: {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

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)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd advocate that we use a more meaningful variable here: maybe: --pf-v5-global--BackgroundColor--200

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

},
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() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ displayMessage() }
{ typeof message === 'string' ? <Text component={TextVariants.p} className={classes.statusMessage}>{message}</Text> : message }

</FlexItem>
{ logSnippet && <FlexItem>
<CodeBlock>
Expand Down