Skip to content
Closed
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
116 changes: 52 additions & 64 deletions components/alert/Alert.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,56 @@
import React from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import Fade from "../fade";
import Fade from '../fade';

/**
* The alert component can be used to display contextual user messages.
*/
const Alert = props => {
const {
className,
closeClassName,
closeAriaLabel,
tag: Tag,
theme,
open,
dismissible,
children,
transition,
fade,
...attrs
} = props;

const classes = classNames(
className,
"alert",
`alert-${theme}`,
dismissible && "alert-dismissible"
);

const closeClasses = classNames("close", closeClassName);

const alertTransition = {
...Fade.defaultProps,
...transition,
baseClass: fade ? transition.baseClass : "",
timeout: fade ? transition.timeout : 0
};

return (
<Fade
{...attrs}
{...alertTransition}
tag={Tag}
className={classes}
in={open}
role="alert"
>
{dismissible ? (
<button
type="button"
className={closeClasses}
aria-label={closeAriaLabel}
onClick={dismissible}
>
<span aria-hidden="true">&times;</span>
</button>
) : null}
{children}
</Fade>
);
};
export const Alert = ({
className,
closeClassName,
closeAriaLabel,
tag: Tag,
theme,
open,
dismissible,
children,
transition,
fade,
...attrs
}) => (
<Fade
{...{
...attrs,
...Fade.defaultProps,
...transition,
baseClass: fade ? transition.baseClass : '',
timeout: fade ? transition.timeout : 0,
tag: Tag,
className: classNames(
className,
'alert',
`alert-${theme}`,
dismissible && 'alert-dismissible'
),
in: open,
role: 'alert',
}}
>
{dismissible ? (
<button
type="button"
className={classNames('close', closeClassName)}
aria-label={closeAriaLabel}
onClick={dismissible}
>
<span aria-hidden="true">&times;</span>
</button>
) : null}
{children}
</Fade>
);

Alert.propTypes = {
/**
Expand Down Expand Up @@ -102,19 +92,17 @@ Alert.propTypes = {
/**
* The component tag type.
*/
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
tag: PropTypes.oneOfType([ PropTypes.func, PropTypes.string ])
};

Alert.defaultProps = {
theme: "primary",
theme: 'primary',
open: true,
tag: "div",
closeAriaLabel: "Close",
tag: 'div',
closeAriaLabel: 'Close',
fade: true,
transition: {
...Fade.defaultProps,
unmountOnExit: true
}
};

export default Alert;
20 changes: 10 additions & 10 deletions components/alert/docs/01-basic-alert.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Alert } from "shards-react";
import React from 'react';
import { Alert } from 'shards-react';

