ion-picker-column-option.entry.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import { r as registerInstance, h, e as Host, f as getElement } from './index-527b9e34.js';
  5. import { h as inheritAttributes } from './helpers-d94bc8ad.js';
  6. import { c as createColorClasses } from './theme-01f3f29c.js';
  7. import { b as getIonMode } from './ionic-global-b26f573e.js';
  8. import './index-cfd9c1f2.js';
  9. 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}";
  10. const IonPickerColumnOptionIosStyle0 = pickerColumnOptionIosCss;
  11. 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)}";
  12. const IonPickerColumnOptionMdStyle0 = pickerColumnOptionMdCss;
  13. const PickerColumnOption = class {
  14. constructor(hostRef) {
  15. registerInstance(this, hostRef);
  16. /**
  17. * We keep track of the parent picker column
  18. * so we can update the value of it when
  19. * clicking an enable option.
  20. */
  21. this.pickerColumn = null;
  22. this.ariaLabel = null;
  23. this.disabled = false;
  24. this.value = undefined;
  25. this.color = 'primary';
  26. }
  27. /**
  28. * The aria-label of the option has changed after the
  29. * first render and needs to be updated within the component.
  30. *
  31. * @param ariaLbl The new aria-label value.
  32. */
  33. onAriaLabelChange(ariaLbl) {
  34. this.ariaLabel = ariaLbl;
  35. }
  36. componentWillLoad() {
  37. const inheritedAttributes = inheritAttributes(this.el, ['aria-label']);
  38. /**
  39. * The initial value of `aria-label` needs to be set for
  40. * the first render.
  41. */
  42. this.ariaLabel = inheritedAttributes['aria-label'] || null;
  43. }
  44. connectedCallback() {
  45. this.pickerColumn = this.el.closest('ion-picker-column');
  46. }
  47. disconnectedCallback() {
  48. this.pickerColumn = null;
  49. }
  50. /**
  51. * The column options can load at any time
  52. * so the options needs to tell the
  53. * parent picker column when it is loaded
  54. * so the picker column can ensure it is
  55. * centered in the view.
  56. *
  57. * We intentionally run this for every
  58. * option. If we only ran this from
  59. * the selected option then if the newly
  60. * loaded options were not selected then
  61. * scrollActiveItemIntoView would not be called.
  62. */
  63. componentDidLoad() {
  64. const { pickerColumn } = this;
  65. if (pickerColumn !== null) {
  66. pickerColumn.scrollActiveItemIntoView();
  67. }
  68. }
  69. /**
  70. * When an option is clicked, update the
  71. * parent picker column value. This
  72. * component will handle centering the option
  73. * in the column view.
  74. */
  75. onClick() {
  76. const { pickerColumn } = this;
  77. if (pickerColumn !== null) {
  78. pickerColumn.setValue(this.value);
  79. }
  80. }
  81. render() {
  82. const { color, disabled, ariaLabel } = this;
  83. const mode = getIonMode(this);
  84. return (h(Host, { key: 'c1353e99c2aa19c0e3ddbe433557ed18e72e1c66', class: createColorClasses(color, {
  85. [mode]: true,
  86. ['option-disabled']: disabled,
  87. }) }, h("button", { key: 'b4ee62ecf7458a07a56e8aa494485766a87a3fcb', tabindex: "-1", "aria-label": ariaLabel, disabled: disabled, onClick: () => this.onClick() }, h("slot", { key: '9ab1e4700c27103b676670a4b3521c183c6ab83d' }))));
  88. }
  89. get el() { return getElement(this); }
  90. static get watchers() { return {
  91. "aria-label": ["onAriaLabelChange"]
  92. }; }
  93. };
  94. PickerColumnOption.style = {
  95. ios: IonPickerColumnOptionIosStyle0,
  96. md: IonPickerColumnOptionMdStyle0
  97. };
  98. export { PickerColumnOption as ion_picker_column_option };