@luscii-healthtech/web-ui 28.2.0 → 28.3.1

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.
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { SIZES } from "../../system/Sizes";
3
3
  import { ELEVATION } from "../../system/Elevation";
4
+ import { BackgroundColor } from "../../types/general.types";
4
5
  type Size = keyof typeof SIZES;
5
6
  declare const spacingKeys: readonly ["p", "pt", "pr", "pb", "pl", "px", "py", "m", "mt", "mr", "mb", "ml", "mx", "my"];
6
7
  type SpacingProps = Partial<Record<(typeof spacingKeys)[number], Size>>;
@@ -15,6 +16,12 @@ export type Props<C extends React.ElementType> = React.ComponentPropsWithoutRef<
15
16
  * Make the item fill up horizontal space
16
17
  */
17
18
  width?: "full" | keyof typeof SIZES;
19
+ backgroundColor?: BackgroundColor;
20
+ /**
21
+ * Will set a border radius based on the standard sizes scale.
22
+ * Check {@link SIZES} for reference.
23
+ */
24
+ borderRadius?: "xxxs";
18
25
  };
19
26
  export declare const Box: <C extends React.ElementType = "div">(props: Props<C>) => React.JSX.Element;
20
27
  export {};
@@ -12,7 +12,30 @@ export interface BaseButtonProps extends React.ComponentPropsWithRef<"button"> {
12
12
  * @deprecated Use `children` instead.
13
13
  */
14
14
  text?: string;
15
+ /**
16
+ * @deprecated Use `leadingIcon` instead.
17
+ */
15
18
  icon?: React.FunctionComponent<IconProps> | IconKey;
19
+ /**
20
+ * Icon that will be rendered before the text. You need to
21
+ * pass in the rendered icon component, not the key.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * <PrimaryButton leadingIcon={<AddIcon />} />
26
+ * ````
27
+ */
28
+ leadingIcon?: React.ReactNode;
29
+ /**
30
+ * Icon that will be rendered before the text. You need to
31
+ * pass in the rendered icon component, not the key.
32
+ *
33
+ * @example
34
+ * ```tsx
35
+ * <PrimaryButton trailingIcon={<AddIcon />} />
36
+ * ````
37
+ */
38
+ trailingIcon?: React.ReactNode;
16
39
  isDisabled?: boolean;
17
40
  className?: string;
18
41
  dataTestId?: string;
@@ -1596,21 +1596,18 @@ const Spinner = (props) => {
1596
1596
 
1597
1597
  const ButtonV2 = React__namespace.default.forwardRef((_a, innerRef) => {
1598
1598
  var _b, _c;
1599
- var { children, size = "medium", onClick, text, textColor, textHoverColor, icon, isDisabled, isPending, className, title, dataTestId, type = "button" } = _a, otherAttributes = __rest(_a, ["children", "size", "onClick", "text", "textColor", "textHoverColor", "icon", "isDisabled", "isPending", "className", "title", "dataTestId", "type"]);
1599
+ var { children, size = "medium", onClick, text, textColor, textHoverColor, icon, leadingIcon, trailingIcon, isDisabled, isPending, className, title, dataTestId, type = "button" } = _a, otherAttributes = __rest(_a, ["children", "size", "onClick", "text", "textColor", "textHoverColor", "icon", "leadingIcon", "trailingIcon", "isDisabled", "isPending", "className", "title", "dataTestId", "type"]);
1600
1600
  const generatedId = React__namespace.default.useId();
1601
1601
  const buttonId = (_b = otherAttributes.id) !== null && _b !== void 0 ? _b : generatedId;
1602
1602
  const buttonTooltipId = `button-tooltip-id-${buttonId}`;
1603
1603
  const content = children !== null && children !== void 0 ? children : text;
1604
1604
  const isInteractive = !isDisabled && !isPending;
1605
- const hasContentAndIcon = content && icon;
1605
+ const hasContentAndLeadingIcon = content && (icon !== null && icon !== void 0 ? icon : leadingIcon);
1606
+ const hasContentAndTrailingIcon = content && trailingIcon;
1606
1607
  function handleClick(event) {
1607
1608
  event.stopPropagation();
1608
1609
  onClick === null || onClick === void 0 ? void 0 : onClick(event);
1609
1610
  }
1610
- if (!content && !icon) {
1611
- console.error("Content (`text` or `children` prop) or an icon is required to use this component, please make sure to pass at least one of them as a prop.");
1612
- return React__namespace.default.createElement("span", null, "Invalid props passed to this component.");
1613
- }
1614
1611
  const buttonClassName = classNames__default.default([
1615
1612
  "[transition:transform_150ms,box-shadow_150ms,color_150ms,background-color_150ms,border-color_150ms,background-position_300ms] ui-ease-out",
1616
1613
  "ui-border",
@@ -1618,16 +1615,19 @@ const ButtonV2 = React__namespace.default.forwardRef((_a, innerRef) => {
1618
1615
  "ui-outline-offset-4 focus:ui-outline-primary",
1619
1616
  "ui-group",
1620
1617
  "ui-relative",
1621
- "ui-inline-flex ui-flex-row ui-items-center ui-justify-center ui-gap-xxs ui-flex-shrink-0",
1618
+ "ui-inline-flex ui-flex-row ui-items-center ui-justify-center ui-flex-shrink-0",
1622
1619
  "ui-shadow-sm"
1623
1620
  ], {
1621
+ "ui-gap-xxs": content
1622
+ }, {
1624
1623
  "ui-opacity-50": isDisabled,
1625
1624
  "ui-cursor-not-allowed": isPending !== null && isPending !== void 0 ? isPending : isDisabled,
1626
1625
  "active:ui-shadow-none active:ui-scale-[0.98]": isInteractive,
1627
1626
  /**
1628
1627
  * Specific paddings for each combination of text and/or icon.
1629
1628
  */
1630
- "ui-pl-m ui-pr-l": hasContentAndIcon,
1629
+ "ui-pl-m ui-pr-l": hasContentAndLeadingIcon,
1630
+ "ui-pl-l ui-pr-m": hasContentAndTrailingIcon,
1631
1631
  /**
1632
1632
  * Deducting 1px from the padding to account for the border.
1633
1633
  */
@@ -1643,19 +1643,12 @@ const ButtonV2 = React__namespace.default.forwardRef((_a, innerRef) => {
1643
1643
  const buttonComponent = React__namespace.default.createElement(
1644
1644
  "button",
1645
1645
  Object.assign({ ref: innerRef }, otherAttributes, { className: buttonClassName, type, onClick: handleClick, disabled: isDisabled !== null && isDisabled !== void 0 ? isDisabled : isPending, "aria-disabled": isDisabled, "aria-busy": isPending, "data-test-id": (_c = dataTestId !== null && dataTestId !== void 0 ? dataTestId : otherAttributes["data-test-id"]) !== null && _c !== void 0 ? _c : otherAttributes.id }, tooltipAttrs),
1646
- icon && React__namespace.default.createElement(IconComponentOrKey, { name: icon, className: classNames__default.default(
1647
- "ui-flex-shrink-0",
1648
- /**
1649
- * Text on a medium button is 2px smaller than the icon. So to
1650
- * make sure the icon can grow beyond the text, we need to
1651
- * allow the icon to grow beyond the text. This essentially
1652
- * vertically centers the icon.
1653
- */
1654
- "-ui-m-[2px]",
1655
- {
1656
- "ui-invisible": isPending
1657
- }
1658
- ) }),
1646
+ leadingIcon && React__namespace.default.createElement(IconLayoutWrapper, { isInvisible: isPending }, leadingIcon),
1647
+ !leadingIcon && icon && React__namespace.default.createElement(
1648
+ IconLayoutWrapper,
1649
+ { isInvisible: isPending },
1650
+ React__namespace.default.createElement(IconComponentOrKey, { name: icon })
1651
+ ),
1659
1652
  isPending && React__namespace.default.createElement(
1660
1653
  "span",
1661
1654
  { className: "ui-absolute ui-left-1/2 ui-top-1/2 ui--translate-x-1/2 ui--translate-y-1/2 ui-transform ui-opacity-100" },
@@ -1663,7 +1656,8 @@ const ButtonV2 = React__namespace.default.forwardRef((_a, innerRef) => {
1663
1656
  ),
1664
1657
  content && React__namespace.default.createElement(Text, { variant: "strong", className: classNames__default.default({
1665
1658
  "ui-opacity-[0.01]": isPending
1666
- }), color: textColor, hoverColor: textHoverColor, hoverInGroup: true }, content)
1659
+ }), color: textColor, hoverColor: textHoverColor, hoverInGroup: true }, content),
1660
+ trailingIcon && React__namespace.default.createElement(IconLayoutWrapper, { isInvisible: isPending }, trailingIcon)
1667
1661
  );
1668
1662
  if (title) {
1669
1663
  return React__namespace.default.createElement(
@@ -1675,6 +1669,22 @@ const ButtonV2 = React__namespace.default.forwardRef((_a, innerRef) => {
1675
1669
  }
1676
1670
  return buttonComponent;
1677
1671
  });
1672
+ function IconLayoutWrapper({ children, className, isInvisible }) {
1673
+ return React__namespace.default.createElement("span", { className: classNames__default.default(
1674
+ "ui-flex-shrink-0",
1675
+ /**
1676
+ * Text on a medium button is 2px smaller than the icon. So to
1677
+ * make sure the icon can grow beyond the text, we need to
1678
+ * allow the icon to grow beyond the text. This essentially
1679
+ * vertically centers the icon.
1680
+ */
1681
+ "-ui-m-[2px]",
1682
+ {
1683
+ "ui-invisible": isInvisible
1684
+ },
1685
+ className
1686
+ ) }, children);
1687
+ }
1678
1688
 
1679
1689
  const SecondaryButton = React__namespace.default.forwardRef((props, innerRef) => {
1680
1690
  return React__namespace.default.createElement(ButtonV2, Object.assign({ ref: innerRef }, props, { className: classNames__default.default([
@@ -1980,9 +1990,15 @@ const Box = (props) => {
1980
1990
  const spacingClasses = createSpacingClassNames(spacingKeys, props);
1981
1991
  const attributesWithoutSpacingKeys = omit__default.default(attributes, spacingKeys);
1982
1992
  return React__namespace.default.createElement(Element, Object.assign({ className: classNames__default.default(spacingClasses, {
1993
+ "ui-bg-slate-100": props.backgroundColor === "base",
1994
+ "ui-bg-blue-50": props.backgroundColor === "blue",
1995
+ "ui-bg-red-50": props.backgroundColor === "red",
1996
+ " ui-bg-green-50": props.backgroundColor === "green",
1997
+ " ui-bg-amber-50": props.backgroundColor === "amber",
1983
1998
  [`ui-shadow-${elevation}`]: elevation,
1984
1999
  [`ui-w-${width}`]: width && width !== "full",
1985
- "ui-w-full": width === "full"
2000
+ "ui-w-full": width === "full",
2001
+ "ui-radius-xxxs": props.borderRadius
1986
2002
  }, className) }, attributesWithoutSpacingKeys));
1987
2003
  };
1988
2004