design-system-next 2.26.2 → 2.26.3

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.
@@ -1,60 +1,60 @@
1
- import type { PropType, ExtractPropTypes } from 'vue';
2
- import type { MenuListType } from '../list';
3
-
4
- export const listItemPropTypes = {
5
- item: {
6
- type: Object as PropType<MenuListType>,
7
- required: true,
8
- },
9
- isSelected: {
10
- type: Boolean,
11
- required: true,
12
- },
13
- classes: {
14
- type: [String, Array, Object] as PropType<string | string[] | Record<string, boolean>>,
15
- required: true,
16
- },
17
- multiSelect: {
18
- type: Boolean,
19
- default: false,
20
- },
21
- lozenge: {
22
- type: Boolean,
23
- default: false,
24
- },
25
- ladderized: {
26
- type: Boolean,
27
- default: false,
28
- },
29
- noCheck: {
30
- type: Boolean,
31
- default: false,
32
- },
33
- itemIcon: {
34
- type: String,
35
- default: '',
36
- },
37
- itemIconTone: {
38
- type: String,
39
- default: 'plain',
40
- },
41
- itemIconFill: {
42
- type: Boolean,
43
- default: false,
44
- },
45
- disabledUnselectedItems: {
46
- type: Boolean,
47
- default: false,
48
- },
49
- radioList: {
50
- type: Boolean,
51
- default: false,
52
- },
53
- };
54
-
55
- export const listItemEmitTypes = {
56
- select: () => true,
57
- };
58
-
59
- export type ListItemPropTypes = ExtractPropTypes<typeof listItemPropTypes>;
60
- export type ListItemEmitTypes = typeof listItemEmitTypes;
1
+ import type { PropType, ExtractPropTypes } from 'vue';
2
+ import type { MenuListType } from '../list';
3
+
4
+ export const listItemPropTypes = {
5
+ item: {
6
+ type: Object as PropType<MenuListType>,
7
+ required: true,
8
+ },
9
+ isSelected: {
10
+ type: Boolean,
11
+ required: true,
12
+ },
13
+ classes: {
14
+ type: [String, Array, Object] as PropType<string | string[] | Record<string, boolean>>,
15
+ required: true,
16
+ },
17
+ multiSelect: {
18
+ type: Boolean,
19
+ default: false,
20
+ },
21
+ lozenge: {
22
+ type: Boolean,
23
+ default: false,
24
+ },
25
+ ladderized: {
26
+ type: Boolean,
27
+ default: false,
28
+ },
29
+ noCheck: {
30
+ type: Boolean,
31
+ default: false,
32
+ },
33
+ itemIcon: {
34
+ type: String,
35
+ default: '',
36
+ },
37
+ itemIconTone: {
38
+ type: String,
39
+ default: 'plain',
40
+ },
41
+ itemIconFill: {
42
+ type: Boolean,
43
+ default: false,
44
+ },
45
+ disabledUnselectedItems: {
46
+ type: Boolean,
47
+ default: false,
48
+ },
49
+ radioList: {
50
+ type: Boolean,
51
+ default: false,
52
+ },
53
+ };
54
+
55
+ export const listItemEmitTypes = {
56
+ select: () => true,
57
+ };
58
+
59
+ export type ListItemPropTypes = ExtractPropTypes<typeof listItemPropTypes>;
60
+ export type ListItemEmitTypes = typeof listItemEmitTypes;
@@ -375,7 +375,7 @@ export const useList = (props: ListPropTypes, emit: SetupContext<ListEmitTypes>[
375
375
  const getListItemClasses = (item: MenuListType) => ({
376
376
  [listClasses.value.listItemClasses]: !item.disabled && !(disabledUnselectedItems.value && !isItemSelected(item)),
377
377
  'spr-background-color-single-active': isItemSelected(item) && !item.disabled && !noCheck.value,
378
- 'spr-cursor-not-allowed spr-flex spr-items-center spr-gap-1.5 spr-rounded-lg':
378
+ 'spr-cursor-not-allowed spr-flex spr-items-center spr-justify-between spr-gap-1.5 spr-rounded-lg':
379
379
  item.disabled || (disabledUnselectedItems.value && !isItemSelected(item)),
380
380
  'spr-p-size-spacing-3xs': !props.lozenge,
381
381
  'spr-py-size-spacing-3xs spr-px-size-spacing-4xs': props.lozenge,
@@ -527,13 +527,13 @@ export const useList = (props: ListPropTypes, emit: SetupContext<ListEmitTypes>[
527
527
  } else {
528
528
  handleSingleSelect(item);
529
529
  }
530
- }
530
+ }
531
531
  };
532
532
 
533
533
  const handleDeselect = (item: MenuListType) => {
534
534
  if (selectedItems.value.length === 0 || !isItemSelected(item)) {
535
- selectedItems.value = [item];
536
- emit('get-single-selected-item', item);
535
+ selectedItems.value = [item];
536
+ emit('get-single-selected-item', item);
537
537
  } else {
538
538
  selectedItems.value = [];
539
539
  emit('get-single-deselected-item', item);
@@ -542,8 +542,8 @@ export const useList = (props: ListPropTypes, emit: SetupContext<ListEmitTypes>[
542
542
 
543
543
  const handleSingleSelect = (item: MenuListType) => {
544
544
  selectedItems.value = [item];
545
- if (item.onClickFn) item.onClickFn();
546
- emit('get-single-selected-item', item);
545
+ if (item.onClickFn) item.onClickFn();
546
+ emit('get-single-selected-item', item);
547
547
  };
548
548
  // #endregion - Helper Methods
549
549
 
@@ -1,65 +1,74 @@
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;
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
+ description?: string;
10
+ }
11
+
12
+ export const radioGroupedPropTypes = {
13
+ id: {
14
+ type: String,
15
+ required: true,
16
+ },
17
+ modelValue: {
18
+ type: [String, Number, Boolean],
19
+ },
20
+ name: {
21
+ type: String,
22
+ required: true,
23
+ },
24
+ options: {
25
+ type: Array as PropType<RadioOption[]>,
26
+ required: true,
27
+ default: () => [],
28
+ },
29
+ disabled: {
30
+ type: Boolean,
31
+ default: false,
32
+ },
33
+ description: {
34
+ type: String,
35
+ },
36
+ fullWidth: {
37
+ type: Boolean,
38
+ default: false,
39
+ },
40
+ bordered: {
41
+ type: Boolean,
42
+ default: false,
43
+ },
44
+ displayHelper: {
45
+ type: Boolean,
46
+ default: false,
47
+ },
48
+ helperIcon: {
49
+ type: String,
50
+ default: null,
51
+ },
52
+ helperText: {
53
+ type: String,
54
+ default: '',
55
+ },
56
+ error: {
57
+ type: Boolean,
58
+ default: false,
59
+ },
60
+ horizontalAlign: {
61
+ type: String as PropType<'left' | 'center' | 'right'>,
62
+ default: 'left',
63
+ },
64
+ choiceBox: {
65
+ type: Boolean,
66
+ default: false,
67
+ },
68
+ };
69
+
70
+ export const radioGroupedEmitTypes = ['update:modelValue'];
71
+
72
+ export type RadioGroupedPropTypes = ExtractPropTypes<typeof radioGroupedPropTypes>;
73
+
74
+ export type RadioGroupedEmitTypes = typeof radioGroupedEmitTypes;
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div :class="['spr-relative']">
2
+ <div :class="['spr-relative', { 'spr-w-full': props.choiceBox || props.fullWidth }]">
3
3
  <div :class="radioGroupedClasses.containerClasses">
4
4
  <spr-radio
5
5
  v-for="(option, index) in renderOptions()"
@@ -9,6 +9,9 @@
9
9
  :name="props.name"
10
10
  :value="option.value"
11
11
  :disabled="isOptionDisabled(option)"
12
+ :choice-box="props.choiceBox"
13
+ :full-width="props.fullWidth || props.choiceBox"
14
+ :description="option.description"
12
15
  >
13
16
  {{ option.text }}
14
17
  </spr-radio>
@@ -1,62 +1,63 @@
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
- };
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, choiceBox } = 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
+ choiceBox,
62
+ };
63
+ };
@@ -33,6 +33,10 @@ export const radioPropTypes = {
33
33
  type: Boolean,
34
34
  default: false,
35
35
  },
36
+ choiceBox: {
37
+ type: Boolean,
38
+ default: false,
39
+ },
36
40
  };
