init component

This commit is contained in:
Robin COuret
2026-02-16 17:28:37 +01:00
parent 460c7a25e0
commit e0e50af706
4557 changed files with 666911 additions and 8 deletions

View File

@@ -0,0 +1,98 @@
import { constVoid } from 'fp-ts/lib/function';
import { inject, shallowRef, onUnmounted, computed } from 'vue';
import { formatTransition } from '../transition';
import { DEFAULT_NOTICE_CONTROLLER_INJECTION, NOTICE_CONTROLLER_SYMBOL } from './provideNoticeController';
export const UseNoticePropsDefinition = {
transition: {
type: [Object, String],
required: false
},
position: {
type: String,
default: 'is-bottom'
},
duration: {
type: Number,
default: 2000
},
message: {
type: String
},
shouldQueue: {
type: Boolean,
default: true
},
variant: {
type: String,
default: ''
},
isIndefinite: {
type: Boolean,
default: false
}
};
export const DEFAULT_USE_NOTICE_PROPS = {
position: UseNoticePropsDefinition.position.default,
duration: UseNoticePropsDefinition.duration.default,
shouldQueue: UseNoticePropsDefinition.shouldQueue.default,
variant: UseNoticePropsDefinition.variant.default,
isIndefinite: UseNoticePropsDefinition.isIndefinite.default
};
function useNoticeTransition(props = DEFAULT_USE_NOTICE_PROPS) {
return computed(() => {
if (props.transition) {
return formatTransition(props.transition);
} else {
switch (props.position) {
case 'is-top-right':
case 'is-top':
case 'is-top-left':
return {
'enter-active-class': 'fadeInDown',
'leave-active-class': 'fadeOutUp'
};
case 'is-bottom-right':
case 'is-bottom':
case 'is-bottom-left':
return {
'enter-active-class': 'fadeInUp',
'leave-active-class': 'fadeOutDown'
};
}
}
});
}
export function useNoticeController(props, render) {
const remove = shallowRef(constVoid);
const {
showNotice
} = inject(NOTICE_CONTROLLER_SYMBOL, DEFAULT_NOTICE_CONTROLLER_INJECTION);
const transition = useNoticeTransition(props);
onUnmounted(() => {
remove.value();
});
function open(options) {
const position = options.position ?? props.position;
remove.value();
remove.value = showNotice({
placement: position.includes('top') ? 'top' : 'bottom',
render: render.value(options),
transition: options.transition ?? transition.value,
shouldQueue: options.shouldQueue ?? props.shouldQueue,
duration: options.isIndefinite || props.isIndefinite ? 0 : options.duration ?? props.duration
});
}
return {
open: open,
close: () => {
remove.value();
remove.value = constVoid;
}
};
}
//# sourceMappingURL=useNoticeController.js.map