tide-design-system 2.0.31 → 2.0.32

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.
package/package.json CHANGED
@@ -52,5 +52,5 @@
52
52
  "main": "dist/tide-design-system.cjs",
53
53
  "module": "dist/tide-design-system.esm.js",
54
54
  "types": "dist/tide-design-system.esm.d.ts",
55
- "version": "2.0.31"
55
+ "version": "2.0.32"
56
56
  }
@@ -2,6 +2,7 @@
2
2
  import { getCurrentInstance, computed, ref, watch } from 'vue';
3
3
 
4
4
  import type { SelectField } from '@/types/Field';
5
+ import type { SelectOption, SelectOptionGroup } from '@/types/Select';
5
6
 
6
7
  import TideIcon from '@/components/TideIcon.vue';
7
8
  import { CSS } from '@/types/Styles';
@@ -21,20 +22,20 @@
21
22
  label: undefined,
22
23
  required: false,
23
24
  supportingText: undefined,
24
- value: '',
25
+ value: undefined,
25
26
  });
26
27
 
27
28
  const error = ref(props.error);
28
29
  const hasFocus = ref(false);
29
30
  const input = ref<HTMLSelectElement | null>(null);
30
31
  const required = ref(props.required);
31
- const value = ref(props.value);
32
+ const value = ref<string | undefined>(props.value);
32
33
 
33
34
  const errorMessage = computed(() => getErrorMessage(props.error, error.value));
34
35
  const formattedLabel = computed(() => (props.required ? `${props.label} *` : props.label));
35
36
  const hasError = computed(() => (props.required && !value.value) || getFieldHasError(error.value, props.error));
36
37
  const hasMinilabel = computed(() => hasFocus.value || !isEmpty.value);
37
- const isEmpty = computed(() => value.value === '');
38
+ const isEmpty = computed(() => value.value === undefined);
38
39
 
39
40
  const uniqueId = computed(() => (props.inputId ? props.inputId : `text-input-${getCurrentInstance()?.uid || ''}`));
40
41
 
@@ -115,22 +116,33 @@
115
116
  :id="uniqueId"
116
117
  v-model="value"
117
118
  >
118
- <component
119
- :class="[CSS.WIDTH.FULL, CSS.BG.SURFACE.DEFAULT]"
120
- :key="optgroup.label"
121
- :label="optgroup.label"
122
- :is="optgroup.options ? 'optgroup' : 'option'"
123
- v-for="optgroup in props.optgroups"
124
- >
119
+ <template v-for="optgroup in props.optgroups">
120
+ <optgroup
121
+ :class="[CSS.WIDTH.FULL, CSS.BG.SURFACE.DEFAULT]"
122
+ :key="(optgroup as SelectOptionGroup).label"
123
+ :label="(optgroup as SelectOptionGroup).label"
124
+ v-if="(optgroup as SelectOptionGroup).options"
125
+ >
126
+ <option
127
+ :class="[CSS.WIDTH.FULL, CSS.BG.SURFACE.DEFAULT]"
128
+ :key="option.value"
129
+ :value="option.value"
130
+ v-for="option in (optgroup as SelectOptionGroup).options"
131
+ >
132
+ {{ option.label }}
133
+ </option>
134
+ </optgroup>
135
+
125
136
  <option
126
137
  :class="[CSS.WIDTH.FULL, CSS.BG.SURFACE.DEFAULT]"
127
- :key="option.value"
128
- :value="option.value"
129
- v-for="option in optgroup.options"
138
+ :key="(optgroup as SelectOption).value"
139
+ :selected="value === (optgroup as SelectOption).value ? true : undefined"
140
+ :value="(optgroup as SelectOption).value"
141
+ v-else
130
142
  >
131
- {{ option.label }}
143
+ {{ (optgroup as SelectOption).label }}
132
144
  </option>
133
- </component>
145
+ </template>
134
146
 
135
147
  <option
136
148
  :class="[CSS.WIDTH.FULL, CSS.BG.SURFACE.DEFAULT]"
@@ -14,26 +14,37 @@ import {
14
14
  } from '@/utilities/storybook';
15
15
 
16
16
  const options = {
17
+ 'Any': '',
17
18
  'Option 1': 1,
18
19
  'Option 2': 2,
19
20
  'Option 3': 3,
21
+ 'Option A1': 'A1',
22
+ 'Option A2': 'A2',
23
+ 'Option A3': 'A3',
24
+ 'Option B1': 'B1',
25
+ 'Option B2': 'B2',
26
+ 'Option B3': 'B3',
20
27
  };
21
28
 
