diff --git a/docs/components/dialog.md b/docs/components/dialog.md index 311551735..028ddff3c 100644 --- a/docs/components/dialog.md +++ b/docs/components/dialog.md @@ -151,6 +151,59 @@ const App = () => { }; ``` +### Header Actions + +The header shows a functional close button by default. You can use the `header-actions` slot to add additional [icon buttons](/components/icon-button) if needed. + +```html preview + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Close + + +Open Dialog + + +``` + +```jsx react +import { useState } from 'react'; +import { SlButton, SlDialog, SlIconButton } from '@shoelace-style/shoelace/dist/react'; + +const App = () => { + const [open, setOpen] = useState(false); + + return ( + <> + setOpen(false)}> + window.open(location.href)} + /> + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + setOpen(false)}> + Close + + + + setOpen(true)}>Open Dialog + + ); +}; +``` + ### Preventing the Dialog from Closing By default, dialogs will close when the user clicks the close button, clicks the overlay, or presses the Escape key. In most cases, the default behavior is the best behavior in terms of UX. However, there are situations where this may be undesirable, such as when data loss will occur. diff --git a/docs/components/drawer.md b/docs/components/drawer.md index d11e70228..4120d44d9 100644 --- a/docs/components/drawer.md +++ b/docs/components/drawer.md @@ -338,6 +338,54 @@ const App = () => { }; ``` +### Header Actions + +The header shows a functional close button by default. You can use the `header-actions` slot to add additional [icon buttons](/components/icon-button) if needed. + +```html preview + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Close + + +Open Drawer + + +``` + +```jsx react +import { useState } from 'react'; +import { SlButton, SlDrawer, SlIconButton } from '@shoelace-style/shoelace/dist/react'; + +const App = () => { + const [open, setOpen] = useState(false); + + return ( + <> + setOpen(false)}> + window.open(location.href)} /> + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + setOpen(false)}> + Close + + + + setOpen(true)}>Open Drawer + + ); +}; +``` + ### Preventing the Drawer from Closing By default, drawers will close when the user clicks the close button, clicks the overlay, or presses the Escape key. In most cases, the default behavior is the best behavior in terms of UX. However, there are situations where this may be undesirable, such as when data loss will occur. diff --git a/docs/resources/changelog.md b/docs/resources/changelog.md index fefadba81..f55213985 100644 --- a/docs/resources/changelog.md +++ b/docs/resources/changelog.md @@ -10,10 +10,12 @@ New versions of Shoelace are released as-needed and generally occur when a criti ## Next +- Added `header-actions` slot to `` and `` - Fixed a bug in `` where `sl-selection-change` was emitted when the selection didn't change [#1030](https://github.com/shoelace-style/shoelace/pull/1030) - Improved IntelliSense in VS Code, courtesy of [Burton's amazing CEM Analyzer plugin](https://github.com/break-stuff/cem-plugin-vs-code-custom-data-generator) - Improved accessibility of `` so the alert is announced and the close button has a label - Removed unused aria attributes from `` +- Replaced the `x` icon in the system icon library with `x-lg` to improve icon consistency ## 2.0.0-beta.85 diff --git a/src/components/dialog/dialog.styles.ts b/src/components/dialog/dialog.styles.ts index b2b878d7c..dae772fbf 100644 --- a/src/components/dialog/dialog.styles.ts +++ b/src/components/dialog/dialog.styles.ts @@ -68,12 +68,21 @@ export default css` margin: 0; } - .dialog__close { + .dialog__header-actions { + flex-shrink: 0; + display: flex; + flex-wrap: wrap; + justify-content: end; + gap: var(--sl-spacing-2x-small); + padding: 0 var(--header-spacing); + } + + .dialog__header-actions sl-icon-button, + .dialog__header-actions ::slotted(sl-icon-button) { flex: 0 0 auto; display: flex; align-items: center; - font-size: var(--sl-font-size-x-large); - padding: 0 var(--header-spacing); + font-size: var(--sl-font-size-medium); } .dialog__body { diff --git a/src/components/dialog/dialog.ts b/src/components/dialog/dialog.ts index 60613f8d4..c77030109 100644 --- a/src/components/dialog/dialog.ts +++ b/src/components/dialog/dialog.ts @@ -42,6 +42,7 @@ import type { CSSResultGroup } from 'lit'; * @csspart overlay - The overlay. * @csspart panel - The dialog panel (where the dialog and its content is rendered). * @csspart header - The dialog header. + * @csspart header-actions - Optional actions to add to the header. Works best with ``. * @csspart title - The dialog title. * @csspart close-button - The close button. * @csspart close-button__base - The close button's `base` part. @@ -279,15 +280,18 @@ export default class SlDialog extends ShoelaceElement {

${this.label.length > 0 ? this.label : String.fromCharCode(65279)}

- +
+ + +
` : ''} diff --git a/src/components/drawer/drawer.styles.ts b/src/components/drawer/drawer.styles.ts index 674eafbdc..89ec7f517 100644 --- a/src/components/drawer/drawer.styles.ts +++ b/src/components/drawer/drawer.styles.ts @@ -99,12 +99,21 @@ export default css` margin: 0; } - .drawer__close { + .drawer__header-actions { + flex-shrink: 0; + display: flex; + flex-wrap: wrap; + justify-content: end; + gap: var(--sl-spacing-2x-small); + padding: 0 var(--header-spacing); + } + + .drawer__header-actions sl-icon-button, + .drawer__header-actions ::slotted(sl-icon-button) { flex: 0 0 auto; display: flex; align-items: center; - font-size: var(--sl-font-size-x-large); - padding: 0 var(--header-spacing); + font-size: var(--sl-font-size-medium); } .drawer__body { diff --git a/src/components/drawer/drawer.ts b/src/components/drawer/drawer.ts index 75943d536..cce1d2244 100644 --- a/src/components/drawer/drawer.ts +++ b/src/components/drawer/drawer.ts @@ -43,6 +43,7 @@ import type { CSSResultGroup } from 'lit'; * @csspart overlay - The overlay. * @csspart panel - The drawer panel (where the drawer and its content is rendered). * @csspart header - The drawer header. + * @csspart header-actions - Optional actions to add to the header. Works best with ``. * @csspart title - The drawer title. * @csspart close-button - The close button. * @csspart close-button__base - The close button's `base` part. @@ -310,15 +311,18 @@ export default class SlDrawer extends ShoelaceElement { ${this.label.length > 0 ? this.label : String.fromCharCode(65279)} - this.requestClose('close-button')} - > +
+ + this.requestClose('close-button')} + > +
` : ''}