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

Commit

Permalink
feat(Form): Add event handling to FormSelect and children
Browse files Browse the repository at this point in the history
fix #219
  • Loading branch information
Greg-Hamel committed Jun 18, 2018
1 parent a30c3df commit 712a5df
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/components/Form/FormSelectGroup.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

import * as React from "react";
import cn from "classnames";
import type {
FormEvents,
FocusEvents,
MouseEvents,
PointerEvents,
} from "../../";

type Props = {|
...FormEvents,
...FocusEvents,
...MouseEvents,
...PointerEvents,
+children: Array<React.Element<any>>,
+className?: string,
+pills?: boolean,
Expand All @@ -15,13 +25,31 @@ function FormSelectGroup({
children,
pills,
canSelectMultiple,
onChange,
onFocus,
onBlur,
onClick,
onMouseEnter,
onMouseLeave,
onPointerEnter,
onPointerLeave,
}: Props): React.Node {
const classes = cn(
{ selectgroup: true, "w-100": true, "selectgroup-pills": pills },
className
);
return (
<div className={classes}>
<div
className={classes}
onChange={onChange}
onClick={onClick}
onFocus={onFocus}
onBlur={onBlur}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onPointerEnter={onPointerEnter}
onPointerLeave={onPointerLeave}
>
{canSelectMultiple
? children.map(itm => React.cloneElement(itm, { type: "checkbox" }))
: children}
Expand Down
34 changes: 34 additions & 0 deletions src/components/Form/FormSelectGroupItem.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
import * as React from "react";
import cn from "classnames";
import { Icon } from "../";
import type {
FormEvents,
FocusEvents,
MouseEvents,
PointerEvents,
} from "../../";

type Props = {|
...FormEvents,
...FocusEvents,
...MouseEvents,
...PointerEvents,
+className?: string,
+label?: string,
+value?: string | number | boolean,
Expand All @@ -22,6 +32,14 @@ function FormSelectGroupItem({
checked,
icon,
type,
onChange,
onFocus,
onBlur,
onClick,
onMouseEnter,
onMouseLeave,
onPointerEnter,
onPointerLeave,
}: Props): React.Node {
const classes = cn({ "selectgroup-item": true }, className);
const btnClasses = cn("selectgroup-button", {
Expand All @@ -37,6 +55,14 @@ function FormSelectGroupItem({
value={value}
className="selectgroup-input"
checked={checked}
onChange={onChange}
onClick={onClick}
onFocus={onFocus}
onBlur={onBlur}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onPointerEnter={onPointerEnter}
onPointerLeave={onPointerLeave}
/>
) : (
<input
Expand All @@ -45,6 +71,14 @@ function FormSelectGroupItem({
value={value}
className="selectgroup-input"
checked={checked}
onChange={onChange}
onClick={onClick}
onFocus={onFocus}
onBlur={onBlur}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onPointerEnter={onPointerEnter}
onPointerLeave={onPointerLeave}
/>
)}
<span className={btnClasses}>{outputLabel}</span>
Expand Down

0 comments on commit 712a5df

Please sign in to comment.