@jobber/components 6.26.3 → 6.27.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.
@@ -51,11 +51,11 @@ function Banner({ children, type, primaryAction, dismissible = true, icon, onDis
51
51
  function getBannerIcon(type) {
52
52
  switch (type) {
53
53
  case "notice":
54
- return "starburst";
54
+ return "info";
55
55
  case "success":
56
56
  return "checkmark";
57
57
  case "warning":
58
- return "help";
58
+ return "warning";
59
59
  case "error":
60
60
  return "alert";
61
61
  }
package/dist/Banner-es.js CHANGED
@@ -49,11 +49,11 @@ function Banner({ children, type, primaryAction, dismissible = true, icon, onDis
49
49
  function getBannerIcon(type) {
50
50
  switch (type) {
51
51
  case "notice":
52
- return "starburst";
52
+ return "info";
53
53
  case "success":
54
54
  return "checkmark";
55
55
  case "warning":
56
- return "help";
56
+ return "warning";
57
57
  case "error":
58
58
  return "alert";
59
59
  }
@@ -1,7 +1,10 @@
1
1
  import React from "react";
2
- import { XOR } from "ts-xor";
3
- import { CardProps } from "./types";
4
- interface LinkCardProps extends CardProps {
2
+ import { CardBodyProps, CardHeaderProps, CardProps } from "./types";
3
+ /**
4
+ * Props for a card that acts as a link.
5
+ * When url is provided, the card becomes clickable and navigates to the specified URL.
6
+ */
7
+ type LinkCardProps = CardProps & {
5
8
  /**
6
9
  * URL that the card would navigate to once clicked.
7
10
  */
@@ -10,10 +13,66 @@ interface LinkCardProps extends CardProps {
10
13
  * Makes the URL open in new tab on click.
11
14
  */
12
15
  external?: boolean;
13
- }
14
- interface ClickableCardProps extends CardProps {
16
+ onClick?: never;
17
+ };
18
+ /**
19
+ * Props for a card that has a click handler.
20
+ * When onClick is provided, the card becomes clickable and triggers the handler on click.
21
+ */
22
+ type ClickableCardProps = CardProps & {
23
+ /**
24
+ * Event handler that gets called when the card is clicked.
25
+ */
15
26
  onClick(event: React.MouseEvent<HTMLAnchorElement | HTMLDivElement>): void;
27
+ url?: never;
28
+ readonly external?: never;
29
+ };
30
+ /**
31
+ * Props for a regular card without any click behavior.
32
+ */
33
+ type RegularCardProps = CardProps & {
34
+ url?: never;
35
+ onClick?: never;
36
+ readonly external?: never;
37
+ };
38
+ type CardPropOptions = LinkCardProps | ClickableCardProps | RegularCardProps;
39
+ /**
40
+ * Header component for the Card.
41
+ * Used in the compound component pattern to provide a consistent header layout.
42
+ *
43
+ * @example
44
+ * ```tsx
45
+ * <Card>
46
+ * <Card.Header>
47
+ * <Text>Header Content</Text>
48
+ * </Card.Header>
49
+ * <Card.Body>
50
+ * <p>Card content</p>
51
+ * </Card.Body>
52
+ * </Card>
53
+ * ```
54
+ */
55
+ declare function CardHeaderCompoundComponent({ children }: CardHeaderProps): JSX.Element;
56
+ /**
57
+ * Body component for the Card.
58
+ * Used in the compound component pattern to provide a consistent content layout.
59
+ *
60
+ * @example
61
+ * ```tsx
62
+ * <Card>
63
+ * <Card.Header>
64
+ * <Text>Header Content</Text>
65
+ * </Card.Header>
66
+ * <Card.Body>
67
+ * <p>Card content</p>
68
+ * </Card.Body>
69
+ * </Card>
70
+ * ```
71
+ */
72
+ declare function CardBodyCompoundComponent({ children }: CardBodyProps): JSX.Element;
73
+ export declare function Card(props: CardPropOptions): JSX.Element;
74
+ export declare namespace Card {
75
+ var Header: typeof CardHeaderCompoundComponent;
76
+ var Body: typeof CardBodyCompoundComponent;
16
77
  }
17
- type CardPropOptions = XOR<CardProps, XOR<LinkCardProps, ClickableCardProps>>;
18
- export declare function Card({ accent, header, children, onClick, title, url, external, elevation, }: CardPropOptions): JSX.Element;
19
78
  export {};
@@ -24,7 +24,6 @@ export interface CardProps {
24
24
  /**
25
25
  * @deprecated
26
26
  * Use header instead.
27
- *
28
27
  */
29
28
  readonly title?: string;
30
29
  /**
@@ -33,3 +32,13 @@ export interface CardProps {
33
32
  readonly header?: string | HeaderActionProps | ReactElement;
34
33
  readonly elevation?: elevationProp;
35
34
  }
35
+ export interface CardHeaderProps {
36
+ readonly children: ReactNode;
37
+ }
38
+ export interface CardBodyProps {
39
+ readonly children: ReactNode;
40
+ }
41
+ export interface CardCompositionProps {
42
+ Header: React.FC<CardHeaderProps>;
43
+ Body: React.FC<CardBodyProps>;
44
+ }
package/dist/Card-cjs.js CHANGED
@@ -69,20 +69,70 @@ function renderHeaderAction(action) {
69
69
  return React.createElement(React.Fragment, null);
70
70
  }
71
71
 
72
- function Card({ accent, header, children, onClick, title, url, external = false, elevation = "none", }) {
73
- const className = classnames(styles.card, accent && styles.accent, (url || onClick) && styles.clickable, accent && colors[accent], elevation !== "none" && elevations[`${elevation}Elevation`]);
74
- const cardContent = (React.createElement(React.Fragment, null,
72
+ /**
73
+ * Header component for the Card.
74
+ * Used in the compound component pattern to provide a consistent header layout.
75
+ *
76
+ * @example
77
+ * ```tsx
78
+ * <Card>
79
+ * <Card.Header>
80
+ * <Text>Header Content</Text>
81
+ * </Card.Header>
82
+ * <Card.Body>
83
+ * <p>Card content</p>
84
+ * </Card.Body>
85
+ * </Card>
86
+ * ```
87
+ */
88
+ function CardHeaderCompoundComponent({ children }) {
89
+ return React.createElement(React.Fragment, null, children);
90
+ }
91
+ /**
92
+ * Body component for the Card.
93
+ * Used in the compound component pattern to provide a consistent content layout.
94
+ *
95
+ * @example
96
+ * ```tsx
97
+ * <Card>
98
+ * <Card.Header>
99
+ * <Text>Header Content</Text>
100
+ * </Card.Header>
101
+ * <Card.Body>
102
+ * <p>Card content</p>
103
+ * </Card.Body>
104
+ * </Card>
105
+ * ```
106
+ */
107
+ function CardBodyCompoundComponent({ children }) {
108
+ return React.createElement(React.Fragment, null, children);
109
+ }
110
+ function renderCardContent(children, title, header) {
111
+ return (React.createElement(React.Fragment, null,
75
112
  React.createElement(CardHeader, { title: title, header: header }),
76
113
  children));
114
+ }
115
+ function renderCardWrapper(className, content, onClick, url, external) {
77
116
  if (onClick) {
78
- return (React.createElement(CardClickable, { className: className, onClick: onClick }, cardContent));
79
- }
80
- else if (url) {
81
- return (React.createElement("a", Object.assign({ className: className, href: url }, (external && { target: "_blank", rel: "noopener noreferrer" })), cardContent));
117
+ return (React.createElement(CardClickable, { className: className, onClick: onClick }, content));
82
118
  }
83
- else {
84
- return React.createElement("div", { className: className }, cardContent);
119
+ if (url) {
120
+ return (React.createElement("a", Object.assign({ className: className, href: url }, (external && { target: "_blank", rel: "noopener noreferrer" })), content));
85
121
  }
122
+ return React.createElement("div", { className: className }, content);
123
+ }
124
+ function Card(props) {
125
+ const { accent, header, children, title, elevation = "none", onClick, url, external, } = props;
126
+ const className = classnames(styles.card, accent && styles.accent, (url || onClick) && styles.clickable, accent && colors[accent], elevation !== "none" && elevations[`${elevation}Elevation`]);
127
+ const isUsingCompoundPattern = React.Children.toArray(children).some(child => React.isValidElement(child) &&
128
+ (child.type === CardHeaderCompoundComponent ||
129
+ child.type === CardBodyCompoundComponent));
130
+ const content = isUsingCompoundPattern
131
+ ? children
132
+ : renderCardContent(children, title, header);
133
+ return renderCardWrapper(className, content, onClick, url, external);
86
134
  }
135
+ Card.Header = CardHeaderCompoundComponent;
136
+ Card.Body = CardBodyCompoundComponent;
87
137
 
88
138
  exports.Card = Card;
package/dist/Card-es.js CHANGED
@@ -67,20 +67,70 @@ function renderHeaderAction(action) {
67
67
  return React__default.createElement(React__default.Fragment, null);
68
68
  }
69
69
 
70
- function Card({ accent, header, children, onClick, title, url, external = false, elevation = "none", }) {
71
- const className = classnames(styles.card, accent && styles.accent, (url || onClick) && styles.clickable, accent && colors[accent], elevation !== "none" && elevations[`${elevation}Elevation`]);
72
- const cardContent = (React__default.createElement(React__default.Fragment, null,
70
+ /**
71
+ * Header component for the Card.
72
+ * Used in the compound component pattern to provide a consistent header layout.
73
+ *
74
+ * @example
75
+ * ```tsx
76
+ * <Card>
77
+ * <Card.Header>
78
+ * <Text>Header Content</Text>
79
+ * </Card.Header>
80
+ * <Card.Body>
81
+ * <p>Card content</p>
82
+ * </Card.Body>
83
+ * </Card>
84
+ * ```
85
+ */
86
+ function CardHeaderCompoundComponent({ children }) {
87
+ return React__default.createElement(React__default.Fragment, null, children);
88
+ }
89
+ /**
90
+ * Body component for the Card.
91
+ * Used in the compound component pattern to provide a consistent content layout.
92
+ *
93
+ * @example
94
+ * ```tsx
95
+ * <Card>
96
+ * <Card.Header>
97
+ * <Text>Header Content</Text>
98
+ * </Card.Header>
99
+ * <Card.Body>
100
+ * <p>Card content</p>
101
+ * </Card.Body>
102
+ * </Card>
103
+ * ```
104
+ */
105
+ function CardBodyCompoundComponent({ children }) {
106
+ return React__default.createElement(React__default.Fragment, null, children);
107
+ }
108
+ function renderCardContent(children, title, header) {
109
+ return (React__default.createElement(React__default.Fragment, null,
73
110
  React__default.createElement(CardHeader, { title: title, header: header }),
74
111
  children));
112
+ }
113
+ function renderCardWrapper(className, content, onClick, url, external) {
75
114
  if (onClick) {
76
- return (React__default.createElement(CardClickable, { className: className, onClick: onClick }, cardContent));
77
- }
78
- else if (url) {
79
- return (React__default.createElement("a", Object.assign({ className: className, href: url }, (external && { target: "_blank", rel: "noopener noreferrer" })), cardContent));
115
+ return (React__default.createElement(CardClickable, { className: className, onClick: onClick }, content));
80
116
  }
81
- else {
82
- return React__default.createElement("div", { className: className }, cardContent);
117
+ if (url) {
118
+ return (React__default.createElement("a", Object.assign({ className: className, href: url }, (external && { target: "_blank", rel: "noopener noreferrer" })), content));
83
119
  }
120
+ return React__default.createElement("div", { className: className }, content);
121
+ }
122
+ function Card(props) {
123
+ const { accent, header, children, title, elevation = "none", onClick, url, external, } = props;
124
+ const className = classnames(styles.card, accent && styles.accent, (url || onClick) && styles.clickable, accent && colors[accent], elevation !== "none" && elevations[`${elevation}Elevation`]);
125
+ const isUsingCompoundPattern = React__default.Children.toArray(children).some(child => React__default.isValidElement(child) &&
126
+ (child.type === CardHeaderCompoundComponent ||
127
+ child.type === CardBodyCompoundComponent));
128
+ const content = isUsingCompoundPattern
129
+ ? children
130
+ : renderCardContent(children, title, header);
131
+ return renderCardWrapper(className, content, onClick, url, external);
84
132
  }
133
+ Card.Header = CardHeaderCompoundComponent;
134
+ Card.Body = CardBodyCompoundComponent;
85
135
 
86
136
  export { Card as C };
@@ -18,6 +18,8 @@
18
18
  "Button.Label",
19
19
  "ButtonDismiss",
20
20
  "Card",
21
+ "Card.Body",
22
+ "Card.Header",
21
23
  "Cell",
22
24
  "CellCurrency",
23
25
  "CellNumeric",
@@ -141,4 +143,4 @@
141
143
  "Tooltip",
142
144
  "Typography"
143
145
  ]
144
- }
146
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "6.26.3",
3
+ "version": "6.27.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -490,5 +490,5 @@
490
490
  "> 1%",
491
491
  "IE 10"
492
492
  ],
493
- "gitHead": "c4962eacf97393ea78117f7dc77392f1a694c075"
493
+ "gitHead": "6599f7dd9b1ee4507e27c053f0ad5764b94ea6cc"
494
494
  }