@sproutsocial/racine 11.3.0-beta.1 → 11.3.0-beta.2

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,35 @@
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
+ ## 11.2.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 514d738: Patch badge component flow issue
14
+
15
+ ## 11.2.2
16
+
17
+ ### Patch Changes
18
+
19
+ - 9cc377e: Created extended theme directory
20
+
21
+ ## 11.2.1
22
+
23
+ ### Patch Changes
24
+
25
+ - 6968733: adds deprecation messaging to typeProps to be displayed on seeds page
26
+
27
+ ## 11.2.0
28
+
29
+ ### Minor Changes
30
+
31
+ - a71a431: backwards compatible style and api changes to the badge component
32
+
3
33
  ## 11.1.2
4
34
 
5
35
  ### Patch Changes
@@ -0,0 +1,48 @@
1
+ //@flow
2
+
3
+ const defaultPurple = {
4
+ color: "colors.text.body",
5
+ background: "colors.container.background.decorative.purple",
6
+ };
7
+
8
+ const suggestion = {
9
+ color: "colors.text.body",
10
+ background: "colors.container.background.decorative.blue",
11
+ };
12
+
13
+ const passive = {
14
+ color: "colors.text.body",
15
+ background: "colors.container.background.decorative.neutral",
16
+ };
17
+
18
+ const primary = {
19
+ color: "colors.text.body",
20
+ background: "colors.container.background.decorative.blue",
21
+ };
22
+
23
+ const secondary = {
24
+ color: "colors.text.body",
25
+ background: "colors.container.background.decorative.yellow",
26
+ };
27
+
28
+ const common = {
29
+ color: "colors.text.inverse",
30
+ background: "colors.aqua.600",
31
+ };
32
+
33
+ const approval = {
34
+ color: "colors.text.body",
35
+ background: "colors.container.background.decorative.orange",
36
+ };
37
+
38
+ //Deprecated former "types"
39
+
40
+ export const legacyBadgeColors = {
41
+ primary,
42
+ secondary,
43
+ passive,
44
+ common,
45
+ approval,
46
+ default: defaultPurple,
47
+ suggestion,
48
+ };
@@ -1,43 +1,70 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
+ import Icon from "../Icon";
3
4
  import Container from "./styles";
5
+ import Box from "../Box";
4
6
 
5
7
  type TypeProps = {
6
- text: React.Node,
7
- type:
8
- | "primary"
9
- | "secondary"
10
- | "passive"
11
- | "common"
12
- | "approval"
13
- | "default"
14
- | "suggestion",
15
- size: "default" | "small",
8
+ children?: React.Node,
9
+ /** DEPRECATED: Use children instead of text */
10
+ text?: React.Node,
11
+ /** Size default is deprecated in favor of small and large */
12
+ size?: "small" | "large" | "default",
13
+ badgeColor?:
14
+ | "green"
15
+ | "blue"
16
+ | "purple"
17
+ | "yellow"
18
+ | "orange"
19
+ | "red"
20
+ | "neutral",
21
+ iconName?: string,
22
+ /** DEPRECATED: Possibly only used for testing. Refrain from using at all if possible. (optional) */
16
23
  tip?: React.Node,
24
+ /** DEPRECATED: The legacy method of choosing a theme. Use badgeColor instead. (optional) */
25
+ type?: string,
17
26
  };
18
27
 
