@sproutsocial/racine 11.7.0 → 11.9.0-typescript.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/__flow__/Button/{index.js → index.tsx} +20 -21
  3. package/__flow__/Button/{styles.js → styles.ts} +1 -1
  4. package/__flow__/Checkbox/index.stories.js +73 -56
  5. package/__flow__/Checkbox/styles.js +75 -75
  6. package/__flow__/Collapsible/index.js +3 -2
  7. package/__flow__/EnumIconNames.js +1 -1
  8. package/__flow__/Icon/index.stories.js +41 -36
  9. package/__flow__/IconViewBoxes.js +1 -1
  10. package/__flow__/Image/index.js +10 -2
  11. package/__flow__/Input/index.js +47 -23
  12. package/__flow__/Input/index.stories.js +59 -33
  13. package/__flow__/Input/index.test.js +20 -0
  14. package/__flow__/Input/styles.js +2 -2
  15. package/__flow__/Loader/index.stories.js +18 -14
  16. package/__flow__/Numeral/index.stories.js +109 -50
  17. package/__flow__/Radio/index.stories.js +41 -26
  18. package/__flow__/SegmentedControl/index.js +3 -2
  19. package/__flow__/Switch/index.stories.js +26 -18
  20. package/__flow__/TableCell/index.js +9 -2
  21. package/__flow__/ToggleHint/index.js +9 -2
  22. package/__flow__/systemProps/color.js +1 -2
  23. package/__flow__/utils/responsiveProps/index.test.js +10 -2
  24. package/commonjs/IconViewBoxes.js +2 -0
  25. package/commonjs/Input/index.js +42 -22
  26. package/commonjs/Input/styles.js +2 -2
  27. package/commonjs/include-icons.js +1 -1
  28. package/dist/iconList.js +1 -1
  29. package/dist/icons.svg +1 -1
  30. package/icons/help-alt.svg +3 -0
  31. package/icons/plug.svg +3 -0
  32. package/includeIcons.js +1 -1
  33. package/lib/IconViewBoxes.js +2 -0
  34. package/lib/Input/index.js +42 -22
  35. package/lib/Input/styles.js +2 -2
  36. package/lib/include-icons.js +1 -1
  37. package/package.json +6 -1
  38. package/commonjs/Button/index.js +0 -70
  39. package/commonjs/Button/styles.js +0 -66
  40. package/lib/Button/index.js +0 -57
  41. package/lib/Button/styles.js +0 -48
@@ -1,9 +1,22 @@
1
1
  import React from "react";
2
- import { number, select } from "@storybook/addon-knobs";
3
2
  import Numeral from "./index";
4
3
 
