design-system-next 2.22.2 → 2.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -494,6 +494,7 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
494
494
  handleConvertMonthIfValid();
495
495
  calendarTabUpdateCalendar();
496
496
  emitDateFormats();
497
+ emitPartialInputValue();
497
498
 
498
499
  datePickerErrors.value = [];
499
500
 
@@ -563,6 +564,7 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
563
564
  handleConvertMonthIfValid();
564
565
  calendarTabUpdateCalendar();
565
566
  emitDateFormats();
567
+ emitPartialInputValue();
566
568
 
567
569
  datePickerErrors.value = [];
568
570
 
@@ -696,14 +698,8 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
696
698
 
697
699
  handleValidateDate();
698
700
 
699
- // Do not set yearInput when typing monthInput
700
- if (!monthInput.value && !dateInput.value && !yearInput.value) {
701
- emit('getInputValue', null);
702
- }
703
-
704
- if (monthInput.value && dateInput.value && yearInput.value) {
705
- emitInputValue();
706
- }
701
+ // Emit the partial date value as user types
702
+ emitPartialInputValue();
707
703
  };
708
704
 
709
705
  const handleDateInput = () => {
@@ -717,14 +713,8 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
717
713
 
718
714
  handleValidateDate();
719
715
 
720
- // Do not set yearInput when typing dateInput
721
- if (!monthInput.value && !dateInput.value && !yearInput.value) {
722
- emit('getInputValue', null);
723
- }
724
-
725
- if (monthInput.value && dateInput.value && yearInput.value) {
726
- emitInputValue();
727
- }
716
+ // Emit the partial date value as user types
717
+ emitPartialInputValue();
728
718
  };
729
719
 
730
720
  const handleYearInput = () => {
@@ -736,20 +726,8 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
736
726
 
737
727
  emit('getDateErrors', datePickerErrors.value);
738
728
 
739
- // Only validate year, do not set monthInput or dateInput
740
- // Only emit year-related changes
741
- // Only validate if yearInput is 4 digits (full year)
742
- if (yearInput.value.length === 4) {
743
- handleValidateDate();
744
-
745
- if (!monthInput.value && !dateInput.value && !yearInput.value) {
746
- emit('getInputValue', null);
747
- }
748
-
749
- if (monthInput.value && dateInput.value && yearInput.value) {
750
- emitInputValue();
751
- }
752
- }
729
+ // Emit the partial date value as user types
730
+ emitPartialInputValue();
753
731
  };
754
732
 
755
733
  const handleConvertMonthIfValid = () => {
@@ -846,6 +824,36 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
846
824
  }
847
825
  };
848
826
 