19
- export default class Badge extends React.Component<TypeProps> {
20
- static defaultProps = {
21
- type: "primary",
22
- size: "default",
23
- };
24
-
25
- render() {
26
- const { size, type, tip, text, ...rest } = this.props;
27
-
28
- return (
29
- <Container
30
- type={type}
31
- small={size === "small"}
32
- data-tip={tip}
33
- data-qa-badge={text || ""}
34
- data-qa-badge-type={type}
35
- data-qa-badge-tip={tip || ""}
36
- // $FlowIssue - upgrade v0.112.0
37
- {...rest}
38
- >
39
- {text}
40
- </Container>
28
+ const Badge = ({
29
+ children,
30
+ text,
31
+ iconName,
32
+ type,
33
+ tip,
34
+ size = "small",
35
+ badgeColor = "blue",
36
+ ...rest
37
+ }: TypeProps) => {
38
+ if (children && text) {
39
+ throw new Error(
40
+ "can't use both `children` and `text` props. Text is deprecated, consider using children."
41
41
  );
42
42
  }
43
- }
43
+
44
+ return (
45
+ <Container
46
+ {...rest}
47
+ // size previously included default, which currently maps to small. Once consumers have updated this can be simplified.
48
+ size={size === "default" ? "large" : size}
49
+ badgeColor={badgeColor}
50
+ data-tip={tip}
51
+ data-qa-badge={text || ""}
52
+ data-qa-badge-type={type}
53
+ data-qa-badge-tip={tip || ""}
54
+ type={type && type}
55
+ >
56
+ <Box display="flex" alignItems="center" JustifyContent="center">
57
+ {iconName ? (
58
+ <Icon
59
+ mr={200}
60
+ name={iconName}
61
+ size={size === "small" ? "mini" : "default"}
62
+ />
63
+ ) : null}
64
+ {children || text}
65
+ </Box>
66
+ </Container>
67
+ );
68
+ };
69
+
70
+ export default Badge;
@@ -1,53 +1,46 @@
1
1
  import React from "react";
2
- import { text } from "@storybook/addon-knobs";
3
2
  import Badge from "./index";
3
+ import Box from "../Box";
4
+ import Numeral from "../Numeral";
5
+ import Text from "../Text";
6
+ import Stack from "../Stack";
4
7
 
5
8
  export default {
6
9
  title: "Badge",
7
10
  };
8
11
 
9
12
  export const permutations = () => (
10
- <>
11
- <Badge
12
- text={text("text", "Test")}
13
- type="default"
14
- size={text("size", "small")}
15
- />
16
- <Badge text={text("text", "Test")} size={text("size", "small")} />
17
- <Badge
18
- text={text("text", "Test")}
19
- type="secondary"
20
- size={text("size", "small")}
21
- />
22
- <Badge
23
- text={text("text", "Test")}
24
- type="passive"
25
- size={text("size", "small")}
26
- />
27
- <Badge
28
- text={text("text", "Test")}
29
- type="common"
30
- size={text("size", "small")}
31
- />
32
- <Badge
33
- text={text("text", "Test")}
34
- type="approval"
35
- size={text("size", "small")}
36
- />
37
- <Badge
38
- text={text("text", "Test")}
39
- type="suggestion"
40
- size={text("size", "small")}
41
- />
42
-
43
- <Badge text={text("text", "Test")} type="default" />
44
- <Badge text={text("text", "Test")} />
45
- <Badge text={text("text", "Test")} type="secondary" />
46
- <Badge text={text("text", "Test")} type="passive" />
47
- <Badge text={text("text", "Test")} type="common" />
48
- <Badge text={text("text", "Test")} type="approval" />
49
- <Badge text={text("text", "Test")} type="suggestion" />
50
- </>
13
+ <Stack space={450}>
14
+ <Box display="flex" alignItems="center">
15
+ <Badge badgeColor="green">Badge</Badge>
16
+ <Badge>Badge</Badge>
17
+ <Badge badgeColor="purple">Badge</Badge>
18
+ <Badge badgeColor="yellow">Badge</Badge>
19
+ <Badge badgeColor="orange">Badge</Badge>
20
+ <Badge badgeColor="red">Badge</Badge>
21
+ <Badge badgeColor="neutral" iconName="atom">
22
+ Badge
23
+ </Badge>
24
+ <Badge
25
+ size="small"
26
+ type="default"
27
+ bg="chartreuse"
28
+ color="crimson"
29
+ p={500}
30
+ >
31
+ Radical overrides!
32
+ </Badge>
33
+ </Box>
34
+ <Box display="flex" alignItems="center">
35
+ <Badge size="large" type="secondary" iconName="sparkles">
36
+ Supports legacy types
37
+ </Badge>
38
+ <Badge size="large">
39
+ <Numeral fontWeight="bold" number={1569241} />
40
+ <Text ml={200}>and children!</Text>
41
+ </Badge>
42
+ </Box>
43
+ </Stack>
51
44
  );
52
45
 
53
46
  permutations.story = {
@@ -3,48 +3,50 @@ import Badge from "./";
3
3
  import { render } from "../utils/react-testing-library";
4
4
  import "jest-styled-components";
5
5
 
6
- describe("Racine Badge", () => {
7
- it("should render with default props", () => {
8
- const { getByText, getByDataQaLabel } = render(<Badge text="Test" />);
6
+ describe("Badge...", () => {
7
+ it("...should render with default props", () => {
8
+ const { getByText } = render(<Badge>Test</Badge>);
9
9
  expect(getByText("Test")).toBeTruthy();
10
- expect(getByDataQaLabel({ "badge-type": "primary" })).toBeTruthy();
10
+ expect(getByText("Test").closest("span")).toHaveStyleRule(
11
+ "padding",
12
+ "0px 4px"
13
+ );
14
+ expect(getByText("Test").closest("span")).toHaveStyleRule(
15
+ "background",
16
+ "#dcf2ff"
17
+ );
11
18
  });
12
19
 
13
- it("should render with correct size styling", () => {
14
- const { getByText } = render(<Badge text="Test" size="small" />);
15
- expect(getByText("Test")).toHaveStyleRule("padding", "4px 8px");
20
+ it("...should render with correct size styling", () => {
21
+ const { getByText } = render(<Badge size="large">Test</Badge>);
22
+ expect(getByText("Test").closest("span")).toHaveStyleRule("padding", "8px");
16
23
  });
17
24
 
18
- it("should render with secondary type", () => {
19
- const { getByText, getByDataQaLabel } = render(
20
- <Badge text="Test" type="secondary" />
21
- );
25
+ it("...should render with legacy type", () => {
26
+ const { getByText } = render(<Badge type="secondary">Test</Badge>);
22
27
  expect(getByText("Test")).toBeTruthy();
23
- expect(getByDataQaLabel({ "badge-type": "secondary" })).toBeTruthy();
24
- });
25
-
26
- it("should render with passive type", () => {
27
- const { getByText, getByDataQaLabel } = render(
28
- <Badge text="Test" type="passive" />
28
+ expect(getByText("Test").closest("span")).toHaveStyleRule(
29
+ "color",
30
+ "#364141"
31
+ );
32
+ expect(getByText("Test").closest("span")).toHaveStyleRule(
33
+ "background",
34
+ "#fdefcd"
29
35
  );
30
- expect(getByText("Test")).toBeTruthy();
31
- expect(getByDataQaLabel({ "badge-type": "passive" })).toBeTruthy();
32
36
  });
33
37
 
34
- it("should render with common type", () => {
35
- const { getByText, getByDataQaLabel } = render(
36
- <Badge text="Test" type="common" />
37
- );
38
+ it("...should render with a badge color", () => {
39
+ const { getByText } = render(<Badge badgeColor="purple">Test</Badge>);
38
40
  expect(getByText("Test")).toBeTruthy();
39
- expect(getByDataQaLabel({ "badge-type": "common" })).toBeTruthy();
41
+ expect(getByText("Test").closest("span")).toHaveStyleRule(
42
+ "background",
43
+ "#eaeaf9"
44
+ );
40
45
  });
41
46
 
42
- it("should render with approval type", () => {
43
- const { getByText, getByDataQaLabel } = render(
44
- <Badge text="Test" type="approval" />
45
- );
46
- expect(getByText("Test")).toBeTruthy();
47
- expect(getByDataQaLabel({ "badge-type": "approval" })).toBeTruthy();
47
+ it("...should render with an icon", () => {
48
+ const { container } = render(<Badge iconName="sparkles">Test</Badge>);
49
+ expect(container.querySelector("svg")).toBeTruthy();
48
50
  });
49
51
  it("should render with suggestion type", () => {
50
52
  const { getByText, getByDataQaLabel } = render(
@@ -54,9 +56,9 @@ describe("Racine Badge", () => {
54
56
  expect(getByDataQaLabel({ "badge-type": "suggestion" })).toBeTruthy();
55
57
  });
56
58
 
57
- it("should render with tooltip class", () => {
59
+ it("...should render with tooltip class", () => {
58
60
  const { getByText, getByDataQaLabel } = render(
59
- <Badge text="Test" tip="test tip" />
61
+ <Badge tip="test tip">Test</Badge>
60
62
  );
61
63
  expect(getByText("Test")).toBeTruthy();
62
64
  expect(getByDataQaLabel({ "badge-tip": "test tip" })).toBeTruthy();
@@ -1,51 +1,31 @@
1
1
  //@flow
2
- import styled, { css, type StyledComponent } from "styled-components";
2
+ import styled, { type StyledComponent } from "styled-components";
3
3
  import { COMMON } from "../utils/system-props";
4
- import { themeGet } from "@styled-system/theme-get";
5
-
6
4
  import type { TypeTheme } from "../types/theme.flow";
7
-
8
- const colors = {
9
- primary: "colors.neutral.0",
10
- secondary: "colors.neutral.800",
11
- passive: "colors.neutral.800",
12
- common: "colors.neutral.0",
13
- approval: "colors.neutral.800",
14
- default: "colors.neutral.0",
15
- suggestion: "colors.neutral.900",
16
- };
17
-
18
- const backgroundColors = {
19
- primary: "colors.blue.700",
20
- secondary: "colors.yellow.500",
21
- passive: "colors.neutral.200",
22
- common: "colors.aqua.600",
23
- approval: "colors.orange.300",
24
- default: "colors.purple.700",
25
- suggestion: "colors.blue.300",
26
- };
5
+ import { themeGet } from "@styled-system/theme-get";
6
+ import { legacyBadgeColors } from "./constants";
27
7
 
28
8
  // eslint-disable-next-line prettier/prettier
29
- const Container: StyledComponent<{type: "primary" | "secondary" | "passive" | "common" | "approval" | "default" | "suggestion", small: boolean, ...}, TypeTheme, *> = styled.span`
9
+ const Container: StyledComponent<{type: ?string, badgeColor: string, size: string, ...}, TypeTheme, *> = styled.span`
10
+ font-family: ${(p) => p.theme.fontFamily};
11
+ ${(p) =>
12
+ p.size === "small" ? p.theme.typography[100] : p.theme.typography[200]};
13
+ border-radius: 9999px;
14
+ line-height: 16px;
30
15
  display: inline-block;
31
- text-align: center;
32
- border-radius: 50px;
33
- font-family: ${(props) => props.theme.fontFamily};
34
-
35
- padding: ${(props) =>
36
- props.small
37
- ? `${props.theme.space[200]} ${props.theme.space[300]}`
38
- : `${props.theme.space[300]} ${props.theme.space[350]}`};
39
-
40
- ${(props) =>
41
- props.small ? props.theme.typography[100] : props.theme.typography[200]}
42
-
43
- ${(props) => css`
44
- color: ${themeGet(colors[props.type])(props)};
45
- background: ${themeGet(backgroundColors[props.type])(props)};
46
- `}
47
-
48
- ${COMMON}
16
+ color: ${(p) =>
17
+ p.type
18
+ ? themeGet(legacyBadgeColors[p.type].color)
19
+ : p.theme.colors.text.body};
20
+ background: ${(p) =>
21
+ p.type
22
+ ? themeGet(legacyBadgeColors[p.type].background)
23
+ : p.theme.colors.container.background.decorative[p.badgeColor]};
24
+ padding: ${(p) =>
25
+ p.size === "small"
26
+ ? `${p.theme.space[0]} ${p.theme.space[200]}`
27
+ : `${p.theme.space[300]}`};
28
+ ${COMMON};
49
29
  `;
50
30
 
51
31
  export default Container;
@@ -72,12 +72,19 @@ type TypeProps = {
72
72
  type TypeInputContext = $Shape<{
73
73
  handleClear: (e: SyntheticEvent<HTMLButtonElement>) => void,
74
74
  clearButtonLabel: string,
75
+ hasValue: boolean,
75
76
  }>;
76
77
 
77
78
  const InputContext = React.createContext<TypeInputContext>({});
78
79
 
79
80
  const ClearButton = () => {
80
- const { handleClear, clearButtonLabel } = React.useContext(InputContext);
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
+ }
81
88
  return (
82
89
  <Button onClick={handleClear}>
83
90
  {/*Unlocalized fallback should not be used. Always include a localized
@@ -87,6 +94,15 @@ const ClearButton = () => {
87
94
  );
88
95
  };
89
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
+
90
106
  class Input extends React.Component<TypeProps> {
91
107
  static defaultProps = {
92
108
  autoFocus: false,
@@ -185,6 +201,7 @@ class Input extends React.Component<TypeProps> {
185
201
  value={{
186
202
  handleClear: this.handleClear,
187
203
  clearButtonLabel,
204
+ hasValue: !!value,
188
205
  }}
189
206
  >
190
207
  {elementBefore && <Accessory before>{elementBefore}</Accessory>}
@@ -219,14 +236,7 @@ class Input extends React.Component<TypeProps> {
219
236
  />
220
237
 
221
238
  {elementAfter && (
222
- <Accessory
223
- after
224
- // Used for positioning. This logic will detect if the element is a ClearButton,
225
- // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
226
- isClearButton={
227
- elementAfter?.type?.prototype === Input.ClearButton.prototype
228
- }
229
- >
239
+ <Accessory after isClearButton={isClearButton(elementAfter)}>
230
240
  {elementAfter}
231
241
  </Accessory>
232
242
  )}
@@ -8,10 +8,11 @@ type TypeProps = {
8
8
  /** Optional prop to make the URL open in a new tab */
9
9
  external?: boolean,
10
10
  children: React.Node,
11
+ /** Setting this prop will cause the component to be rendered as a link */
11
12
  href?: string,
12
13
  /** Disables user action and applies a disabled style to the component */
13
14
  disabled?: boolean,
14
- /** Setting this prop will cause the component to be rendered as a button instead of an anchor) */
15
+ /** Can be used in addition to an href but still renders as a link. Omitting href will render as button */
15
16
  onClick?: (e: SyntheticEvent<HTMLButtonElement>) => void,
16
17
  as?: $PropertyType<TypeStyledComponentsCommonProps, "as">,
17
18
  underline?: boolean,
@@ -0,0 +1,6 @@
1
+ ## Extended Theme Directory
2
+
3
+ This directory serves as a shared environment for all extended themes. Each unique theme should have its own folder and theme.js file.
4
+ `src/themes/extendedThemes/customTheme/theme.js`
5
+
6
+ Check out our documentation for [How to extend the theme](https://seeds.sproutsocial.com/components/theme#extending-the-theme) on Seeds.
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.legacyBadgeColors = void 0;
5
+ var defaultPurple = {
6
+ color: "colors.text.body",
7
+ background: "colors.container.background.decorative.purple"
8
+ };
9
+ var suggestion = {
10
+ color: "colors.text.body",
11
+ background: "colors.container.background.decorative.blue"
12
+ };
13
+ var passive = {
14
+ color: "colors.text.body",
15
+ background: "colors.container.background.decorative.neutral"
16
+ };
17
+ var primary = {
18
+ color: "colors.text.body",
19
+ background: "colors.container.background.decorative.blue"
20
+ };
21
+ var secondary = {
22
+ color: "colors.text.body",
23
+ background: "colors.container.background.decorative.yellow"
24
+ };
25
+ var common = {
26
+ color: "colors.text.inverse",
27
+ background: "colors.aqua.600"
28
+ };
29
+ var approval = {
30
+ color: "colors.text.body",
31
+ background: "colors.container.background.decorative.orange"
32
+ }; //Deprecated former "types"
33
+
34
+ var legacyBadgeColors = {
35
+ primary: primary,
36
+ secondary: secondary,
37
+ passive: passive,
38
+ common: common,
39
+ approval: approval,
40
+ default: defaultPurple,
41
+ suggestion: suggestion
42
+ };
43
+ exports.legacyBadgeColors = legacyBadgeColors;
@@ -5,9 +5,13 @@ exports.default = void 0;
5
5
 
6
6
  var React = _interopRequireWildcard(require("react"));
7
7
 
8
+ var _Icon = _interopRequireDefault(require("../Icon"));
9
+
8
10
  var _styles = _interopRequireDefault(require("./styles"));
9
11
 
10
- var _excluded = ["size", "type", "tip", "text"];
12
+ var _Box = _interopRequireDefault(require("../Box"));
13
+
14
+ var _excluded = ["children", "text", "iconName", "type", "tip", "size", "badgeColor"];
11
15
 
12
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
17
 
@@ -19,43 +23,41 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
19
23
 
20
24
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
21
25
 
22
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
23
-
24
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
25
-
26
- var Badge = /*#__PURE__*/function (_React$Component) {
27
- _inheritsLoose(Badge, _React$Component);
28
-
29
- function Badge() {
30
- return _React$Component.apply(this, arguments) || this;
26
+ var Badge = function Badge(_ref) {
27
+ var children = _ref.children,
28
+ text = _ref.text,
29
+ iconName = _ref.iconName,
30
+ type = _ref.type,
31
+ tip = _ref.tip,
32
+ _ref$size = _ref.size,
33
+ size = _ref$size === void 0 ? "small" : _ref$size,
34
+ _ref$badgeColor = _ref.badgeColor,
35
+ badgeColor = _ref$badgeColor === void 0 ? "blue" : _ref$badgeColor,
36
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
37
+
38
+ if (children && text) {
39
+ throw new Error("can't use both `children` and `text` props. Text is deprecated, consider using children.");
31
40
  }
32
41
 
33
- var _proto = Badge.prototype;
34
-
35
- _proto.render = function render() {
36
- var _this$props = this.props,
37
- size = _this$props.size,
38
- type = _this$props.type,
39
- tip = _this$props.tip,
40
- text = _this$props.text,
41
- rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
42
-
43
- return /*#__PURE__*/React.createElement(_styles.default, _extends({
44
- type: type,
45
- small: size === "small",
46
- "data-tip": tip,
47
- "data-qa-badge": text || "",
48
- "data-qa-badge-type": type,
49
- "data-qa-badge-tip": tip || "" // $FlowIssue - upgrade v0.112.0
50
-
51
- }, rest), text);
52
- };
53
-
54
- return Badge;
55
- }(React.Component);
56
-
57
- exports.default = Badge;
58
- Badge.defaultProps = {
59
- type: "primary",
60
- size: "default"
61
- };
42
+ return /*#__PURE__*/React.createElement(_styles.default, _extends({}, rest, {
43
+ // size previously included default, which currently maps to small. Once consumers have updated this can be simplified.
44
+ size: size === "default" ? "large" : size,
45
+ badgeColor: badgeColor,
46
+ "data-tip": tip,
47
+ "data-qa-badge": text || "",
48
+ "data-qa-badge-type": type,
49
+ "data-qa-badge-tip": tip || "",
50
+ type: type && type
51
+ }), /*#__PURE__*/React.createElement(_Box.default, {
52
+ display: "flex",
53
+ alignItems: "center",
54
+ JustifyContent: "center"
55
+ }, iconName ? /*#__PURE__*/React.createElement(_Icon.default, {
56
+ mr: 200,
57
+ name: iconName,
58
+ size: size === "small" ? "mini" : "default"
59
+ }) : null, children || text));
60
+ };
61
+
62
+ var _default = Badge;
63
+ exports.default = _default;
@@ -3,46 +3,30 @@
3
3
  exports.__esModule = true;
4
4
  exports.default = void 0;
5
5
 
6
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
6
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
7
7
 
8
8
  var _systemProps = require("../utils/system-props");
9
9
 
10
10
  var _themeGet = require("@styled-system/theme-get");
11
11
 
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
-
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
- var colors = {
17
- primary: "colors.neutral.0",
18
- secondary: "colors.neutral.800",
19
- passive: "colors.neutral.800",
20
- common: "colors.neutral.0",
21
- approval: "colors.neutral.800",
22
- default: "colors.neutral.0",
23
- suggestion: "colors.neutral.900"
24
- };
25
- var backgroundColors = {
26
- primary: "colors.blue.700",
27
- secondary: "colors.yellow.500",
28
- passive: "colors.neutral.200",
29
- common: "colors.aqua.600",
30
- approval: "colors.orange.300",
31
- default: "colors.purple.700",
32
- suggestion: "colors.blue.300"
33
- }; // eslint-disable-next-line prettier/prettier
12
+ var _constants = require("./constants");
34
13
 
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ // eslint-disable-next-line prettier/prettier
35
17
  var Container = _styledComponents.default.span.withConfig({
36
18
  displayName: "styles__Container",
37
19
  componentId: "sc-g1g76b-0"
38
- })(["display:inline-block;text-align:center;border-radius:50px;font-family:", ";padding:", ";", " ", " ", ""], function (props) {
39
- return props.theme.fontFamily;
40
- }, function (props) {
41
- return props.small ? props.theme.space[200] + " " + props.theme.space[300] : props.theme.space[300] + " " + props.theme.space[350];
42
- }, function (props) {
43
- return props.small ? props.theme.typography[100] : props.theme.typography[200];
44
- }, function (props) {
45
- return (0, _styledComponents.css)(["color:", ";background:", ";"], (0, _themeGet.themeGet)(colors[props.type])(props), (0, _themeGet.themeGet)(backgroundColors[props.type])(props));
20
+ })(["font-family:", ";", ";border-radius:9999px;line-height:16px;display:inline-block;color:", ";background:", ";padding:", ";", ";"], function (p) {
21
+ return p.theme.fontFamily;
22
+ }, function (p) {
23
+ return p.size === "small" ? p.theme.typography[100] : p.theme.typography[200];
24
+ }, function (p) {
25
+ return p.type ? (0, _themeGet.themeGet)(_constants.legacyBadgeColors[p.type].color) : p.theme.colors.text.body;
26
+ }, function (p) {
27
+ return p.type ? (0, _themeGet.themeGet)(_constants.legacyBadgeColors[p.type].background) : p.theme.colors.container.background.decorative[p.badgeColor];
28
+ }, function (p) {
29
+ return p.size === "small" ? p.theme.space[0] + " " + p.theme.space[200] : "" + p.theme.space[300];
46
30
  }, _systemProps.COMMON);
47
31
 
48
32
  var _default = Container;
@@ -32,7 +32,13 @@ var InputContext = /*#__PURE__*/React.createContext({});
32
32
  var ClearButton = function ClearButton() {
33
33
  var _React$useContext = React.useContext(InputContext),
34
34
  handleClear = _React$useContext.handleClear,
35
- clearButtonLabel = _React$useContext.clearButtonLabel;
35
+ clearButtonLabel = _React$useContext.clearButtonLabel,
36
+ hasValue = _React$useContext.hasValue; // Hide the button when there is no text to clear.
37
+
38
+
39
+ if (!hasValue) {
40
+ return null;
41
+ }
36
42
 
37
43
  return /*#__PURE__*/React.createElement(_Button.default, {
38
44
  onClick: handleClear
@@ -40,6 +46,16 @@ var ClearButton = function ClearButton() {
40
46
  name: "circlex",
41
47
  title: clearButtonLabel || "Clear"
42
48
  }));
49
+ }; // Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
50
+ // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
51
+
52
+
53
+ var isClearButton = function isClearButton(elem) {
54
+ if (elem != null && elem.type) {
55
+ return elem.type.displayName === "Input.ClearButton";
56
+ }
57
+
58
+ return false;
43
59
  };
44
60
 
45
61
  var Input = /*#__PURE__*/function (_React$Component) {
@@ -88,8 +104,6 @@ var Input = /*#__PURE__*/function (_React$Component) {
88
104
  var _proto = Input.prototype;
89
105
 
90
106
  _proto.render = function render() {
91
- var _elementAfter$type;
92
-
93
107
  var _this$props = this.props,
94
108
  autoComplete = _this$props.autoComplete,
95
109
  autoFocus = _this$props.autoFocus,
@@ -149,7 +163,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
149
163
  }, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
150
164
  value: {
151
165
  handleClear: this.handleClear,
152
- clearButtonLabel: clearButtonLabel
166
+ clearButtonLabel: clearButtonLabel,
167
+ hasValue: !!value
153
168
  }
154
169
  }, elementBefore && /*#__PURE__*/React.createElement(_styles.Accessory, {
155
170
  before: true
@@ -179,10 +194,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
179
194
  "data-qa-input-isdisabled": disabled === true,
180
195
  "data-qa-input-isrequired": required === true
181
196
  }, qa, inputProps)), elementAfter && /*#__PURE__*/React.createElement(_styles.Accessory, {
182
- after: true // Used for positioning. This logic will detect if the element is a ClearButton,
183
- // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
184
- ,
185
- isClearButton: (elementAfter == null ? void 0 : (_elementAfter$type = elementAfter.type) == null ? void 0 : _elementAfter$type.prototype) === Input.ClearButton.prototype
197
+ after: true,
198
+ isClearButton: isClearButton(elementAfter)
186
199
  }, elementAfter)));
187
200
  };
188
201
 
@@ -0,0 +1,38 @@
1
+ var defaultPurple = {
2
+ color: "colors.text.body",
3
+ background: "colors.container.background.decorative.purple"
4
+ };
5
+ var suggestion = {
6
+ color: "colors.text.body",
7
+ background: "colors.container.background.decorative.blue"
8
+ };
9
+ var passive = {
10
+ color: "colors.text.body",
11
+ background: "colors.container.background.decorative.neutral"
12
+ };
13
+ var primary = {
14
+ color: "colors.text.body",
15
+ background: "colors.container.background.decorative.blue"
16
+ };
17
+ var secondary = {
18
+ color: "colors.text.body",
19
+ background: "colors.container.background.decorative.yellow"
20
+ };
21
+ var common = {
22
+ color: "colors.text.inverse",
23
+ background: "colors.aqua.600"
24
+ };
25
+ var approval = {
26
+ color: "colors.text.body",
27
+ background: "colors.container.background.decorative.orange"
28
+ }; //Deprecated former "types"
29
+
30
+ export var legacyBadgeColors = {
31
+ primary: primary,
32
+ secondary: secondary,
33
+ passive: passive,
34
+ common: common,
35
+ approval: approval,
36
+ default: defaultPurple,
37
+ suggestion: suggestion
38
+ };
@@ -1,49 +1,48 @@
1
- var _excluded = ["size", "type", "tip", "text"];
1
+ var _excluded = ["children", "text", "iconName", "type", "tip", "size", "badgeColor"];
2
2
 
3
3
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
4
 
5
5
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
6
 
7
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
8
-
9
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
10
-
11
7
  import * as React from "react";
8
+ import Icon from "../Icon";
12
9
  import Container from "./styles";
13
-
14
- var Badge = /*#__PURE__*/function (_React$Component) {
15
- _inheritsLoose(Badge, _React$Component);
16
-
17
- function Badge() {
18
- return _React$Component.apply(this, arguments) || this;
10
+ import Box from "../Box";
11
+
12
+ var Badge = function Badge(_ref) {
13
+ var children = _ref.children,
14
+ text = _ref.text,
15
+ iconName = _ref.iconName,
16
+ type = _ref.type,
17
+ tip = _ref.tip,
18
+ _ref$size = _ref.size,
19
+ size = _ref$size === void 0 ? "small" : _ref$size,
20
+ _ref$badgeColor = _ref.badgeColor,
21
+ badgeColor = _ref$badgeColor === void 0 ? "blue" : _ref$badgeColor,
22
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
23
+
24
+ if (children && text) {
25
+ throw new Error("can't use both `children` and `text` props. Text is deprecated, consider using children.");
19
26
  }
20
27
 
21
- var _proto = Badge.prototype;
22
-
23
- _proto.render = function render() {
24
- var _this$props = this.props,
25
- size = _this$props.size,
26
- type = _this$props.type,
27
- tip = _this$props.tip,
28
- text = _this$props.text,
29
- rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
30
-
31
- return /*#__PURE__*/React.createElement(Container, _extends({
32
- type: type,
33
- small: size === "small",
34
- "data-tip": tip,
35
- "data-qa-badge": text || "",
36
- "data-qa-badge-type": type,
37
- "data-qa-badge-tip": tip || "" // $FlowIssue - upgrade v0.112.0
38
-
39
- }, rest), text);
40
- };
41
-
42
- return Badge;
43
- }(React.Component);
44
-
45
- Badge.defaultProps = {
46
- type: "primary",
47
- size: "default"
28
+ return /*#__PURE__*/React.createElement(Container, _extends({}, rest, {
29
+ // size previously included default, which currently maps to small. Once consumers have updated this can be simplified.
30
+ size: size === "default" ? "large" : size,
31
+ badgeColor: badgeColor,
32
+ "data-tip": tip,
33
+ "data-qa-badge": text || "",
34
+ "data-qa-badge-type": type,
35
+ "data-qa-badge-tip": tip || "",
36
+ type: type && type
37
+ }), /*#__PURE__*/React.createElement(Box, {
38
+ display: "flex",
39
+ alignItems: "center",
40
+ JustifyContent: "center"
41
+ }, iconName ? /*#__PURE__*/React.createElement(Icon, {
42
+ mr: 200,
43
+ name: iconName,
44
+ size: size === "small" ? "mini" : "default"
45
+ }) : null, children || text));
48
46
  };
49
- export { Badge as default };
47
+
48
+ export default Badge;
@@ -1,35 +1,20 @@
1
- import styled, { css } from "styled-components";
1
+ import styled from "styled-components";
2
2
  import { COMMON } from "../utils/system-props";
3
3
  import { themeGet } from "@styled-system/theme-get";
4
- var colors = {
5
- primary: "colors.neutral.0",
6
- secondary: "colors.neutral.800",
7
- passive: "colors.neutral.800",
8
- common: "colors.neutral.0",
9
- approval: "colors.neutral.800",
10
- default: "colors.neutral.0",
11
- suggestion: "colors.neutral.900"
12
- };
13
- var backgroundColors = {
14
- primary: "colors.blue.700",
15
- secondary: "colors.yellow.500",
16
- passive: "colors.neutral.200",
17
- common: "colors.aqua.600",
18
- approval: "colors.orange.300",
19
- default: "colors.purple.700",
20
- suggestion: "colors.blue.300"
21
- }; // eslint-disable-next-line prettier/prettier
4
+ import { legacyBadgeColors } from "./constants"; // eslint-disable-next-line prettier/prettier
22
5
 
23
6
  var Container = styled.span.withConfig({
24
7
  displayName: "styles__Container",
25
8
  componentId: "sc-g1g76b-0"
26
- })(["display:inline-block;text-align:center;border-radius:50px;font-family:", ";padding:", ";", " ", " ", ""], function (props) {
27
- return props.theme.fontFamily;
28
- }, function (props) {
29
- return props.small ? props.theme.space[200] + " " + props.theme.space[300] : props.theme.space[300] + " " + props.theme.space[350];
30
- }, function (props) {
31
- return props.small ? props.theme.typography[100] : props.theme.typography[200];
32
- }, function (props) {
33
- return css(["color:", ";background:", ";"], themeGet(colors[props.type])(props), themeGet(backgroundColors[props.type])(props));
9
+ })(["font-family:", ";", ";border-radius:9999px;line-height:16px;display:inline-block;color:", ";background:", ";padding:", ";", ";"], function (p) {
10
+ return p.theme.fontFamily;
11
+ }, function (p) {
12
+ return p.size === "small" ? p.theme.typography[100] : p.theme.typography[200];
13
+ }, function (p) {
14
+ return p.type ? themeGet(legacyBadgeColors[p.type].color) : p.theme.colors.text.body;
15
+ }, function (p) {
16
+ return p.type ? themeGet(legacyBadgeColors[p.type].background) : p.theme.colors.container.background.decorative[p.badgeColor];
17
+ }, function (p) {
18
+ return p.size === "small" ? p.theme.space[0] + " " + p.theme.space[200] : "" + p.theme.space[300];
34
19
  }, COMMON);
35
20
  export default Container;
@@ -17,7 +17,13 @@ var InputContext = /*#__PURE__*/React.createContext({});
17
17
  var ClearButton = function ClearButton() {
18
18
  var _React$useContext = React.useContext(InputContext),
19
19
  handleClear = _React$useContext.handleClear,
20
- clearButtonLabel = _React$useContext.clearButtonLabel;
20
+ clearButtonLabel = _React$useContext.clearButtonLabel,
21
+ hasValue = _React$useContext.hasValue; // Hide the button when there is no text to clear.
22
+
23
+
24
+ if (!hasValue) {
25
+ return null;
26
+ }
21
27
 
22
28
  return /*#__PURE__*/React.createElement(Button, {
23
29
  onClick: handleClear
@@ -25,6 +31,16 @@ var ClearButton = function ClearButton() {
25
31
  name: "circlex",
26
32
  title: clearButtonLabel || "Clear"
27
33
  }));
34
+ }; // Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
35
+ // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
36
+
37
+
38
+ var isClearButton = function isClearButton(elem) {
39
+ if (elem != null && elem.type) {
40
+ return elem.type.displayName === "Input.ClearButton";
41
+ }
42
+
43
+ return false;
28
44
  };
29
45
 
30
46
  var Input = /*#__PURE__*/function (_React$Component) {
@@ -73,8 +89,6 @@ var Input = /*#__PURE__*/function (_React$Component) {
73
89
  var _proto = Input.prototype;
74
90
 
75
91
  _proto.render = function render() {
76
- var _elementAfter$type;
77
-
78
92
  var _this$props = this.props,
79
93
  autoComplete = _this$props.autoComplete,
80
94
  autoFocus = _this$props.autoFocus,
@@ -134,7 +148,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
134
148
  }, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
135
149
  value: {
136
150
  handleClear: this.handleClear,
137
- clearButtonLabel: clearButtonLabel
151
+ clearButtonLabel: clearButtonLabel,
152
+ hasValue: !!value
138
153
  }
139
154
  }, elementBefore && /*#__PURE__*/React.createElement(Accessory, {
140
155
  before: true
@@ -164,10 +179,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
164
179
  "data-qa-input-isdisabled": disabled === true,
165
180
  "data-qa-input-isrequired": required === true
166
181
  }, qa, inputProps)), elementAfter && /*#__PURE__*/React.createElement(Accessory, {
167
- after: true // Used for positioning. This logic will detect if the element is a ClearButton,
168
- // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
169
- ,
170
- isClearButton: (elementAfter == null ? void 0 : (_elementAfter$type = elementAfter.type) == null ? void 0 : _elementAfter$type.prototype) === Input.ClearButton.prototype
182
+ after: true,
183
+ isClearButton: isClearButton(elementAfter)
171
184
  }, elementAfter)));
172
185
  };
173
186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sproutsocial/racine",
3
- "version": "11.3.0-beta.1",
3
+ "version": "11.3.0-beta.2",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "__flow__",