@nswds/ui 9.5.0 → 9.6.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.
Files changed (36) hide show
  1. package/dist/components/alert-dialog.js +2 -2
  2. package/dist/components/alert-dialog.js.map +1 -1
  3. package/dist/components/button-group.d.ts +2 -2
  4. package/dist/components/button-group.js.map +1 -1
  5. package/dist/components/combobox.js +2 -2
  6. package/dist/components/combobox.js.map +1 -1
  7. package/dist/components/component-preview.d.ts +7 -5
  8. package/dist/components/component-preview.js +53 -7
  9. package/dist/components/component-preview.js.map +1 -1
  10. package/dist/components/dialog.js +2 -2
  11. package/dist/components/dialog.js.map +1 -1
  12. package/dist/components/drawer.js +2 -2
  13. package/dist/components/drawer.js.map +1 -1
  14. package/dist/components/dropdown-menu.js +2 -2
  15. package/dist/components/dropdown-menu.js.map +1 -1
  16. package/dist/components/hover-card.js +2 -2
  17. package/dist/components/hover-card.js.map +1 -1
  18. package/dist/components/navigation-menu.js +2 -1
  19. package/dist/components/navigation-menu.js.map +1 -1
  20. package/dist/components/popover.js +2 -2
  21. package/dist/components/popover.js.map +1 -1
  22. package/dist/components/select.js +2 -2
  23. package/dist/components/select.js.map +1 -1
  24. package/dist/components/sheet.js +2 -2
  25. package/dist/components/sheet.js.map +1 -1
  26. package/dist/components/site-search.js +2 -2
  27. package/dist/components/site-search.js.map +1 -1
  28. package/dist/components/tooltip.js +2 -2
  29. package/dist/components/tooltip.js.map +1 -1
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +1 -0
  32. package/dist/lib/portal-boundary.d.ts +47 -0
  33. package/dist/lib/portal-boundary.js +24 -0
  34. package/dist/lib/portal-boundary.js.map +1 -0
  35. package/dist/styles.css +1 -1
  36. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -71,6 +71,7 @@ export * from './components/toggle-group.js';
71
71
  export * from './components/toggle.js';
72
72
  export * from './components/tooltip.js';
73
73
  export * from './hooks/use-chrome-height.js';
74
+ export * from './lib/portal-boundary.js';
74
75
  export * from './lib/utils.js';
75
76
  //# sourceMappingURL=index.js.map