22
- const selectOptionGroups: SelectOptionGroup[] = [
29
+ const selectOptionGroups: (SelectOption | SelectOptionGroup)[] = [
30
+ {
31
+ label: 'Any',
32
+ value: '',
33
+ },
23
34
  {
24
35
  label: 'Group A',
25
36
  options: [
26
37
  {
27
- label: 'Option 1',
28
- value: 1,
38
+ label: 'Option A1',
39
+ value: 'A1',
29
40
  },
30
41
  {
31
- label: 'Option 2',
32
- value: 2,
42
+ label: 'Option A2',
43
+ value: 'A2',
33
44
  },
34
45
  {
35
- label: 'Option 3',
36
- value: 3,
46
+ label: 'Option A3',
47
+ value: 'A3',
37
48
  },
38
49
  ],
39
50
  },
@@ -41,16 +52,16 @@ const selectOptionGroups: SelectOptionGroup[] = [
41
52
  label: 'Group B',
42
53
  options: [
43
54
  {
44
- label: 'Option 4',
45
- value: 4,
55
+ label: 'Option B1',
56
+ value: 'B1',
46
57
  },
47
58
  {
48
- label: 'Option 5',
49
- value: 5,
59
+ label: 'Option B2',
60
+ value: 'B2',
50
61
  },
51
62
  {
52
- label: 'Option 6',
53
- value: 6,
63
+ label: 'Option B3',
64
+ value: 'B3',
54
65
  },
55
66
  ],
56
67
  },
@@ -59,15 +70,15 @@ const selectOptionGroups: SelectOptionGroup[] = [
59
70
  const selectOptions: SelectOption[] = [
60
71
  {
61
72
  label: 'Option 1',
62
- value: 1,
73
+ value: '1',
63
74
  },
64
75
  {
65
76
  label: 'Option 2',
66
- value: 2,
77
+ value: '2',
67
78
  },
68
79
  {
69
80
  label: 'Option 3',
70
- value: 3,
81
+ value: '3',
71
82
  },
72
83
  ];
73
84
 
@@ -76,7 +87,7 @@ const render = (args: any, { updateArgs }: any) => ({
76
87
  methods: {
77
88
  doSomething,
78
89
  handleChange: (event: Event) => {
79
- const value = parseInt((event?.target as HTMLSelectElement).value, 10);
90
+ const value = (event?.target as HTMLSelectElement).value;
80
91
 
81
92
  updateArgs({ ...args, value });
82
93
  action('TideInputSelect changed')(event);
@@ -22,7 +22,7 @@ const GROSS_WEIGHT_MAX = 12000;
22
22
  export const GROSS_WEIGHT_OPTIONS: SelectOption[] = [
23
23
  {
24
24
  label: 'Any',
25
- value: null,
25
+ value: undefined,
26
26
  },
27
27
  ...Array.from({ length: Math.floor((GROSS_WEIGHT_MAX - GROSS_WEIGHT_MIN) / 1000) + 1 }, (_, index) => ({
28
28
  label: (GROSS_WEIGHT_MAX - index * 1000).toString(),
@@ -35,7 +35,7 @@ const SLEEP_CAP_MAX = 10;
35
35
  export const SLEEPING_CAPACITY_OPTIONS: SelectOption[] = [
36
36
  {
37
37
  label: 'Any',
38
- value: null,
38
+ value: undefined,
39
39
  },
40
40
  ...Array.from({ length: SLEEP_CAP_MAX - SLEEP_CAP_MIN + 1 }, (_, index) => ({
41
41
  label: (SLEEP_CAP_MAX - index).toString(),
@@ -48,7 +48,7 @@ const SLIDEOUT_MAX = 5;
48
48
  export const SLIDEOUT_OPTIONS: SelectOption[] = [
49
49
  {
50
50
  label: 'Any',
51
- value: null,
51
+ value: undefined,
52
52
  },
53
53
  ...Array.from({ length: SLIDEOUT_MAX - SLIDEOUT_MIN + 1 }, (_, index) => ({
54
54
  label: (SLIDEOUT_MAX - index).toString(),
@@ -61,7 +61,7 @@ const LENGTH_MAX = 50;
61
61
  export const LENGTH_OPTIONS: SelectOption[] = [
62
62
  {
63
63
  label: 'Any',
64
- value: null,
64
+ value: undefined,
65
65
  },
66
66
  ...Array.from({ length: LENGTH_MAX - LENGTH_MIN + 1 }, (_, index) => ({
67
67
  label: (LENGTH_MAX - index).toString(),
@@ -75,7 +75,7 @@ const YEAR_MAX = today.getFullYear() + 2;
75
75
  export const YEAR_OPTIONS: SelectOption[] = [
76
76
  {
77
77
  label: 'Any',
78
- value: null,
78
+ value: undefined,
79
79
  },
80
80
  ...Array.from({ length: YEAR_MAX - YEAR_MIN + 1 }, (_, index) => ({
81
81
  label: (YEAR_MAX - index).toString(),
@@ -25,7 +25,7 @@ interface GenericInput {
25
25
  }
26
26
 
27
27
  interface SelectField extends GenericInput, StringValue {
28
- optgroups?: SelectOptionGroup[];
28
+ optgroups?: (SelectOption | SelectOptionGroup)[];
29
29
  options?: SelectOption[];
30
30
  }
31
31
 
package/src/types/Form.ts CHANGED
@@ -24,7 +24,7 @@ export type SelectInput = GenericInput &
24
24
  StringValue & {
25
25
  options?: SelectOption[] | readonly SelectOption[];
26
26
  placeholder?: string;
27
- optgroups?: SelectOptionGroup[];
27
+ optgroups?: (SelectOption | SelectOptionGroup)[];
28
28
  };
29
29
 
30
30
  export type TextInput = GenericInput &
@@ -1,9 +1,9 @@
1
1
  export type SelectOption = {
2
- label: string | number;
3
- value: any;
2
+ label: string;
3
+ value?: string;
4
4
  };
5
5
 
6
6
  export type SelectOptionGroup = {
7
7
  label: string;
8
- options?: SelectOption[];
8
+ options: SelectOption[];
9
9
  };