ion-picker-column-option.cjs.entry.js 4.5 KB

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