Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #221 from MrJarv1s/events
Browse files Browse the repository at this point in the history
Event Types
  • Loading branch information
jonthomp authored Jun 14, 2018
2 parents e5f3e29 + 7d04234 commit d78c711
Show file tree
Hide file tree
Showing 22 changed files with 553 additions and 38 deletions.
28 changes: 21 additions & 7 deletions src/components/Alert/Alert.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import * as React from "react";
import cn from "classnames";
import { Icon, Avatar } from "../";
import { Icon, Avatar, Button } from "../";
import AlertLink from "./AlertLink.react";

import type { MouseEvents, PointerEvents } from "../../";

type AlertType =
| "primary"
| "secondary"
Expand All @@ -14,6 +16,8 @@ type AlertType =
| "danger";

type Props = {|
...MouseEvents,
...PointerEvents,
+children?: React.Node,
+className?: string,
/**
Expand Down Expand Up @@ -68,6 +72,11 @@ class Alert extends React.Component<Props, State> {
hasExtraSpace,
isDismissible,
avatar,
onClick,
onMouseEnter,
onMouseLeave,
onPointerEnter,
onPointerLeave,
}: Props = this.props;
const classes = cn(
"alert",
Expand All @@ -80,15 +89,20 @@ class Alert extends React.Component<Props, State> {
},
className
);

const events = {
onClick: onClick,
onMouseEnter: onMouseEnter,
onMouseLeave: onMouseLeave,
onPointerEnter: onPointerEnter,
onPointerLeave: onPointerLeave,
};

return (
!isDismissed && (
<div className={classes} role="alert">
<div {...events} className={classes} role="alert">
{isDismissible && (
<button
type="button"
className="close"
onClick={this._handleOnDismissClick}
/>
<Button className="close" onClick={this._handleOnDismissClick} />
)}
{avatar && <Avatar imageURL={avatar} />}
{icon && <Icon name={icon} className="mr-2" isAriaHidden={true} />}
Expand Down
14 changes: 14 additions & 0 deletions src/components/Avatar/Avatar.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { Icon } from "../";
import cn from "classnames";
import AvatarList from "./AvatarList.react";

import type { MouseEvents, PointerEvents } from "../../";

export type Props = {|
...MouseEvents,
...PointerEvents,
+children?: React.Node,
+className?: string,
/**
Expand Down Expand Up @@ -45,6 +49,11 @@ function Avatar({
placeholder,
icon,
color = "",
onClick,
onMouseEnter,
onMouseLeave,
onPointerEnter,
onPointerLeave,
}: Props): React.Node {
const classes = cn(
{
Expand All @@ -68,6 +77,11 @@ function Avatar({
)
: style
}
onClick={onClick}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onPointerEnter={onPointerEnter}
onPointerLeave={onPointerLeave}
>
{icon && <Icon name={icon} />}
{status && <span className={`avatar-status bg-${status}`} />}
Expand Down
51 changes: 20 additions & 31 deletions src/components/Button/Button.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { Icon } from "../";
import ButtonList from "./ButtonList.react";
import ButtonDropdown from "./ButtonDropdown.react";

import type { MouseEvents, PointerEvents } from "../../";

type PropsForAll = {|
...MouseEvents,
...PointerEvents,
+size?: "sm" | "lg",
+outline?: boolean,
+link?: boolean,
Expand All @@ -24,31 +28,27 @@ type PropsForAll = {|
+to?: string,
+isOption?: boolean,
+rootRef?: (?HTMLElement) => void,
+onClick?: (event: SyntheticMouseEvent<HTMLElement>) => mixed,
|};

type DefaultButtonComponent = {|
...PropsForAll,
+RootComponent?: "button",
+type?: "button" | "submit" | "reset",
+value?: string,
+onClick?: (event: SyntheticMouseEvent<HTMLInputElement>) => mixed,
|};

type BtnAComponent = {|
...PropsForAll,
+RootComponent: "a",
+href?: string,
+target?: string,
+onClick?: (SyntheticMouseEvent<HTMLLinkElement>) => mixed,
|};

type BtnInputComponent = {|
...PropsForAll,
+RootComponent: "input",
+type?: "button" | "submit" | "reset",
+value?: string,
+onClick?: (SyntheticMouseEvent<HTMLInputElement>) => mixed,
|};

export type Props = DefaultButtonComponent | BtnAComponent | BtnInputComponent;
Expand All @@ -73,6 +73,10 @@ const Button = (props: Props): React.Node => {
rootRef,
to,
onClick,
onMouseEnter,
onMouseLeave,
onPointerEnter,
onPointerLeave,
} = props;

const classes = cn(
Expand All @@ -98,6 +102,11 @@ const Button = (props: Props): React.Node => {
const propsForAll = {
className: classes,
disabled: disabled,
onClick: onClick,
onMouseEnter: onMouseEnter,
onMouseLeave: onMouseLeave,
onPointerEnter: onPointerEnter,
onPointerLeave: onPointerLeave,
};

const childrenForAll = (
Expand All @@ -112,49 +121,29 @@ const Button = (props: Props): React.Node => {
);

if (!props.RootComponent || props.RootComponent === "button") {
const { type, value, onClick } = props;
const { type, value } = props;
return (
<button
{...propsForAll}
type={type}
value={value}
onClick={onClick}
ref={rootRef}
>
<button {...propsForAll} type={type} value={value} ref={rootRef}>
{childrenForAll}
</button>
);
} else if (props.RootComponent === "input") {
const { type, value, onClick } = props;
const { type, value } = props;

return (
<input
{...propsForAll}
type={type}
value={value}
onClick={onClick}
ref={rootRef}
/>
);
return <input {...propsForAll} type={type} value={value} ref={rootRef} />;
} else if (props.RootComponent === "a") {
const { href, target, onClick } = props;
const { href, target } = props;

return (
<a
{...propsForAll}
href={href}
target={target}
onClick={onClick}
ref={rootRef}
>
<a {...propsForAll} href={href} target={target} ref={rootRef}>
{childrenForAll}
</a>
);
} else {
const Component: React.ElementType = props.RootComponent;

return (
<Component {...propsForAll} to={to} onClick={onClick}>
<Component {...propsForAll} to={to}>
{childrenForAll}
</Component>
);
Expand Down
20 changes: 20 additions & 0 deletions src/flow/events/Animation.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @flow

/**
* Type definitions for Animation EventHandling
*/

export type Animation = {|
/**
* Handle Animation Start
*/
+onAnimationStart?: (event: SyntheticAnimationEvent<*>) => mixed,
/**
* Handle Animation End
*/
+onAnimationEnd?: (event: SyntheticAnimationEvent<*>) => mixed,
/**
* Handle Animation Interation
*/
+onAnimationIteration?: (event: SyntheticAnimationEvent<*>) => mixed,
|};
20 changes: 20 additions & 0 deletions src/flow/events/Clipboard.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @flow

/**
* Type definitions for Clipboard EventHandling
*/

export type Clipboard = {|
/**
* Handle Copy Event
*/
+onCopy?: (event: SyntheticClipboardEvent<*>) => mixed,
/**
* Handle Cut Event
*/
+onCut?: (event: SyntheticClipboardEvent<*>) => mixed,
/**
* Handle Paste Event
*/
+onPaste?: (event: SyntheticClipboardEvent<*>) => mixed,
|};
20 changes: 20 additions & 0 deletions src/flow/events/Composition.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @flow

/**
* Type definitions for Composition EventHandling
*/

export type Composition = {|
/**
* Handle Composition Start
*/
+onCompositionStart?: (event: SyntheticClipboardEvent<*>) => mixed,
/**
* Handle Composition End
*/
+onCompositionEnd?: (event: SyntheticClipboardEvent<*>) => mixed,
/**
* Handle Composition Update
*/
+onCompositionUpdate?: (event: SyntheticClipboardEvent<*>) => mixed,
|};
16 changes: 16 additions & 0 deletions src/flow/events/Focus.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow

/**
* Type definitions for Focus EventHandling
*/

export type Focus = {|
/**
* Handle Blur Event
*/
+onBlur?: (event: SyntheticFocusEvent<*>) => mixed,
/**
* Handle Focus Event
*/
+onFocus?: (event: SyntheticFocusEvent<*>) => mixed,
|};
24 changes: 24 additions & 0 deletions src/flow/events/Form.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @flow

/**
* Type definitions for Form EventHandling
*/

export type Form = {|
/**
* Handle Change Event
*/
+onChange?: (event: SyntheticInputEvent<*>) => mixed,
/**
* Handle Input Event
*/
+onInput?: (event: SyntheticInputEvent<*>) => mixed,
/**
* Handle Invalid Input Event
*/
+onInvalid?: (event: SyntheticInputEvent<*>) => mixed,
/**
* Handle Form Submit Event
*/
+onSubmit?: (event: SyntheticInputEvent<*>) => mixed,
|};
16 changes: 16 additions & 0 deletions src/flow/events/Image.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow

/**
* Type definitions for Image EventHandling
*/

export type Image = {|
/**
* Handle Image Loading Event
*/
+onLoad?: (event: SyntheticEvent<*>) => mixed,
/**
* Handle Image Error Event
*/
+onError?: (event: SyntheticEvent<*>) => mixed,
|};
20 changes: 20 additions & 0 deletions src/flow/events/Keyboard.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @flow

/**
* Type definitions for Keyboard EventHandling
*/

export type Keyboard = {|
/**
* Handle Key Down Event
*/
+onKeyDown?: (event: SyntheticKeyboardEvent<*>) => mixed,
/**
* Handle Key Press Event
*/
+onKeyPress?: (event: SyntheticKeyboardEvent<*>) => mixed,
/**
* Handle Key Up Event
*/
+onKeyUp?: (event: SyntheticKeyboardEvent<*>) => mixed,
|};
Loading

0 comments on commit d78c711

Please sign in to comment.