76
77
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,47 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * What a region of the page hands the popups opened from inside it, so they
5
+ * look as though they were still inside it: a class, a text direction,
6
+ * attributes and custom properties for an element wrapped around the popup's
7
+ * portalled contents.
8
+ *
9
+ * A popup portals to the end of the page, so nothing set on an ancestor of its
10
+ * trigger reaches it through the DOM: not a custom property, not the `dark`
11
+ * class, not `dir`. React context does cross a portal, and every popup in this
12
+ * package passes through `PortalBoundary` there, which is where a scope is
13
+ * applied. ComponentPreview's stage provides one: its colour scheme, its
14
+ * tokens and its direction. `null` everywhere else, which leaves a portal's
15
+ * contents exactly as they were.
16
+ */
17
+ type PortalScope = {
18
+ className?: string;
19
+ style?: React.CSSProperties;
20
+ dir?: 'ltr' | 'rtl';
21
+ /** `data-*` attributes for the wrapping element. */
22
+ attributes?: Record<`data-${string}`, string | undefined>;
23
+ };
24
+ declare const PortalScopeContext: React.Context<PortalScope | null>;
25
+ /**
26
+ * The one child of every portal in this package. It does the two things a
27
+ * portal needs because React context crosses it and the DOM does not:
28
+ *
29
+ * - resets a ButtonGroup's context, so a Button inside the popup does not
30
+ * render as a segment of the group the popup was opened from (see
31
+ * `ButtonGroupBoundary`, which does only this);
32
+ * - applies the `PortalScope` the popup was opened in, if there is one, by
33
+ * wrapping the contents in one element that carries it.
34
+ *
35
+ * That element is `display: contents`, so it generates no box: the popup is
36
+ * positioned and stacked as before, and only inheritance and ancestor
37
+ * selectors see it. Outside a scope there is no element at all.
38
+ *
39
+ * Wrap the portalled contents of an overlay from another library in this to
40
+ * get both. `check:portal-boundary` requires it of every portal here.
41
+ */
42
+ declare function PortalBoundary({ children }: {
43
+ children: React.ReactNode;
44
+ }): React.JSX.Element;
45
+
46
+ export { PortalBoundary, PortalScopeContext };
47
+ export type { PortalScope };
@@ -0,0 +1,24 @@
1
+ "use client"
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import * as React from 'react';
4
+ import { ButtonGroupBoundary } from './button-group-context.js';
5
+
6
+ const PortalScopeContext = React.createContext(null);
7
+ function PortalBoundary({ children }) {
8
+ const scope = React.useContext(PortalScopeContext);
9
+ return /* @__PURE__ */ jsx(ButtonGroupBoundary, { children: scope ? /* @__PURE__ */ jsx(
10
+ "div",
11
+ {
12
+ ...scope.attributes,
13
+ "data-slot": "portal-scope",
14
+ dir: scope.dir,
15
+ className: scope.className ? `contents ${scope.className}` : "contents",
16
+ style: scope.style,
17
+ children
18
+ }
19
+ ) : children });
20
+ }
21
+
22
+ export { PortalBoundary, PortalScopeContext };
23
+ //# sourceMappingURL=portal-boundary.js.map
24
+ //# sourceMappingURL=portal-boundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/portal-boundary.tsx"],"names":[],"mappings":";;;;AA4BA,MAAM,kBAAA,GAAqB,KAAA,CAAM,aAAA,CAAkC,IAAI;AAmBvE,SAAS,cAAA,CAAe,EAAE,QAAA,EAAS,EAAkC;AACnE,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,UAAA,CAAW,kBAAkB,CAAA;AAEjD,EAAA,uBACE,GAAA,CAAC,uBACE,QAAA,EAAA,KAAA,mBACC,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACE,GAAG,KAAA,CAAM,UAAA;AAAA,MACV,WAAA,EAAU,cAAA;AAAA,MACV,KAAK,KAAA,CAAM,GAAA;AAAA,MACX,WAAW,KAAA,CAAM,SAAA,GAAY,CAAA,SAAA,EAAY,KAAA,CAAM,SAAS,CAAA,CAAA,GAAK,UAAA;AAAA,MAC7D,OAAO,KAAA,CAAM,KAAA;AAAA,MAEZ;AAAA;AAAA,MAGH,QAAA,EAEJ,CAAA;AAEJ","file":"portal-boundary.js","sourcesContent":["'use client'\n\nimport * as React from 'react'\n\nimport { ButtonGroupBoundary } from './button-group-context.js'\n\n/**\n * What a region of the page hands the popups opened from inside it, so they\n * look as though they were still inside it: a class, a text direction,\n * attributes and custom properties for an element wrapped around the popup's\n * portalled contents.\n *\n * A popup portals to the end of the page, so nothing set on an ancestor of its\n * trigger reaches it through the DOM: not a custom property, not the `dark`\n * class, not `dir`. React context does cross a portal, and every popup in this\n * package passes through `PortalBoundary` there, which is where a scope is\n * applied. ComponentPreview's stage provides one: its colour scheme, its\n * tokens and its direction. `null` everywhere else, which leaves a portal's\n * contents exactly as they were.\n */\ntype PortalScope = {\n className?: string\n style?: React.CSSProperties\n dir?: 'ltr' | 'rtl'\n /** `data-*` attributes for the wrapping element. */\n attributes?: Record<`data-${string}`, string | undefined>\n}\n\nconst PortalScopeContext = React.createContext<PortalScope | null>(null)\n\n/**\n * The one child of every portal in this package. It does the two things a\n * portal needs because React context crosses it and the DOM does not:\n *\n * - resets a ButtonGroup's context, so a Button inside the popup does not\n * render as a segment of the group the popup was opened from (see\n * `ButtonGroupBoundary`, which does only this);\n * - applies the `PortalScope` the popup was opened in, if there is one, by\n * wrapping the contents in one element that carries it.\n *\n * That element is `display: contents`, so it generates no box: the popup is\n * positioned and stacked as before, and only inheritance and ancestor\n * selectors see it. Outside a scope there is no element at all.\n *\n * Wrap the portalled contents of an overlay from another library in this to\n * get both. `check:portal-boundary` requires it of every portal here.\n */\nfunction PortalBoundary({ children }: { children: React.ReactNode }) {\n const scope = React.useContext(PortalScopeContext)\n\n return (\n <ButtonGroupBoundary>\n {scope ? (\n <div\n {...scope.attributes}\n data-slot='portal-scope'\n dir={scope.dir}\n className={scope.className ? `contents ${scope.className}` : 'contents'}\n style={scope.style}\n >\n {children}\n </div>\n ) : (\n children\n )}\n </ButtonGroupBoundary>\n )\n}\n\nexport { PortalBoundary, PortalScopeContext }\nexport type { PortalScope }\n"]}