Skip to content

Commit 7b33483

Browse files
author
Sasha Kondrashov
committed
move data passed back from components out of props
1 parent ef8684c commit 7b33483

27 files changed

+123
-147
lines changed

src/addons/Pagination/Pagination.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import * as React from 'react'
33
import { ForwardRefComponent, SemanticShorthandItem } from '../../generic'
44
import PaginationItem, { PaginationItemProps } from './PaginationItem'
55

6-
export interface PaginationProps extends StrictPaginationProps {
7-
[key: string]: any
8-
}
9-
10-
export interface StrictPaginationProps {
6+
export interface PaginationProps {
117
/** A pagination item can have an aria label. */
128
'aria-label'?: string
139

@@ -47,7 +43,11 @@ export interface StrictPaginationProps {
4743
* @param {SyntheticEvent} event - React's original SyntheticEvent.
4844
* @param {object} data - All props.
4945
*/
50-
onPageChange?: (event: React.MouseEvent<HTMLAnchorElement>, data: PaginationProps) => void
46+
onPageChange?: (
47+
event: React.MouseEvent<HTMLAnchorElement>,
48+
props: PaginationProps,
49+
activePage: number,
50+
) => void
5151

5252
/** Number of always visible pages before and after the current one. */
5353
siblingRange?: number | string

src/addons/Pagination/Pagination.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const Pagination = React.forwardRef(function (props, ref) {
5555
}
5656

5757
setActivePage(nextActivePage)
58-
_.invoke(props, 'onPageChange', e, { ...props, activePage: nextActivePage })
58+
_.invoke(props, 'onPageChange', e, props, nextActivePage)
5959
}
6060

6161
const handleItemOverrides = (active, type, value) => (predefinedProps) => ({

src/addons/Portal/Portal.d.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import * as React from 'react'
22
import PortalInner from './PortalInner'
33

4-
export interface PortalProps extends StrictPortalProps {
5-
[key: string]: any
6-
}
7-
8-
export interface StrictPortalProps {
4+
export interface PortalProps {
95
/** Primary content. */
106
children?: React.ReactNode
117

@@ -52,31 +48,31 @@ export interface StrictPortalProps {
5248
* @param {SyntheticEvent} event - React's original SyntheticEvent.
5349
* @param {object} data - All props.
5450
*/
55-
onClose?: (event: React.MouseEvent<HTMLElement>, data: PortalProps) => void
51+
onClose?: (event: React.MouseEvent<HTMLElement>, props: PortalProps, open: boolean) => void
5652

5753
/**
5854
* Called when the portal is mounted on the DOM
5955
*
6056
* @param {null}
6157
* @param {object} data - All props.
6258
*/
63-
onMount?: (nothing: null, data: PortalProps) => void
59+
onMount?: (nothing: null, props: PortalProps) => void
6460

6561
/**
6662
* Called when an open event happens
6763
*
6864
* @param {SyntheticEvent} event - React's original SyntheticEvent.
6965
* @param {object} data - All props.
7066
*/
71-
onOpen?: (event: React.MouseEvent<HTMLElement>, data: PortalProps) => void
67+
onOpen?: (event: React.MouseEvent<HTMLElement>, props: PortalProps, open: boolean) => void
7268

7369
/**
7470
* Called when the portal is unmounted from the DOM
7571
*
7672
* @param {null}
7773
* @param {object} data - All props.
7874
*/
79-
onUnmount?: (nothing: null, data: PortalProps) => void
75+
onUnmount?: (nothing: null, props: PortalProps) => void
8076

8177
/** Controls whether or not the portal is displayed. */
8278
open?: boolean

src/addons/Portal/Portal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function Portal(props) {
6161
debug('open()')
6262

6363
setOpen(true)
64-
_.invoke(props, 'onOpen', e, { ...props, open: true })
64+
_.invoke(props, 'onOpen', e, props, true)
6565
}
6666

6767
const openPortalWithTimeout = (e, delay) => {
@@ -77,7 +77,7 @@ function Portal(props) {
7777
debug('close()')
7878

7979
setOpen(false)
80-
_.invoke(props, 'onClose', e, { ...props, open: false })
80+
_.invoke(props, 'onClose', e, props, false)
8181
}
8282

8383
const closePortalWithTimeout = (e, delay) => {

src/addons/Portal/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default, PortalProps, StrictPortalProps } from './Portal'
1+
export { default, PortalProps } from './Portal'

src/addons/TextArea/TextArea.d.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import * as React from 'react'
22
import { ForwardRefComponent } from '../../generic'
33

4-
export interface TextAreaProps extends StrictTextAreaProps {
5-
[key: string]: any
6-
}
7-
8-
export interface StrictTextAreaProps {
4+
export interface TextAreaProps {
95
/** An element type to render as (string or function). */
106
as?: any
117

@@ -15,15 +11,23 @@ export interface StrictTextAreaProps {
1511
* @param {SyntheticEvent} event - The React SyntheticEvent object
1612
* @param {object} data - All props and the event value.
1713
*/
18-
onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, data: TextAreaProps) => void
14+
onChange?: (
15+
event: React.ChangeEvent<HTMLTextAreaElement>,
16+
props: TextAreaProps,
17+
value: string,
18+
) => void
1919

2020
/**
2121
* Called on input.
2222
*
2323
* @param {SyntheticEvent} event - The React SyntheticEvent object
2424
* @param {object} data - All props and the event value.
2525
*/
26-
onInput?: (event: React.FormEvent<HTMLTextAreaElement>, data: TextAreaProps) => void
26+
onInput?: (
27+
event: React.FormEvent<HTMLTextAreaElement>,
28+
props: TextAreaProps,
29+
value: string,
30+
) => void
2731

2832
/** Indicates row count for a TextArea. */
2933
rows?: number | string

src/addons/TextArea/TextArea.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ const TextArea = React.forwardRef(function (props, ref) {
1515
const handleChange = (e) => {
1616
const newValue = _.get(e, 'target.value')
1717

18-
_.invoke(props, 'onChange', e, { ...props, value: newValue })
18+
_.invoke(props, 'onChange', e, props, newValue)
1919
}
2020

2121
const handleInput = (e) => {
2222
const newValue = _.get(e, 'target.value')
2323

24-
_.invoke(props, 'onInput', e, { ...props, value: newValue })
24+
_.invoke(props, 'onInput', e, props, newValue)
2525
}
2626

2727
const rest = getUnhandledProps(TextArea, props)

src/elements/Input/Input.d.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import * as React from 'react'
33
import { ForwardRefComponent, HtmlInputrops, SemanticShorthandItem } from '../../generic'
44
import { LabelProps } from '../Label'
55

6-
export interface InputProps extends StrictInputProps {
7-
[key: string]: any
8-
}
9-
10-
export interface StrictInputProps {
6+
export interface InputProps {
117
/** An element type to render as (string or function). */
128
as?: any
139

@@ -62,7 +58,7 @@ export interface StrictInputProps {
6258
* @param {ChangeEvent} event - React's original SyntheticEvent.
6359
* @param {object} data - All props and a proposed value.
6460
*/
65-
onChange?: (event: React.ChangeEvent<HTMLInputElement>, data: InputOnChangeData) => void
61+
onChange?: (event: React.ChangeEvent<HTMLInputElement>, props: InputProps, value: string) => void
6662

6763
/** An Input can vary in size. */
6864
size?: 'mini' | 'small' | 'large' | 'big' | 'huge' | 'massive'
@@ -77,10 +73,6 @@ export interface StrictInputProps {
7773
type?: string
7874
}
7975

80-
export interface InputOnChangeData extends InputProps {
81-
value: string
82-
}
83-
8476
declare const Input: ForwardRefComponent<InputProps, HTMLInputElement>
8577

8678
export default Input

src/elements/Input/Input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const Input = React.forwardRef(function (props, ref) {
7272
const handleChange = (e) => {
7373
const newValue = _.get(e, 'target.value')
7474

75-
_.invoke(props, 'onChange', e, { ...props, value: newValue })
75+
_.invoke(props, 'onChange', e, props, newValue)
7676
}
7777

7878
const partitionProps = () => {

src/modules/Checkbox/Checkbox.d.ts

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import * as React from 'react'
22
import { ForwardRefComponent, HtmlLabelProps, SemanticShorthandItem } from '../../generic'
33

4-
export interface CheckboxProps extends StrictCheckboxProps {
5-
[key: string]: any
6-
}
7-
8-
export interface StrictCheckboxProps {
4+
export interface CheckboxProps {
95
/** An element type to render as (string or function). */
106
as?: any
117

@@ -45,31 +41,51 @@ export interface StrictCheckboxProps {
4541
* @param {SyntheticEvent} event - React's original SyntheticEvent.
4642
* @param {object} data - All props and proposed checked/indeterminate state.
4743
*/
48-
onChange?: (event: React.FormEvent<HTMLInputElement>, data: CheckboxProps) => void
44+
onChange?: (
45+
event: React.FormEvent<HTMLInputElement>,
46+
props: CheckboxProps,
47+
checked: boolean,
48+
indeterminate: boolean,
49+
) => void
4950

5051
/**
5152
* Called when the checkbox or label is clicked.
5253
*
5354
* @param {SyntheticEvent} event - React's original SyntheticEvent.
5455
* @param {object} data - All props and current checked/indeterminate state.
5556
*/
56-
onClick?: (event: React.MouseEvent<HTMLInputElement>, data: CheckboxProps) => void
57+
onClick?: (
58+
event: React.MouseEvent<HTMLInputElement>,
59+
props: CheckboxProps,
60+
checked: boolean,
61+
indeterminate: boolean,
62+
) => void
5763

5864
/**
5965
* Called when the user presses down on the mouse.
6066
*
6167
* @param {SyntheticEvent} event - React's original SyntheticEvent.
6268
* @param {object} data - All props and current checked/indeterminate state.
6369
*/
64-
onMouseDown?: (event: React.MouseEvent<HTMLInputElement>, data: CheckboxProps) => void
70+
onMouseDown?: (
71+
event: React.MouseEvent<HTMLInputElement>,
72+
props: CheckboxProps,
73+
checked: boolean,
74+
indeterminate: boolean,
75+
) => void
6576

6677
/**
6778
* Called when the user releases the mouse.
6879
*
6980
* @param {SyntheticEvent} event - React's original SyntheticEvent.
7081
* @param {object} data - All props and current checked/indeterminate state.
7182
*/
72-
onMouseUp?: (event: React.MouseEvent<HTMLInputElement>, data: CheckboxProps) => void
83+
onMouseUp?: (
84+
event: React.MouseEvent<HTMLInputElement>,
85+
props: CheckboxProps,
86+
checked: boolean,
87+
indeterminate: boolean,
88+
) => void
7389

7490
/** Format as a radio element. This means it is an exclusive option. */
7591
radio?: boolean

src/modules/Checkbox/Checkbox.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ const Checkbox = React.forwardRef(function (props, ref) {
9696

9797
debug('handleChange()', _.get(e, 'target.tagName'))
9898

99-
_.invoke(props, 'onChange', e, {
100-
...props,
99+
_.invoke(props, 'onChange', e, props, {
101100
checked: !checked,
102101
indeterminate: false,
103102
})
@@ -117,8 +116,7 @@ const Checkbox = React.forwardRef(function (props, ref) {
117116

118117
// https://github.com/Semantic-Org/Semantic-UI-React/pull/3351
119118
if (!isLabelClickAndForwardedToInput) {
120-
_.invoke(props, 'onClick', e, {
121-
...props,
119+
_.invoke(props, 'onClick', e, props, {
122120
checked: !checked,
123121
indeterminate: !!indeterminate,
124122
})
@@ -147,8 +145,7 @@ const Checkbox = React.forwardRef(function (props, ref) {
147145
const handleMouseDown = (e) => {
148146
debug('handleMouseDown()')
149147

150-
_.invoke(props, 'onMouseDown', e, {
151-
...props,
148+
_.invoke(props, 'onMouseDown', e, props, {
152149
checked: !!checked,
153150
indeterminate: !!indeterminate,
154151
})
@@ -166,8 +163,7 @@ const Checkbox = React.forwardRef(function (props, ref) {
166163
debug('handleMouseUp()')
167164

168165
isClickFromMouse.current = true
169-
_.invoke(props, 'onMouseUp', e, {
170-
...props,
166+
_.invoke(props, 'onMouseUp', e, props, {
171167
checked: !!checked,
172168
indeterminate: !!indeterminate,
173169
})

src/modules/Embed/Embed.d.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import {
88
} from '../../generic'
99
import { IconProps } from '../../elements/Icon'
1010

11-
export interface EmbedProps extends StrictEmbedProps {
12-
[key: string]: any
13-
}
14-
15-
export interface StrictEmbedProps {
11+
export interface EmbedProps {
1612
/** An element type to render as (string or function). */
1713
as?: any
1814

@@ -61,7 +57,7 @@ export interface StrictEmbedProps {
6157
* @param {SyntheticEvent} event - React's original SyntheticEvent.
6258
* @param {object} data - All props and proposed value.
6359
*/
64-
onClick?: (event: React.MouseEvent<HTMLDivElement>, data: EmbedProps) => void
60+
onClick?: (event: React.MouseEvent<HTMLDivElement>, props: EmbedProps, active: boolean) => void
6561

6662
/** A placeholder image for embed. */
6763
placeholder?: string

src/modules/Embed/Embed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const Embed = React.forwardRef(function (props, ref) {
7070
}
7171

7272
const handleClick = (e) => {
73-
_.invoke(props, 'onClick', e, { ...props, active: true })
73+
_.invoke(props, 'onClick', e, props, true)
7474
if (!active) {
7575
setActive(true)
7676
}

0 commit comments

Comments
 (0)