@sproutsocial/racine 11.3.0-beta.2 → 11.3.1-beta-deps.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,11 +1,5 @@
1
1
  # Change Log
2
2
 
3
- ## 11.2.4
4
-
5
- ### Patch Changes
6
-
7
- - 206bd32: copy updates to the TypeProps comments that power Seeds prop tables
8
-
9
3
  ## 11.2.3
10
4
 
11
5
  ### Patch Changes
@@ -60,6 +60,7 @@ const Button = ({
60
60
 
61
61
  return (
62
62
  <Container
63
+ className="container"
63
64
  title={title}
64
65
  active={active}
65
66
  href={href}
@@ -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
  };
@@ -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
  />
@@ -1,8 +1,6 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
3
  import Container, { Accessory } from "./styles";
4
- import Button from "../Button";
5
- import Icon from "../Icon";
6
4
 
7
5
  type TypeProps = {
8
6
  /** ID of the form element, should match the "for" value of the associated label */
@@ -12,8 +10,6 @@ type TypeProps = {
12
10
  ariaLabel?: string,
13
11
  /** Attribute used to associate other elements that describe the Input, like an error */
14
12
  ariaDescribedby?: string,
15
- /** Label for Input.ClearButton. Required when using <Input type="search"/> or <Input.ClearButton/>. */
16
- clearButtonLabel?: string,
17
13
  /** Placeholder text for when value is undefined or empty */
18
14
  placeholder?: string,
19
15
  /** Current value of the input */
@@ -46,8 +42,6 @@ type TypeProps = {
46
42
  innerRef?: React.Ref<"input">,
47
43
  onBlur?: (e: SyntheticFocusEvent<HTMLInputElement>) => void,
48
44
  onChange?: (e: SyntheticInputEvent<HTMLInputElement>, value: string) => void,
49
- /** Called on Input.ClearButton trigger. */
50
- onClear?: (e: SyntheticEvent<HTMLButtonElement>) => void,
51
45
  onFocus?: (e: SyntheticFocusEvent<HTMLInputElement>) => void,
52
46
  onKeyDown?: (
53
47
  e: SyntheticKeyboardEvent<HTMLInputElement>,
@@ -60,50 +54,14 @@ type TypeProps = {
60
54
  onPaste?: (e: SyntheticInputEvent<HTMLInputElement>, value: string) => void,
61
55
  size?: "large" | "small" | "default",
62
56
  qa?: Object,
63
- /**
64
- Controls the styles of the input. Primary is our standard input styles and secondary is a borderless input.
57
+ /**
58
+ Controls the styles of the input. Primary is our standard input styles and secondary is a borderless input.
65
59
  Note that this prop should only be used to alter styles and not functionality.
66
60
  */
67
61
  appearance?: "primary" | "secondary",
68
62
  };
69
63
 
70
- // Using Context so that Input's Input.ClearButton-specific props can be passed to Input.ClearButton,
71
- // regardless of whether it is manually included as elemAfter or automatically included for type="search" Inputs.
72
- type TypeInputContext = $Shape<{
73
- handleClear: (e: SyntheticEvent<HTMLButtonElement>) => void,
74
- clearButtonLabel: string,
75
- hasValue: boolean,
76
- }>;
77
-
78
- const InputContext = React.createContext<TypeInputContext>({});
79
-
80
- const ClearButton = () => {
81
- const { handleClear, clearButtonLabel, hasValue } =
82
- React.useContext(InputContext);
83
-
84
- // Hide the button when there is no text to clear.
85
- if (!hasValue) {
86
- return null;
87
- }
88
- return (
89
- <Button onClick={handleClear}>
90
- {/*Unlocalized fallback should not be used. Always include a localized
91
- clearButtonLabel when using <Input.ClearButton/> or <Input type="search"/>.*/}
92
- <Icon name="circlex" title={clearButtonLabel || "Clear"} />
93
- </Button>
94
- );
95
- };
96
-
97
- // Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
98
- // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
99
- const isClearButton = (elem: any) => {
100
- if (elem?.type) {
101
- return elem.type.displayName === "Input.ClearButton";
102
- }
103
- return false;
104
- };
105
-
106
- class Input extends React.Component<TypeProps> {
64
+ export default class Input extends React.Component<TypeProps> {
107
65
  static defaultProps = {
108
66
  autoFocus: false,
109
67
  disabled: false,
@@ -112,28 +70,41 @@ class Input extends React.Component<TypeProps> {
112
70
  appearance: "primary",
113
71
  };
114
72
 
115
- static ClearButton = ClearButton;
116
-
117
- handleBlur = (e: SyntheticFocusEvent<HTMLInputElement>) =>
118
- this.props.onBlur?.(e);
119
-
120
- handleClear = (e: SyntheticEvent<HTMLButtonElement>) =>
121
- this.props.onClear?.(e);
73
+ handleBlur = (e: SyntheticFocusEvent<HTMLInputElement>) => {
74
+ if (this.props.onBlur) {
75
+ this.props.onBlur(e);
76
+ }
77
+ };
122
78
 
123
- handleChange = (e: SyntheticInputEvent<HTMLInputElement>) =>
124
- this.props.onChange?.(e, e.currentTarget.value);
79
+ handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
80
+ if (this.props.onChange) {
81
+ this.props.onChange(e, e.currentTarget.value);
82
+ }
83
+ };
125
84
 
126
- handleFocus = (e: SyntheticFocusEvent<HTMLInputElement>) =>
127
- this.props.onFocus?.(e);
85
+ handleFocus = (e: SyntheticFocusEvent<HTMLInputElement>) => {
86
+ if (this.props.onFocus) {
87
+ this.props.onFocus(e);
88
+ }
89
+ };
128
90
 
129
- handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) =>
130
- this.props.onKeyDown?.(e, e.currentTarget.value);
91
+ handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
92
+ if (this.props.onKeyDown) {
93
+ this.props.onKeyDown(e, e.currentTarget.value);
94
+ }
95
+ };
131
96
 
132
- handleKeyUp = (e: SyntheticKeyboardEvent<HTMLInputElement>) =>
133
- this.props.onKeyUp?.(e, e.currentTarget.value);
97
+ handleKeyUp = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
98
+ if (this.props.onKeyUp) {
99
+ this.props.onKeyUp(e, e.currentTarget.value);
100
+ }
101
+ };
134
102
 
135
- handlePaste = (e: SyntheticInputEvent<HTMLInputElement>) =>
136
- this.props.onPaste?.(e, e.currentTarget.value);
103
+ handlePaste = (e: SyntheticInputEvent<HTMLInputElement>) => {
104
+ if (this.props.onPaste) {
105
+ this.props.onPaste(e, e.currentTarget.value);
106
+ }
107
+ };
137
108
 
138
109
  render() {
139
110
  const {
@@ -154,11 +125,9 @@ class Input extends React.Component<TypeProps> {
154
125
  maxLength,
155
126
  ariaLabel,
156
127
  ariaDescribedby,
157
- clearButtonLabel,
158
128
  innerRef,
159
129
  onBlur,
160
130
  onChange,
161
- onClear,
162
131
  onFocus,
163
132
  onKeyDown,
164
133
  onKeyUp,
@@ -169,27 +138,15 @@ class Input extends React.Component<TypeProps> {
169
138
  ...rest
170
139
  } = this.props;
171
140
 
172
- // Convert autoComplete from a boolean prop to a string value.
173
141
  let autoCompleteValue = undefined;
174
142
  if (autoComplete !== undefined) {
175
143
  autoCompleteValue = autoComplete ? "on" : "off";
176
144
  }
177
145
 
178
- // Add default elemBefore and elemAfter elements if type is search.
179
- const elementBefore =
180
- type === "search" && !elemBefore ? (
181
- <Icon name="search" ariaHidden />
182
- ) : (
183
- elemBefore
184
- );
185
- // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
186
- const elementAfter =
187
- type === "search" && onClear && !elemAfter ? <ClearButton /> : elemAfter;
188
-
189
146
  return (
190
147
  <Container
191
- hasBeforeElement={!!elementBefore}
192
- hasAfterElement={!!elementAfter}
148
+ hasBeforeElement={!!elemBefore}
149
+ hasAfterElement={!!elemAfter}
193
150
  disabled={disabled}
194
151
  invalid={!!isInvalid}
195
152
  warning={hasWarning}
@@ -197,55 +154,39 @@ class Input extends React.Component<TypeProps> {
197
154
  // $FlowIssue - upgrade v0.112.0
198
155
  {...rest}
199
156
  >
200
- <InputContext.Provider
201
- value={{
202
- handleClear: this.handleClear,
203
- clearButtonLabel,
204
- hasValue: !!value,
205
- }}
206
- >
207
- {elementBefore && <Accessory before>{elementBefore}</Accessory>}
208
-
209
- <input
210
- aria-invalid={!!isInvalid}
211
- aria-label={ariaLabel}
212
- aria-describedby={ariaDescribedby}
213
- autoComplete={autoCompleteValue}
214
- autoFocus={autoFocus}
215
- disabled={disabled}
216
- readOnly={readOnly}
217
- id={id}
218
- name={name}
219
- placeholder={placeholder}
220
- type={type}
221
- required={required}
222
- value={value}
223
- maxLength={maxLength}
224
- onBlur={this.handleBlur}
225
- onChange={this.handleChange}
226
- onFocus={this.handleFocus}
227
- onKeyDown={this.handleKeyDown}
228
- onKeyUp={this.handleKeyUp}
229
- onPaste={this.handlePaste}
230
- ref={innerRef}
231
- data-qa-input={name || ""}
232
- data-qa-input-isdisabled={disabled === true}
233
- data-qa-input-isrequired={required === true}
234
- {...qa}
235
- {...inputProps}
236
- />
237
-
238
- {elementAfter && (
239
- <Accessory after isClearButton={isClearButton(elementAfter)}>
240
- {elementAfter}
241
- </Accessory>
242
- )}
243
- </InputContext.Provider>
157
+ {elemBefore && <Accessory before>{elemBefore}</Accessory>}
158
+
159
+ <input
160
+ aria-invalid={!!isInvalid}
161
+ aria-label={ariaLabel}
162
+ aria-describedby={ariaDescribedby}
163
+ autoComplete={autoCompleteValue}
164
+ autoFocus={autoFocus}
165
+ disabled={disabled}
166
+ readOnly={readOnly}
167
+ id={id}
168
+ name={name}
169
+ placeholder={placeholder}
170
+ type={type}
171
+ required={required}
172
+ value={value}
173
+ maxLength={maxLength}
174
+ onBlur={this.handleBlur}
175
+ onChange={this.handleChange}
176
+ onFocus={this.handleFocus}
177
+ onKeyDown={this.handleKeyDown}
178
+ onKeyUp={this.handleKeyUp}
179
+ onPaste={this.handlePaste}
180
+ ref={innerRef}
181
+ data-qa-input={name || ""}
182
+ data-qa-input-isdisabled={disabled === true}
183
+ data-qa-input-isrequired={required === true}
184
+ {...qa}
185
+ {...inputProps}
186
+ />
187
+
188
+ {elemAfter && <Accessory after>{elemAfter}</Accessory>}
244
189
  </Container>
245
190
  );
246
191
  }
247
192
  }
248
-
249
- Input.ClearButton.displayName = "Input.ClearButton";
250
-
251
- export default Input;
@@ -141,39 +141,6 @@ leftAndRightIcons.story = {
141
141
  name: "Left and right icons",
142
142
  };
143
143
 
144
- export const searchInput = () => (
145
- <Input
146
- type="search"
147
- placeholder={text("placeholder", "Please enter a value...")}
148
- value={text("value", "val")}
149
- onClear={() => window.alert("Cleared!")}
150
- clearButtonLabel={text("clearButtonLabel", "Clear search")}
151
- ariaLabel={text("ariaLabel", "Descriptive label goes here")}
152
- />
153
- );
154
-
155
- searchInput.story = {
156
- name: "Search Input",
157
- };
158
-
159
- export const nonSearchClearButtonInput = () => {
160
- return (
161
- <Input
162
- type="text"
163
- placeholder={text("placeholder", "Please enter a value...")}
164
- value={text("value", "val")}
165
- onClear={() => window.alert("Cleared!")}
166
- ariaLabel={text("ariaLabel", "Descriptive label goes here")}
167
- clearButtonLabel={text("clearButtonLabel", "Clear text")}
168
- elemAfter={<Input.ClearButton />}
169
- />
170
- );
171
- };
172
-
173
- nonSearchClearButtonInput.story = {
174
- name: "Input.ClearButton usage",
175
- };
176
-
177
144
  export const autofocus = () => (
178
145
  <Input
179
146
  autoFocus