picker-column-option.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
  5. import { d as inheritAttributes } from './helpers.js';
  6. import { c as createColorClasses } from './theme.js';
  7. import { b as getIonMode } from './ionic-global.js';
  8. const pickerColumnOptionIosCss = "button{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;width:100%;height:34px;border:0px;outline:none;background:transparent;color:inherit;font-family:var(--ion-font-family, inherit);font-size:inherit;line-height:34px;text-align:inherit;text-overflow:ellipsis;white-space:nowrap;cursor:pointer;overflow:hidden}:host(.option-disabled){opacity:0.4}:host(.option-disabled) button{cursor:default}";
  9. const IonPickerColumnOptionIosStyle0 = pickerColumnOptionIosCss;
  10. const pickerColumnOptionMdCss = "button{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;width:100%;height:34px;border:0px;outline:none;background:transparent;color:inherit;font-family:var(--ion-font-family, inherit);font-size:inherit;line-height:34px;text-align:inherit;text-overflow:ellipsis;white-space:nowrap;cursor:pointer;overflow:hidden}:host(.option-disabled){opacity:0.4}:host(.option-disabled) button{cursor:default}:host(.option-active){color:var(--ion-color-base)}";
  11. const IonPickerColumnOptionMdStyle0 = pickerColumnOptionMdCss;
  12. const PickerColumnOption = /*@__PURE__*/ proxyCustomElement(class PickerColumnOption extends HTMLElement {
  13. constructor() {
  14. super();
  15. this.__registerHost();
  16. this.__attachShadow();
  17. /**
  18. * We keep track of the parent picker column
  19. * so we can update the value of it when
  20. * clicking an enable option.
  21. */
  22. this.pickerColumn = null;
  23. this.ariaLabel = null;
  24. this.disabled = false;
  25. this.value = undefined;
  26. this.color = 'primary';
  27. }
  28. /**
  29. * The aria-label of the option has changed after the
  30. * first render and needs to be updated within the component.
  31. *
  32. * @param ariaLbl The new aria-label value.
  33. */
  34. onAriaLabelChange(ariaLbl) {
  35. this.ariaLabel = ariaLbl;
  36. }
  37. componentWillLoad() {
  38. const inheritedAttributes = inheritAttributes(this.el, ['aria-label']);
  39. /**
  40. * The initial value of `aria-label` needs to be set for
  41. * the first render.
  42. */
  43. this.ariaLabel = inheritedAttributes['aria-label'] || null;
  44. }
  45. connectedCallback() {
  46. this.pickerColumn = this.el.closest('ion-picker-column');
  47. }
  48. disconnectedCallback() {
  49. this.pickerColumn = null;
  50. }
  51. /**
  52. * The column options can load at any time
  53. * so the options needs to tell the
  54. * parent picker column when it is loaded
  55. * so the picker column can ensure it is
  56. * centered in the view.
  57. *
  58. * We intentionally run this for every
  59. * option. If we only ran this from
  60. * the selected option then if the newly
  61. * loaded options were not selected then
  62. * scrollActiveItemIntoView would not be called.
  63. */
  64. componentDidLoad() {
  65. const { pickerColumn } = this;
  66. if (pickerColumn !== null) {
  67. pickerColumn.scrollActiveItemIntoView();
  68. }
  69. }
  70. /**
  71. * When an option is clicked, update the
  72. * parent picker column value. This
  73. * component will handle centering the option
  74. * in the column view.
  75. */
  76. onClick() {
  77. const { pickerColumn } = this;
  78. if (pickerColumn !== null) {
  79. pickerColumn.setValue(this.value);
  80. }
  81. }
  82. render() {
  83. const { color, disabled, ariaLabel } = this;
  84. const mode = getIonMode(this);
  85. return (h(Host, { key: 'c1353e99c2aa19c0e3ddbe433557ed18e72e1c66', class: createColorClasses(color, {
  86. [mode]: true,
  87. ['option-disabled']: disabled,
  88. }) }, h("button", { key: 'b4ee62ecf7458a07a56e8aa494485766a87a3fcb', tabindex: "-1", "aria-label": ariaLabel, disabled: disabled, onClick: () => this.onClick() }, h("slot", { key: '9ab1e4700c27103b676670a4b3521c183c6ab83d' }))));
  89. }
  90. get el() { return this; }
  91. static get watchers() { return {
  92. "aria-label": ["onAriaLabelChange"]
  93. }; }
  94. static get style() { return {
  95. ios: IonPickerColumnOptionIosStyle0,
  96. md: IonPickerColumnOptionMdStyle0
  97. }; }
  98. }, [33, "ion-picker-column-option", {
  99. "disabled": [4],
  100. "value": [8],
  101. "color": [513],
  102. "ariaLabel": [32]
  103. }, undefined, {
  104. "aria-label": ["onAriaLabelChange"]
  105. }]);
  106. function defineCustomElement() {
  107. if (typeof customElements === "undefined") {
  108. return;
  109. }
  110. const components = ["ion-picker-column-option"];
  111. components.forEach(tagName => { switch (tagName) {
  112. case "ion-picker-column-option":
  113. if (!customElements.get(tagName)) {
  114. customElements.define(tagName, PickerColumnOption);
  115. }
  116. break;
  117. } });
  118. }
  119. export { PickerColumnOption as P, defineCustomElement as d };