@sproutsocial/racine 11.2.5-sproutTheme-beta.1 → 11.2.5-sproutTheme-beta.4

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 (52) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/__flow__/Button/index.stories.js +6 -21
  3. package/__flow__/Input/index.js +185 -66
  4. package/__flow__/Input/index.stories.js +65 -0
  5. package/__flow__/Input/index.test.js +230 -1
  6. package/__flow__/Input/styles.js +1 -1
  7. package/__flow__/ThemeProvider/index.js +5 -1
  8. package/__flow__/TokenInput/index.js +1 -1
  9. package/__flow__/index.js +1 -0
  10. package/__flow__/themes/dark/theme.js +3 -0
  11. package/__flow__/themes/extendedThemes/sproutTheme/NonColorThemeValues/index.js +17 -0
  12. package/__flow__/themes/extendedThemes/sproutTheme/dark/getDarkThemeColors.js +57 -0
  13. package/__flow__/themes/extendedThemes/sproutTheme/dark/theme.js +17 -35
  14. package/__flow__/themes/extendedThemes/sproutTheme/index.js +2 -0
  15. package/__flow__/themes/extendedThemes/sproutTheme/light/getLightThemeColors.js +53 -0
  16. package/__flow__/themes/extendedThemes/sproutTheme/light/theme.js +17 -45
  17. package/__flow__/themes/extendedThemes/sproutTheme/sproutThemeType.flow.js +36 -0
  18. package/__flow__/themes/light/theme.js +3 -0
  19. package/__flow__/types/theme.colors.flow.js +3 -0
  20. package/__flow__/types/theme.flow.js +15 -0
  21. package/commonjs/Input/index.js +124 -30
  22. package/commonjs/Input/styles.js +1 -1
  23. package/commonjs/TokenInput/index.js +1 -1
  24. package/commonjs/themes/dark/theme.js +4 -1
  25. package/commonjs/themes/extendedThemes/sproutTheme/NonColorThemeValues/index.js +15 -0
  26. package/commonjs/themes/extendedThemes/sproutTheme/dark/getDarkThemeColors.js +57 -0
  27. package/commonjs/themes/extendedThemes/sproutTheme/dark/theme.js +14 -33
  28. package/commonjs/themes/extendedThemes/sproutTheme/light/getLightThemeColors.js +53 -0
  29. package/commonjs/themes/extendedThemes/sproutTheme/light/theme.js +14 -43
  30. package/commonjs/themes/extendedThemes/sproutTheme/{dark/colors.js → sproutThemeType.flow.js} +0 -0
  31. package/commonjs/themes/light/theme.js +4 -1
  32. package/dist/themes/dark/dark.scss +4 -1
  33. package/dist/themes/light/light.scss +4 -1
  34. package/lib/Input/index.js +117 -30
  35. package/lib/Input/styles.js +1 -1
  36. package/lib/TokenInput/index.js +1 -1
  37. package/lib/themes/dark/theme.js +4 -1
  38. package/lib/themes/extendedThemes/sproutTheme/NonColorThemeValues/index.js +10 -0
  39. package/lib/themes/extendedThemes/sproutTheme/dark/getDarkThemeColors.js +52 -0
  40. package/lib/themes/extendedThemes/sproutTheme/dark/theme.js +11 -33
  41. package/lib/themes/extendedThemes/sproutTheme/light/getLightThemeColors.js +48 -0
  42. package/lib/themes/extendedThemes/sproutTheme/light/theme.js +10 -42
  43. package/{__flow__/themes/extendedThemes/sproutTheme/dark/colors.js → lib/themes/extendedThemes/sproutTheme/sproutThemeType.flow.js} +0 -0
  44. package/lib/themes/light/theme.js +4 -1
  45. package/package.json +1 -1
  46. package/__flow__/themes/extendedThemes/sproutTheme/light/colors.js +0 -0
  47. package/__flow__/themes/extendedThemes/sproutTheme/otherVals/theme.js +0 -6
  48. package/commonjs/themes/extendedThemes/sproutTheme/light/colors.js +0 -1
  49. package/commonjs/themes/extendedThemes/sproutTheme/otherVals/theme.js +0 -9
  50. package/lib/themes/extendedThemes/sproutTheme/dark/colors.js +0 -0
  51. package/lib/themes/extendedThemes/sproutTheme/light/colors.js +0 -0
  52. package/lib/themes/extendedThemes/sproutTheme/otherVals/theme.js +0 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Change Log
