braid-design-system 32.12.0 → 32.12.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.
@@ -49,8 +49,7 @@ const useThemeName = () => sideEffects_lib_components_BraidProvider_BraidProvide
49
49
  const useSpace = () => sideEffects_lib_components_BraidProvider_BraidProvider_cjs.useBraidTheme().space;
50
50
  function resolveResponsiveObject(breakpointName, value) {
51
51
  let resolvedValue = null;
52
- for (let i = 0; i < styles_lib_css_breakpoints_cjs.breakpointNames.length; i++) {
53
- const currentBreakpointName = styles_lib_css_breakpoints_cjs.breakpointNames[i];
52
+ for (const currentBreakpointName of styles_lib_css_breakpoints_cjs.breakpointNames) {
54
53
  const valueForBreakpoint = value[currentBreakpointName];
55
54
  if (valueForBreakpoint !== void 0) {
56
55
  resolvedValue = valueForBreakpoint;
@@ -1292,6 +1291,12 @@ const buttonVariants = [
1292
1291
  "soft",
1293
1292
  "transparent"
1294
1293
  ];
1294
+ const buttonTones = [
1295
+ "formAccent",
1296
+ "brandAccent",
1297
+ "critical",
1298
+ "neutral"
1299
+ ];
1295
1300
  const variants = {
1296
1301
  solid: {
1297
1302
  formAccent: {
@@ -1762,6 +1767,17 @@ const TooltipContent = ({
1762
1767
  }
1763
1768
  );
1764
1769
  const validPlacements = ["top", "bottom"];
1770
+ const normaliseRect = (domRect) => ({
1771
+ top: Math.round((domRect == null ? void 0 : domRect.top) || 0),
1772
+ left: Math.round((domRect == null ? void 0 : domRect.left) || 0),
1773
+ height: Math.round((domRect == null ? void 0 : domRect.height) || 0),
1774
+ width: Math.round((domRect == null ? void 0 : domRect.width) || 0)
1775
+ });
1776
+ const defaultRect = normaliseRect();
1777
+ const doesBoundingBoxNeedUpdating = (element, previousRect) => {
1778
+ const currentRect = normaliseRect(element == null ? void 0 : element.getBoundingClientRect());
1779
+ return JSON.stringify(currentRect) !== JSON.stringify(previousRect);
1780
+ };
1765
1781
  const TooltipRenderer = ({
1766
1782
  id,
1767
1783
  tooltip,
@@ -1778,6 +1794,8 @@ const TooltipRenderer = ({
1778
1794
  const [controlledVisible, setControlledVisible] = React.useState(false);
1779
1795
  const [opacity, setOpacity] = React.useState(0);
1780
1796
  const { grid, space } = useSpace();
1797
+ const triggerBoundingBoxRef = React.useRef(defaultRect);
1798
+ const tooltipBoundingRectRef = React.useRef(defaultRect);
1781
1799
  const {
1782
1800
  visible,
1783
1801
  getTooltipProps,
@@ -1785,13 +1803,22 @@ const TooltipRenderer = ({
1785
1803
  tooltipRef,
1786
1804
  setTriggerRef,
1787
1805
  triggerRef,
1788
- getArrowProps
1806
+ getArrowProps,
1807
+ update
1789
1808
  } = reactPopperTooltip.usePopperTooltip(
1790
1809
  {
1791
1810
  placement,
1792
1811
  trigger: [isMobile__default.default() ? "click" : "hover", "focus"],
1793
1812
  visible: isStatic || controlledVisible,
1794
- onVisibleChange: setControlledVisible
1813
+ onVisibleChange: (newState) => {
1814
+ triggerBoundingBoxRef.current = normaliseRect(
1815
+ triggerRef == null ? void 0 : triggerRef.getBoundingClientRect()
1816
+ );
1817
+ tooltipBoundingRectRef.current = normaliseRect(
1818
+ tooltipRef == null ? void 0 : tooltipRef.getBoundingClientRect()
1819
+ );
1820
+ setControlledVisible(newState);
1821
+ }
1795
1822
  },
1796
1823
  {
1797
1824
  modifiers: [
@@ -1824,6 +1851,17 @@ const TooltipRenderer = ({
1824
1851
  ]
1825
1852
  }
1826
1853
  );
1854
+ React.useLayoutEffect(() => {
1855
+ if (controlledVisible && update && (doesBoundingBoxNeedUpdating(triggerRef, triggerBoundingBoxRef.current) || doesBoundingBoxNeedUpdating(tooltipRef, tooltipBoundingRectRef.current))) {
1856
+ triggerBoundingBoxRef.current = normaliseRect(
1857
+ triggerRef == null ? void 0 : triggerRef.getBoundingClientRect()
1858
+ );
1859
+ tooltipBoundingRectRef.current = normaliseRect(
1860
+ tooltipRef == null ? void 0 : tooltipRef.getBoundingClientRect()
1861
+ );
1862
+ update();
1863
+ }
1864
+ });
1827
1865
  React.useEffect(() => {
1828
1866
  if (visible) {
1829
1867
  const handleKeyDown = ({ key }) => {
@@ -1912,6 +1950,7 @@ const TooltipRenderer = ({
1912
1950
  ] });
1913
1951
  };
1914
1952
  const buttonIconVariants = ["soft", "transparent"];
1953
+ const buttonIconTones = ["neutral", "secondary"];
1915
1954
  const padding = "xsmall";
1916
1955
  const PrivateButtonIcon = React.forwardRef(
1917
1956
  ({
@@ -2606,7 +2645,9 @@ exports.ToastProvider = ToastProvider;
2606
2645
  exports.TooltipRenderer = TooltipRenderer;
2607
2646
  exports.Typography = Typography;
2608
2647
  exports.buildDataAttributes = buildDataAttributes;
2648
+ exports.buttonIconTones = buttonIconTones;
2609
2649
  exports.buttonIconVariants = buttonIconVariants;
2650
+ exports.buttonTones = buttonTones;
2610
2651
  exports.buttonVariants = buttonVariants;
2611
2652
  exports.flattenChildren = flattenChildren;
2612
2653
  exports.iconContainerSize = iconContainerSize;
@@ -1,4 +1,4 @@
1
- import React, { createContext, useContext, forwardRef, createElement, useEffect, Children, isValidElement, cloneElement, useMemo, useState, useRef, useCallback, useLayoutEffect, Fragment as Fragment$1, useReducer } from "react";
1
+ import React, { createContext, useContext, forwardRef, createElement, useEffect, Children, isValidElement, cloneElement, useMemo, useState, useRef, useLayoutEffect, useCallback, Fragment as Fragment$1, useReducer } from "react";
2
2
  import { useBraidTheme, VanillaThemeContainer, breakpointContext, useLinkComponent } from "./side-effects/lib/components/BraidProvider/BraidProvider.mjs";
3
3
  import { breakpointNames } from "./styles/lib/css/breakpoints.mjs";
4
4
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
@@ -42,8 +42,7 @@ const useThemeName = () => useBraidTheme().name;
42
42
  const useSpace = () => useBraidTheme().space;
43
43
  function resolveResponsiveObject(breakpointName, value) {
44
44
  let resolvedValue = null;
45
- for (let i = 0; i < breakpointNames.length; i++) {
46
- const currentBreakpointName = breakpointNames[i];
45
+ for (const currentBreakpointName of breakpointNames) {
47
46
  const valueForBreakpoint = value[currentBreakpointName];
48
47
  if (valueForBreakpoint !== void 0) {
49
48
  resolvedValue = valueForBreakpoint;
@@ -1285,6 +1284,12 @@ const buttonVariants = [
1285
1284
  "soft",
1286
1285
  "transparent"
1287
1286
  ];
1287
+ const buttonTones = [
1288
+ "formAccent",
1289
+ "brandAccent",
1290
+ "critical",
1291
+ "neutral"
1292
+ ];
1288
1293
  const variants = {
1289
1294
  solid: {
1290
1295
  formAccent: {
@@ -1755,6 +1760,17 @@ const TooltipContent = ({
1755
1760
  }
1756
1761
  );
1757
1762
  const validPlacements = ["top", "bottom"];
1763
+ const normaliseRect = (domRect) => ({
1764
+ top: Math.round((domRect == null ? void 0 : domRect.top) || 0),
1765
+ left: Math.round((domRect == null ? void 0 : domRect.left) || 0),
1766
+ height: Math.round((domRect == null ? void 0 : domRect.height) || 0),
1767
+ width: Math.round((domRect == null ? void 0 : domRect.width) || 0)
1768
+ });
1769
+ const defaultRect = normaliseRect();
1770
+ const doesBoundingBoxNeedUpdating = (element, previousRect) => {
1771
+ const currentRect = normaliseRect(element == null ? void 0 : element.getBoundingClientRect());
1772
+ return JSON.stringify(currentRect) !== JSON.stringify(previousRect);
1773
+ };
1758
1774
  const TooltipRenderer = ({
1759
1775
  id,
1760
1776
  tooltip,
@@ -1771,6 +1787,8 @@ const TooltipRenderer = ({
1771
1787
  const [controlledVisible, setControlledVisible] = useState(false);
1772
1788
  const [opacity, setOpacity] = useState(0);
1773
1789
  const { grid, space } = useSpace();
1790
+ const triggerBoundingBoxRef = useRef(defaultRect);
1791
+ const tooltipBoundingRectRef = useRef(defaultRect);
1774
1792
  const {
1775
1793
  visible,
1776
1794
  getTooltipProps,
@@ -1778,13 +1796,22 @@ const TooltipRenderer = ({
1778
1796
  tooltipRef,
1779
1797
  setTriggerRef,
1780
1798
  triggerRef,
1781
- getArrowProps
1799
+ getArrowProps,
1800
+ update
1782
1801
  } = usePopperTooltip(
1783
1802
  {
1784
1803
  placement,
1785
1804
  trigger: [isMobile() ? "click" : "hover", "focus"],
1786
1805
  visible: isStatic || controlledVisible,
1787
- onVisibleChange: setControlledVisible
1806
+ onVisibleChange: (newState) => {
1807
+ triggerBoundingBoxRef.current = normaliseRect(
1808
+ triggerRef == null ? void 0 : triggerRef.getBoundingClientRect()
1809
+ );
1810
+ tooltipBoundingRectRef.current = normaliseRect(
1811
+ tooltipRef == null ? void 0 : tooltipRef.getBoundingClientRect()
1812
+ );
1813
+ setControlledVisible(newState);
1814
+ }
1788
1815
  },
1789
1816
  {
1790
1817
  modifiers: [
@@ -1817,6 +1844,17 @@ const TooltipRenderer = ({
1817
1844
  ]
1818
1845
  }
1819
1846
  );
1847
+ useLayoutEffect(() => {
1848
+ if (controlledVisible && update && (doesBoundingBoxNeedUpdating(triggerRef, triggerBoundingBoxRef.current) || doesBoundingBoxNeedUpdating(tooltipRef, tooltipBoundingRectRef.current))) {
1849
+ triggerBoundingBoxRef.current = normaliseRect(
1850
+ triggerRef == null ? void 0 : triggerRef.getBoundingClientRect()
1851
+ );
1852
+ tooltipBoundingRectRef.current = normaliseRect(
1853
+ tooltipRef == null ? void 0 : tooltipRef.getBoundingClientRect()
1854
+ );
1855
+ update();
1856
+ }
1857
+ });
1820
1858
  useEffect(() => {
1821
1859
  if (visible) {
1822
1860
  const handleKeyDown = ({ key }) => {
@@ -1905,6 +1943,7 @@ const TooltipRenderer = ({
1905
1943
  ] });
1906
1944
  };
1907
1945
  const buttonIconVariants = ["soft", "transparent"];
1946
+ const buttonIconTones = ["neutral", "secondary"];
1908
1947
  const padding = "xsmall";
1909
1948
  const PrivateButtonIcon = forwardRef(
1910
1949
  ({
@@ -2600,7 +2639,9 @@ export {
2600
2639
  TooltipRenderer,
2601
2640
  Typography,
2602
2641
  buildDataAttributes,
2642
+ buttonIconTones,
2603
2643
  buttonIconVariants,
2644
+ buttonTones,
2604
2645
  buttonVariants,
2605
2646
  flattenChildren,
2606
2647
  iconContainerSize,
@@ -5091,7 +5091,7 @@ const Loader = ({
5091
5091
  styles_lib_components_Loader_Loader_css_cjs.currentColor,
5092
5092
  styles_lib_css_typography_css_cjs.tone.neutral
5093
5093
  ].join(" "),
5094
- viewBox: "0 0 300 134",
5094
+ viewBox: "0 0 302 134",
5095
5095
  "aria-hidden": true,
5096
5096
  children: [
5097
5097
  /* @__PURE__ */ jsxRuntime.jsx("circle", { className: styles_lib_components_Loader_Loader_css_cjs.circle, cy: "67", cx: "40", r: "40" }),
@@ -5083,7 +5083,7 @@ const Loader = ({
5083
5083
  currentColor$1,
5084
5084
  tone.neutral
5085
5085
  ].join(" "),
5086
- viewBox: "0 0 300 134",
5086
+ viewBox: "0 0 302 134",
5087
5087
  "aria-hidden": true,
5088
5088
  children: [
5089
5089
  /* @__PURE__ */ jsx("circle", { className: circle, cy: "67", cx: "40", r: "40" }),
@@ -161,13 +161,15 @@ const Box = React.forwardRef((props, ref) => {
161
161
  });
162
162
  Box.displayName = "Box";
163
163
  const Button = React.forwardRef(
164
- ({ variant, ...restProps }, ref) => {
164
+ ({ variant, tone, ...restProps }, ref) => {
165
165
  const isValidVariant = variant && ToastContext.buttonVariants.indexOf(variant) > -1;
166
+ const isValidTone = tone && ToastContext.buttonTones.indexOf(tone) > -1;
166
167
  return /* @__PURE__ */ jsxRuntime.jsx(
167
168
  ToastContext.Button,
168
169
  {
169
170
  ref,
170
171
  variant: isValidVariant ? variant : void 0,
172
+ tone: isValidTone ? tone : void 0,
171
173
  ...restProps
172
174
  }
173
175
  );
@@ -175,15 +177,17 @@ const Button = React.forwardRef(
175
177
  );
176
178
  Button.displayName = "Button";
177
179
  const ButtonIcon = React.forwardRef(
178
- ({ variant, id, ...restProps }, ref) => {
180
+ ({ variant, id, tone, ...restProps }, ref) => {
179
181
  const fallbackId = useFallbackId();
180
182
  const isValidVariant = variant && ToastContext.buttonIconVariants.indexOf(variant) > -1;
183
+ const isValidTone = tone && ToastContext.buttonIconTones.indexOf(tone) > -1;
181
184
  return /* @__PURE__ */ jsxRuntime.jsx(
182
185
  ToastContext.ButtonIcon,
183
186
  {
184
187
  ref,
185
188
  id: id ?? fallbackId,
186
189
  variant: isValidVariant ? variant : void 0,
190
+ tone: isValidTone ? tone : void 0,
187
191
  ...restProps
188
192
  }
189
193
  );
@@ -266,8 +270,9 @@ const cleanSpaceValue = (space) => {
266
270
  const validResponsiveObject = typeof space === "object" && Object.keys(space).some(
267
271
  (bp) => styles_lib_css_breakpoints_cjs.breakpointNames.includes(bp) && validSpaceValues.includes(space[bp])
268
272
  );
273
+ const validArray = Array.isArray(space) && space.some((s) => validSpaceValues.includes(s));
269
274
  const validSpace = typeof space === "string" && validSpaceValues.includes(space);
270
- return validSpace || validResponsiveObject ? space : void 0;
275
+ return validSpace || validResponsiveObject || validArray ? space : void 0;
271
276
  };
272
277
  const Columns = ({
273
278
  space,
@@ -11,7 +11,7 @@ import { Actions, BoxRenderer, HiddenVisually, IconAdd, IconArrow, IconBookmark,
11
11
  import { useFallbackState } from "../playroomState.chunk.mjs";
12
12
  import { useRef, forwardRef, useState, useEffect } from "react";
13
13
  import { v4 } from "uuid";
14
- import { Bleed as Bleed$1, validBleedComponents, Box as Box$1, Button as Button$1, buttonVariants, ButtonIcon as ButtonIcon$1, buttonIconVariants, Columns as Columns$1, validColumnsComponents, Inline as Inline$1, validInlineComponents, IconClear, Stack as Stack$1, validStackComponents, TooltipRenderer as TooltipRenderer$1, useBackgroundLightness, PublicBox, Text } from "../ToastContext.chunk.mjs";
14
+ import { Bleed as Bleed$1, validBleedComponents, Box as Box$1, Button as Button$1, buttonVariants, buttonTones, ButtonIcon as ButtonIcon$1, buttonIconVariants, buttonIconTones, Columns as Columns$1, validColumnsComponents, Inline as Inline$1, validInlineComponents, IconClear, Stack as Stack$1, validStackComponents, TooltipRenderer as TooltipRenderer$1, useBackgroundLightness, PublicBox, Text } from "../ToastContext.chunk.mjs";
15
15
  import { BraidPortal, Column, ContentBlock, Divider, Hidden, IconCritical, IconPositive, IconRenderer, TextLink, TextLinkButton, ToastProvider, useResponsiveValue, useSpace, useThemeName, useToast } from "../ToastContext.chunk.mjs";
16
16
  import { atoms } from "../styles/lib/css/atoms/atoms.mjs";
17
17
  import { breakpointNames } from "../styles/lib/css/breakpoints.mjs";
@@ -159,13 +159,15 @@ const Box = forwardRef((props, ref) => {
159
159
  });
160
160
  Box.displayName = "Box";
161
161
  const Button = forwardRef(
162
- ({ variant, ...restProps }, ref) => {
162
+ ({ variant, tone, ...restProps }, ref) => {
163
163
  const isValidVariant = variant && buttonVariants.indexOf(variant) > -1;
164
+ const isValidTone = tone && buttonTones.indexOf(tone) > -1;
164
165
  return /* @__PURE__ */ jsx(
165
166
  Button$1,
166
167
  {
167
168
  ref,
168
169
  variant: isValidVariant ? variant : void 0,
170
+ tone: isValidTone ? tone : void 0,
169
171
  ...restProps
170
172
  }
171
173
  );
@@ -173,15 +175,17 @@ const Button = forwardRef(
173
175
  );
174
176
  Button.displayName = "Button";
175
177
  const ButtonIcon = forwardRef(
176
- ({ variant, id, ...restProps }, ref) => {
178
+ ({ variant, id, tone, ...restProps }, ref) => {
177
179
  const fallbackId = useFallbackId();
178
180
  const isValidVariant = variant && buttonIconVariants.indexOf(variant) > -1;
181
+ const isValidTone = tone && buttonIconTones.indexOf(tone) > -1;
179
182
  return /* @__PURE__ */ jsx(
180
183
  ButtonIcon$1,
181
184
  {
182
185
  ref,
183
186
  id: id ?? fallbackId,
184
187
  variant: isValidVariant ? variant : void 0,
188
+ tone: isValidTone ? tone : void 0,
185
189
  ...restProps
186
190
  }
187
191
  );
@@ -264,8 +268,9 @@ const cleanSpaceValue = (space2) => {
264
268
  const validResponsiveObject = typeof space2 === "object" && Object.keys(space2).some(
265
269
  (bp) => breakpointNames.includes(bp) && validSpaceValues.includes(space2[bp])
266
270
  );
271
+ const validArray = Array.isArray(space2) && space2.some((s) => validSpaceValues.includes(s));
267
272
  const validSpace = typeof space2 === "string" && validSpaceValues.includes(space2);
268
- return validSpace || validResponsiveObject ? space2 : void 0;
273
+ return validSpace || validResponsiveObject || validArray ? space2 : void 0;
269
274
  };
270
275
  const Columns = ({
271
276
  space: space2,