Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui-shell): add preventCloseOnClickOutside to HeaderAction #1625

Merged
merged 3 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions COMPONENT_INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -1601,14 +1601,15 @@ None.

### Props

| Prop name | Required | Kind | Reactive | Type | Default value | Description |
| :--------- | :------- | :--------------- | :------- | ----------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------- |
| ref | No | <code>let</code> | Yes | <code>null &#124; HTMLButtonElement</code> | <code>null</code> | Obtain a reference to the button HTML element |
| isOpen | No | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to open the panel |
| icon | No | <code>let</code> | No | <code>typeof import("svelte").SvelteComponent</code> | <code>undefined</code> | Specify the icon to render when the action panel is closed.<br />Defaults to `&lt;Switcher size={20} /&gt;` |
| closeIcon | No | <code>let</code> | No | <code>typeof import("svelte").SvelteComponent</code> | <code>undefined</code> | Specify the icon to render when the action panel is open.<br />Defaults to `&lt;Close size={20} /&gt;` |
| text | No | <code>let</code> | No | <code>string</code> | <code>undefined</code> | Specify the text<br />Alternatively, use the named slot "text" (e.g., &lt;div slot="text"&gt;...&lt;/div&gt;) |
| transition | No | <code>let</code> | No | <code>false &#124; import("svelte/transition").SlideParams</code> | <code>{ duration: 200 }</code> | Customize the panel transition (i.e., `transition:slide`).<br />Set to `false` to disable the transition |
| Prop name | Required | Kind | Reactive | Type | Default value | Description |
| :------------------------- | :------- | :--------------- | :------- | ----------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------- |
| ref | No | <code>let</code> | Yes | <code>null &#124; HTMLButtonElement</code> | <code>null</code> | Obtain a reference to the button HTML element |
| isOpen | No | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to open the panel |
| icon | No | <code>let</code> | No | <code>typeof import("svelte").SvelteComponent</code> | <code>undefined</code> | Specify the icon to render when the action panel is closed.<br />Defaults to `&lt;Switcher size={20} /&gt;` |
| closeIcon | No | <code>let</code> | No | <code>typeof import("svelte").SvelteComponent</code> | <code>undefined</code> | Specify the icon to render when the action panel is open.<br />Defaults to `&lt;Close size={20} /&gt;` |
| text | No | <code>let</code> | No | <code>string</code> | <code>undefined</code> | Specify the text<br />Alternatively, use the named slot "text" (e.g., &lt;div slot="text"&gt;...&lt;/div&gt;) |
| transition | No | <code>let</code> | No | <code>false &#124; import("svelte/transition").SlideParams</code> | <code>{ duration: 200 }</code> | Customize the panel transition (i.e., `transition:slide`).<br />Set to `false` to disable the transition |
| preventCloseOnClickOutside | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to prevent the panel from closing when clicking outside |

### Slots

Expand Down
12 changes: 12 additions & 0 deletions docs/src/COMPONENT_API.json
Original file line number Diff line number Diff line change
Expand Up @@ -4923,6 +4923,18 @@
"isRequired": false,
"constant": false,
"reactive": false
},
{
"name": "preventCloseOnClickOutside",
"kind": "let",
"description": "Set to `true` to prevent the panel from closing when clicking outside",
"type": "boolean",
"value": "false",
"isFunction": false,
"isFunctionDeclaration": false,
"isRequired": false,
"constant": false,
"reactive": false
}
],
"moduleExports": [],
Expand Down
10 changes: 9 additions & 1 deletion src/UIShell/HeaderAction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
*/
export let transition = { duration: 200 };

/** Set to `true` to prevent the panel from closing when clicking outside */
export let preventCloseOnClickOutside = false;

import { createEventDispatcher } from "svelte";
import { slide } from "svelte/transition";
import Close from "../icons/Close.svelte";
Expand All @@ -50,7 +53,12 @@

<svelte:window
on:click="{({ target }) => {
if (isOpen && !ref.contains(target) && !refPanel.contains(target)) {
if (
isOpen &&
!ref.contains(target) &&
!refPanel.contains(target) &&
!preventCloseOnClickOutside
) {
isOpen = false;
dispatch('close');
}
Expand Down
6 changes: 6 additions & 0 deletions types/UIShell/HeaderAction.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export interface HeaderActionProps
*/
transition?: false | import("svelte/transition").SlideParams;

/**
* Set to `true` to prevent the panel from closing when clicking outside
* @default false
*/
preventCloseOnClickOutside?: boolean;

[key: `data-${string}`]: any;
}

Expand Down