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,321 @@
import './number-input.sass';
import { FunctionN } from 'fp-ts/lib/function';
import { VNode, PropType, ExtractPropTypes } from 'vue';
import { InputIcons, NumberInputIcons } from '../shared/types';
export declare type BNumberInputControlsPosition = 'compact' | '';
declare const BNumberInputPropsDefinition: {
min: {
type: PropType<number>;
default: number;
};
max: {
type: PropType<number>;
default: number;
};
step: {
type: PropType<number>;
default: number;
};
displayControls: {
type: PropType<boolean>;
default: boolean;
};
controlsRounded: {
type: PropType<boolean>;
default: boolean;
};
controlsPosition: {
type: PropType<BNumberInputControlsPosition>;
default: "";
};
inputIcons: {
type: PropType<InputIcons>;
default: import("fp-ts/lib/function").Lazy<InputIcons>;
};
numberInputIcons: {
type: PropType<NumberInputIcons>;
default: import("fp-ts/lib/function").Lazy<NumberInputIcons>;
};
isFocused: {
type: PropType<boolean>;
default: boolean;
};
onFocus: {
type: PropType<(e?: Event | undefined) => void>;
required: false;
};
onBlur: {
type: PropType<(e?: Event | undefined) => void>;
required: false;
};
focusOnMount: {
type: PropType<boolean>;
default: boolean;
};
isDisabled: {
type: PropType<boolean>;
required: boolean;
default: boolean;
};
isReadonly: {
type: PropType<boolean>;
required: boolean;
default: boolean;
};
disableIfReadonly: {
type: PropType<boolean>;
required: boolean;
default: boolean;
};
useNativeValidation: {
type: PropType<boolean>;
default: boolean;
};
isValid: {
type: PropType<boolean>;
default: boolean;
};
'onUpdate:isValid': {
type: PropType<FunctionN<[boolean], void>>;
default: import("fp-ts/lib/function").Lazy<() => void>;
};
variant: {
type: PropType<import("../../..").ColorVariant>;
default: "";
};
type: {
type: PropType<string>;
};
autocomplete: {
type: PropType<string>;
};
placeholder: {
type: PropType<string>;
};
size: {
type: PropType<import("../../..").SizeVariant>;
default: import("../../..").SizeVariant;
};
isRequired: {
type: BooleanConstructor;
default: boolean;
};
isExpanded: {
type: PropType<boolean>;
default: boolean;
};
isLoading: {
type: PropType<boolean>;
default: boolean;
};
isRounded: {
type: PropType<boolean>;
default: boolean;
};
maxlength: {
type: PropType<string | number>;
};
icon: null;
usePasswordReveal: {
type: PropType<boolean>;
default: undefined;
};
modelValue: {
type: PropType<number>;
required: false;
};
'onUpdate:modelValue': {
type: PropType<FunctionN<[number], void>>;
default: import("fp-ts/lib/function").Lazy<FunctionN<[number], void>>;
};
};
export declare type BNumberInputProps = ExtractPropTypes<typeof BNumberInputPropsDefinition>;
export declare function getNumberInputIcons(icons: Partial<NumberInputIcons>): NumberInputIcons;
declare const _default: import("vue").DefineComponent<{
min: {
type: PropType<number>;
default: number;
};
max: {
type: PropType<number>;
default: number;
};
step: {
type: PropType<number>;
default: number;
};
displayControls: {
type: PropType<boolean>;
default: boolean;
};
controlsRounded: {
type: PropType<boolean>;
default: boolean;
};
controlsPosition: {
type: PropType<BNumberInputControlsPosition>;
default: "";
};
inputIcons: {
type: PropType<InputIcons>;
default: import("fp-ts/lib/function").Lazy<InputIcons>;
};
numberInputIcons: {
type: PropType<NumberInputIcons>;
default: import("fp-ts/lib/function").Lazy<NumberInputIcons>;
};
isFocused: {
type: PropType<boolean>;
default: boolean;
};
onFocus: {
type: PropType<(e?: Event | undefined) => void>;
required: false;
};
onBlur: {
type: PropType<(e?: Event | undefined) => void>;
required: false;
};
focusOnMount: {
type: PropType<boolean>;
default: boolean;
};
isDisabled: {
type: PropType<boolean>;
required: boolean;
default: boolean;
};
isReadonly: {
type: PropType<boolean>;
required: boolean;
default: boolean;
};
disableIfReadonly: {
type: PropType<boolean>;
required: boolean;
default: boolean;
};
useNativeValidation: {
type: PropType<boolean>;
default: boolean;
};
isValid: {
type: PropType<boolean>;
default: boolean;
};
'onUpdate:isValid': {
type: PropType<FunctionN<[boolean], void>>;
default: import("fp-ts/lib/function").Lazy<() => void>;
};
variant: {
type: PropType<import("../../..").ColorVariant>;
default: "";
};
type: {
type: PropType<string>;
};
autocomplete: {
type: PropType<string>;
};
placeholder: {
type: PropType<string>;
};
size: {
type: PropType<import("../../..").SizeVariant>;
default: import("../../..").SizeVariant;
};
isRequired: {
type: BooleanConstructor;
default: boolean;
};
isExpanded: {
type: PropType<boolean>;
default: boolean;
};
isLoading: {
type: PropType<boolean>;
default: boolean;
};
isRounded: {
type: PropType<boolean>;
default: boolean;
};
maxlength: {
type: PropType<string | number>;
};
icon: null;
usePasswordReveal: {
type: PropType<boolean>;
default: undefined;
};
modelValue: {
type: PropType<number>;
required: false;
};
'onUpdate:modelValue': {
type: PropType<FunctionN<[number], void>>;
default: import("fp-ts/lib/function").Lazy<FunctionN<[number], void>>;
};
}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}>, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{
variant: import("../../..").ColorVariant;
size: import("../../..").SizeVariant;
isExpanded: boolean;
isRounded: boolean;
isLoading: boolean;
isFocused: boolean;
isDisabled: boolean;
focusOnMount: boolean;
"onUpdate:modelValue": FunctionN<[number], void>;
isReadonly: boolean;
disableIfReadonly: boolean;
useNativeValidation: boolean;
isValid: boolean;
"onUpdate:isValid": FunctionN<[boolean], void>;
isRequired: boolean;
usePasswordReveal: boolean;
inputIcons: InputIcons;
min: number;
max: number;
step: number;
displayControls: boolean;
controlsRounded: boolean;
controlsPosition: BNumberInputControlsPosition;
numberInputIcons: NumberInputIcons;
} & {
icon?: any;
type?: string | undefined;
onFocus?: ((e?: Event | undefined) => void) | undefined;
onBlur?: ((e?: Event | undefined) => void) | undefined;
modelValue?: number | undefined;
autocomplete?: string | undefined;
placeholder?: string | undefined;
maxlength?: string | number | undefined;
}>, {
variant: import("../../..").ColorVariant;
size: import("../../..").SizeVariant;
isExpanded: boolean;
isRounded: boolean;
isLoading: boolean;
isFocused: boolean;
isDisabled: boolean;
focusOnMount: boolean;
"onUpdate:modelValue": FunctionN<[number], void>;
isReadonly: boolean;
disableIfReadonly: boolean;
useNativeValidation: boolean;
isValid: boolean;
"onUpdate:isValid": FunctionN<[boolean], void>;
isRequired: boolean;
usePasswordReveal: boolean;
inputIcons: InputIcons;
min: number;
max: number;
step: number;
displayControls: boolean;
controlsRounded: boolean;
controlsPosition: BNumberInputControlsPosition;
numberInputIcons: NumberInputIcons;
}>;
export default _default;