5
- const localeOptions = {
6
- "": null,
4
+ const localeOptions = [
5
+ "United States (en-US)",
6
+ "English (en)",
7
+ "Arabic (ar-EG)",
8
+ "Brazil (pt-BR)",
9
+ "India (en-IN)",
10
+ "French (fr-FR)",
11
+ "Spain (es-ES)",
12
+ "Mexico (es-MX)",
13
+ "Germany (de-DE)",
14
+ "German (de)",
15
+ "Japan (ja-JP)",
16
+ "Japanese (ja)",
17
+ ];
18
+
19
+ const localeMapping = {
7
20
  "United States (en-US)": "en-US",
8
21
  "English (en)": "en",
9
22
  "Arabic (ar-EG)": "ar-EG",
@@ -18,8 +31,15 @@ const localeOptions = {
18
31
  "Japanese (ja)": "ja",
19
32
  };
20
33
 
21
- const currencyOptions = {
22
- "": null,
34
+ const currencyOptions = [
35
+ "Egyptian £",
36
+ "European €",
37
+ "Indian ₹",
38
+ "Japanese ¥",
39
+ "USA $",
40
+ ];
41
+
42
+ const currencyMapping = {
23
43
  "Egyptian £": "EGP",
24
44
  "European €": "EUR",
25
45
  "Indian ₹": "INR",
@@ -27,15 +47,24 @@ const currencyOptions = {
27
47
  "USA $": "USD",
28
48
  };
29
49
 
30
- const formatOptions = {
31
- "": null,
50
+ const formatOptions = ["decimal", "currency", "percent"];
51
+
52
+ const formatMapping = {
32
53
  decimal: "decimal",
33
54
  currency: "currency",
34
55
  percent: "percent",
35
56
  };
36
57
 
37
- const abbreviateOptions = {
38
- "": null,
58
+ const abbreviateOptions = [
59
+ "true",
60
+ "false",
61
+ " 500",
62
+ "1_000",
63
+ "10_000",
64
+ "100_000",
65
+ ];
66
+
67
+ const abbreviateMapping = {
39
68
  true: true,
40
69
  false: false,
41
70
  " 500": 500,
@@ -44,79 +73,109 @@ const abbreviateOptions = {
44
73
  "100_000": 100000,
45
74
  };
46
75
 
47
- const precisionOptions = {
48
- "": null,
49
- " 0": 0,
50
- " 1": 1,
51
- " 2": 2,
52
- " 3": 3,
53
- " 6": 6,
76
+ const precisionOptions = ["0", "1", "2", "3", "6", "none"];
77
+
78
+ const precisionMapping = {
79
+ "0": 0,
80
+ "1": 1,
81
+ "2": 2,
82
+ "3": 3,
83
+ "6": 6,
54
84
  none: "none",
55
85
  };
56
86
 
57
87
  export default {
58
88
  title: "Numeral",
89
+ component: Numeral,
90
+ argTypes: {
91
+ locale: {
92
+ control: "select",
93
+ options: localeOptions,
94
+ mapping: localeMapping,
95
+ },
96
+ format: {
97
+ control: "select",
98
+ options: formatOptions,
99
+ mapping: formatMapping,
100
+ },
101
+ currency: {
102
+ control: "select",
103
+ options: currencyOptions,
104
+ mapping: currencyMapping,
105
+ },
106
+ abbreviate: {
107
+ control: "select",
108
+ options: abbreviateOptions,
109
+ mapping: abbreviateMapping,
110
+ },
111
+ precision: {
112
+ control: "select",
113
+ options: precisionOptions,
114
+ mapping: precisionMapping,
115
+ },
116
+ },
117
+ args: {
118
+ color: "text.headline",
119
+ number: 12.89,
120
+ },
59
121
  };
60
122
 
61
- // We wrap the knobs select function to properly create undefined values
62
- const _select = (...args) => {
63
- const answer = select(...args);
64
-
65
- return answer === null ? undefined : answer;
66
- };
67
-
68
- export const defaultStory = () => (
69
- <Numeral
70
- number={number("Number", 12.89)}
71
- locale={_select("Locale", localeOptions)}
72
- format={_select("Format", formatOptions)}
73
- currency={_select("Currency", currencyOptions)}
74
- abbreviate={_select("Abbreviate", abbreviateOptions)}
75
- precision={_select("Precision", precisionOptions)}
76
- color="text.headline"
77
- />
78
- );
123
+ export const defaultStory = (args) => <Numeral {...args} />;
79
124
 
80
125
  defaultStory.story = {
81
126
  name: "Default",
82
127
  };
83
128
 
84
- export const total = () => (
85
- <Numeral
86
- number={100}
87
- fontWeight="semibold"
88
- fontSize={500}
89
- color="text.headline"
90
- />
91
- );
129
+ export const total = (args) => <Numeral {...args} />;
130
+
131
+ total.args = {
132
+ number: 100,
133
+ fontWeight: "semibold",
134
+ fontSize: 500,
135
+ };
92
136
 
93
137
  total.story = {
94
138
  name: "Total",
95
139
  };
96
140
 
97
- export const trend = () => <Numeral number={100} color="teal.500" />;
141
+ export const trend = (args) => <Numeral {...args} />;
142
+
143
+ trend.args = {
144
+ number: 100,
145
+ color: "teal.500",
146
+ };
98
147
 
99
148
  trend.story = {
100
149
  name: "Trend",
101
150
  };
102
151
 
103
- export const noPrecision = () => (
104
- <Numeral number={123.45678} precision="none" color="text.headline" />
105
- );
152
+ export const noPrecision = (args) => <Numeral {...args} />;
153
+
154
+ noPrecision.args = {
155
+ number: 123.45678,
156
+ precision: "none",
157
+ };
106
158
 
107
159
  noPrecision.story = {
108
160
  name: "No Precision",
109
161
  };
110
162
 
111
- export const currencyPrecision = () => (
112
- <Numeral number={123.4} format="currency" color="text.headline" />
113
- );
163
+ export const currencyPrecision = (args) => <Numeral {...args} />;
164
+
165
+ currencyPrecision.args = {
166
+ number: 123.4,
167
+ format: "currency",
168
+ };
114
169
 
115
170
  currencyPrecision.story = {
116
171
  name: "Currency precision",
117
172
  };
118
173
 
119
- export const invalid = () => <Numeral number={null} />;
174
+ export const invalid = (args) => <Numeral {...args} />;
175
+
176
+ invalid.args = {
177
+ number: null,
178
+ };
120
179
 
121
180
  invalid.story = {
122
181
  name: "Invalid",
@@ -1,58 +1,73 @@
1
1
  import React from "react";
2
- import { boolean } from "@storybook/addon-knobs";
3
-
4
2
  import Radio from "./";
5
3
 
6
4
  export default {
7
5
  title: "Radio",
6
+ component: Radio,
7
+ };
8
+
9
+ export const Unchecked = (args) => <Radio {...args} />;
10
+
11
+ Unchecked.args = {
12
+ checked: false,
8
13
  };
9
14
 
10
- export const Unchecked = () => <Radio checked={boolean("checked", false)} />;
15
+ export const Checked = (args) => <Radio {...args} />;
11
16
 
12
- export const Checked = () => <Radio checked={boolean("checked", true)} />;
17
+ Checked.args = {
18
+ checked: true,
19
+ };
20
+
21
+ export const DisabledUnchecked = (args) => <Radio {...args} />;
13
22
 
14
- export const DisabledUnchecked = () => (
15
- <Radio disabled={boolean("disabled", true)} />
16
- );
23
+ DisabledUnchecked.args = {
24
+ disabled: true,
25
+ };
17
26
 
18
27
  DisabledUnchecked.story = {
19
28
  name: "Disabled/Unchecked",
20
29
  };
21
30
 
22
- export const DisabledChecked = () => (
23
- <Radio
24
- checked={boolean("checked", true)}
25
- disabled={boolean("disabled", true)}
26
- />
27
- );
31
+ export const DisabledChecked = (args) => <Radio {...args} />;
32
+
33
+ DisabledChecked.args = {
34
+ checked: true,
35
+ disabled: true,
36
+ };
28
37
 
29
38
  DisabledChecked.story = {
30
39
  name: "Disabled/Checked",
31
40
  };
32
41
 
33
- export const LabelledChecked = () => (
34
- <Radio checked={boolean("checked", true)} label="Toggle Me" />
35
- );
42
+ export const LabelledChecked = (args) => <Radio {...args} />;
43
+
44
+ LabelledChecked.args = {
45
+ checked: true,
46
+ label: "Toggle Me",
47
+ };
36
48
 
37
49
  LabelledChecked.story = {
38
50
  name: "Labelled/Checked",
39
51
  };
40
52
 
41
- export const LabelledUnchecked = () => (
42
- <Radio checked={boolean("checked", false)} label="Toggle Me" />
43
- );
53
+ export const LabelledUnchecked = (args) => <Radio {...args} />;
54
+
55
+ LabelledUnchecked.args = {
56
+ checked: false,
57
+ label: "Toggle Me",
58
+ };
44
59
 
45
60
  LabelledUnchecked.story = {
46
61
  name: "Labelled/Unchecked",
47
62
  };
48
63
 
49
- export const LabelledDisabled = () => (
50
- <Radio
51
- checked={boolean("checked", true)}
52
- disabled={boolean("disabled", true)}
53
- label="Toggle Me"
54
- />
55
- );
64
+ export const LabelledDisabled = (args) => <Radio {...args} />;
65
+
66
+ LabelledDisabled.args = {
67
+ checked: false,
68
+ disabled: true,
69
+ label: "Toggle Me",
70
+ };
56
71
 
57
72
  LabelledDisabled.story = {
58
73
  name: "Labelled/Disabled",
@@ -17,8 +17,9 @@ type TypeSegmentedControlContext = {
17
17
  onChange: (e: SyntheticInputEvent<HTMLInputElement>) => void,
18
18
  };
19
19
 
20
- const SegmentedControlContext =
21
- React.createContext<?TypeSegmentedControlContext>(null);
20
+ const SegmentedControlContext = React.createContext<?TypeSegmentedControlContext>(
21
+ null
22
+ );
22
23
 
23
24
  type TypeSegmentedControlItemProps = {
24
25
  /** The value of this item. Should be unique among sibling items. */
@@ -1,33 +1,41 @@
1
1
  import React from "react";
2
- import { boolean } from "@storybook/addon-knobs";
3
-
4
2
  import Switch from "./";
5
3
 
6
4
  export default {
7
5
  title: "Switch",
6
+ component: Switch,
8
7
  };
9
8
 
10
- export const Off = () => <Switch checked={boolean("checked", false)} />;
11
- export const On = () => <Switch checked={boolean("checked", true)} />;
9
+ export const On = (args) => <Switch {...args} />;
12
10
 
13
- export const DisabledOff = () => (
14
- <Switch
15
- checked={boolean("checked", false)}
16
- disabled={boolean("disabled", true)}
17
- />
18
- );
11
+ On.args = {
12
+ checked: true,
13
+ };
19
14
 
20
- DisabledOff.story = {
21
- name: "Disabled/Off",
15
+ export const Off = (args) => <Switch {...args} />;
16
+
17
+ Off.args = {
18
+ checked: false,
22
19
  };
23
20
 
24
- export const DisabledOn = () => (
25
- <Switch
26
- checked={boolean("checked", true)}
27
- disabled={boolean("disabled", true)}
28
- />
29
- );
21
+ export const DisabledOn = (args) => <Switch {...args} />;
22
+
23
+ DisabledOn.args = {
24
+ checked: true,
25
+ disabled: true,
26
+ };
30
27
 
31
28
  DisabledOn.story = {
32
29
  name: "Disabled/On",
33
30
  };
31
+
32
+ export const DisabledOff = (args) => <Switch {...args} />;
33
+
34
+ DisabledOff.args = {
35
+ checked: false,
36
+ disabled: true,
37
+ };
38
+
39
+ DisabledOff.story = {
40
+ name: "Disabled/Off",
41
+ };
@@ -22,8 +22,15 @@ export type TypeTableCell = {
22
22
  */
23
23
  export default class TableCell extends React.Component<TypeTableCell> {
24
24
  render() {
25
- const { id, content, colSpan, width, align, children, ...rest } =
26
- this.props;
25
+ const {
26
+ id,
27
+ content,
28
+ colSpan,
29
+ width,
30
+ align,
31
+ children,
32
+ ...rest
33
+ } = this.props;
27
34
 
28
35
  return (
29
36
  <Container
@@ -32,8 +32,15 @@ export default class ToggleHint extends React.Component<TypeProps> {
32
32
  };
33
33
 
34
34
  render() {
35
- const { icon, isOpen, openString, closeString, qa, className, ...rest } =
36
- this.props;
35
+ const {
36
+ icon,
37
+ isOpen,
38
+ openString,
39
+ closeString,
40
+ qa,
41
+ className,
42
+ ...rest
43
+ } = this.props;
37
44
 
38
45
  return (
39
46
  <Container
@@ -14,8 +14,7 @@ import type {
14
14
 
15
15
  // https://styled-system.com/table#color
16
16
 
17
- type TypeBackgroundColorSystemProp =
18
- TypeResponsiveBaseSystemProp<BackgroundColorProperty>;
17
+ type TypeBackgroundColorSystemProp = TypeResponsiveBaseSystemProp<BackgroundColorProperty>;
19
18
  export type TypeColorSystemProps = $ReadOnly<{|
20
19
  backgroundColor?: TypeBackgroundColorSystemProp,
21
20
  bg?: TypeBackgroundColorSystemProp,
@@ -19,13 +19,21 @@ describe("normalizeResponsiveProp", () => {
19
19
 
20
20
  it("should handle arrays with 4 values", () => {
21
21
  expect(normalizeResponsiveProp([0, 1, 2, 3])).toMatchObject([
22
- 0, 1, 2, 3, 3,
22
+ 0,
23
+ 1,
24
+ 2,
25
+ 3,
26
+ 3,
23
27
  ]);
24
28
  });
25
29
 
26
30
  it("should handle arrays with 5 values", () => {
27
31
  expect(normalizeResponsiveProp([0, 1, 2, 3, 4])).toMatchObject([
28
- 0, 1, 2, 3, 4,
32
+ 0,
33
+ 1,
34
+ 2,
35
+ 3,
36
+ 4,
29
37
  ]);
30
38
  });
31
39
  });
@@ -173,6 +173,7 @@ module.exports = {
173
173
  "heart-outline": "0 0 16 16",
174
174
  "heart": "0 0 16 16",
175
175
  "heartbeat": "0 0 18 16",
176
+ "help-alt": "0 0 12 16",
176
177
  "help": "0 0 16 16",
177
178
  "hiking": "0 0 16 16",
178
179
  "history": "0 0 16 16",
@@ -255,6 +256,7 @@ module.exports = {
255
256
  "pinterest": "0 0 16 16",
256
257
  "play-circle": "0 0 16 16",
257
258
  "play": "0 0 14 16",
259
+ "plug": "0 0 12 16",
258
260
  "plus": "0 0 16 18",
259
261
  "positive-sentiment": "0 0 16 16",
260
262
  "power-up-outline": "0 0 12 16",
@@ -41,7 +41,6 @@ var StyledButton = (0, _styledComponents.default)(_Button.default).withConfig({
41
41
 
42
42
  var ClearButton = function ClearButton() {
43
43
  var _React$useContext = React.useContext(InputContext),
44
- onClear = _React$useContext.onClear,
45
44
  handleClear = _React$useContext.handleClear,
46
45
  clearButtonLabel = _React$useContext.clearButtonLabel,
47
46
  hasValue = _React$useContext.hasValue,
@@ -50,13 +49,6 @@ var ClearButton = function ClearButton() {
50
49
 
51
50
  if (!hasValue) {
52
51
  return null;
53
- } // Log a warning and hide the button when no onClear callback is provided.
54
- // If we called handleClear with no onClear prop, all the button would do is focus the Input.
55
-
56
-
57
- if (!onClear) {
58
- console.warn("Warning: No onClear prop provided to Input when using Input.ClearButton. Omitting Input.ClearButton.");
59
- return null;
60
52
  } // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
61
53
 
62
54
 
@@ -95,14 +87,10 @@ var isClearButton = function isClearButton(elem) {
95
87
  var Input = /*#__PURE__*/function (_React$Component) {
96
88
  _inheritsLoose(Input, _React$Component);
97
89
 
98
- function Input() {
90
+ function Input(props) {
99
91
  var _this;
100
92
 
101
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
102
- args[_key] = arguments[_key];
103
- }
104
-
105
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
93
+ _this = _React$Component.call(this, props) || this;
106
94
  _this.inputRef = /*#__PURE__*/React.createRef();
107
95
 
108
96
  _this.handleBlur = function (e) {
@@ -110,14 +98,31 @@ var Input = /*#__PURE__*/function (_React$Component) {
110
98
  };
111
99
 
112
100
  _this.handleClear = function (e) {
113
- var _this$inputRef, _this$inputRef$curren;
101
+ var input = _this.inputRef.current;
102
+
103
+ if (input) {
104
+ var _Object$getOwnPropert;
105
+
106
+ // Clear the value via the input prototype, then dispatch an input event in order to trigger handleChange
107
+ var nativeInputValueSetter = (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")) == null ? void 0 : _Object$getOwnPropert.set;
108
+ nativeInputValueSetter == null ? void 0 : nativeInputValueSetter.call(input, "");
109
+ var inputEvent = new Event("input", {
110
+ bubbles: true
111
+ });
112
+ input.dispatchEvent(inputEvent); // Focus the input, update hasValue, and call any onClear callback
113
+
114
+ input.focus();
115
+
116
+ _this.updateState("");
114
117
 
115
- (_this$inputRef = _this.inputRef) == null ? void 0 : (_this$inputRef$curren = _this$inputRef.current) == null ? void 0 : _this$inputRef$curren.focus();
116
- _this.props.onClear == null ? void 0 : _this.props.onClear(e);
118
+ _this.props.onClear == null ? void 0 : _this.props.onClear(e);
119
+ }
117
120
  };
118
121
 
119
122
  _this.handleChange = function (e) {
120
- return _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
123
+ _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
124
+
125
+ _this.updateState(e.currentTarget.value);
121
126
  };
122
127
 
123
128
  _this.handleFocus = function (e) {
@@ -136,6 +141,22 @@ var Input = /*#__PURE__*/function (_React$Component) {
136
141
  return _this.props.onPaste == null ? void 0 : _this.props.onPaste(e, e.currentTarget.value);
137
142
  };
138
143
 
144
+ _this.updateState = function (inputValue) {
145
+ var hasValue = inputValue !== "";
146
+ var previousHasValue = _this.state.hasValue; // Only update state if the value of `hasValue` has changed to avoid unnecessary renders.
147
+
148
+ if (hasValue !== previousHasValue) {
149
+ _this.setState({
150
+ hasValue: hasValue
151
+ });
152
+ }
153
+ };
154
+
155
+ _this.state = {
156
+ // Tracking hasValue in state allows us to hide ClearButton when there is no value to clear
157
+ // for both controlled and uncontrolled inputs.
158
+ hasValue: !!props.value
159
+ };
139
160
  return _this;
140
161
  }
141
162
 
@@ -189,9 +210,9 @@ var Input = /*#__PURE__*/function (_React$Component) {
189
210
  name: "search",
190
211
  ariaHidden: true,
191
212
  color: "icon.base"
192
- }) : elemBefore; // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
213
+ }) : elemBefore; // Do not add a ClearButton if an elemAfter prop was passed.
193
214
 
194
- var elementAfter = type === "search" && onClear && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
215
+ var elementAfter = type === "search" && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
195
216
  return /*#__PURE__*/React.createElement(_styles.default, _extends({
196
217
  hasBeforeElement: !!elementBefore,
197
218
  hasAfterElement: !!elementAfter,
@@ -204,9 +225,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
204
225
  }, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
205
226
  value: {
206
227
  handleClear: this.handleClear,
207
- hasValue: !!value,
228
+ hasValue: this.state.hasValue,
208
229
  clearButtonLabel: clearButtonLabel,
209
- onClear: onClear,
210
230
  size: size
211
231
  }
212
232
  }, elementBefore && /*#__PURE__*/React.createElement(_styles.Accessory, {
@@ -84,9 +84,9 @@ var Accessory = _styledComponents.default.div.withConfig({
84
84
  })(["position:absolute;top:50%;transform:translateY(-50%);color:", ";display:flex;align-items:center;", ";", ";"], function (props) {
85
85
  return props.theme.colors.icon.base;
86
86
  }, function (props) {
87
- return props.before && (0, _styledComponents.css)(["left:", ";"], props.theme.space[350]);
87
+ return props.before && (0, _styledComponents.css)(["left:", ";"], props.theme.space[300]);
88
88
  }, function (props) {
89
- return props.after && (0, _styledComponents.css)(["right:", ";"], props.isClearButton ? 0 : props.theme.space[350]);
89
+ return props.after && (0, _styledComponents.css)(["right:", ";"], props.isClearButton ? 0 : props.theme.space[300]);
90
90
  });
91
91
 
92
92
  exports.Accessory = Accessory;