From ce49f50ceeff9bc2f171e18126aa126ff73c508c Mon Sep 17 00:00:00 2001 From: Hunter Johnston <64506580+huntabyte@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:28:00 -0400 Subject: [PATCH] next: `Portal` utility component (#716) --- .changeset/early-points-study.md | 5 ++ packages/bits-ui/package.json | 3 - packages/bits-ui/src/lib/bits/index.ts | 1 + .../lib/bits/utilities/portal/portal.svelte | 17 ++-- .../src/lib/bits/utilities/portal/types.ts | 5 +- .../bits-ui/src/lib/internal/cssToStyleObj.ts | 2 +- packages/bits-ui/src/lib/internal/strings.ts | 82 +++++++++++++++++++ packages/bits-ui/src/lib/internal/style.ts | 2 +- .../bits-ui/src/lib/internal/styleToCSS.ts | 29 +++++++ .../shared/style-object-to-css-string.d.ts | 10 --- packages/bits-ui/src/lib/types.ts | 1 + pnpm-lock.yaml | 9 -- sites/docs/content/utilities/portal.md | 56 +++++++++++++ 13 files changed, 191 insertions(+), 31 deletions(-) create mode 100644 .changeset/early-points-study.md create mode 100644 packages/bits-ui/src/lib/internal/strings.ts create mode 100644 packages/bits-ui/src/lib/internal/styleToCSS.ts delete mode 100644 packages/bits-ui/src/lib/shared/style-object-to-css-string.d.ts create mode 100644 sites/docs/content/utilities/portal.md diff --git a/.changeset/early-points-study.md b/.changeset/early-points-study.md new file mode 100644 index 000000000..38a79506f --- /dev/null +++ b/.changeset/early-points-study.md @@ -0,0 +1,5 @@ +--- +"bits-ui": patch +--- + +feat: export and document `Portal` utility component diff --git a/packages/bits-ui/package.json b/packages/bits-ui/package.json index 9f511cecc..048a3702e 100644 --- a/packages/bits-ui/package.json +++ b/packages/bits-ui/package.json @@ -60,10 +60,7 @@ "@internationalized/date": "^3.5.4", "clsx": "^2.1.1", "esm-env": "^1.0.0", - "nanoid": "^5.0.7", "runed": "^0.15.2", - "scule": "^1.3.0", - "style-object-to-css-string": "^1.1.3", "style-to-object": "^1.0.6", "svelte-toolbelt": "^0.3.1" }, diff --git a/packages/bits-ui/src/lib/bits/index.ts b/packages/bits-ui/src/lib/bits/index.ts index c078f6475..0fb808049 100644 --- a/packages/bits-ui/src/lib/bits/index.ts +++ b/packages/bits-ui/src/lib/bits/index.ts @@ -36,3 +36,4 @@ export * as Toggle from "./toggle/index.js"; export * as ToggleGroup from "./toggle-group/index.js"; export * as Toolbar from "./toolbar/index.js"; export * as Tooltip from "./tooltip/index.js"; +export { default as Portal } from "./utilities/portal/portal.svelte"; diff --git a/packages/bits-ui/src/lib/bits/utilities/portal/portal.svelte b/packages/bits-ui/src/lib/bits/utilities/portal/portal.svelte index 840771663..d10d5cefc 100644 --- a/packages/bits-ui/src/lib/bits/utilities/portal/portal.svelte +++ b/packages/bits-ui/src/lib/bits/utilities/portal/portal.svelte @@ -1,5 +1,6 @@ + + +
This content will be portalled to the body
+
+``` + +### Custom target + +You can use the `to` prop to specify a custom target element or selector to render the content to. + +```svelte + + +
+ +
+ +
This content will be portalled to the #custom-target element
+
+
+``` + +### Disable + +You can use the `disabled` prop to disable the portal behavior. + +```svelte + + + +
This content will not be portalled
+
+```