37
41
 
38
42
  export const radioEmitTypes = ['update:modelValue'];
@@ -1,5 +1,10 @@
1
1
  <template>
2
- <div :class="['spr-relative', { 'spr-w-full': props.fullWidth }]">
2
+ <div
3
+ :class="radioClasses.baseClasses"
4
+ @click="radioRef?.click()"
5
+ @mouseenter="isHovered = true"
6
+ @mouseleave="isHovered = false"
7
+ >
3
8
  <input
4
9
  :id="props.id"
5
10
  ref="radioRef"
@@ -8,7 +13,7 @@
8
13
  :name="props.name"
9
14
  :value="props.value"
10
15
  :disabled="props.disabled"
11
- :class="radioClasses.baseClasses"
16
+ :class="radioClasses.baseInputClasses"
12
17
  />
13
18
  <label
14
19
  ref="radioRef"
@@ -25,8 +30,9 @@
25
30
  'spr-text-xs spr-font-normal spr-leading-4 spr-text-mushroom-600',
26
31
  { 'spr-text-color-disabled': props.disabled },
27
32
  ]"
28
- >{{ props.description }}</span
29
33
  >
34
+ {{ props.description }}
35
+ </span>
30
36
  </div>
31
37
  </label>
32
38
  </div>
@@ -42,7 +48,7 @@ const props = defineProps(radioPropTypes);
42
48
  const emit = defineEmits(radioEmitTypes);
