1.0.6 • Published 5 years ago

@singleware/ui-popover v1.0.6

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

UI-Popover

Custom HTML element used to wrap a simple popover, composed by the slots: input and content. See demo

Usage

Instantiate the component that initializes the custom element.

import * as JSX from '@singleware/jsx';
import * as Popover from '@singleware/ui-popover';

const component = (
  <Popover.Component dismiss>
    <button slot="input">Input</button>
    <div slot="content">Content</div>
  </Popover.Component>
) as Popover.Element;

Show, Hide and Toggle programmatically.

component.show();
component.hide();
component.toggle();

Be informed about the component actions.

component.addEventListener('show', (event: Event) => console.log(`Yes! It's visible now.`));
component.addEventListener('hide', (event: Event) => console.log(`No! It's hidden now.`));

Help

Attributes

NameDescription
dismissAssigned when the content can be hidden by clicking anywhere
openAutomatically assigned when the content is shown and removed when hidden

Properties

NameTypeDescription
emptyboolGet the current empty state from the input slot element
namestringGet and set the property name from the input slot element
valueanyGet and set the property value from the input slot element
defaultValueanyGet and set the property defaultValue from the input slot element
requiredboolGet and set the required state from the input slot element
readOnlyboolGet and set the readOnly state from the input slot element
disabledboolGet and set the disabled state from the input slot element
dismissboolGet and set the dismiss state
openboolGet the current open state
placement-Get and set the element placement state. Use top, right, bottom or left
alignment-Get and set the element alignment state. Use start, middle or end

Methods

NameDescription
focusMoves the current focus to the input slot element
resetReset the current value in the input slot element
showShows the content element
hideHides the content element
toggleToggles the content element
checkValidityGet the validity from the input slot element
setCustomValiditySet a custom validity in the input slot element

Slots

NameDescription
inputElement to receive the popover show and hide actions
contentElement to be displayed while the open action is active

Events

NameDescription
showDispatched when the alert becomes visible
hideDispatched when the alert becomes hidden

Styles

NameDescription
--swe-popover-content-border-radiusDetermines the content border radius
--swe-popover-content-border-sizeDetermines the content border size
--swe-popover-content-border-colorDetermines the content border color

These variables above are useful to customize the closed shadow DOM.

Install

Using npm:

npm i @singleware/ui-popover

License

MIT © Silas B. Domingos