View File

@@ -0,0 +1,152 @@
import "../../../../src/components/form/numberInput/number-input.sass";
import { getUseInputPropsDefinition } from '../../../composables/input/useInput';
import { constant } from 'fp-ts/lib/function';
import { h, defineComponent, defineAsyncComponent, computed, toRef } from 'vue';
import { useProxy } from '../../../composables/proxy';
import { isNumber, isString } from '../../../utils/helpers';
import BButton from '../../button/BButton';
import { BInput } from '../input/BInput';
import { DEFAULT_INPUT_ICONS } from '../shared/types';
const DEFAULT_NUMBER_INPUT_ICONS = {
minus: defineAsyncComponent(() => import('../../icons/minus')),
plus: defineAsyncComponent(() => import('../../icons/plus'))
};
const BNumberInputPropsDefinition = { ...getUseInputPropsDefinition(),
min: {
type: Number,
default: Number.MIN_SAFE_INTEGER
},
max: {
type: Number,
default: Number.MAX_SAFE_INTEGER
},
step: {
type: Number,
default: 1
},
displayControls: {
type: Boolean,
default: true
},
controlsRounded: {
type: Boolean,
default: false
},
controlsPosition: {
type: String,
default: ''
},
inputIcons: {
type: Object,
default: constant(DEFAULT_INPUT_ICONS)
},
numberInputIcons: {
type: Object,
default: constant(DEFAULT_NUMBER_INPUT_ICONS)
}
};
export function getNumberInputIcons(icons) {
return { ...DEFAULT_NUMBER_INPUT_ICONS,
...icons
};
}
function getFieldClasses(controlsPosition, isExpanded) {
const isCompact = controlsPosition === 'compact';
return {
'is-expanded': isExpanded,
'has-addons': isCompact,
'is-grouped': !isCompact
};
}
function generateControl(props, data, isDecrement) {
return h('p', {
class: 'control'
}, [h(BButton, {
variant: props.variant || 'is-primary',
size: props.size,
isRounded: props.controlsRounded,
isDisabled: isDecrement ? !data.canDecrement.value : !data.canIncrement.value,
onClick: isDecrement ? data.onDecrement : data.onIncrement
}, () => h(isDecrement ? props.numberInputIcons.minus : props.numberInputIcons.plus, {
size: props.size
}))]);
}
function generateInput(props, data, context) {
return h(BInput, { ...context.attrs,
modelValue: data.number.value,
'onUpdate:modelValue': data.set,
type: 'number',
size: props.size,
placeholder: props.placeholder ? `${props.placeholder}` : '',
isDisabled: props.isDisabled,
inputIcons: props.inputIcons,
isReadonly: props.isReadonly,
isLoading: props.isLoading,
isRounded: props.isRounded,
icon: props.icon,
isExpanded: props.isExpanded,
step: props.step,
max: props.max,
min: props.min
});
}
export default defineComponent({
name: 'b-number-input',
props: BNumberInputPropsDefinition,
setup(props, context) {
const {
value: number
} = useProxy(toRef(props, 'modelValue'), toRef(props, 'onUpdate:modelValue'));
const defaultMin = computed(() => props.min === Number.MIN_SAFE_INTEGER ? 0 : props.min);
const defaultMax = computed(() => props.max === Number.MAX_SAFE_INTEGER ? 0 : props.max);
const canDecrement = computed(() => (number.value ?? defaultMax.value) - props.step >= props.min);
function onDecrement() {
if (canDecrement.value) {
number.value = (number.value ?? 0) - props.step;
}
}
const canIncrement = computed(() => (props.modelValue ?? defaultMin.value) + props.step <= props.max);
function onIncrement() {
if (canIncrement.value) {
number.value = (number.value ?? 0) + props.step;
}
}
function set(val) {
if (isString(val)) {
const x = Number.parseFloat(val);
if (Number.isNaN(x)) return;
number.value = x;
}
if (isNumber(val)) {
number.value = val;
}
}
const data = {
set,
number,
canDecrement,
canIncrement,
onDecrement,
onIncrement
};
return () => {
const nodes = props.displayControls ? [generateControl(props, data, true), generateInput(props, data, context), generateControl(props, data, false)] : [generateInput(props, data, context)];
return h('div', {
class: ['b-number-input field', getFieldClasses(props.controlsPosition, props.isExpanded)]
}, nodes);
};
}
});
//# sourceMappingURL=BNumberInput.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
import BNumberInput from './BNumberInput';
export { BNumberInput };
export default BNumberInput;

View File

@@ -0,0 +1,4 @@
import BNumberInput from './BNumberInput';
export { BNumberInput };
export default BNumberInput;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/components/form/numberInput/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAP,MAAyB,gBAAzB;AAEA,SAAS,YAAT;AAEA,eAAe,YAAf","sourcesContent":["import BNumberInput from './BNumberInput';\n\nexport { BNumberInput };\n\nexport default BNumberInput;\n"],"sourceRoot":"","file":"index.js"}