Skip to content

Commit 317ba96

Browse files
Checkbox: Add checkProps if using old checkbox
If oldEventParameterOrder is true, a warning will fire. This will tell folks to change their path—if they are consuming the source code. The CommonJS named imports will just have to break at the next breaking change due to the parameter change, since you can’t change the path.
1 parent abd737c commit 317ba96

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

components/checkbox/__examples__/default.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
// `~` is replaced with design-system-react at runtime
33
import IconSettings from '~/components/icon-settings';
4-
import Checkbox from '~/components/checkbox';
4+
import Checkbox from '~/components/forms/checkbox';
55

66
class Example extends React.Component {
77
static displayName = 'CheckboxExample';

components/checkbox/check-props.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@
33
/* eslint-disable import/no-mutable-exports */
44
/* eslint-disable max-len */
55

6+
import deprecatedEventParameter from '../../utilities/warning/deprecated-event-parameter';
67
import onlyOneOfProperties from '../../utilities/warning/only-one-of-properties';
78

89
let checkProps = function () {};
910

1011
if (process.env.NODE_ENV !== 'production') {
1112
checkProps = function (COMPONENT, props) {
13+
deprecatedEventParameter(
14+
COMPONENT,
15+
{
16+
oldEventParameterOrder: props.oldEventParameterOrder,
17+
propAsString: 'onChange',
18+
propAsValue: props.onChange,
19+
},
20+
'`components/forms/checkbox` is deprecated. `components/checkbox` should be used. When this path update is made `onChange` event parameters will change from `onChange(value, event, { value } to `onChange(event, { value }). Please update your event parameters when you change paths.` If you are using the CommonJS named import, `Checkbox` events will break at the next breaking change release. Please review https://github.com/salesforce/design-system-react/releases when you upgrade.'
21+
);
22+
1223
if (props.variant === 'toggle' && props.indeterminate === true) {
1324
onlyOneOfProperties(
1425
COMPONENT,

components/forms/checkbox/index.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import React from 'react';
55
// Alias
66
import Checkbox from '../../checkbox';
77

8-
const OldCheckbox = (props) => (
9-
<Checkbox oldEventParameterOrder {...props} />
10-
);
8+
const OldCheckbox = (props) => <Checkbox oldEventParameterOrder {...props} />;
119

1210
export default OldCheckbox;

components/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export CardEmpty from './card/empty';
4747
export SLDSCardFilter from './card/filter';
4848
export CardFilter from './card/filter';
4949

50-
export SLDSCheckbox from './checkbox';
51-
export Checkbox from './checkbox';
50+
export SLDSCheckbox from './forms/checkbox';
51+
export Checkbox from './forms/checkbox';
5252

5353
export SLDSCombobox from './combobox';
5454
export Combobox from './combobox';
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */
2+
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
3+
4+
/* eslint-disable import/no-mutable-exports */
5+
/* eslint-disable max-len */
6+
7+
// This function will deliver a warning message to the browser console about an event parameter change.
8+
import lowPriorityWarning from './low-priority-warning';
9+
10+
let deprecated = function () {};
11+
12+
if (process.env.NODE_ENV !== 'production') {
13+
const hasWarned = {};
14+
15+
deprecated = function (
16+
control,
17+
{
18+
oldEventParameterOrder, // flag that tells which parameter order is in use
19+
propAsString, // key name of prop being warned about
20+
log, // log function that will disable console warning and pipe to another function log({ message })
21+
},
22+
comment
23+
) {
24+
const additionalComment = comment ? ` ${comment}` : '';
25+
const warnOnFirstOccurrenceKey = control + propAsString;
26+
const triggerWarning = oldEventParameterOrder;
27+
28+
if (!hasWarned[warnOnFirstOccurrenceKey]) {
29+
const message = `[Design System React] ${additionalComment}`;
30+
31+
if (triggerWarning && log) {
32+
log({ message });
33+
} else {
34+
lowPriorityWarning(
35+
!triggerWarning, // false value triggers warning
36+
message
37+
);
38+
}
39+
// store global flag to limit warnings to first issue
40+
hasWarned[warnOnFirstOccurrenceKey] = triggerWarning;
41+
}
42+
};
43+
}
44+
45+
export default deprecated;

0 commit comments

Comments
 (0)