827
+ const emitPartialInputValue = () => {
828
+ // Convert month to numeric format if it's text
829
+ let emittedMonth = monthInput.value;
830
+
831
+ if (monthInput.value) {
832
+ const isNumeric = !isNaN(Number(monthInput.value)) && !isNaN(parseFloat(monthInput.value));
833
+
834
+ if (!isNumeric) {
835
+ const monthIsValid = monthsList.value.find(
836
+ (_month: MonthsList) => _month.text.toLowerCase() === monthInput.value.toLowerCase(),
837
+ );
838
+
839
+ if (monthIsValid) {
840
+ emittedMonth =
841
+ monthIsValid.monthValue < 10 ? `0${monthIsValid.monthValue + 1}` : `${monthIsValid.monthValue + 1}`;
842
+ }
843
+ }
844
+ }
845
+
846
+ // Build the partial date string with zeros for empty fields
847
+ const partialMonth = emittedMonth || '0';
848
+ const partialDate = dateInput.value || '0';
849
+ const partialYear = yearInput.value || '0';
850
+
851
+ const partialDateString = `${partialMonth}-${partialDate}-${partialYear}`;
852
+
853
+ // Emit the partial date string
854
+ emit('getInputValue', partialDateString);
855
+ };
856
+
849
857
  const emitDateFormats = () => {
850
858
  if (monthInput.value && dateInput.value && yearInput.value) {
851
859
  const monthIsValid = monthsList.value.find(
@@ -934,8 +942,8 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
934
942
  };
935
943
 
936
944
  const handleSlotClick = () => {
937
- if(disabled.value || readonly.value) return;
938
- datePopperState.value = true;
945
+ if (disabled.value || readonly.value) return;
946
+ datePopperState.value = true;
939
947
  };
940
948
 
941
949
  watch(datePopperState, (newValue) => {
@@ -1037,6 +1045,6 @@ export const useDatePicker = (props: DatePickerPropTypes, emit: SetupContext<Dat
1037
1045
  handleTabClick,
1038
1046
  handleBackspace,
1039
1047
  clearDate,
1040
- handleSlotClick
1048
+ handleSlotClick,
1041
1049
  };
1042
1050
  };
@@ -47,6 +47,22 @@ export const inputContactNumberPropTypes = {
47
47
  type: Boolean,
48
48
  default: false,
49
49
  },
50
+ displayHelper: {
51
+ type: Boolean,
52
+ default: false,
53
+ },
54
+ helperText: {
55
+ type: String,
56
+ default: '',
57
+ },
58
+ helperIcon: {
59
+ type: String,
60
+ default: null,
61
+ },
62
+ error: {
63
+ type: Boolean,
64
+ default: false,
65
+ },
50
66
  };
51
67
 
52
68
  export const inputContactNumberEmitTypes = {
@@ -6,6 +6,10 @@
6
6
  :placeholder="props.placeholder"
7
7
  :active="popperState"
8
8
  :disabled="props.disabled"
9
+ :display-helper="props.displayHelper"
10
+ :helper-text="props.helperText"
11
+ :helper-icon="props.helperIcon"
12
+ :error="props.error"
9
13
  @keyup="handleContactNumberInput"
10
14
  @blur="formatContactNumber"
11
15
  @update:model-value="handleUpdateModelValue"
@@ -29,6 +33,10 @@
29
33
  </div>
30
34
  </spr-dropdown>
31
35
  </template>
36
+
37
+ <template #helperMessage>
38
+ <slot name="helperMessage" />
39
+ </template>
32
40
  </spr-input>
33
41
  </template>
34
42
 
@@ -32,7 +32,7 @@ export const radioPropTypes = {
32
32
  fullWidth: {
33
33
  type: Boolean,
34
34
  default: false,
35
- }
35
+ },
36
36
  };
37
37
 
38
38
  export const radioEmitTypes = ['update:modelValue'];
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div :class="['spr-relative', { 'spr-w-full' : props.fullWidth }]">
2
+ <div :class="['spr-relative', { 'spr-w-full': props.fullWidth }]">
3
3
  <input
4
4
  :id="props.id"
5
5
  ref="radioRef"
@@ -21,7 +21,10 @@
21
21
  <slot />
22
22
  <span
23
23
  v-if="props.description && props.description !== ''"
24
- :class="['spr-text-xs spr-font-normal spr-leading-4 spr-text-mushroom-600', { 'spr-text-color-disabled' : props.disabled}]"
24
+ :class="[
25
+ 'spr-text-xs spr-font-normal spr-leading-4 spr-text-mushroom-600',
26
+ { 'spr-text-color-disabled': props.disabled },
27
+ ]"
25
28
  >{{ props.description }}</span
26
29
  >
27
30
  </div>
@@ -0,0 +1,65 @@
1
+ import type { PropType, ExtractPropTypes } from 'vue';
2
+
3
+ export const definePropType = <T>(val: unknown): PropType<T> => val as PropType<T>;
4
+
5
+ export interface RadioOption {
6
+ text: string;
7
+ value: string | number | boolean;
8
+ disabled?: boolean;
9
+ }
10
+
11
+ export const radioGroupedPropTypes = {
12
+ id: {
13
+ type: String,
14
+ required: true,
15
+ },
16
+ modelValue: {
17
+ type: [String, Number, Boolean],
18
+ },
19
+ name: {
20
+ type: String,
21
+ required: true,
22
+ },
23
+ options: {
24
+ type: Array as PropType<RadioOption[]>,
25
+ required: true,
26
+ default: () => [],
27
+ },
28
+ disabled: {
29
+ type: Boolean,
30
+ default: false,
31
+ },
32
+ description: {
33
+ type: String,
34
+ },
35
+ bordered: {
36
+ type: Boolean,
37
+ default: false,
38
+ },
39
+ displayHelper: {
40
+ type: Boolean,
41
+ default: false,
42
+ },
43
+ helperIcon: {
44
+ type: String,
45
+ default: null,
46
+ },
47
+ helperText: {
48
+ type: String,
49
+ default: '',
50
+ },
51
+ error: {
52
+ type: Boolean,
53
+ default: false,
54
+ },
55
+ horizontalAlign: {
56
+ type: String as PropType<'left' | 'center' | 'right'>,
57
+ default: 'left',
58
+ },
59
+ };
60
+
61
+ export const radioGroupedEmitTypes = ['update:modelValue'];
62
+
63
+ export type RadioGroupedPropTypes = ExtractPropTypes<typeof radioGroupedPropTypes>;
64
+
65
+ export type RadioGroupedEmitTypes = typeof radioGroupedEmitTypes;
@@ -0,0 +1,37 @@
1
+ <template>
2
+ <div :class="['spr-relative']">
3
+ <div :class="radioGroupedClasses.containerClasses">
4
+ <spr-radio
5
+ v-for="(option, index) in renderOptions()"
6
+ :id="`${props.id}-${index}`"
7
+ :key="`${props.id}-option-${index}`"
8
+ v-model="proxyValue"
9
+ :name="props.name"
10
+ :value="option.value"
11
+ :disabled="isOptionDisabled(option)"
12
+ >
13
+ {{ option.text }}
14
+ </spr-radio>
15
+ </div>
16
+
17
+ <div v-if="props.displayHelper" :class="radioGroupedClasses.helperClasses">
18
+ <slot name="helperMessage">
19
+ <Icon v-if="props.helperIcon" class="spr-h-5 spr-min-h-5 spr-w-5 spr-min-w-5" :icon="props.helperIcon" />
20
+ <span>{{ props.helperText }}</span>
21
+ </slot>
22
+ </div>
23
+ </div>
24
+ </template>
25
+
26
+ <script setup lang="ts">
27
+ import { Icon } from '@iconify/vue';
28
+ import SprRadio from '@/components/radio/radio.vue';
29
+
30
+ import { radioGroupedPropTypes, radioGroupedEmitTypes } from './radio-grouped';
31
+ import { useRadioGrouped } from './use-radio-grouped';
32
+
33
+ const props = defineProps(radioGroupedPropTypes);
34
+ const emit = defineEmits(radioGroupedEmitTypes);
35
+
36
+ const { radioGroupedClasses, proxyValue, renderOptions, isOptionDisabled } = useRadioGrouped(props, emit);
37
+ </script>
@@ -0,0 +1,62 @@
1
+ import { toRefs, computed, ComputedRef } from 'vue';
2
+ import { useVModel } from '@vueuse/core';
3
+
4
+ import classNames from 'classnames';
5
+
6
+ import type { SetupContext } from 'vue';
7
+ import type { RadioGroupedPropTypes, RadioGroupedEmitTypes, RadioOption } from './radio-grouped';
8
+
9
+ interface RadioGroupedClasses {
10
+ containerClasses: string;
11
+ helperClasses: string;
12
+ }
13
+
14
+ export const useRadioGrouped = (props: RadioGroupedPropTypes, emit: SetupContext<RadioGroupedEmitTypes>['emit']) => {
15
+ const { disabled, horizontalAlign, displayHelper, error } = toRefs(props);
16
+
17
+ const radioGroupedClasses: ComputedRef<RadioGroupedClasses> = computed(() => {
18
+ const alignmentMap = {
19
+ left: 'spr-justify-start',
20
+ center: 'spr-justify-center',
21
+ right: 'spr-justify-end',
22
+ };
23
+
24
+ const containerClasses = classNames('spr-flex spr-flex-col spr-gap-2', {
25
+ [alignmentMap[horizontalAlign.value as keyof typeof alignmentMap]]: true,
26
+ });
27
+
28
+ const helperClasses = classNames(
29
+ 'spr-flex spr-items-center spr-gap-1 spr-mt-size-spacing-2xs spr-body-sm-regular',
30
+ {
31
+ 'spr-text-mushroom-600': !error.value,
32
+ 'spr-text-color-danger-base': error.value,
33
+ },
34
+ );
35
+
36
+ return {
37
+ containerClasses,
38
+ helperClasses,
39
+ };
40
+ });
41
+
42
+ const proxyValue = useVModel(props, 'modelValue', emit);
43
+
44
+ const renderOptions = (): RadioOption[] => {
45
+ return props.options || [];
46
+ };
47
+
48
+ const isOptionDisabled = (option: RadioOption): boolean => {
49
+ return disabled.value || (option.disabled ?? false);
50
+ };
51
+
52
+ return {
53
+ radioGroupedClasses,
54
+ proxyValue,
55
+ renderOptions,
56
+ isOptionDisabled,
57
+ disabled,
58
+ displayHelper,
59
+ horizontalAlign,
60
+ error,
61
+ };
62
+ };