index.js 933 B

123456789101112131415161718192021222324252627282930
  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 Checkbox = function (props) {
  7. var _a = useMixState(props.defaultChecked, {
  8. value: props.checked,
  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 newValue = !value;
  13. if (!isControlled) {
  14. update(newValue);
  15. }
  16. triggerEvent('change', newValue, e);
  17. });
  18. return {
  19. mixin: {
  20. value: value,
  21. },
  22. };
  23. };
  24. mountComponent(Checkbox, {
  25. value: null,
  26. checked: null,
  27. defaultChecked: null,
  28. disabled: false,
  29. color: '',
  30. });