Skip to content

chore(alert): move examples to individual files #11957

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
301 changes: 26 additions & 275 deletions packages/react-core/src/components/Alert/examples/Alert.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Fragment } from 'react';
import { Alert } from '@patternfly/react-core';
import UsersIcon from '@patternfly/react-icons/dist/esm/icons/users-icon';
import BoxIcon from '@patternfly/react-icons/dist/esm/icons/box-icon';
import DatabaseIcon from '@patternfly/react-icons/dist/esm/icons/database-icon';
import ServerIcon from '@patternfly/react-icons/dist/esm/icons/server-icon';
import LaptopIcon from '@patternfly/react-icons/dist/esm/icons/laptop-icon';

export const AlertCustomIcons: React.FunctionComponent = () => (
<Fragment>
<Alert customIcon={<UsersIcon />} title="Default alert title" />
<Alert customIcon={<BoxIcon />} variant="info" title="Info alert title" />
<Alert customIcon={<DatabaseIcon />} variant="success" title="Success alert title" />
<Alert customIcon={<ServerIcon />} variant="warning" title="Warning alert title" />
<Alert customIcon={<LaptopIcon />} variant="danger" title="Danger alert title" />
</Fragment>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Fragment } from 'react';
import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core';

export const AlertExpandable: React.FunctionComponent = () => (
<Fragment>
<Alert
isExpandable
variant="success"
title="Success alert title"
// eslint-disable-next-line no-console
actionClose={<AlertActionCloseButton onClose={() => console.log('Clicked the close button')} />}
>
<p>Success alert description. This should tell the user more information about the alert.</p>
</Alert>
<Alert
isExpandable
isInline
variant="success"
title="Success alert title"
actionLinks={
<Fragment>
<AlertActionLink component="a" href="#">
View details
</AlertActionLink>
<AlertActionLink // eslint-disable-next-line no-console
onClick={() => console.log('Clicked on Ignore')}
>
Ignore
</AlertActionLink>
</Fragment>
}
>
<p>Success alert description. This should tell the user more information about the alert.</p>
</Alert>
</Fragment>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Fragment } from 'react';
import { Alert } from '@patternfly/react-core';

export const AlertInlineVariants: React.FunctionComponent = () => (
<Fragment>
<Alert variant="custom" isInline title="Custom 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" />
<Alert variant="danger" isInline title="Danger inline alert title" />
</Fragment>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Fragment } from 'react';
import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core';

export const AlertInlineVariations: React.FunctionComponent = () => (
<Fragment>
<Alert
isInline
variant="success"
title="Success alert title"
actionLinks={
<Fragment>
<AlertActionLink component="a" href="#">
View details
</AlertActionLink>
<AlertActionLink // eslint-disable-next-line no-console
onClick={() => console.log('Clicked on Ignore')}
>
Ignore
</AlertActionLink>
</Fragment>
}
>
<p>Success alert description. This should tell the user more information about the alert.</p>
</Alert>
<Alert isInline variant="success" title="Success alert title">
<p>
Success alert description. This should tell the user more information about the alert.{' '}
<a href="#">This is a link.</a>
</p>
</Alert>
<Alert
isInline
variant="success"
title="Success alert title"
// eslint-disable-next-line no-console
actionClose={<AlertActionCloseButton onClose={() => console.log('Clicked the close button')} />}
>
<p>Short alert description.</p>
</Alert>
<Alert isInline variant="success" title="div success alert title" component="div" />
<Alert isInline variant="success" title="h6 Success alert title" component="h6">
<p>Short alert description.</p>
</Alert>
</Fragment>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Fragment } from 'react';
import { Alert } from '@patternfly/react-core';

export const AlertPlainInlineVariants: React.FunctionComponent = () => (
<Fragment>
<Alert variant="custom" isInline isPlain title="Custom inline alert title" />
<Alert variant="info" isInline isPlain title="Info inline alert title" />
<Alert variant="success" isInline isPlain title="Success inline alert title" />
<Alert variant="warning" isInline isPlain title="Warning inline alert title" />
<Alert variant="danger" isInline isPlain title="Danger inline alert title" />
</Fragment>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Alert } from '@patternfly/react-core';

export const AlertPlainInlineVariations: React.FunctionComponent = () => (
<Alert isInline isPlain variant="success" title="Success alert title">
<p>Success alert description. This should tell the user more information about the alert.</p>
</Alert>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Fragment } from 'react';
import { Alert, AlertActionCloseButton } from '@patternfly/react-core';

export const AlertStaticLiveRegion: React.FunctionComponent = () => (
<Fragment>
<Alert
isLiveRegion
variant="info"
title="Default live region configuration"
// eslint-disable-next-line no-console
actionClose={<AlertActionCloseButton onClose={() => console.log('Clicked the close button')} />}
>
This alert uses the recommended <code>isLiveRegion</code> prop to automatically set ARIA attributes and CSS
classes.
</Alert>
<Alert
aria-live="assertive"
aria-relevant="additions text"
aria-atomic="true"
variant="info"
title="Customized live region"
// eslint-disable-next-line no-console
actionClose={<AlertActionCloseButton onClose={() => console.log('Clicked the close button')} />}
>
You can alternatively omit the <code>isLiveRegion</code> prop to specify ARIA attributes and CSS manually on the
containing element.
</Alert>
</Fragment>
);
45 changes: 45 additions & 0 deletions packages/react-core/src/components/Alert/examples/AlertTimeout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Fragment, useState } from 'react';
import { Alert, AlertActionLink, AlertGroup, Button } from '@patternfly/react-core';

