@sproutsocial/racine 11.4.2-input-beta.0 → 11.5.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 11.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - fa8a45d: Dependency upgrades: upgraded severe vulnerabilities as well as storybook and jest suite fixes. Upgraded styled components from beta to stable v5.2.3.
8
+
3
9
  ## 11.4.1
4
10
 
5
11
  ### Patch Changes
@@ -84,4 +84,6 @@ const Button = ({
84
84
  );
85
85
  };
86
86
 
87
+ Button.displayName = "Button";
88
+
87
89
  export default Button;
@@ -1,5 +1,4 @@
1
1
  import React from "react";
2
- import { boolean, text, number } from "@storybook/addon-knobs";
3
2
  import Button from "./index";
4
3
  import Icon from "../Icon";
5
4
  import Box from "../Box";
@@ -8,155 +7,140 @@ export default {
8
7
  title: "Button",
9
8
  };
10
9
 
11
- export const defaultStory = () => (
12
- <Button
13
- appearance={text("appearance", "default")}
14
- onClick={() => alert("Testing...")}
15
- >
10
+ export const defaultStory = (args) => (
11
+ <Button {...args} onClick={() => alert("Testing...")}>
16
12
  Default
17
13
  </Button>
18
14
  );
19
15
 
16
+ defaultStory.args = { appearance: "default" };
17
+
20
18
  defaultStory.story = {
21
19
  name: "Default",
22
20
  };
23
21
 
24
- export const primary = () => (
25
- <Button
26
- appearance={text("appearance", "primary")}
27
- onClick={() => alert("Testing...")}
28
- >
22
+ export const primary = (args) => (
23
+ <Button {...args} onClick={() => alert("Testing...")}>
29
24
  Primary Button
30
25
  </Button>
31
26
  );
32
27
 
28
+ primary.args = { appearance: "primary" };
29
+
33
30
  primary.story = {
34
31
  name: "Primary",
35
32
  };
36
33
 
37
- export const secondary = () => (
38
- <Button appearance={text("appearance", "secondary")}>Secondary Button</Button>
39
- );
34
+ export const secondary = (args) => <Button {...args}>Secondary Button</Button>;
35
+
36
+ secondary.args = { appearance: "secondary" };
40
37
 
41
38
  secondary.story = {
42
39
  name: "Secondary",
43
40
  };
44
41
 
45
- export const destructive = () => (
46
- <Button appearance={text("appearance", "destructive")}>
47
- Destructive Button
48
- </Button>
42
+ export const destructive = (args) => (
43
+ <Button {...args}>Destructive Button</Button>
49
44
  );
50
45
 
46
+ destructive.args = { appearance: "destructive" };
51
47
  destructive.story = {
52
48
  name: "Destructive",
53
49
  };
54
50
 
55
- export const placeholder = () => (
56
- <Button appearance={text("appearance", "placeholder")}>
57
- Placeholder Button
58
- </Button>
51
+ export const placeholder = (args) => (
52
+ <Button {...args}>Placeholder Button</Button>
59
53
  );
60
54
 
55
+ placeholder.args = { appearance: "placeholder" };
61
56
  placeholder.story = {
62
57
  name: "Placeholder",
63
58
  };
64
59
 
65
- export const largeButton = () => (
66
- <Button
67
- appearance={text("appearance", "primary")}
68
- size={text("size", "large")}
69
- >
70
- Large Button
71
- </Button>
72
- );
60
+ export const largeButton = (args) => <Button {...args}>Large Button</Button>;
61
+ largeButton.args = { size: "large", appearance: "primary" };
73
62
 
74
63
  largeButton.story = {
75
64
  name: "Large button",
76
65
  };
77
66
 
78
- export const pillButton = () => (
67
+ export const pillButton = (args) => (
79
68
  <Box bg="container.background.base" p={400}>
80
- <Button appearance={text("shape", "pill")}>
69
+ <Button {...args}>
81
70
  <Icon name="reply" mr={350} />
82
71
  Pill Button
83
72
  </Button>
84
73
  </Box>
85
74
  );
86
-
75
+ pillButton.args = { appearance: "pill" };
87
76
  pillButton.story = {
88
77
  name: "Pill button",
89
78
  };
90
79
 
91
- export const pillIconOnlyButton = () => (
80
+ export const pillIconOnlyButton = (args) => (
92
81
  <Box bg="container.background.base" p={400}>
93
- <Button appearance={text("shape", "pill")} ariaLabel="This is a label">
82
+ <Button {...args} ariaLabel="This is a label">
94
83
  <Icon name="circle-check-outline" />
95
84
  </Button>
96
85
  </Box>
97
86
  );
98
87
 
88
+ pillIconOnlyButton.args = { appearance: "pill" };
99
89
  pillIconOnlyButton.story = {
100
90
  name: "Pill icon only button",
101
91
  };
102
92
 
103
- export const activeButton = () => (
104
- <Button
105
- appearance={text("appearance", "secondary")}
106
- active={boolean("active", true)}
107
- >
108
- Active Button
109
- </Button>
110
- );
93
+ export const activeButton = (args) => <Button {...args}>Active Button</Button>;
111
94
 
95
+ activeButton.args = { appearance: "secondary", active: true };
112
96
  activeButton.story = {
113
97
  name: "Active button",
114
98
  };
115
99
 
116
- export const buttonAsALink = () => (
117
- <Button
118
- href={text("href", "http://sproutsocial.style")}
119
- external={boolean("external", true)}
120
- appearance={text("appearance", "primary")}
121
- >
122
- Button using anchor element
123
- </Button>
100
+ export const buttonAsALink = (args) => (
101
+ <Button {...args}>Button using anchor element</Button>
124
102
  );
125
-
103
+ buttonAsALink.args = {
104
+ appearance: "primary",
105
+ external: true,
106
+ href: "http://sproutsocial.style",
107
+ };
126
108
  buttonAsALink.story = {
127
109
  name: "Button as a link",
128
110
  };
129
111
 
130
- export const disabledButton = () => (
131
- <Button
132
- appearance={text("appearance", "primary")}
133
- disabled={text("disabled", "true")}
134
- >
135
- This Button is disabled
136
- </Button>
112
+ export const disabledButton = (args) => (
113
+ <Button {...args}>This Button is disabled</Button>
137
114
  );
138
-
115
+ disabledButton.args = {
116
+ appearance: "primary",
117
+ disabled: true,
118
+ };
139
119
  disabledButton.story = {
140
120
  name: "Disabled button",
141
121
  };
142
122
 
143
- export const fullWidthButton = () => (
144
- <Button appearance={text("appearance", "primary")} width={number("width", 1)}>
145
- Full-Width Button
146
- </Button>
123
+ export const fullWidthButton = (args) => (
124
+ <Button {...args}>Full-Width Button</Button>
147
125
  );
148
-
126
+ fullWidthButton.args = {
127
+ appearance: "primary",
128
+ width: 1,
129
+ };
149
130
  fullWidthButton.story = {
150
131
  name: "Full width button",
151
132
  };
152
133
 
153
- export const withIcon = () => (
154
- <Button appearance={text("appearance", "secondary")}>
134
+ export const withIcon = (args) => (
135
+ <Button {...args}>
155
136
  <Icon name="twitter" mr={350} />
156
137
  Secondary Button
157
138
  </Button>
158
139
  );
159
140
 
141
+ withIcon.args = {
142
+ appearance: "secondary",
143
+ };
160
144
  withIcon.story = {
161
145
  name: "With icon",
162
146
  };
@@ -99,7 +99,7 @@ const Container: StyledComponent<any, TypeTheme, *> = styled.button`
99
99
  ${LAYOUT}
100
100
  ${COMMON}
101
101
  `;
102
-
102
+ Container.displayName = "Button-Container";
103
103
  export default Container;
104
104
 
105
105
  //${props.theme.mode === "dark" ? "screen" : "multiply"}
@@ -182,90 +182,90 @@ const getIcon = (type, color) => {
182
182
 
183
183
  // eslint-disable-next-line prettier/prettier
184
184
  export const CheckboxContainer: StyledComponent<any, TypeTheme, *> = styled.span(
185
- (props) => css`
186
- display: inline-flex;
187
- align-items: center;
188
- box-sizing: border-box;
189
- position: relative;
190
- transition: all ${props.theme.duration.fast} ${props.theme.easing.ease_in};
191
-
192
- @supports (-webkit-appearance: none) {
193
- &:before {
194
- /* stylelint-disable */
195
- content: url("data:image/svg+xml;utf8,${getIcon(
196
- props.indeterminate ? "indeterminate" : "check",
197
-
198
- props.checked
199
- ? props.theme.colors.form.background.base
200
- : props.theme.colors.form.border.base
201
- )}");
202
- opacity: ${props.checked ? 1 : 0};
203
- position: absolute;
204
- width: ${props.theme.space[400]};
205
- height: ${props.theme.space[400]};
206
- text-align: center;
207
- transform: translateY(1px);
208
- line-height: 1;
209
- margin: auto;
210
- pointer-events: none;
211
- transition: ${props.theme.duration.fast}
212
- ${props.theme.easing.ease_inout};
213
- }
214
-
215
- &:hover:before {
216
- opacity: ${props.disabled && !props.checked ? 0 : 1};
217
- }
218
-
219
- ${props.disabled &&
220
- css`
221
- opacity: 0.4;
222
- `}
223
-
224
- input[type='checkbox'] {
225
- box-sizing: border-box;
226
- appearance: none;
227
- margin: 0;
228
- padding: 0;
229
- width: ${props.theme.space[400]};
230
- height: ${props.theme.space[400]};
231
- border: 1px solid ${props.theme.colors.form.border.base};
232
- border-radius: 4px;
233
- background-color: ${props.theme.colors.form.background.base};
234
- transition: all ${props.theme.duration.fast}
235
- ${props.theme.easing.ease_in};
236
- cursor: ${props.disabled ? "not-allowed" : "pointer"};
237
- flex-shrink: 0;
238
-
239
- &:not(:checked) {
240
- ${!props.indeterminate &&
241
- css`
242
- border-color: ${props.theme.colors
243
- .neutral[300]} !important; /* We don't want the focus ring to remove the border */
244
- background-color: ${props.theme.colors.form.background.base};
245
- `}
185
+ (props) => css`
186
+ display: inline-flex;
187
+ align-items: center;
188
+ box-sizing: border-box;
189
+ position: relative;
190
+ transition: all ${props.theme.duration.fast} ${props.theme.easing.ease_in};
191
+
192
+ @supports (-webkit-appearance: none) {
193
+ &:before {
194
+ /* stylelint-disable */
195
+ content: url("data:image/svg+xml;utf8,${getIcon(
196
+ props.indeterminate ? "indeterminate" : "check",
197
+
198
+ props.checked
199
+ ? props.theme.colors.form.background.base
200
+ : props.theme.colors.form.border.base
201
+ )}");
202
+ opacity: ${props.checked ? 1 : 0};
203
+ position: absolute;
204
+ width: ${props.theme.space[400]};
205
+ height: ${props.theme.space[400]};
206
+ text-align: center;
207
+ transform: translateY(1px);
208
+ line-height: 1;
209
+ margin: auto;
210
+ pointer-events: none;
211
+ transition: ${props.theme.duration.fast}
212
+ ${props.theme.easing.ease_inout};
246
213
  }
247
214
 
248
- &:checked {
249
- border-color: ${props.theme.colors.form.border.selected};
250
- background-color: ${props.theme.colors.form.background.selected};
215
+ &:hover:before {
216
+ opacity: ${props.disabled && !props.checked ? 0 : 1};
251
217
  }
252
218
 
253
- ${props.indeterminate &&
254
- props.checked &&
219
+ ${props.disabled &&
255
220
  css`
256
- border-color: ${props.theme.colors.form.border.selected} !important;
257
- background-color: ${props.theme.colors.form.background
258
- .selected} !important;
221
+ opacity: 0.4;
259
222
  `}
260
223
 
261
- &:focus {
262
- ${focusRing}
224
+ input[type='checkbox'] {
225
+ box-sizing: border-box;
226
+ appearance: none;
227
+ margin: 0;
228
+ padding: 0;
229
+ width: ${props.theme.space[400]};
230
+ height: ${props.theme.space[400]};
231
+ border: 1px solid ${props.theme.colors.form.border.base};
232
+ border-radius: 4px;
233
+ background-color: ${props.theme.colors.form.background.base};
234
+ transition: all ${props.theme.duration.fast}
235
+ ${props.theme.easing.ease_in};
236
+ cursor: ${props.disabled ? "not-allowed" : "pointer"};
237
+ flex-shrink: 0;
238
+
239
+ &:not(:checked) {
240
+ ${!props.indeterminate &&
241
+ css`
242
+ border-color: ${props.theme.colors
243
+ .neutral[300]} !important; /* We don't want the focus ring to remove the border */
244
+ background-color: ${props.theme.colors.form.background.base};
245
+ `}
246
+ }
247
+
248
+ &:checked {
249
+ border-color: ${props.theme.colors.form.border.selected};
250
+ background-color: ${props.theme.colors.form.background.selected};
251
+ }
252
+
253
+ ${props.indeterminate &&
254
+ props.checked &&
255
+ css`
256
+ border-color: ${props.theme.colors.form.border.selected} !important;
257
+ background-color: ${props.theme.colors.form.background
258
+ .selected} !important;
259
+ `}
260
+
261
+ &:focus {
262
+ ${focusRing}
263
+ }
263
264
  }
264
265
  }
265
- }
266
266
 
267
- ${COMMON}
268
- `
269
- );
267
+ ${COMMON}
268
+ `
269
+ );
270
270
 
271
271
  export default Container;
@@ -73,9 +73,8 @@ const Trigger = ({ children, ...rest }) => {
73
73
  };
74
74
 
75
75
  const Panel = ({ children, ...rest }) => {
76
- const { isOpen, id, offset, collapsedHeight, openHeight } = useContext(
77
- CollapsibleContext
78
- );
76
+ const { isOpen, id, offset, collapsedHeight, openHeight } =
77
+ useContext(CollapsibleContext);
79
78
  const ref = useRef();
80
79
  const measurement = useMeasure(ref);
81
80
  const [isHidden, setIsHidden] = useState(undefined);
@@ -105,7 +105,7 @@ describe("EmptyState", () => {
105
105
  <EmptyState
106
106
  media={
107
107
  <Image
108
- alt="No assets matching yoursearch or filters"
108
+ alt="No assets matching your search or filters"
109
109
  src="https://cl.ly/db498c7682df/download/analytics.svg"
110
110
  m={0}
111
111
  />
@@ -80,16 +80,8 @@ export default class Image extends React.Component<TypeProps, TypeState> {
80
80
  };
81
81
 
82
82
  render() {
83
- const {
84
- alt,
85
- title,
86
- onClick,
87
- onError,
88
- onLoad,
89
- src,
90
- qa,
91
- ...rest
92
- } = this.props;
83
+ const { alt, title, onClick, onError, onLoad, src, qa, ...rest } =
84
+ this.props;
93
85
 
94
86
  return (
95
87
  <ImageContainer
@@ -74,10 +74,6 @@ type TypeProps = {
74
74
  appearance?: "primary" | "secondary",
75
75
  };
76
76
 
77
- type TypeState = {
78
- hasValue: boolean,
79
- };
80
-
81
77
  // Using Context so that Input's Input.ClearButton-specific props can be passed to Input.ClearButton,
82
78
  // regardless of whether it is manually included as elemAfter or automatically included for type="search" Inputs.
83
79
  type TypeInputContext = $Shape<{
@@ -158,16 +154,7 @@ const isClearButton = (elem: any) => {
158
154
  return false;
159
155
  };
160
156
 
161
- class Input extends React.Component<TypeProps, TypeState> {
162
- constructor(props: TypeProps) {
163
- super(props);
164
- this.state = {
165
- // tracking hasValue in state allows us to hide ClearButton when there is no value to clear
166
- // for both controlled and uncontrolled inputs.
167
- hasValue: !!props.value,
168
- };
169
- }
170
-
157
+ class Input extends React.Component<TypeProps> {
171
158
  static defaultProps = {
172
159
  autoFocus: false,
173
160
  disabled: false,
@@ -190,10 +177,8 @@ class Input extends React.Component<TypeProps, TypeState> {
190
177
  this.props.onClear?.(e);
191
178
  };
192
179
 
193
- handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
180
+ handleChange = (e: SyntheticInputEvent<HTMLInputElement>) =>
194
181
  this.props.onChange?.(e, e.currentTarget.value);
195
- this.updateState(e.currentTarget.value);
196
- };
197
182
 
198
183
  handleFocus = (e: SyntheticFocusEvent<HTMLInputElement>) =>
199
184
  this.props.onFocus?.(e);
@@ -207,15 +192,6 @@ class Input extends React.Component<TypeProps, TypeState> {
207
192
  handlePaste = (e: SyntheticInputEvent<HTMLInputElement>) =>
208
193
  this.props.onPaste?.(e, e.currentTarget.value);
209
194
 
210
- updateState = (value: string) => {
211
- const hasValue = value !== "";
212
- const hadValue = this.state.hasValue;
213
- // Only update state if the value has changed to avoid unnecessary renders.
214
- if (hasValue !== hadValue) {
215
- this.setState({ hasValue });
216
- }
217
- };
218
-
219
195
  render() {
220
196
  const {
221
197
  autoComplete,
@@ -283,7 +259,7 @@ class Input extends React.Component<TypeProps, TypeState> {
283
259
  <InputContext.Provider
284
260
  value={{
285
261
  handleClear: this.handleClear,
286
- hasValue: this.state.hasValue,
262
+ hasValue: !!value,
287
263
  clearButtonLabel,
288
264
  onClear,
289
265
  size,
@@ -188,20 +188,6 @@ largeSearchInput.story = {
188
188
  name: "Large Search Input",
189
189
  };
190
190
 
191
- export const uncontrolledSearchInput = () => (
192
- <Input
193
- type="search"
194
- placeholder={text("placeholder", "Please enter a value...")}
195
- onClear={() => window.alert("Cleared!")}
196
- clearButtonLabel={text("clearButtonLabel", "Clear search")}
197
- ariaLabel={text("ariaLabel", "Descriptive label goes here")}
198
- />
199
- );
200
-
201
- uncontrolledSearchInput.story = {
202
- name: "Uncontrolled Search Input",
203
- };
204
-
205
191
  export const nonSearchClearButtonInput = () => {
206
192
  return (
207
193
  <Input
@@ -85,24 +85,6 @@ describe("Input", () => {
85
85
  expect(getByRole("button")).toBeTruthy();
86
86
  });
87
87
 
88
- it("should render a clear button for an uncontrolled search Input only once it is typed in", () => {
89
- const { getByRole, queryByRole } = render(
90
- <Input
91
- id="name"
92
- name="name"
93
- type="search"
94
- onClear={jest.fn()}
95
- clearButtonLabel="Clear search"
96
- />
97
- );
98
- expect(queryByRole("button")).toBeFalsy();
99
- const input = getByRole("searchbox");
100
- userEvent.tab();
101
- expect(input).toHaveFocus();
102
- userEvent.keyboard("some text");
103
- expect(getByRole("button")).toBeTruthy();
104
- });
105
-
106
88
  it("should not render a clear button for search Inputs if there is no text", () => {
107
89
  const { queryByRole } = render(
108
90
  <Input
@@ -14,12 +14,12 @@ exports[`Menu AsMenuButton should match snapshot 1`] = `
14
14
  fill: currentColor;
15
15
  }
16
16
 
17
- _:-ms-fullscreen .c3,
17
+ _:-ms-fullscreen .c2,
18
18
  html .c3 {
19
19
  width: 16px;
20
20
  }
21
21
 
22
- .pdf-page .c3 {
22
+ .pdf-page .c2 {
23
23
  width: 16px;
24
24
  }
25
25
 
@@ -17,9 +17,8 @@ type TypeSegmentedControlContext = {
17
17
  onChange: (e: SyntheticInputEvent<HTMLInputElement>) => void,
18
18
  };
19
19
 
20
- const SegmentedControlContext = React.createContext<?TypeSegmentedControlContext>(
21
- null
22
- );
20
+ const SegmentedControlContext =
21
+ React.createContext<?TypeSegmentedControlContext>(null);
23
22
 
24
23
  type TypeSegmentedControlItemProps = {
25
24
  /** The value of this item. Should be unique among sibling items. */
@@ -22,15 +22,8 @@ export type TypeTableCell = {
22
22
  */
23
23
  export default class TableCell extends React.Component<TypeTableCell> {
24
24
  render() {
25
- const {
26
- id,
27
- content,
28
- colSpan,
29
- width,
30
- align,
31
- children,
32
- ...rest
33
- } = this.props;
25
+ const { id, content, colSpan, width, align, children, ...rest } =
26
+ this.props;
34
27
 
35
28
  return (
36
29
  <Container
@@ -32,15 +32,8 @@ export default class ToggleHint extends React.Component<TypeProps> {
32
32
  };
33
33
 
34
34
  render() {
35
- const {
36
- icon,
37
- isOpen,
38
- openString,
39
- closeString,
40
- qa,
41
- className,
42
- ...rest
43
- } = this.props;
35
+ const { icon, isOpen, openString, closeString, qa, className, ...rest } =
36
+ this.props;
44
37
 
45
38
  return (
46
39
  <Container
@@ -1,5 +1,5 @@
1
1
  import "mutationobserver-shim";
2
- import "jest-dom/extend-expect";
2
+ import "@testing-library/jest-dom/extend-expect";
3
3
  import "jest-axe/extend-expect";
4
4
  import "babel-polyfill";
5
5
  import "jest-styled-components";
@@ -14,7 +14,8 @@ import type {
14
14
 
15
15
  // https://styled-system.com/table#color
16
16
 
17
- type TypeBackgroundColorSystemProp = TypeResponsiveBaseSystemProp<BackgroundColorProperty>;
17
+ type TypeBackgroundColorSystemProp =
18
+ TypeResponsiveBaseSystemProp<BackgroundColorProperty>;
18
19
  export type TypeColorSystemProps = $ReadOnly<{|
19
20
  backgroundColor?: TypeBackgroundColorSystemProp,
20
21
  bg?: TypeBackgroundColorSystemProp,
@@ -1,19 +1,5 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`layout system props display 1`] = `
4
- .c0 {
5
- display: -webkit-string;
6
- display: string;
7
- }
8
-
9
- <div>
10
- <div
11
- class="c0"
12
- display="string"
13
- />
14
- </div>
15
- `;
16
-
17
3
  exports[`layout system props height 1`] = `
18
4
  .c0 {
19
5
  height: string;