Popovers
Stylised native HTML [popover] modals with transition animation styles.
Examples (anchor)
The popover styles can be customized before compiling using Sass or in real-time with CSS variables. The button styles are not included but provided with the forms and buttons and/or the buttons component if required.
Default (anchor)
Popovers have light-dismiss behaviour by default so the closing button is optional.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
Examples HTML
<button popovertarget="popover">Popover</button>
<div id="popover" popover>
<p>The quick brown fox jumps over the lazy dog.</p>
</div>
<button popovertarget="pop-close">With close button</button>
<div id="pop-close" popover>
<p>The quick brown fox jumps over the lazy dog.</p>
<button popovertarget="pop-close" popovertargetaction="hide">Close</button>
</div>Transition (anchor)
The optional transition animation style is compiled with @media (prefers-reduced-motion: no-preference) to respect a users preferences. If included the default .25s transition timing can be customized inline using the CSS variable --popover-transition.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
Examples HTML
The popover animation is enabled so the 'No transition' example uses the variable to remove the default .25s transition included to demonstrate default non-animated popovers.
<button popovertarget="popover-no-transition">No transition</button>
<div id="popover-no-transition" popover style="--popover-transition: 0s;">
<p>The quick brown fox jumps over the lazy dog.</p>
</div>
<button popovertarget="popover-transition">Enabled (default .25s)</button>
<div id="popover-transition" popover>
<p>The quick brown fox jumps over the lazy dog.</p>
</div>
<button popovertarget="popover-custom-transition">Enabled (custom 1.5s)</button>
<div id="popover-custom-transition" popover style="--popover-transition: 1.5s;">
<p>The quick brown fox jumps over the lazy dog.</p>
</div>Fixed light and dark (anchor)
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
Example HTML
<button popovertarget="popover-light" class="btn-light">Light popover</button>
<div class="popover-light" id="popover-light" popover>
<p>The quick brown fox jumps over the lazy dog.</p>
</div>
<button popovertarget="popover-dark" class="btn-dark">Dark popover</button>
<div class="popover-dark" id="popover-dark" popover>
<p>The quick brown fox jumps over the lazy dog.</p>
</div>Using the module (anchor)
Load StyleMods as demonstrated (change file path as required) then include the Sass mixin anywhere below.
Default with transition styles:
@use "stylemods/scss" as *;
@include popovers-css;With no transition:
@use "stylemods/scss" as *;
@include popovers-no-transition-css;Or individually:
@use "stylemods/scss" as *;
@include popover-styles-css;
@include popover-transition-css;See the using modules page for more information.
Using the framework (anchor)
Using the recommended custom setup enable the styles in an overrides document:
@use "stylemods/scss/configuration" as *;
$enable-popovers: true;
$enable-popovers-transition: true;Include the overrides and the framework styles with your custom document for compiling the framework:
@use "overrides";
@use "stylemods/scss/stylemods";See using the framework for more information.
Source code (anchor)
The Popovers source file is included with the components module files, you can view the source code from the latest release (v1.5.0) via the Github link below.
- Source document
- stylemods/scss/components/popovers.scss
- View on Github
- https://github.com/pmbrown/StyleMods/blob/main/scss/components/popovers.scss
Shared documentation about how to customize the default property values for the styles using the Sass and CSS variables is provided on the customizing page.