43
49
  const slots = useSlots();
44
50
 
45
- const { proxyValue, radioRef, radioClasses } = useRadioButton(props, emit, slots);
51
+ const { proxyValue, radioRef, radioClasses, isHovered } = useRadioButton(props, emit, slots);
46
52
  </script>
47
53
 
48
54
  <style scoped>
@@ -8,6 +8,7 @@ import type { RadioPropTypes, RadioEmitTypes } from './radio';
8
8
 
9
9
  interface RadioClasses {
10
10
  baseClasses: string;
11
+ baseInputClasses: string;
11
12
  baseIndicatorClasses: string;
12
13
  labelClasses: string;
13
14
  borderedClasses: string;
@@ -18,13 +19,24 @@ export const useRadioButton = (
18
19
  emit: SetupContext<RadioEmitTypes>['emit'],
19
20
  slots: Record<string, unknown>,
20
21
  ) => {
21
- const { modelValue, disabled, description, bordered, fullWidth } = toRefs(props);
22
+ const { modelValue, disabled, description, bordered, fullWidth, choiceBox } = toRefs(props);
22
23
 
23
24
  const radioRef = ref<HTMLInputElement | null>(null);
24
25
  const isHovered = useElementHover(radioRef);
25
26
 
26
27
  const radioClasses: ComputedRef<RadioClasses> = computed(() => {
27
- const baseClasses = classNames('spr-sr-only spr-peer spr-inline-block', {
28
+ const baseClasses = classNames('spr-relative spr-m-0', {
29
+ 'spr-inline-block': !choiceBox.value,
30
+ 'spr-block': choiceBox.value,
31
+ 'spr-w-full': fullWidth.value || choiceBox.value,
32
+ 'spr-align-middle': !choiceBox.value,
33
+ 'spr-border-color spr-border-color-weak spr-border spr-border-solid spr-p-2 spr-rounded-lg spr-transition spr-ease-in-out spr-duration-150 active:spr-scale-[0.98]':
34
+ choiceBox.value,
35
+ 'spr-cursor-pointer': choiceBox.value && !disabled.value,
36
+ 'spr-cursor-not-allowed': disabled.value && choiceBox.value,
37
+ });
38
+
39
+ const baseInputClasses = classNames('spr-sr-only spr-peer spr-inline-block', {
28
40
  'spr-cursor-not-allowed': disabled.value,
29
41
  });
30
42
 
@@ -121,6 +133,7 @@ export const useRadioButton = (
121
133
 
122
134
  return {
123
135
  baseClasses,
136
+ baseInputClasses,
124
137
  baseIndicatorClasses,
125
138
  labelClasses,
126
139
  borderedClasses,
@@ -132,6 +145,7 @@ export const useRadioButton = (
132
145
  return {
133
146
  radioRef,
134
147
  radioClasses,
148
+ isHovered,
135
149
  proxyValue,
136
150
  description,
137
151
  bordered,