FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(Alert): Add the default alert variant by tlabaj · Pull Request #2648 · patternfly/patternfly-react · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) .snap  (1) .ts  (1) .tsx  (3) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
      • Alert.md
      • Alert.tsx
      • AlertIcon.tsx
        • Alert.test.tsx.snap
        • alert.spec.ts
        • AlertDemo.tsx
This file contains hidden or 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
Expand Up @@ -7,6 +7,47 @@ propComponents: ['Alert', 'AlertActionCloseButton', 'AlertActionLink']
import { Alert, AlertActionLink, AlertActionCloseButton } from '@patternfly/react-core';
import './examples/alert.scss';

## Default alert
```js
import React from 'react';
import { Alert, AlertActionLink, AlertActionCloseButton } from '@patternfly/react-core';

class DefaultAlert extends React.Component {
constructor(props) {
super(props);
this.state = { alertOneVisible: true, alertTwoVisible: true };
this.hideAlertOne = () => this.setState({ alertOneVisible: false });
this.hideAlertTwo = () => this.setState({ alertTwoVisible: false });
}

render() {
const { alertOneVisible, alertTwoVisible } = this.state;
return (
<React.Fragment>
{alertOneVisible && (
<Alert
variant="default"
title="Default alert title"
action={<AlertActionCloseButton onClose={this.hideAlertOne} />}
>
Info alert description. <a href="#">This is a link.</a>
</Alert>
)}
{alertTwoVisible && (
<Alert
variant="default"
title="Default alert title"
action={<AlertActionCloseButton onClose={this.hideAlertTwo} />}
/>
)}
<Alert variant="default" title="Default alert title" action={<AlertActionLink>Action Button</AlertActionLink>} />
<Alert variant="default" title="Default alert title" />
</React.Fragment>
);
}
}
```

## Info alert
```js
import React from 'react';
Expand Down Expand Up @@ -185,6 +226,7 @@ class InlineAlert extends React.Component {
render() {
return (
<React.Fragment>
<Alert variant="default" isInline title="Default inline alert title"/>
<Alert variant="info" isInline title="Info inline alert title"/>
<Alert variant="success" isInline title="Success inline alert title" />
<Alert variant="warning" isInline title="Warning inline alert title" />
Expand Down
This file contains hidden or 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
Expand Up @@ -10,13 +10,14 @@ export enum AlertVariant {
success = 'success',
danger = 'danger',
warning = 'warning',
info = 'info'
info = 'info',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

feel like these should be in alphabetical order ...

default = 'default'
}

export interface AlertProps
extends Omit<React.HTMLProps<HTMLDivElement>, 'action' | 'title'> {
/** Adds Alert variant styles */
variant?: 'success' | 'danger' | 'warning' | 'info';
variant?: 'success' | 'danger' | 'warning' | 'info' | 'default';
/** Flag to indicate if the Alert is inline */
isInline?: boolean;
/** Title of the Alert */
Expand Down Expand Up @@ -51,7 +52,7 @@ export const Alert: React.FunctionComponent<AlertProps> = ({
</React.Fragment>
);

const customClassName = css(styles.alert, isInline && styles.modifiers.inline, getModifier(styles, variant, styles.modifiers.info), className);
const customClassName = css(styles.alert, isInline && styles.modifiers.inline, (variant !== AlertVariant.default ) && getModifier(styles, variant, styles.modifiers.info), className);

return (
<div {...props} className={customClassName} aria-label={ariaLabel}>
Expand Down
This file contains hidden or 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
Expand Up @@ -5,19 +5,21 @@ import {
CheckCircleIcon,
ExclamationCircleIcon,
ExclamationTriangleIcon,
InfoCircleIcon
InfoCircleIcon,
BellIcon
} from '@patternfly/react-icons';

export const variantIcons = {
success: CheckCircleIcon,
danger: ExclamationCircleIcon,
warning: ExclamationTriangleIcon,
info: InfoCircleIcon
info: InfoCircleIcon,
default: BellIcon
};

export interface AlertIconProps extends React.HTMLProps<HTMLDivElement> {
/** variant */
variant: 'success' | 'danger' | 'warning' | 'info';
variant: 'success' | 'danger' | 'warning' | 'info' | 'default';
/** className */
className?: string;
};
Expand Down
Loading

Back | FazBrowse Home | New Git URL