export const AlertTimeout: React.FunctionComponent = () => {
const [alerts, setAlerts] = useState<React.ReactNode[]>([]);
const [newAlertKey, setNewAlertKey] = useState<number>(0);

const onClick = () => {
const timeout = 8000;
setNewAlertKey((key) => key + 1);
setAlerts((prevAlerts) => [
<Alert
title="Default timeout Alert"
timeout={timeout}
actionLinks={
<Fragment>
<AlertActionLink component="a" href="#">
View details
</AlertActionLink>
<AlertActionLink // eslint-disable-next-line no-console
onClick={() => console.log('Clicked on Ignore')}
>
Ignore
</AlertActionLink>
</Fragment>
}
key={newAlertKey}
>
This alert will dismiss after {`${timeout / 1000} seconds`}
</Alert>,
...prevAlerts
]);
};

return (
<Fragment>
<Button variant="secondary" onClick={onClick}>
Add alert
</Button>
<AlertGroup hasAnimations isLiveRegion>
{alerts}
</AlertGroup>
</Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Fragment } from 'react';
import { Alert } from '@patternfly/react-core';

export const AlertTruncated: React.FunctionComponent = () => (
<Fragment>
<Alert
variant="info"
truncateTitle={1}
title={`
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pellentesque neque cursus enim fringilla tincidunt. Proin lobortis aliquam dictum. Nam vel ullamcorper nulla, nec blandit dolor. Vivamus pellentesque neque justo, nec accumsan nulla rhoncus id. Suspendisse mollis, tortor quis faucibus volutpat, sem leo fringilla turpis, ac lacinia augue metus in nulla. Cras vestibulum lacinia orci. Pellentesque sodales consequat interdum. Sed porttitor tincidunt metus nec iaculis. Pellentesque non commodo justo. Morbi feugiat rhoncus neque, vitae facilisis diam aliquam nec. Sed dapibus vitae quam at tristique. Nunc vel commodo mi. Mauris et rhoncus leo.
`}
/>
<Alert
variant="warning"
truncateTitle={2}
title={`
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pellentesque neque cursus enim fringilla tincidunt. Proin lobortis aliquam dictum. Nam vel ullamcorper nulla, nec blandit dolor. Vivamus pellentesque neque justo, nec accumsan nulla rhoncus id. Suspendisse mollis, tortor quis faucibus volutpat, sem leo fringilla turpis, ac lacinia augue metus in nulla. Cras vestibulum lacinia orci. Pellentesque sodales consequat interdum. Sed porttitor tincidunt metus nec iaculis. Pellentesque non commodo justo. Morbi feugiat rhoncus neque, vitae facilisis diam aliquam nec. Sed dapibus vitae quam at tristique. Nunc vel commodo mi. Mauris et rhoncus leo.
`}
/>
<Alert
variant="danger"
truncateTitle={3}
title={`
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pellentesque neque cursus enim fringilla tincidunt. Proin lobortis aliquam dictum. Nam vel ullamcorper nulla, nec blandit dolor. Vivamus pellentesque neque justo, nec accumsan nulla rhoncus id. Suspendisse mollis, tortor quis faucibus volutpat, sem leo fringilla turpis, ac lacinia augue metus in nulla. Cras vestibulum lacinia orci. Pellentesque sodales consequat interdum. Sed porttitor tincidunt metus nec iaculis. Pellentesque non commodo justo. Morbi feugiat rhoncus neque, vitae facilisis diam aliquam nec. Sed dapibus vitae quam at tristique. Nunc vel commodo mi. Mauris et rhoncus leo.
`}
/>
</Fragment>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Fragment } from 'react';
import { Alert } from '@patternfly/react-core';

export const AlertVariants: React.FunctionComponent = () => (
<Fragment>
<Alert title="Custom alert title" ouiaId="CustomAlert" />
<Alert variant="info" title="Info alert title" ouiaId="InfoAlert" />
<Alert variant="success" title="Success alert title" ouiaId="SuccessAlert" />
<Alert variant="warning" title="Warning alert title" ouiaId="WarningAlert" />
<Alert variant="danger" title="Danger alert title" ouiaId="DangerAlert" />
</Fragment>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Fragment } from 'react';
import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core';

export const AlertVariations: React.FunctionComponent = () => (
<Fragment>
<Alert
variant="success"
title="Success alert title"
actionLinks={
<Fragment>
<AlertActionLink component="a" href="#">
View details
</AlertActionLink>
<AlertActionLink // eslint-disable-next-line no-console
onClick={() => console.log('Clicked on Ignore')}
>
Ignore
</AlertActionLink>
</Fragment>
}
>
<p>Success alert description. This should tell the user more information about the alert.</p>
</Alert>
<Alert variant="success" title="Success alert title">
<p>
Success alert description. This should tell the user more information about the alert.{' '}
<a href="#">This is a link.</a>
</p>
</Alert>
<Alert
variant="success"
title="Success alert title"
// eslint-disable-next-line no-console
actionClose={<AlertActionCloseButton onClose={() => console.log('Clicked the close button')} />}
>
<p>Short alert description.</p>
</Alert>
<Alert variant="success" title="div success alert title" component="div" />
<Alert variant="success" title="h6 Success alert title" component="h6">
<p>Short alert description.</p>
</Alert>
</Fragment>
);
Loading