1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import TComponent from '../common/component';
- import config from '../common/config';
- const { prefix } = config;
- const name = `${prefix}-dropdown-menu`;
- TComponent({
- properties: {
- overlay: {
- type: Boolean,
- value: true,
- },
- duration: {
- type: Number,
- value: 200,
- },
- closeOnClickOverlay: {
- type: Boolean,
- value: true,
- },
- },
- data: {
- classBasePrefix: prefix,
- classPrefix: name,
- nodes: null,
- menus: null,
- activeIdx: -1,
- bottom: 0,
- },
- relations: {
- './dropdown-item': {
- type: 'child',
- },
- },
- methods: {
- _getAllItems() {
- const nodes = this.getRelationNodes('./dropdown-item');
- const menus = nodes.map((a) => {
- const { title, disabled } = a.data;
- return { title, disabled };
- });
- this.setData({
- nodes,
- menus,
- });
- },
- _toggleDropdown(e) {
- const idx = e.target.dataset.index;
- const { activeIdx } = this.data;
- if (activeIdx !== -1) {
- this.triggerEvent('close');
- this.data.nodes[activeIdx].setData({
- show: false,
- });
- this.triggerEvent('closed');
- }
- if (activeIdx === idx) {
- this.setData({
- activeIdx: -1,
- });
- }
- else {
- this.triggerEvent('open');
- this.setData({
- activeIdx: idx,
- });
- this.data.nodes[idx].setData({
- show: true,
- });
- this.triggerEvent('opened');
- }
- },
- },
- ready() {
- this._getAllItems();
- },
- });
- //# sourceMappingURL=dropdown-menu.js.map
|