2
2
 
3
+ ## 11.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d888fa0: Add search icon to type "search" Input
8
+ - "<Icon name="search" />" is added to Inputs with type "search" unless an elemBefore prop is passed to override it.
9
+ - d888fa0: Add Input.ClearButton
10
+ - This button is automatically included when Input has type "search" and no "elemAfter" prop is passed
11
+ - This button can be manually included with the "elemAfter" prop for non-search inputs
12
+ - In either case, the button will only be rendered if an "onClear" callback is passed to the Input component
13
+ - A "clearButtonLabel" prop should also be passed to the Input component
14
+
15
+ ## 11.3.0
16
+
17
+ ### Minor Changes
18
+
19
+ - e8a9df6: Add text highlight style to theme
20
+
21
+ ### Patch Changes
22
+
23
+ - 9e66592: Pass TokenInput autocomplete prop to input as autoComplete to suppress JSX console warnings
24
+
3
25
  ## 11.2.5
4
26
 
5
27
  ### Patch Changes
@@ -3,11 +3,6 @@ import { boolean, text, number } from "@storybook/addon-knobs";
3
3
  import Button from "./index";
4
4
  import Icon from "../Icon";
5
5
  import Box from "../Box";
6
- import ThemeProvider from "../ThemeProvider";
7
- import {
8
- sproutLightTheme,
9
- sproutDarkTheme,
10
- } from "../themes/extendedThemes/sproutTheme";
11
6
 
