index.js 936 B

123456789101112131415161718192021222324252627
  1. import { useEvent } from 'functional-mini/component';
  2. import { mountComponent } from '../_util/component';
  3. import { useComponentEvent } from '../_util/hooks/useComponentEvent';
  4. import { useMixState } from '../_util/hooks/useMixState';
  5. import { TabBarFunctionalProps } from './props';
  6. var TabBar = function (props) {
  7. var _a = useMixState(props.defaultCurrent, {
  8. value: props.current,
  9. }), value = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
  10. var triggerEvent = useComponentEvent(props).triggerEvent;
  11. useEvent('onChange', function (e) {
  12. var index = e.currentTarget.dataset.index;
  13. if (index === value) {
  14. return;
  15. }
  16. if (!isControlled) {
  17. update(index);
  18. }
  19. triggerEvent('change', index, e);
  20. });
  21. return {
  22. mixin: {
  23. value: value,
  24. },
  25. };
  26. };
  27. mountComponent(TabBar, TabBarFunctionalProps);