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

Commit 1e15422

Browse files
authored
Merge pull request #239 from MrJarv1s/FormEvents
Add Form component event handling
2 parents a1db287 + 712a5df commit 1e15422

20 files changed

+388
-37
lines changed

src/components/Form/Form.react.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ import FormInputGroupPrepend from "./FormInputGroupPrepend.react";
2929
import FormMaskedInput from "./FormMaskedInput.react";
3030
import FormDatePicker from "./FormDatePicker.react";
3131

32+
import type { FormEvents } from "../../";
33+
3234
export type Props = {|
35+
...FormEvents,
3336
+children?: React.Node,
3437
+className?: string,
3538
+action?: string,
3639
+method?: string,
37-
+onSubmit?: Function,
3840
|};
3941

4042
function Form({

src/components/Form/FormCheckbox.react.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import * as React from "react";
44
import cn from "classnames";
55
import Form from "./";
66

7+
import type { FormEvents, FocusEvents } from "../../";
8+
79
export type Props = {|
10+
...FormEvents,
11+
...FocusEvents,
812
+className?: string,
913
/**
1014
* Wrap the checkbox with a label
@@ -15,8 +19,6 @@ export type Props = {|
1519
+checked?: boolean,
1620
+disabled?: boolean,
1721
+readOnly?: boolean,
18-
+onChange?: (event: SyntheticInputEvent<HTMLInputElement>) => void,
19-
+onBlur?: (event: SyntheticInputEvent<HTMLInputElement>) => void,
2022
+isInline?: boolean,
2123
|};
2224

@@ -29,6 +31,8 @@ function FormCheckbox({
2931
disabled,
3032
readOnly,
3133
onChange,
34+
onFocus,
35+
onBlur,
3236
isInline,
3337
}: Props): React.Node {
3438
const classes = cn(
@@ -46,6 +50,8 @@ function FormCheckbox({
4650
disabled={disabled}
4751
readOnly={readOnly}
4852
onChange={onChange}
53+
onBlur={onBlur}
54+
onFocus={onFocus}
4955
/>
5056
);
5157

src/components/Form/FormColorCheckItem.react.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,27 @@ import * as React from "react";
44
import cn from "classnames";
55
import Grid from "../Grid";
66

7-
type Props = {| +className?: string, +color: string |};
7+
import type { MouseEvents, PointerEvents, FocusEvents } from "../../";
88

9-
function FormColorCheckItem({ className, color }: Props): React.Node {
9+
type Props = {|
10+
...MouseEvents,
11+
...PointerEvents,
12+
...FocusEvents,
13+
+className?: string,
14+
+color: string,
15+
|};
16+
17+
function FormColorCheckItem({
18+
className,
19+
color,
20+
onClick,
21+
onMouseEnter,
22+
onMouseLeave,
23+
onPointerEnter,
24+
onPointerLeave,
25+
onFocus,
26+
onBlur,
27+
}: Props): React.Node {
1028
const classes = cn(className);
1129
return (
1230
<Grid.Col auto className={classes}>
@@ -16,6 +34,13 @@ function FormColorCheckItem({ className, color }: Props): React.Node {
1634
type="checkbox"
1735
value={color}
1836
className="colorinput-input"
37+
onClick={onClick}
38+
onMouseEnter={onMouseEnter}
39+
onMouseLeave={onMouseLeave}
40+
onPointerEnter={onPointerEnter}
41+
onPointerLeave={onPointerLeave}
42+
onFocus={onFocus}
43+
onBlur={onBlur}
1944
/>
2045
<span className={`colorinput-color bg-${color}`} />
2146
</label>

src/components/Form/FormFileInput.react.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@
33
import * as React from "react";
44
import cn from "classnames";
55

6+
import type {
7+
FormEvents,
8+
FocusEvents,
9+
MouseEvents,
10+
PointerEvents,
11+
} from "../../";
12+
613
type Props = {|
14+
...FormEvents,
15+
...FocusEvents,
16+
...MouseEvents,
17+
...PointerEvents,
718
+className?: string,
819
+value?: string | number | boolean,
920
+name?: string,
1021
+label?: string,
1122
+disabled?: boolean,
1223
+readOnly?: boolean,
13-
+onChange?: (event: SyntheticInputEvent<HTMLInputElement>) => void,
1424
|};
1525

1626
type State = {| fileName: string |};
@@ -36,6 +46,13 @@ class FormFileInput extends React.Component<Props, State> {
3646
label: labelFromProps = "Choose file",
3747
disabled,
3848
readOnly,
49+
onClick,
50+
onMouseEnter,
51+
onMouseLeave,
52+
onPointerEnter,
53+
onPointerLeave,
54+
onFocus,
55+
onBlur,
3956
} = this.props;
4057

4158
const classes = cn("custom-file", className);
@@ -50,6 +67,13 @@ class FormFileInput extends React.Component<Props, State> {
5067
disabled={disabled}
5168
readOnly={readOnly}
5269
onChange={this._handleOnChange}
70+
onClick={onClick}
71+
onMouseEnter={onMouseEnter}
72+
onMouseLeave={onMouseLeave}
73+
onPointerEnter={onPointerEnter}
74+
onPointerLeave={onPointerLeave}
75+
onFocus={onFocus}
76+
onBlur={onBlur}
5377
/>
5478
<label
5579
className="custom-file-label"

src/components/Form/FormImageCheckItem.react.js

+18
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
import * as React from "react";
44
import Grid from "../Grid";
5+
import type { MouseEvents, PointerEvents, FocusEvents } from "../../";
56

67
type Props = {|
8+
...MouseEvents,
9+
...PointerEvents,
10+
...FocusEvents,
711
+className?: string,
812
+value: string | number,
913
+imageURL: string,
@@ -20,6 +24,13 @@ function FormImageCheckItem({
2024
col: { width = 6, sm = 4, md = 0, lg = 0 } = {},
2125
imageURL,
2226
value,
27+
onClick,
28+
onMouseEnter,
29+
onMouseLeave,
30+
onPointerEnter,
31+
onPointerLeave,
32+
onFocus,
33+
onBlur,
2334
}: Props): React.Node {
2435
return (
2536
<Grid.Col width={width} sm={sm} md={md} lg={lg}>
@@ -29,6 +40,13 @@ function FormImageCheckItem({
2940
type="checkbox"
3041
value={value}
3142
className="imagecheck-input"
43+
onClick={onClick}
44+
onMouseEnter={onMouseEnter}
45+
onMouseLeave={onMouseLeave}
46+
onPointerEnter={onPointerEnter}
47+
onPointerLeave={onPointerLeave}
48+
onFocus={onFocus}
49+
onBlur={onBlur}
3250
/>
3351
<figure className="imagecheck-figure">
3452
<img src={imageURL} alt="Select" className="imagecheck-image" />

src/components/Form/FormInput.react.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import { Icon } from "../";
55
import cn from "classnames";
66
import FormGroup from "./FormGroup.react";
77

8+
import type {
9+
FormEvents,
10+
MouseEvents,
11+
PointerEvents,
12+
FocusEvents,
13+
} from "../../";
14+
815
type FormStyle = {|
916
+className?: string,
1017
+icon?: string,
@@ -26,8 +33,10 @@ type FormStyle = {|
2633

2734
export type Props = {|
2835
...FormStyle,
29-
+onChange?: (event: SyntheticInputEvent<HTMLInputElement>) => void,
30-
+onBlur?: (event: SyntheticInputEvent<HTMLInputElement>) => void,
36+
...FormEvents,
37+
...MouseEvents,
38+
...PointerEvents,
39+
...FocusEvents,
3140
+placeholder?: string,
3241
+type?: "checkbox" | "radio" | "text" | "email" | "password",
3342
+value?: string | number | boolean,
@@ -55,6 +64,11 @@ function FormInput(props: Props): React.Node {
5564
value,
5665
checked,
5766
onChange,
67+
onMouseEnter,
68+
onMouseLeave,
69+
onPointerEnter,
70+
onPointerLeave,
71+
onFocus,
5872
onBlur,
5973
disabled,
6074
readOnly,
@@ -85,6 +99,11 @@ function FormInput(props: Props): React.Node {
8599
disabled,
86100
readOnly,
87101
onChange,
102+
onMouseEnter,
103+
onMouseLeave,
104+
onPointerEnter,
105+
onPointerLeave,
106+
onFocus,
88107
onBlur,
89108
};
90109

src/components/Form/FormLabel.react.js

+27-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,36 @@
33
import * as React from "react";
44
import cn from "classnames";
55

6-
type Props = {| +children?: React.Node, +className?: string, +aside?: string |};
6+
import type { MouseEvents, PointerEvents } from "../../";
77

8-
function FormLabel({ className, aside, children }: Props): React.Node {
8+
type Props = {|
9+
...MouseEvents,
10+
...PointerEvents,
11+
+children?: React.Node,
12+
+className?: string,
13+
+aside?: string,
14+
|};
15+
16+
function FormLabel({
17+
className,
18+
aside,
19+
children,
20+
onClick,
21+
onMouseEnter,
22+
onMouseLeave,
23+
onPointerEnter,
24+
onPointerLeave,
25+
}: Props): React.Node {
926
const classes = cn("form-label", className);
1027
return (
11-
<label className={classes}>
28+
<label
29+
className={classes}
30+
onClick={onClick}
31+
onMouseEnter={onMouseEnter}
32+
onMouseLeave={onMouseLeave}
33+
onPointerEnter={onPointerEnter}
34+
onPointerLeave={onPointerLeave}
35+
>
1236
{aside && <span className="form-label-small">{aside}</span>}
1337
{children}
1438
</label>

src/components/Form/FormMaskedInput.react.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@ import * as React from "react";
33
import cn from "classnames";
44
import MaskedInput from "react-text-mask";
55

6+
import type {
7+
FormEvents,
8+
FocusEvents,
9+
MouseEvents,
10+
PointerEvents,
11+
} from "../../";
12+
613
type Props = {|
14+
...FormEvents,
15+
...FocusEvents,
16+
...MouseEvents,
17+
...PointerEvents,
718
+mask: Array<string | RegExp>,
819
+className?: string,
920
+placeholder?: string,
1021
+guide?: boolean,
1122
+id?: string,
12-
+onBlur?: () => {},
13-
+onChange?: () => {},
1423
+value?: string,
1524
+valid?: boolean,
1625
+tick?: boolean,
@@ -35,6 +44,7 @@ function FormMaskedInput(props: Props): React.Node {
3544
},
3645
props.className
3746
);
47+
3848
return (
3949
<React.Fragment>
4050
<MaskedInput className={classes} {...props} />

src/components/Form/FormRadio.react.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@ import * as React from "react";
44
import cn from "classnames";
55
import Form from "./";
66

7+
import type {
8+
MouseEvents,
9+
PointerEvents,
10+
FormEvents,
11+
FocusEvents,
12+
} from "../../";
13+
714
type Props = {|
15+
...MouseEvents,
16+
...PointerEvents,
17+
...FormEvents,
18+
...FocusEvents,
819
+className?: string,
920
/**
1021
* Wrap the checkbox with a label
@@ -15,7 +26,6 @@ type Props = {|
1526
+checked?: boolean,
1627
+disabled?: boolean,
1728
+readOnly?: boolean,
18-
+onChange?: (event: SyntheticInputEvent<HTMLInputElement>) => void,
1929
+isInline?: boolean,
2030
|};
2131

@@ -28,15 +38,35 @@ function FormRadio({
2838
disabled,
2939
readOnly,
3040
onChange,
41+
onMouseEnter,
42+
onMouseLeave,
43+
onPointerEnter,
44+
onPointerLeave,
45+
onBlur,
46+
onFocus,
47+
onClick,
3148
isInline,
3249
}: Props): React.Node {
3350
const classes = cn(
3451
"custom-control custom-radio",
3552
{ "custom-control-inline": isInline },
3653
className
3754
);
55+
56+
const events = {
57+
onChange: onChange,
58+
onMouseEnter: onMouseEnter,
59+
onMouseLeave: onMouseLeave,
60+
onPointerEnter: onPointerEnter,
61+
onPointerLeave: onPointerLeave,
62+
onBlur: onBlur,
63+
onFocus: onFocus,
64+
onClick: onClick,
65+
};
66+
3867
const inputComponent = (
3968
<Form.Input
69+
{...events}
4070
type="radio"
4171
name={name}
4272
value={value}

0 commit comments

Comments
 (0)