index.js 990 B

123456789101112131415161718192021222324252627282930313233
  1. import { useEvent } from 'functional-mini/component';
  2. import '../_util/assert-component2';
  3. import { mountComponent } from '../_util/component';
  4. import { useComponentEvent } from '../_util/hooks/useComponentEvent';
  5. import { useMixState } from '../_util/hooks/useMixState';
  6. var Radio = function (props) {
  7. var _a = useMixState(props.defaultChecked, {
  8. value: props.checked,
  9. }), radioValue = _a[0], _b = _a[1], isControlled = _b.isControlled, update = _b.update;
  10. var triggerEvent = useComponentEvent(props).triggerEvent;
  11. useEvent('handleTap', function (e) {
  12. // 只能从 false -> true
  13. if (radioValue) {
  14. return;
  15. }
  16. if (!isControlled) {
  17. update(true);
  18. }
  19. triggerEvent('change', true, e);
  20. });
  21. return {
  22. mixin: {
  23. value: radioValue,
  24. },
  25. };
  26. };
  27. mountComponent(Radio, {
  28. value: null,
  29. defaultChecked: null,
  30. color: '',
  31. checked: null,
  32. disabled: false,
  33. });