123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- /*!
- * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
- * v1.0.0-beta.97
- */
- import { h } from "@stencil/core";
- import { CSS, SLOTS, TEXT } from "./resources";
- import { StatusIcons } from "../alert/interfaces";
- import { getSlotted, setRequestedIcon } from "../../utils/dom";
- import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot";
- /**
- * Notices are intended to be used to present users with important-but-not-crucial contextual tips or copy. Because
- * notices are displayed inline, a common use case is displaying them on page-load to present users with short hints or contextual copy.
- * They are optionally dismissible - useful for keeping track of whether or not a user has dismissed the notice. You can also choose not
- * to display a notice on page load and set the "active" attribute as needed to contextually provide inline messaging to users.
- */
- /**
- * @slot title - A slot for adding the title.
- * @slot message - A slot for adding the message.
- * @slot link - A slot for adding actions to take, such as: undo, try again, link to page, etc.
- * @slot actions-end - A slot for adding actions to the end of the component. It is recommended to use two or less actions.
- */
- export class Notice {
- constructor() {
- //--------------------------------------------------------------------------
- //
- // Properties
- //
- //---------------------------------------------------------------------------
- /**
- * When `true`, the component is active.
- *
- * @deprecated Use `open` instead.
- */
- this.active = false;
- /** When `true`, the component is visible. */
- this.open = false;
- /** The color for the component's top border and icon. */
- this.color = "blue";
- /**
- * When `true`, a close button is added to the component.
- *
- * @deprecated use `closable` instead.
- */
- this.dismissible = false;
- /** When `true`, a close button is added to the component. */
- this.closable = false;
- /**
- * Accessible name for the close button.
- *
- * @default "Close"
- */
- this.intlClose = TEXT.close;
- /** Specifies the size of the component. */
- this.scale = "m";
- /** Specifies the width of the component. */
- this.width = "auto";
- //--------------------------------------------------------------------------
- //
- // Private Methods
- //
- //--------------------------------------------------------------------------
- this.close = () => {
- this.open = false;
- this.calciteNoticeClose.emit();
- };
- }
- activeHandler(value) {
- this.open = value;
- }
- openHandler(value) {
- this.active = value;
- }
- handleDismissible(value) {
- this.closable = value;
- }
- handleClosable(value) {
- this.dismissible = value;
- }
- updateRequestedIcon() {
- this.requestedIcon = setRequestedIcon(StatusIcons, this.icon, this.color);
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- connectedCallback() {
- connectConditionalSlotComponent(this);
- const isOpen = this.active || this.open;
- if (isOpen) {
- this.activeHandler(isOpen);
- this.openHandler(isOpen);
- }
- if (this.dismissible) {
- this.handleDismissible(this.dismissible);
- }
- if (this.closable) {
- this.handleClosable(this.closable);
- }
- }
- disconnectedCallback() {
- disconnectConditionalSlotComponent(this);
- }
- componentWillLoad() {
- this.requestedIcon = setRequestedIcon(StatusIcons, this.icon, this.color);
- }
- render() {
- const { el } = this;
- const closeButton = (h("button", { "aria-label": this.intlClose, class: CSS.close, onClick: this.close, ref: (el) => (this.closeButton = el) }, h("calcite-icon", { icon: "x", scale: this.scale === "l" ? "m" : "s" })));
- const hasActionEnd = getSlotted(el, SLOTS.actionsEnd);
- return (h("div", { class: CSS.container }, this.requestedIcon ? (h("div", { class: CSS.icon }, h("calcite-icon", { icon: this.requestedIcon, scale: this.scale === "l" ? "m" : "s" }))) : null, h("div", { class: CSS.content }, h("slot", { name: SLOTS.title }), h("slot", { name: SLOTS.message }), h("slot", { name: SLOTS.link })), hasActionEnd ? (h("div", { class: CSS.actionsEnd }, h("slot", { name: SLOTS.actionsEnd }))) : null, this.closable ? closeButton : null));
- }
- //--------------------------------------------------------------------------
- //
- // Public Methods
- //
- //--------------------------------------------------------------------------
- /** Sets focus on the component. */
- async setFocus() {
- const noticeLinkEl = this.el.querySelector("calcite-link");
- if (!this.closeButton && !noticeLinkEl) {
- return;
- }
- if (noticeLinkEl) {
- noticeLinkEl.setFocus();
- }
- else if (this.closeButton) {
- this.closeButton.focus();
- }
- }
- static get is() { return "calcite-notice"; }
- static get encapsulation() { return "shadow"; }
- static get originalStyleUrls() {
- return {
- "$": ["notice.scss"]
- };
- }
- static get styleUrls() {
- return {
- "$": ["notice.css"]
- };
- }
- static get properties() {
- return {
- "active": {
- "type": "boolean",
- "mutable": true,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [{
- "name": "deprecated",
- "text": "Use `open` instead."
- }],
- "text": "When `true`, the component is active."
- },
- "attribute": "active",
- "reflect": true,
- "defaultValue": "false"
- },
- "open": {
- "type": "boolean",
- "mutable": true,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When `true`, the component is visible."
- },
- "attribute": "open",
- "reflect": true,
- "defaultValue": "false"
- },
- "color": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "StatusColor",
- "resolved": "\"blue\" | \"green\" | \"red\" | \"yellow\"",
- "references": {
- "StatusColor": {
- "location": "import",
- "path": "../alert/interfaces"
- }
- }
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "The color for the component's top border and icon."
- },
- "attribute": "color",
- "reflect": true,
- "defaultValue": "\"blue\""
- },
- "dismissible": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [{
- "name": "deprecated",
- "text": "use `closable` instead."
- }],
- "text": "When `true`, a close button is added to the component."
- },
- "attribute": "dismissible",
- "reflect": true,
- "defaultValue": "false"
- },
- "closable": {
- "type": "boolean",
- "mutable": false,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": true,
- "docs": {
- "tags": [],
- "text": "When `true`, a close button is added to the component."
- },
- "attribute": "closable",
- "reflect": true,
- "defaultValue": "false"
- },
- "icon": {
- "type": "any",
- "mutable": false,
- "complexType": {
- "original": "string | boolean",
- "resolved": "boolean | string",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "When `true`, shows a default recommended icon. Alternatively, pass a Calcite UI Icon name to display a specific icon."
- },
- "attribute": "icon",
- "reflect": true
- },
- "intlClose": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [{
- "name": "default",
- "text": "\"Close\""
- }],
- "text": "Accessible name for the close button."
- },
- "attribute": "intl-close",
- "reflect": false,
- "defaultValue": "TEXT.close"
- },
- "scale": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "Scale",
- "resolved": "\"l\" | \"m\" | \"s\"",
- "references": {
- "Scale": {
- "location": "import",
- "path": "../interfaces"
- }
- }
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Specifies the size of the component."
- },
- "attribute": "scale",
- "reflect": true,
- "defaultValue": "\"m\""
- },
- "width": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "Width",
- "resolved": "\"auto\" | \"full\" | \"half\"",
- "references": {
- "Width": {
- "location": "import",
- "path": "../interfaces"
- }
- }
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Specifies the width of the component."
- },
- "attribute": "width",
- "reflect": true,
- "defaultValue": "\"auto\""
- }
- };
- }
- static get events() {
- return [{
- "method": "calciteNoticeClose",
- "name": "calciteNoticeClose",
- "bubbles": true,
- "cancelable": false,
- "composed": true,
- "docs": {
- "tags": [],
- "text": "Fired when the component is closed."
- },
- "complexType": {
- "original": "void",
- "resolved": "void",
- "references": {}
- }
- }, {
- "method": "calciteNoticeOpen",
- "name": "calciteNoticeOpen",
- "bubbles": true,
- "cancelable": false,
- "composed": true,
- "docs": {
- "tags": [],
- "text": "Fired when the component is opened."
- },
- "complexType": {
- "original": "void",
- "resolved": "void",
- "references": {}
- }
- }];
- }
- static get methods() {
- return {
- "setFocus": {
- "complexType": {
- "signature": "() => Promise<void>",
- "parameters": [],
- "references": {
- "Promise": {
- "location": "global"
- }
- },
- "return": "Promise<void>"
- },
- "docs": {
- "text": "Sets focus on the component.",
- "tags": []
- }
- }
- };
- }
- static get elementRef() { return "el"; }
- static get watchers() {
- return [{
- "propName": "active",
- "methodName": "activeHandler"
- }, {
- "propName": "open",
- "methodName": "openHandler"
- }, {
- "propName": "dismissible",
- "methodName": "handleDismissible"
- }, {
- "propName": "closable",
- "methodName": "handleClosable"
- }, {
- "propName": "icon",
- "methodName": "updateRequestedIcon"
- }, {
- "propName": "color",
- "methodName": "updateRequestedIcon"
- }];
- }
- }
|