This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
feat(alert): v1 #1063
Merged
Merged
feat(alert): v1 #1063
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1fcbc00
feat(alert): v1
bmdalex 1bbf46a
addressed PR comments
bmdalex 770c5ac
reverted major color changes
bmdalex 1965de2
rearranged methods in Alert.tsx
bmdalex 38c2e00
added closeButton color styles
bmdalex f482118
fixed colors in siteVariables and added changelog
bmdalex c1f9c9c
- removed onClose prop;
bmdalex 7de8cbb
aligned with latest design
bmdalex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExampleRtl = () => <Alert content="مرحبا العالم" /> | ||
|
||
export default AlertExampleRtl |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as React from 'react' | ||
|
||
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
import NonPublicSection from 'docs/src/components/ComponentDoc/NonPublicSection' | ||
|
||
const Rtl = () => ( | ||
<NonPublicSection title="Rtl"> | ||
<ComponentExample examplePath="components/Alert/Rtl/AlertExample.rtl" /> | ||
</NonPublicSection> | ||
) | ||
|
||
export default Rtl |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Alert/Types/AlertExample.shorthand.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExample = () => <Alert content="This is a default alert" /> | ||
|
||
export default AlertExample |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExample = () => <Alert>This is a default alert</Alert> | ||
|
||
export default AlertExample |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as React from 'react' | ||
|
||
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
bmdalex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
||
const Types = () => ( | ||
<ExampleSection title="Types"> | ||
<ComponentExample | ||
title="Default" | ||
description="A default Alert." | ||
examplePath="components/Alert/Types/AlertExample" | ||
/> | ||
</ExampleSection> | ||
) | ||
|
||
export default Types |
19 changes: 19 additions & 0 deletions
19
docs/src/examples/components/Alert/Variations/AlertExampleAction.shorthand.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
class AlertExampleClosable extends React.Component<{}, { open: boolean }> { | ||
state = { open: true } | ||
|
||
render() { | ||
return ( | ||
this.state.open && ( | ||
<Alert | ||
content="This is a closable alert" | ||
action={{ icon: 'close', onClick: () => this.setState({ open: false }) }} | ||
/> | ||
) | ||
) | ||
} | ||
} | ||
|
||
export default AlertExampleClosable |
14 changes: 14 additions & 0 deletions
14
docs/src/examples/components/Alert/Variations/AlertExampleAttached.shorthand.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as React from 'react' | ||
import { Alert, Input } from '@stardust-ui/react' | ||
|
||
const AlertExampleShorthand = () => ( | ||
<> | ||
<Alert attached content="This is a top attached alert" /> | ||
<Input fluid placeholder="Name..." /> | ||
<br /> <br /> | ||
<Input fluid placeholder="Surname..." /> | ||
<Alert attached="bottom" content="This is a bottom attached alert" /> | ||
</> | ||
bmdalex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
export default AlertExampleShorthand |
14 changes: 14 additions & 0 deletions
14
docs/src/examples/components/Alert/Variations/AlertExampleAttached.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as React from 'react' | ||
import { Alert, Input } from '@stardust-ui/react' | ||
|
||
const AlertExampleShorthand = () => ( | ||
<> | ||
<Alert attached>This is a top attached alert</Alert> | ||
<Input fluid placeholder="Name..." /> | ||
<br /> <br /> | ||
<Input fluid placeholder="Surname..." /> | ||
<Alert attached="bottom">This is a bottom attached alert</Alert> | ||
</> | ||
) | ||
|
||
export default AlertExampleShorthand |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Alert/Variations/AlertExampleDanger.shorthand.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExampleDanger = () => <Alert danger content="This is a danger alert" /> | ||
|
||
export default AlertExampleDanger |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Alert/Variations/AlertExampleDanger.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExampleDanger = () => <Alert danger>This is a danger alert</Alert> | ||
|
||
export default AlertExampleDanger |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Alert/Variations/AlertExampleInfo.shorthand.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExampleInfo = () => <Alert info content="This is an informational alert" /> | ||
|
||
export default AlertExampleInfo |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Alert/Variations/AlertExampleInfo.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExampleInfo = () => <Alert info>This is an informational alert</Alert> | ||
|
||
export default AlertExampleInfo |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Alert/Variations/AlertExampleSuccess.shorthand.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExampleSuccess = () => <Alert success content="This is a success alert" /> | ||
|
||
export default AlertExampleSuccess |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Alert/Variations/AlertExampleSuccess.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExampleSuccess = () => <Alert success>This is a success alert</Alert> | ||
|
||
export default AlertExampleSuccess |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Alert/Variations/AlertExampleWarning.shorthand.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExampleWarning = () => <Alert warning content="This is a warning alert" /> | ||
|
||
export default AlertExampleWarning |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Alert/Variations/AlertExampleWarning.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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react' | ||
import { Alert } from '@stardust-ui/react' | ||
|
||
const AlertExampleWarning = () => <Alert warning>This is a warning alert</Alert> | ||
|
||
export default AlertExampleWarning |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as React from 'react' | ||
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
||
const Variations = () => ( | ||
<ExampleSection title="Variations"> | ||
<ComponentExample | ||
title="Info" | ||
description="An alert may be formatted to display information." | ||
examplePath="components/Alert/Variations/AlertExampleInfo" | ||
/> | ||
<ComponentExample | ||
title="Warning" | ||
description="An alert may be formatted to display a warning message." | ||
examplePath="components/Alert/Variations/AlertExampleWarning" | ||
/> | ||
<ComponentExample | ||
title="Success" | ||
description="An alert may be formatted to display a successful message." | ||
examplePath="components/Alert/Variations/AlertExampleSuccess" | ||
/> | ||
<ComponentExample | ||
title="Danger" | ||
description="An alert may be formatted to display a danger message." | ||
examplePath="components/Alert/Variations/AlertExampleDanger" | ||
/> | ||
<ComponentExample | ||
title="Attached" | ||
description="An Alert can be can be formatted to attach itself to other content." | ||
examplePath="components/Alert/Variations/AlertExampleAttached" | ||
/> | ||
<ComponentExample | ||
title="Action" | ||
description="An Alert can provide the user with an action. Click on the icon to see the effect." | ||
examplePath="components/Alert/Variations/AlertExampleAction" | ||
/> | ||
</ExampleSection> | ||
) | ||
|
||
export default Variations |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as React from 'react' | ||
|
||
import Rtl from './Rtl' | ||
import Types from './Types' | ||
import Variations from './Variations' | ||
|
||
const AlertExamples = () => ( | ||
<> | ||
<Types /> | ||
<Variations /> | ||
<Rtl /> | ||
</> | ||
) | ||
|
||
export default AlertExamples |
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 |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import * as _ from 'lodash' | ||
import * as PropTypes from 'prop-types' | ||
import * as React from 'react' | ||
|
||
import { | ||
UIComponent, | ||
UIComponentProps, | ||
ContentComponentProps, | ||
commonPropTypes, | ||
customPropTypes, | ||
childrenExist, | ||
rtlTextContainer, | ||
} from '../../lib' | ||
import { RenderResultConfig } from 'src/lib/renderComponent' | ||
import { defaultBehavior } from '../../lib/accessibility' | ||
import { Accessibility } from '../../lib/accessibility/types' | ||
import { ReactProps, ShorthandValue } from '../../types' | ||
import Box from '../Box/Box' | ||
import Button, { ButtonProps } from '../Button/Button' | ||
|
||
export interface AlertSlotClassNames { | ||
content: string | ||
action: string | ||
} | ||
|
||
export interface AlertProps extends UIComponentProps, ContentComponentProps<ShorthandValue> { | ||
/** | ||
* Accessibility behavior if overridden by the user. | ||
* @default defaultBehavior | ||
*/ | ||
accessibility?: Accessibility | ||
|
||
/** Button shorthand for the action slot. */ | ||
action?: ShorthandValue<ButtonProps> | ||
|
||
/** Controls Alert's relation to neighboring items. */ | ||
attached?: boolean | 'top' | 'bottom' | ||
bmdalex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** An alert may be formatted to display a danger message. */ | ||
danger?: boolean | ||
|
||
/** An alert may be formatted to display information. */ | ||
info?: boolean | ||
|
||
/** An alert may be formatted to display a successful message. */ | ||
success?: boolean | ||
|
||
/** An alert may be formatted to display a warning message. */ | ||
warning?: boolean | ||
} | ||
|
||
/** | ||
* A Alert displays information that explains nearby content. | ||
* @accessibility | ||
* Other considerations: | ||
* - if Alert contains action slot, textual representation needs to be provided by using 'title', 'aria-label' or 'aria-labelledby' attributes | ||
*/ | ||
class Alert extends UIComponent<ReactProps<AlertProps>> { | ||
static displayName = 'Alert' | ||
static className = 'ui-alert' | ||
|
||
static slotClassNames: AlertSlotClassNames = { | ||
content: `${Alert.className}__content`, | ||
action: `${Alert.className}__action`, | ||
} | ||
|
||
static propTypes = { | ||
...commonPropTypes.createCommon({ content: 'shorthand' }), | ||
action: customPropTypes.itemShorthand, | ||
attached: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['top', 'bottom'])]), | ||
danger: PropTypes.bool, | ||
info: PropTypes.bool, | ||
success: PropTypes.bool, | ||
warning: PropTypes.bool, | ||
} | ||
|
||
static defaultProps = { accessibility: defaultBehavior } | ||
|
||
renderContent = ({ styles }: RenderResultConfig<AlertProps>) => { | ||
const { action, content } = this.props | ||
|
||
return ( | ||
<> | ||
{Box.create(content, { | ||
defaultProps: { | ||
className: Alert.slotClassNames.content, | ||
styles: styles.content, | ||
}, | ||
})} | ||
{Button.create(action, { | ||
defaultProps: { | ||
iconOnly: true, | ||
text: true, | ||
className: Alert.slotClassNames.action, | ||
styles: styles.action, | ||
}, | ||
})} | ||
</> | ||
) | ||
} | ||
|
||
renderComponent(config: RenderResultConfig<AlertProps>) { | ||
const { accessibility, classes, ElementType, unhandledProps } = config | ||
const { children, content } = this.props | ||
|
||
return ( | ||
<ElementType | ||
className={classes.root} | ||
{...accessibility.attributes.root} | ||
{...rtlTextContainer.getAttributes({ forElements: [children, content] })} | ||
{...unhandledProps} | ||
> | ||
{childrenExist(children) ? children : this.renderContent(config)} | ||
</ElementType> | ||
) | ||
} | ||
} | ||
bmdalex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export default Alert |
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.