/**
* ## Basic Alerts
Expand All @@ -10,49 +10,49 @@ export default function AlertExample() {
return (
<div className="example">
<Alert theme="primary">
Alert - Primary Theme (default) -{" "}
Alert - Primary Theme (default) -{' '}
<a className="alert-link" href="#">
Example Link
</a>
</Alert>
<Alert theme="secondary">
Alert - Secondary Theme -{" "}
Alert - Secondary Theme -{' '}
<a className="alert-link" href="#">
Example Link
</a>
</Alert>
<Alert theme="success">
Alert - Success Theme -{" "}
Alert - Success Theme -{' '}
<a className="alert-link" href="#">
Example Link
</a>
</Alert>
<Alert theme="danger">
Alert - Danger Theme -{" "}
Alert - Danger Theme -{' '}
<a className="alert-link" href="#">
Example Link
</a>
</Alert>
<Alert theme="warning">
Alert - Warning Theme -{" "}
Alert - Warning Theme -{' '}
<a className="alert-link" href="#">
Example Link
</a>
</Alert>
<Alert theme="info">
Alert - Info Theme -{" "}
Alert - Info Theme -{' '}
<a className="alert-link" href="#">
Example Link
</a>
</Alert>
<Alert theme="light">
Alert - Light Theme -{" "}
Alert - Light Theme -{' '}
<a className="alert-link" href="#">
Example Link
</a>
</Alert>
<Alert theme="dark">
Alert - Dark Theme -{" "}
Alert - Dark Theme -{' '}
<a className="alert-link" href="#">
Example Link
</a>
Expand Down
8 changes: 4 additions & 4 deletions components/alert/docs/02-dismissible-alert.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Alert } from "shards-react";
import React from 'react';
import { Alert } from 'shards-react';

/**
* ## Dismissible Alerts
Expand All @@ -10,7 +10,7 @@ export default class DismissibleAlertExample extends React.Component {
constructor(props) {
super(props);
this.dismiss = this.dismiss.bind(this);
this.state = { visible: true };
this.state = {visible: true};
}

render() {
Expand All @@ -22,6 +22,6 @@ export default class DismissibleAlertExample extends React.Component {
}

dismiss() {
this.setState({ visible: false });
this.setState({visible: false});
}
}
12 changes: 6 additions & 6 deletions components/alert/docs/03-self-dismissing-alert.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Alert, Button } from "shards-react";
import React from 'react';
import { Alert, Button } from 'shards-react';

/**
* ## Self Dismissing Alert
Expand All @@ -24,20 +24,20 @@ export default class SelfDismissingAlertExample extends React.Component {

showAlert() {
this.clearInterval();
this.setState({ visible: true, countdown: 0, timeUntilDismissed: 5 });
this.setState({visible: true, countdown: 0, timeUntilDismissed: 5});
this.interval = setInterval(this.handleTimeChange, 1000);
}

handleTimeChange() {
if (this.state.countdown < this.state.timeUntilDismissed - 1) {
this.setState({
...this.state,
...{ countdown: this.state.countdown + 1 }
...{countdown: this.state.countdown + 1}
});
return;
}

this.setState({ ...this.state, ...{ visible: false } });
this.setState({...this.state, ...{visible: false}});
this.clearInterval();
}

Expand All @@ -50,7 +50,7 @@ export default class SelfDismissingAlertExample extends React.Component {
return (
<div>
<Alert className="mb-3" open={this.state.visible} theme="success">
Success! This alert will will be dismissed in{" "}
Success! This alert will will be dismissed in{' '}
{this.state.timeUntilDismissed - this.state.countdown} seconds!
</Alert>
<Button onClick={this.showAlert}>Show Alert!</Button>
Expand Down
4 changes: 1 addition & 3 deletions components/alert/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import Alert from "./Alert";

export default Alert;
export * from './Alert';
45 changes: 24 additions & 21 deletions components/badge/Badge.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import React from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

/**
* Badges are really great for labels and count values.
*/
const Badge = props => {
let { tag: Tag, className, theme, pill, outline, ...attrs } = props;
export const Badge = ({
tag: Tag,
className,
theme,
pill,
outline,
...attrs
}) => {
Tag = attrs.href && Tag === 'span' ? 'a' : Tag;

const classes = classNames(
className,
"badge",
theme && !outline && `badge-${theme}`,
outline && `badge-outline-${theme}`,
pill && "badge-pill"
);

Tag = attrs.href && Tag === "span" ? "a" : Tag;

return <Tag {...attrs} className={classes} />;
return <Tag {...attrs} className={
classNames(
className,
'badge',
theme && !outline && `badge-${theme}`,
outline && `badge-outline-${theme}`,
pill && 'badge-pill'
)
}/>;
};

Badge.propTypes = {
Expand All @@ -45,14 +50,12 @@ Badge.propTypes = {
/**
* The component tag.
*/
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
tag: PropTypes.oneOfType([ PropTypes.func, PropTypes.string ])
};

Badge.defaultProps = {
theme: "primary",
theme: 'primary',
pill: false,
outline: false,
tag: "span"
tag: 'span'
};

export default Badge;
4 changes: 2 additions & 2 deletions components/badge/docs/01-basic-badges.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Badge } from "shards-react";
import React from 'react';
import { Badge } from 'shards-react';

/**
* ## Contextual Variations
Expand Down
4 changes: 2 additions & 2 deletions components/badge/docs/02-pill-badges.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Badge } from "shards-react";
import React from 'react';
import { Badge } from 'shards-react';

/**
* ## Pill-Shaped Badges
Expand Down
4 changes: 2 additions & 2 deletions components/badge/docs/03-outline-badges.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Badge } from "shards-react";
import React from 'react';
import { Badge } from 'shards-react';

/**
* ## Outline Badges
Expand Down
4 changes: 2 additions & 2 deletions components/badge/docs/04-mixed-badges.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Badge } from "shards-react";
import React from 'react';
import { Badge } from 'shards-react';

/**
* ## Mixed Effects
Expand Down
4 changes: 2 additions & 2 deletions components/badge/docs/05-link-badges.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Badge } from "shards-react";
import React from 'react';
import { Badge } from 'shards-react';

/**
* ## Link Badges
Expand Down
4 changes: 1 addition & 3 deletions components/badge/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import Badge from "./Badge";

export default Badge;
export * from './Badge';
Loading