12
7
  export default {
13
8
  title: "Button",
@@ -27,22 +22,12 @@ defaultStory.story = {
27
22
  };
28
23
 
29
24
  export const primary = () => (
30
- <>
31
- <Button
32
- appearance={text("appearance", "primary")}
33
- onClick={() => alert("Testing...")}
34
- >
35
- Primary Button
36
- </Button>
37
- <ThemeProvider theme={(theme) => sproutLightTheme(theme)}>
38
- <Button
39
- appearance={text("appearance", "primary")}
40
- onClick={() => alert("Testing...")}
41
- >
42
- Primary Button
43
- </Button>
44
- </ThemeProvider>
45
- </>
25
+ <Button
26
+ appearance={text("appearance", "primary")}
27
+ onClick={() => alert("Testing...")}
28
+ >
29
+ Primary Button
30
+ </Button>
46
31
  );
47
32
 
48
33
  primary.story = {
@@ -1,6 +1,11 @@
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
+ import styled from "styled-components";
7
+ import type { StyledComponent } from "styled-components";
8
+ import type { TypeTheme } from "../types/theme.flow";
4
9
 
5
10
  type TypeProps = {
6
11
  /** ID of the form element, should match the "for" value of the associated label */
@@ -10,6 +15,8 @@ type TypeProps = {
10
15
  ariaLabel?: string,
11
16
  /** Attribute used to associate other elements that describe the Input, like an error */
12
17
  ariaDescribedby?: string,
18
+ /** Label for Input.ClearButton. Required when using <Input type="search"/> or <Input.ClearButton/>. */
19
+ clearButtonLabel?: string,
13
20
  /** Placeholder text for when value is undefined or empty */
14
21
  placeholder?: string,
15
22
  /** Current value of the input */
@@ -39,9 +46,14 @@ type TypeProps = {
39
46
  /** Props to spread onto the underlying input element */
40
47
  inputProps?: any,
41
48
  /** Used to get a reference to the underlying element */
42
- innerRef?: React.Ref<"input">,
49
+ innerRef?:
50
+ | {| current: null | HTMLInputElement |}
51
+ | ((React.ElementRef<any> | HTMLElement) => void),
43
52
  onBlur?: (e: SyntheticFocusEvent<HTMLInputElement>) => void,
44
53
  onChange?: (e: SyntheticInputEvent<HTMLInputElement>, value: string) => void,
54
+ /** Input.ClearButton onClick callback. Required when using <Input type="search"/> or <Input.ClearButton/>.
55
+ The component handles returning focus to Input after onClear is called only. You must reset "value" yourself.*/
56
+ onClear?: (e: SyntheticEvent<HTMLButtonElement>) => void,
45
57
  onFocus?: (e: SyntheticFocusEvent<HTMLInputElement>) => void,
46
58
  onKeyDown?: (
47
59
  e: SyntheticKeyboardEvent<HTMLInputElement>,
@@ -54,57 +66,130 @@ type TypeProps = {
54
66
  onPaste?: (e: SyntheticInputEvent<HTMLInputElement>, value: string) => void,
55
67
  size?: "large" | "small" | "default",
56
68
  qa?: Object,
57
- /**
58
- Controls the styles of the input. Primary is our standard input styles and secondary is a borderless input.
69
+ /**
70
+ Controls the styles of the input. Primary is our standard input styles and secondary is a borderless input.
59
71
  Note that this prop should only be used to alter styles and not functionality.
60
72
  */
61
73
  appearance?: "primary" | "secondary",
62
74
  };
63
75
 
64
- export default class Input extends React.Component<TypeProps> {
76
+ // Using Context so that Input's Input.ClearButton-specific props can be passed to Input.ClearButton,
77
+ // regardless of whether it is manually included as elemAfter or automatically included for type="search" Inputs.
78
+ type TypeInputContext = $Shape<{
79
+ onClear?: (e: SyntheticEvent<HTMLButtonElement>) => void,
80
+ handleClear: (e: SyntheticEvent<HTMLButtonElement>) => void,
81
+ clearButtonLabel: string,
82
+ hasValue: boolean,
83
+ size: "large" | "small" | "default",
84
+ }>;
85
+
86
+ const InputContext = React.createContext<TypeInputContext>({});
87
+
88
+ const StyledButton: StyledComponent<any, TypeTheme, *> = styled(Button)`
89
+ &:hover,
90
+ &:active {
91
+ color: ${(props) =>
92
+ props.theme.utils.interact(props.theme.colors.icon.base)};
93
+ }
94
+ `;
95
+
96
+ const ClearButton = () => {
97
+ const {
98
+ onClear,
99
+ handleClear,
100
+ clearButtonLabel,
101
+ hasValue,
102
+ size: inputSize,
103
+ } = React.useContext(InputContext);
104
+
105
+ // Hide the button when there is no text to clear.
106
+ if (!hasValue) {
107
+ return null;
108
+ }
109
+
110
+ // Log a warning and hide the button when no onClear callback is provided.
111
+ // If we called handleClear with no onClear prop, all the button would do is focus the Input.
112
+ if (!onClear) {
113
+ console.warn(
114
+ "Warning: No onClear prop provided to Input when using Input.ClearButton. Omitting Input.ClearButton."
115
+ );
116
+ return null;
117
+ }
118
+
119
+ // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
120
+ if (!clearButtonLabel) {
121
+ console.warn(
122
+ "Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized clearButtonLabel to Input."
123
+ );
124
+ }
125
+
126
+ // Reduce Button padding for size small Inputs so that the Button won't go outside the bounds of the Input.
127
+ // This adjustment is handled automatically for default and large Inputs via Button's size. There is no "small" Button.
128
+ const py = inputSize === "small" ? 100 : undefined;
129
+ const px = inputSize === "small" ? 200 : undefined;
130
+ const buttonSize = inputSize === "small" ? "default" : inputSize;
131
+
132
+ return (
133
+ <StyledButton
134
+ onClick={handleClear}
135
+ size={buttonSize}
136
+ py={py}
137
+ px={px}
138
+ title={clearButtonLabel || "Clear"}
139
+ ariaLabel={clearButtonLabel || "Clear"}
140
+ color="icon.base"
141
+ >
142
+ <Icon name="circlex" />
143
+ </StyledButton>
144
+ );
145
+ };
146
+
147
+ // Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
148
+ // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
149
+ const isClearButton = (elem: any) => {
150
+ if (elem?.type) {
151
+ return elem.type.displayName === "Input.ClearButton";
152
+ }
153
+ return false;
154
+ };
155
+
156
+ class Input extends React.Component<TypeProps> {
65
157
  static defaultProps = {
66
158
  autoFocus: false,
67
159
  disabled: false,
68
160
  type: "text",
69
161
  size: "default",
70
162
  appearance: "primary",
163
+ innerRef: React.createRef<HTMLInputElement>(),
71
164
  };
72
165
 
73
- handleBlur = (e: SyntheticFocusEvent<HTMLInputElement>) => {
74
- if (this.props.onBlur) {
75
- this.props.onBlur(e);
76
- }
77
- };
166
+ static ClearButton = ClearButton;
78
167
 
79
- handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
80
- if (this.props.onChange) {
81
- this.props.onChange(e, e.currentTarget.value);
82
- }
83
- };
168
+ handleBlur = (e: SyntheticFocusEvent<HTMLInputElement>) =>
169
+ this.props.onBlur?.(e);
84
170
 
85
- handleFocus = (e: SyntheticFocusEvent<HTMLInputElement>) => {
86
- if (this.props.onFocus) {
87
- this.props.onFocus(e);
171
+ handleClear = (e: SyntheticEvent<HTMLButtonElement>) => {
172
+ // Only attempt to focus the input if the ref is an object. It won't work for refs that are functions.
173
+ if (typeof this.props.innerRef === "object") {
174
+ this.props.innerRef.current?.focus();
88
175
  }
176
+ this.props.onClear?.(e);
89
177
  };
90
178
 
91
- handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
92
- if (this.props.onKeyDown) {
93
- this.props.onKeyDown(e, e.currentTarget.value);
94
- }
95
- };
179
+ handleChange = (e: SyntheticInputEvent<HTMLInputElement>) =>
180
+ this.props.onChange?.(e, e.currentTarget.value);
96
181
 
97
- handleKeyUp = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
98
- if (this.props.onKeyUp) {
99
- this.props.onKeyUp(e, e.currentTarget.value);
100
- }
101
- };
182
+ handleFocus = (e: SyntheticFocusEvent<HTMLInputElement>) =>
183
+ this.props.onFocus?.(e);
102
184
 
103
- handlePaste = (e: SyntheticInputEvent<HTMLInputElement>) => {
104
- if (this.props.onPaste) {
105
- this.props.onPaste(e, e.currentTarget.value);
106
- }
107
- };
185
+ handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) =>
186
+ this.props.onKeyDown?.(e, e.currentTarget.value);
187
+
188
+ handleKeyUp = (e: SyntheticKeyboardEvent<HTMLInputElement>) =>
189
+ this.props.onKeyUp?.(e, e.currentTarget.value);
190
+
191
+ handlePaste = (e: SyntheticInputEvent<HTMLInputElement>) =>
192
+ this.props.onPaste?.(e, e.currentTarget.value);
108
193
 
109
194
  render() {
110
195
  const {
@@ -125,9 +210,11 @@ export default class Input extends React.Component<TypeProps> {
125
210
  maxLength,
126
211
  ariaLabel,
127
212
  ariaDescribedby,
213
+ clearButtonLabel,
128
214
  innerRef,
129
215
  onBlur,
130
216
  onChange,
217
+ onClear,
131
218
  onFocus,
132
219
  onKeyDown,
133
220
  onKeyUp,
@@ -135,58 +222,90 @@ export default class Input extends React.Component<TypeProps> {
135
222
  inputProps = {},
136
223
  qa = {},
137
224
  appearance,
225
+ size,
138
226
  ...rest
139
227
  } = this.props;
140
228
 
229
+ // Convert autoComplete from a boolean prop to a string value.
141
230
  let autoCompleteValue = undefined;
142
231
  if (autoComplete !== undefined) {
143
232
  autoCompleteValue = autoComplete ? "on" : "off";
144
233
  }
145
234
 
235
+ // Add default elemBefore and elemAfter elements if type is search.
236
+ const elementBefore =
237
+ type === "search" && !elemBefore ? (
238
+ <Icon name="search" ariaHidden color="icon.base" />
239
+ ) : (
240
+ elemBefore
241
+ );
242
+ // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
243
+ const elementAfter =
244
+ type === "search" && onClear && !elemAfter ? <ClearButton /> : elemAfter;
245
+
146
246
  return (
147
247
  <Container
148
- hasBeforeElement={!!elemBefore}
149
- hasAfterElement={!!elemAfter}
248
+ hasBeforeElement={!!elementBefore}
249
+ hasAfterElement={!!elementAfter}
150
250
  disabled={disabled}
151
251
  invalid={!!isInvalid}
152
252
  warning={hasWarning}
153
253
  appearance={appearance}
254
+ size={size}
154
255
  // $FlowIssue - upgrade v0.112.0
155
256
  {...rest}
156
257
  >
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>}
258
+ <InputContext.Provider
259
+ value={{
260
+ handleClear: this.handleClear,
261
+ hasValue: !!value,
262
+ clearButtonLabel,
263
+ onClear,
264
+ size,
265
+ }}
266
+ >
267
+ {elementBefore && <Accessory before>{elementBefore}</Accessory>}
268
+
269
+ <input
270
+ aria-invalid={!!isInvalid}
271
+ aria-label={ariaLabel}
272
+ aria-describedby={ariaDescribedby}
273
+ autoComplete={autoCompleteValue}
274
+ autoFocus={autoFocus}
275
+ disabled={disabled}
276
+ readOnly={readOnly}
277
+ id={id}
278
+ name={name}
279
+ placeholder={placeholder}
280
+ type={type}
281
+ required={required}
282
+ value={value}
283
+ maxLength={maxLength}
284
+ onBlur={this.handleBlur}
285
+ onChange={this.handleChange}
286
+ onFocus={this.handleFocus}
287
+ onKeyDown={this.handleKeyDown}
288
+ onKeyUp={this.handleKeyUp}
289
+ onPaste={this.handlePaste}
290
+ ref={innerRef}
291
+ data-qa-input={name || ""}
292
+ data-qa-input-isdisabled={disabled === true}
293
+ data-qa-input-isrequired={required === true}
294
+ {...qa}
295
+ {...inputProps}
296
+ />
297
+
298
+ {elementAfter && (
299
+ <Accessory after isClearButton={isClearButton(elementAfter)}>
300
+ {elementAfter}
301
+ </Accessory>
302
+ )}
303
+ </InputContext.Provider>
189
304
  </Container>
190
305
  );
191
306
  }
192
307
  }
308
+
309
+ Input.ClearButton.displayName = "Input.ClearButton";
310
+
311
+ export default Input;
@@ -141,6 +141,71 @@ 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 smallSearchInput = () => (
160
+ <Input
161
+ type="search"
162
+ size="small"
163
+ placeholder={text("placeholder", "Please enter a value...")}
164
+ value={text("value", "val")}
165
+ onClear={() => window.alert("Cleared!")}
166
+ clearButtonLabel={text("clearButtonLabel", "Clear search")}
167
+ ariaLabel={text("ariaLabel", "Descriptive label goes here")}
168
+ />
169
+ );
170
+
171
+ smallSearchInput.story = {
172
+ name: "Small Search Input",
173
+ };
174
+
175
+ export const largeSearchInput = () => (
176
+ <Input
177
+ type="search"
178
+ size="large"
179
+ placeholder={text("placeholder", "Please enter a value...")}
180
+ value={text("value", "val")}
181
+ onClear={() => window.alert("Cleared!")}
182
+ clearButtonLabel={text("clearButtonLabel", "Clear search")}
183
+ ariaLabel={text("ariaLabel", "Descriptive label goes here")}
184
+ />
185
+ );
186
+
187
+ largeSearchInput.story = {
188
+ name: "Large Search Input",
189
+ };
190
+
191
+ export const nonSearchClearButtonInput = () => {
192
+ return (
193
+ <Input
194
+ type="text"
195
+ placeholder={text("placeholder", "Please enter a value...")}
196
+ value={text("value", "val")}
197
+ onClear={() => window.alert("Cleared!")}
198
+ ariaLabel={text("ariaLabel", "Descriptive label goes here")}
199
+ clearButtonLabel={text("clearButtonLabel", "Clear text")}
200
+ elemAfter={<Input.ClearButton />}
201
+ />
202
+ );
203
+ };
204
+
205
+ nonSearchClearButtonInput.story = {
206
+ name: "Manual Input.ClearButton usage",
207
+ };
208
+
144
209
  export const autofocus = () => (
145
210
  <Input
146
211
  autoFocus