calcite-notice.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client/index.js';
  7. import { S as StatusIcons } from './interfaces.js';
  8. import { s as setRequestedIcon, b as getSlotted } from './dom.js';
  9. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot.js';
  10. import { d as defineCustomElement$2 } from './icon.js';
  11. const TEXT = {
  12. close: "Close"
  13. };
  14. const SLOTS = {
  15. title: "title",
  16. message: "message",
  17. link: "link",
  18. actionsEnd: "actions-end"
  19. };
  20. const CSS = {
  21. actionsEnd: "actions-end",
  22. close: "notice-close",
  23. container: "container",
  24. content: "notice-content",
  25. icon: "notice-icon"
  26. };
  27. const noticeCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([scale=s]){--calcite-notice-spacing-token-small:0.5rem;--calcite-notice-spacing-token-large:0.75rem}:host([scale=s]) .container slot[name=title]::slotted(*),:host([scale=s]) .container *::slotted([slot=title]){margin-block:0.125rem;font-size:var(--calcite-font-size--1);line-height:1.375}:host([scale=s]) .container slot[name=message]::slotted(*),:host([scale=s]) .container *::slotted([slot=message]){margin-block:0.125rem;font-size:var(--calcite-font-size--2);line-height:1.375}:host([scale=s]) ::slotted(calcite-link){margin-block:0.125rem;font-size:var(--calcite-font-size--2);line-height:1.375}:host([scale=s]) .notice-close{padding:0.5rem}:host([scale=m]){--calcite-notice-spacing-token-small:0.75rem;--calcite-notice-spacing-token-large:1rem}:host([scale=m]) .container slot[name=title]::slotted(*),:host([scale=m]) .container *::slotted([slot=title]){margin-block:0.125rem;font-size:var(--calcite-font-size-0);line-height:1.375}:host([scale=m]) .container slot[name=message]::slotted(*),:host([scale=m]) .container *::slotted([slot=message]){margin-block:0.125rem;font-size:var(--calcite-font-size--1);line-height:1.375}:host([scale=m]) ::slotted(calcite-link){margin-block:0.125rem;font-size:var(--calcite-font-size--1);line-height:1.375}:host([scale=l]){--calcite-notice-spacing-token-small:1rem;--calcite-notice-spacing-token-large:1.25rem}:host([scale=l]) .container slot[name=title]::slotted(*),:host([scale=l]) .container *::slotted([slot=title]){margin-block:0.125rem;font-size:var(--calcite-font-size-1);line-height:1.375}:host([scale=l]) .container slot[name=message]::slotted(*),:host([scale=l]) .container *::slotted([slot=message]){margin-block:0.125rem;font-size:var(--calcite-font-size-0);line-height:1.375}:host([scale=l]) ::slotted(calcite-link){margin-block:0.125rem;font-size:var(--calcite-font-size-0);line-height:1.375}:host([width=auto]){--calcite-notice-width:auto}:host([width=half]){--calcite-notice-width:50%}:host([width=full]){--calcite-notice-width:100%}:host{margin-inline:auto;display:none;max-inline-size:100%;align-items:center;inline-size:var(--calcite-notice-width)}.container{pointer-events:none;margin-block:0px;box-sizing:border-box;display:none;inline-size:100%;background-color:var(--calcite-ui-foreground-1);opacity:0;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;max-block-size:0;text-align:start;border-inline-start:0px solid;box-shadow:0 0 0 0 transparent}.notice-close{outline-color:transparent}.notice-close:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}:host{display:flex}:host([open]) .container{pointer-events:auto;display:flex;max-block-size:100%;align-items:center;border-width:2px;opacity:1;--tw-shadow:0 4px 8px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);--tw-shadow-colored:0 4px 8px -1px var(--tw-shadow-color), 0 2px 4px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}.container slot[name=title]::slotted(*),.container *::slotted([slot=title]){margin:0px;font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-1)}.container slot[name=message]::slotted(*),.container *::slotted([slot=message]){margin:0px;display:inline;font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-2);margin-inline-end:var(--calcite-notice-spacing-token-small)}.notice-content{box-sizing:border-box;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;padding-inline:var(--calcite-notice-spacing-token-large);flex:0 0 auto;display:flex;min-inline-size:0px;flex-direction:column;overflow-wrap:break-word;flex:1 1 0;padding-block:var(--calcite-notice-spacing-token-small);padding-inline:0 var(--calcite-notice-spacing-token-small)}.notice-content:first-of-type:not(:only-child){padding-inline-start:var(--calcite-notice-spacing-token-large)}.notice-content:only-of-type{padding-block:var(--calcite-notice-spacing-token-small);padding-inline:var(--calcite-notice-spacing-token-large)}.notice-icon{display:flex;align-items:center;box-sizing:border-box;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;padding-block:var(--calcite-notice-spacing-token-small);padding-inline:var(--calcite-notice-spacing-token-large);flex:0 0 auto}.notice-close{display:flex;cursor:pointer;align-items:center;align-self:stretch;border-style:none;background-color:transparent;color:var(--calcite-ui-text-3);outline:2px solid transparent;outline-offset:2px;box-sizing:border-box;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;padding-block:var(--calcite-notice-spacing-token-small);padding-inline:var(--calcite-notice-spacing-token-large);flex:0 0 auto;-webkit-appearance:none}.notice-close:hover,.notice-close:focus{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1)}.notice-close:active{background-color:var(--calcite-ui-foreground-3)}.actions-end{display:flex;align-self:stretch}:host([color=blue]) .container{border-color:var(--calcite-ui-brand)}:host([color=blue]) .container .notice-icon{color:var(--calcite-ui-brand)}:host([color=red]) .container{border-color:var(--calcite-ui-danger)}:host([color=red]) .container .notice-icon{color:var(--calcite-ui-danger)}:host([color=yellow]) .container{border-color:var(--calcite-ui-warning)}:host([color=yellow]) .container .notice-icon{color:var(--calcite-ui-warning)}:host([color=green]) .container{border-color:var(--calcite-ui-success)}:host([color=green]) .container .notice-icon{color:var(--calcite-ui-success)}";
  28. const Notice = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  29. constructor() {
  30. super();
  31. this.__registerHost();
  32. this.__attachShadow();
  33. this.calciteNoticeClose = createEvent(this, "calciteNoticeClose", 6);
  34. this.calciteNoticeOpen = createEvent(this, "calciteNoticeOpen", 6);
  35. //--------------------------------------------------------------------------
  36. //
  37. // Properties
  38. //
  39. //---------------------------------------------------------------------------
  40. /**
  41. * When `true`, the component is active.
  42. *
  43. * @deprecated Use `open` instead.
  44. */
  45. this.active = false;
  46. /** When `true`, the component is visible. */
  47. this.open = false;
  48. /** The color for the component's top border and icon. */
  49. this.color = "blue";
  50. /**
  51. * When `true`, a close button is added to the component.
  52. *
  53. * @deprecated use `closable` instead.
  54. */
  55. this.dismissible = false;
  56. /** When `true`, a close button is added to the component. */
  57. this.closable = false;
  58. /**
  59. * Accessible name for the close button.
  60. *
  61. * @default "Close"
  62. */
  63. this.intlClose = TEXT.close;
  64. /** Specifies the size of the component. */
  65. this.scale = "m";
  66. /** Specifies the width of the component. */
  67. this.width = "auto";
  68. //--------------------------------------------------------------------------
  69. //
  70. // Private Methods
  71. //
  72. //--------------------------------------------------------------------------
  73. this.close = () => {
  74. this.open = false;
  75. this.calciteNoticeClose.emit();
  76. };
  77. }
  78. activeHandler(value) {
  79. this.open = value;
  80. }
  81. openHandler(value) {
  82. this.active = value;
  83. }
  84. handleDismissible(value) {
  85. this.closable = value;
  86. }
  87. handleClosable(value) {
  88. this.dismissible = value;
  89. }
  90. updateRequestedIcon() {
  91. this.requestedIcon = setRequestedIcon(StatusIcons, this.icon, this.color);
  92. }
  93. //--------------------------------------------------------------------------
  94. //
  95. // Lifecycle
  96. //
  97. //--------------------------------------------------------------------------
  98. connectedCallback() {
  99. connectConditionalSlotComponent(this);
  100. const isOpen = this.active || this.open;
  101. if (isOpen) {
  102. this.activeHandler(isOpen);
  103. this.openHandler(isOpen);
  104. }
  105. if (this.dismissible) {
  106. this.handleDismissible(this.dismissible);
  107. }
  108. if (this.closable) {
  109. this.handleClosable(this.closable);
  110. }
  111. }
  112. disconnectedCallback() {
  113. disconnectConditionalSlotComponent(this);
  114. }
  115. componentWillLoad() {
  116. this.requestedIcon = setRequestedIcon(StatusIcons, this.icon, this.color);
  117. }
  118. render() {
  119. const { el } = this;
  120. 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" })));
  121. const hasActionEnd = getSlotted(el, SLOTS.actionsEnd);
  122. 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));
  123. }
  124. //--------------------------------------------------------------------------
  125. //
  126. // Public Methods
  127. //
  128. //--------------------------------------------------------------------------
  129. /** Sets focus on the component. */
  130. async setFocus() {
  131. const noticeLinkEl = this.el.querySelector("calcite-link");
  132. if (!this.closeButton && !noticeLinkEl) {
  133. return;
  134. }
  135. if (noticeLinkEl) {
  136. noticeLinkEl.setFocus();
  137. }
  138. else if (this.closeButton) {
  139. this.closeButton.focus();
  140. }
  141. }
  142. get el() { return this; }
  143. static get watchers() { return {
  144. "active": ["activeHandler"],
  145. "open": ["openHandler"],
  146. "dismissible": ["handleDismissible"],
  147. "closable": ["handleClosable"],
  148. "icon": ["updateRequestedIcon"],
  149. "color": ["updateRequestedIcon"]
  150. }; }
  151. static get style() { return noticeCss; }
  152. }, [1, "calcite-notice", {
  153. "active": [1540],
  154. "open": [1540],
  155. "color": [513],
  156. "dismissible": [516],
  157. "closable": [516],
  158. "icon": [520],
  159. "intlClose": [1, "intl-close"],
  160. "scale": [513],
  161. "width": [513],
  162. "setFocus": [64]
  163. }]);
  164. function defineCustomElement$1() {
  165. if (typeof customElements === "undefined") {
  166. return;
  167. }
  168. const components = ["calcite-notice", "calcite-icon"];
  169. components.forEach(tagName => { switch (tagName) {
  170. case "calcite-notice":
  171. if (!customElements.get(tagName)) {
  172. customElements.define(tagName, Notice);
  173. }
  174. break;
  175. case "calcite-icon":
  176. if (!customElements.get(tagName)) {
  177. defineCustomElement$2();
  178. }
  179. break;
  180. } });
  181. }
  182. defineCustomElement$1();
  183. const CalciteNotice = Notice;
  184. const defineCustomElement = defineCustomElement$1;
  185. export { CalciteNotice, defineCustomElement };