@carbon/vue 3.0.7-alpha.0 → 3.0.8-alpha.0

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.
Files changed (73) hide show
  1. package/README.md +7 -0
  2. package/dist/carbon-vue-3.common.js +3438 -177
  3. package/dist/carbon-vue-3.common.js.map +1 -1
  4. package/dist/carbon-vue-3.umd.js +3438 -177
  5. package/dist/carbon-vue-3.umd.js.map +1 -1
  6. package/dist/carbon-vue-3.umd.min.js +4 -4
  7. package/dist/carbon-vue-3.umd.min.js.map +1 -1
  8. package/package.json +7 -4
  9. package/src/components/CvCheckbox/CvCheckbox.stories.js +18 -7
  10. package/src/components/CvCheckbox/CvCheckbox.vue +19 -3
  11. package/src/components/CvCheckbox/CvCheckboxSkeleton.vue +16 -0
  12. package/src/components/CvCheckbox/__tests__/__snapshots__/CvCheckboxSkeleton.spec.js.snap +3 -0
  13. package/src/components/CvCheckbox/index.js +2 -1
  14. package/src/components/CvDropdown/CvDropdown.vue +0 -2
  15. package/src/components/CvFileUploader/CvFileUploader.stories.mdx +333 -0
  16. package/src/components/CvFileUploader/CvFileUploader.vue +286 -0
  17. package/src/components/CvFileUploader/CvFileUploaderItem.vue +92 -0
  18. package/src/components/CvFileUploader/CvFileUploaderSkeleton.vue +16 -0
  19. package/src/components/CvFileUploader/const.js +10 -0
  20. package/src/components/CvFileUploader/index.js +5 -0
  21. package/src/components/CvMultiSelect/CvMultiSelect.stories.mdx +1 -1
  22. package/src/components/CvProgress/CvProgress.stories.mdx +202 -0
  23. package/src/components/CvProgress/CvProgress.vue +78 -0
  24. package/src/components/CvProgress/CvProgressStep.vue +124 -0
  25. package/src/components/CvProgress/index.js +4 -0
  26. package/src/components/CvRadioButton/CvRadioButton.stories.js +166 -0
  27. package/src/components/CvRadioButton/CvRadioButton.vue +57 -0
  28. package/src/components/CvRadioButton/CvRadioGroup.vue +27 -0
  29. package/src/components/CvRadioButton/__tests__/__snapshots__/CvRadioButton.spec.js.snap +27 -0
  30. package/src/components/CvRadioButton/index.js +6 -0
  31. package/src/components/CvSearch/CvSearch.stories.mdx +168 -0
  32. package/src/components/CvSearch/CvSearch.vue +250 -0
  33. package/src/components/CvSearch/index.js +3 -0
  34. package/src/components/CvSelect/CvSelect.vue +27 -6
  35. package/src/components/CvSlider/CvSlider.stories.js +166 -0
  36. package/src/components/CvSlider/CvSlider.vue +324 -0
  37. package/src/components/CvSlider/CvSliderSkeleton.stories.js +26 -0
  38. package/src/components/CvSlider/CvSliderSkeleton.vue +18 -0
  39. package/src/components/CvSlider/__tests__/__snapshots__/CvSlider.spec.js.snap +13 -0
  40. package/src/components/CvSlider/__tests__/__snapshots__/CvSliderSkeleton.spec.js.snap +13 -0
  41. package/src/components/CvSlider/index.js +5 -0
  42. package/src/components/CvSlider/sbSliderPrefix.js +2 -0
  43. package/src/components/CvTextArea/CvTextArea.stories.js +2 -2
  44. package/src/components/CvTextArea/CvTextAreaSkeleton.stories.js +29 -0
  45. package/src/components/CvTextArea/CvTextAreaSkeleton.vue +10 -0
  46. package/src/components/CvTextArea/StorybookGroupConst.js +1 -0
  47. package/src/components/CvTextArea/__tests__/__snapshots__/CvTextAreaSkeleton.spec.js.snap +7 -0
  48. package/src/components/CvTextArea/index.js +2 -1
  49. package/src/components/CvTimePicker/CvTimePicker.stories.mdx +325 -0
  50. package/src/components/CvTimePicker/CvTimePicker.vue +217 -0
  51. package/src/components/CvTimePicker/index.js +21 -0
  52. package/src/components/CvToggle/CvToggle-Skeleton.vue +27 -12
  53. package/src/components/CvToggle/CvToggle.stories.js +20 -3
  54. package/src/components/CvToggle/CvToggle.vue +22 -5
  55. package/src/components/CvToggle/__tests__/__snapshots__/CvToggle.spec.js.snap +3 -3
  56. package/src/components/CvTooltip/CvDefinitionTooltip.stories.js +80 -0
  57. package/src/components/CvTooltip/CvDefinitionTooltip.vue +61 -0
  58. package/src/components/CvTooltip/CvInteractiveTooltip.stories.js +90 -0
  59. package/src/components/CvTooltip/CvInteractiveTooltip.vue +267 -0
  60. package/src/components/CvTooltip/CvTooltip.stories.js +128 -0
  61. package/src/components/CvTooltip/CvTooltip.vue +44 -0
  62. package/src/components/CvTooltip/__tests__/__snapshots__/CvTooltip.spec.js.snap +525 -0
  63. package/src/components/CvTooltip/consts.js +15 -0
  64. package/src/components/CvTooltip/index.js +6 -0
  65. package/src/components/CvTooltip/sbTooltipPrefix.js +2 -0
  66. package/src/components/CvUIShell/CvSideNav.vue +10 -1
  67. package/src/components/CvUIShell/CvUIShell.stories.mdx +116 -50
  68. package/src/index.d.ts +6 -0
  69. package/src/index.js +11 -0
  70. package/src/use/cvCheck.js +3 -0
  71. package/src/use/index.js +2 -0
  72. package/src/use/useMethods.js +18 -0
  73. package/src/use/useRadio.js +25 -0
@@ -0,0 +1,325 @@
1
+ import { Canvas, Meta, Story } from '@storybook/addon-docs';
2
+ import CvTimePicker from './CvTimePicker.vue';
3
+ import { sbCompPrefix } from '../../global/storybook-utils';
4
+ import { action } from '@storybook/addon-actions';
5
+ import {
6
+ FIELD_MEDIUM,
7
+ TIME_PICKER_AM,
8
+ TIME_PICKER_HOURS,
9
+ TIME_PICKER_SIZES,
10
+ } from './index';
11
+ import { ref } from 'vue';
12
+ const myTime = ref('10:04');
13
+ const myHour = ref('PM');
14
+ const myZone = ref('America/Los_Angeles');
15
+
16
+ <Meta title={`${sbCompPrefix}/CvTimePicker`} component={CvTimePicker} />
17
+
18
+ export const Template = args => ({
19
+ // Components used in your story `template` are defined in the `components` object
20
+ components: {
21
+ CvTimePicker,
22
+ },
23
+ // The story's `args` need to be mapped into the template through the `setup()` method
24
+ setup() {
25
+ return {
26
+ light: args.light,
27
+ ampm: args.ampm,
28
+ ampmSelectLabel: args.ampmSelectLabel,
29
+ disabled: args.disabled,
30
+ invalidMessage: args.invalidMessage,
31
+ label: args.label,
32
+ pattern: args.pattern,
33
+ placeholder: args.placeholder,
34
+ time: args.time,
35
+ timezone: args.timezone,
36
+ timezones: args.timezones,
37
+ timezonesSelectLabel: args.timezonesSelectLabel,
38
+ fieldSize: args.fieldSize,
39
+ slotInvalidText: args.slotInvalidText,
40
+ myTime,
41
+ myHour,
42
+ myZone,
43
+ onChange: action('change'),
44
+ };
45
+ },
46
+ // And then the `args` are bound to your component with `v-bind="args"`
47
+ template: args.template,
48
+ });
49
+ const defaultTemplate = `
50
+ <cv-time-picker
51
+ :light="light"
52
+ :label="label"
53
+ :time="time"
54
+ :ampm="ampm"
55
+ :pattern="pattern"
56
+ :placeholder="placeholder"
57
+ :ampm-select-label="ampmSelectLabel"
58
+ :invalid-message="invalidMessage"
59
+ :disabled="disabled"
60
+ :fieldSize="fieldSize"
61
+ @change="onChange">
62
+ </cv-time-picker>`;
63
+ const timezoneTemplate = `
64
+ <cv-time-picker
65
+ :timezone="timezone"
66
+ :timezones="timezones"
67
+ :timezones-select-label="timezonesSelectLabel"
68
+ :fieldSize="fieldSize"
69
+ @change="onChange">
70
+ </cv-time-picker>`;
71
+ const slotTemplate = `
72
+ <cv-time-picker
73
+ @change="onChange">
74
+ <template v-if="slotInvalidText" v-slot:invalid-message>Temporal paradox</template>
75
+ </cv-time-picker>`;
76
+ const vModelTemplate = `
77
+ <div>
78
+ <cv-time-picker
79
+ v-model:time="myTime"
80
+ v-model:ampm="myHour"
81
+ v-model:timezone="myZone"
82
+ :timezones="timezones"
83
+ @change="onChange">
84
+ </cv-time-picker>
85
+ <div style="margin-top: 1rem; background-color: rgb(136, 136, 136); padding: 1rem;">
86
+ <h2>Sample interaction</h2>
87
+ <div>
88
+ <label>time: <input type="text" v-model="myTime"></label>
89
+ <label>Ampm:
90
+ <select v-model="myHour">
91
+ <option value="AM">AM</option>
92
+ <option value="PM">PM</option>
93
+ </select>
94
+ </label>
95
+ <label>Timezone:
96
+ <select v-model="myZone">
97
+ <option value="America/Los_Angeles">America/Los Angeles</option>
98
+ <option value="Moon/Tranquility_Base">Moon Standard Time</option>
99
+ </select>
100
+ </label>
101
+ </div>
102
+ </div>
103
+ </div>`;
104
+
105
+ # CvTimePicker
106
+
107
+ **Migration notes:**
108
+
109
+ - The `formItem` boolean property is shown in the Vue 2 storybook, but it has no effect. It is removed from this version.
110
+ - The `fieldSize` property is new.
111
+
112
+ <Canvas>
113
+ <Story
114
+ name="Default"
115
+ parameters={{
116
+ controls: {
117
+ exclude: [
118
+ 'change',
119
+ 'template',
120
+ 'update:ampm',
121
+ 'update:time',
122
+ 'update:timezone',
123
+ 'invalid-message',
124
+ 'timezone',
125
+ 'timezones',
126
+ 'timezonesSelectLabel',
127
+ ],
128
+ },
129
+ docs: { source: { code: defaultTemplate } },
130
+ }}
131
+ args={{
132
+ light: false,
133
+ template: defaultTemplate,
134
+ }}
135
+ argTypes={{
136
+ light: {
137
+ type: String,
138
+ description: '`true` to use the light version',
139
+ table: { category: 'props' },
140
+ },
141
+ fieldSize: {
142
+ control: 'select',
143
+ default: FIELD_MEDIUM,
144
+ options: TIME_PICKER_SIZES,
145
+ },
146
+ ampm: {
147
+ control: 'select',
148
+ default: TIME_PICKER_AM,
149
+ options: TIME_PICKER_HOURS,
150
+ },
151
+ }}
152
+ >
153
+ {Template.bind({})}
154
+ </Story>
155
+ </Canvas>
156
+
157
+ # With timezones
158
+
159
+ - The timezone field does not appear unless there is a value for `timezones` array
160
+ - Sample is initialized with this data
161
+
162
+ ```js
163
+ {
164
+ timezones: [
165
+ { value: 'America/New_York', label: 'America/New York' },
166
+ { value: 'Europe/Berlin', label: 'Europe/Berlin' },
167
+ { value: 'Asia/Dubai', label: 'Asia/Dubai' },
168
+ { value: 'Asia/Calcutta', label: 'Indian Standard Time' },
169
+ { value: 'Asia/Shanghai', label: 'China Standard Time' },
170
+ { value: 'Moon/Tranquility_Base', label: 'Moon Standard Time' },
171
+ ];
172
+ }
173
+ ```
174
+
175
+ <Canvas>
176
+ <Story
177
+ name="Include timezone"
178
+ parameters={{
179
+ controls: {
180
+ exclude: [
181
+ 'change',
182
+ 'template',
183
+ 'update:ampm',
184
+ 'update:time',
185
+ 'update:timezone',
186
+ 'invalid-message',
187
+ 'ampm',
188
+ 'ampmSelectLabel',
189
+ 'disabled',
190
+ 'invalidMessage',
191
+ 'label',
192
+ 'light',
193
+ 'pattern',
194
+ 'placeholder',
195
+ 'time',
196
+ ],
197
+ },
198
+ docs: { source: { code: timezoneTemplate } },
199
+ }}
200
+ args={{
201
+ light: false,
202
+ template: timezoneTemplate,
203
+ timezones: [
204
+ { value: 'America/New_York', label: 'America/New York' },
205
+ { value: 'Europe/Berlin', label: 'Europe/Berlin' },
206
+ { value: 'Asia/Dubai', label: 'Asia/Dubai' },
207
+ { value: 'Asia/Calcutta', label: 'Indian Standard Time' },
208
+ { value: 'Asia/Shanghai', label: 'China Standard Time' },
209
+ { value: 'Moon/Tranquility_Base', label: 'Moon Standard Time' },
210
+ ],
211
+ }}
212
+ argTypes={{
213
+ timezones: { control: false },
214
+ fieldSize: {
215
+ control: 'select',
216
+ default: FIELD_MEDIUM,
217
+ options: TIME_PICKER_SIZES,
218
+ },
219
+ }}
220
+ >
221
+ {Template.bind({})}
222
+ </Story>
223
+ </Canvas>
224
+
225
+ # With `invalid-message` slot
226
+
227
+ <Canvas>
228
+ <Story
229
+ name="Slots"
230
+ parameters={{
231
+ controls: {
232
+ exclude: [
233
+ 'change',
234
+ 'template',
235
+ 'update:ampm',
236
+ 'update:time',
237
+ 'update:timezone',
238
+ 'invalid-message',
239
+ 'ampm',
240
+ 'ampmSelectLabel',
241
+ 'disabled',
242
+ 'invalidMessage',
243
+ 'label',
244
+ 'light',
245
+ 'pattern',
246
+ 'placeholder',
247
+ 'time',
248
+ 'fieldSize',
249
+ 'timezone',
250
+ 'timezones',
251
+ 'timezonesSelectLabel',
252
+ ],
253
+ },
254
+ docs: { source: { code: slotTemplate } },
255
+ }}
256
+ args={{
257
+ template: slotTemplate,
258
+ slotInvalidText: false,
259
+ }}
260
+ argTypes={{}}
261
+ >
262
+ {Template.bind({})}
263
+ </Story>
264
+ </Canvas>
265
+
266
+ # v-model
267
+
268
+ <Canvas>
269
+ <Story
270
+ name="v-model"
271
+ parameters={{
272
+ controls: {
273
+ exclude: [
274
+ 'change',
275
+ 'template',
276
+ 'update:ampm',
277
+ 'update:time',
278
+ 'update:timezone',
279
+ 'invalid-message',
280
+ 'timezone',
281
+ 'timezones',
282
+ 'timezonesSelectLabel',
283
+ 'ampm',
284
+ 'ampmSelectLabel',
285
+ 'disabled',
286
+ 'invalidMessage',
287
+ 'fieldSize',
288
+ 'label',
289
+ 'light',
290
+ 'pattern',
291
+ 'placeholder',
292
+ 'time',
293
+ ],
294
+ },
295
+ docs: { source: { code: vModelTemplate } },
296
+ }}
297
+ args={{
298
+ light: false,
299
+ template: vModelTemplate,
300
+ timezones: [
301
+ { value: 'America/Los_Angeles', label: 'America/Los Angeles' },
302
+ { value: 'Moon/Tranquility_Base', label: 'Moon Standard Time' },
303
+ ],
304
+ }}
305
+ argTypes={{
306
+ light: {
307
+ type: String,
308
+ description: '`true` to use the light version',
309
+ table: { category: 'props' },
310
+ },
311
+ fieldSize: {
312
+ control: 'select',
313
+ default: FIELD_MEDIUM,
314
+ options: TIME_PICKER_SIZES,
315
+ },
316
+ ampm: {
317
+ control: 'select',
318
+ default: TIME_PICKER_AM,
319
+ options: TIME_PICKER_HOURS,
320
+ },
321
+ }}
322
+ >
323
+ {Template.bind({})}
324
+ </Story>
325
+ </Canvas>
@@ -0,0 +1,217 @@
1
+ <!--suppress ES6PreferShortImport -->
2
+ <template>
3
+ <div :class="`cv-time-picker ${carbonPrefix}--form-item`">
4
+ <div
5
+ :class="[
6
+ `${carbonPrefix}--time-picker`,
7
+ `${carbonPrefix}--time-picker--${fieldSize}`,
8
+ { [`${carbonPrefix}--time-picker--light`]: isLight },
9
+ ]"
10
+ :data-invalid="isInvalid"
11
+ >
12
+ <div :class="`${carbonPrefix}--time-picker__input`">
13
+ <label :for="uid" :class="`${carbonPrefix}--label`">{{ label }}</label>
14
+ <input
15
+ :id="uid"
16
+ type="text"
17
+ :class="[
18
+ `${carbonPrefix}--time-picker__input-field ${carbonPrefix}--text-input`,
19
+ { [`${carbonPrefix}--text-input--light`]: isLight },
20
+ ]"
21
+ :pattern="pattern"
22
+ v-bind="$attrs"
23
+ :placeholder="placeholder"
24
+ :maxlength="placeholder.length"
25
+ :value="time"
26
+ :disabled="isDisabled"
27
+ @input="onInput"
28
+ />
29
+ </div>
30
+ <cv-select
31
+ v-if="ampm !== TIME_PICKER_24"
32
+ :class="`${carbonPrefix}--time-picker__select`"
33
+ :form-item="false"
34
+ hide-label
35
+ :label="ampmSelectLabel"
36
+ :value="ampm"
37
+ :disabled="isDisabled"
38
+ :size="fieldSize"
39
+ @change="onChangeAMPM"
40
+ >
41
+ <cv-select-option
42
+ :class="`${carbonPrefix}--select-option`"
43
+ :value="TIME_PICKER_AM"
44
+ >{{ TIME_PICKER_AM }}</cv-select-option
45
+ >
46
+ <cv-select-option
47
+ :class="`${carbonPrefix}--select-option`"
48
+ :value="TIME_PICKER_PM"
49
+ >{{ TIME_PICKER_PM }}</cv-select-option
50
+ >
51
+ </cv-select>
52
+ <div v-else>&nbsp;</div>
53
+
54
+ <cv-select
55
+ v-if="timezones.length > 0"
56
+ :class="`${carbonPrefix}--time-picker__select`"
57
+ :form-item="false"
58
+ hide-label
59
+ :label="timezonesSelectLabel"
60
+ :value="validTimezone"
61
+ :disabled="isDisabled"
62
+ :size="fieldSize"
63
+ @change="onChangeTimeZone"
64
+ >
65
+ <cv-select-option
66
+ v-for="item in timezones"
67
+ :key="item.value"
68
+ :class="`${carbonPrefix}--select-option`"
69
+ :value="item.value"
70
+ >{{ item.label }}</cv-select-option
71
+ >
72
+ </cv-select>
73
+ </div>
74
+ <div v-if="isInvalid" :class="`${carbonPrefix}--form-requirement`">
75
+ <slot name="invalid-message">{{ invalidMessage }}</slot>
76
+ </div>
77
+ </div>
78
+ </template>
79
+
80
+ <script setup>
81
+ import { carbonPrefix } from '../../global/settings';
82
+ import { props as propsCvId, useCvId } from '../../use/cvId';
83
+ import { props as propsTheme, useIsLight } from '../../use/cvTheme';
84
+ import CvSelect from '../CvSelect/CvSelect.vue';
85
+ import CvSelectOption from '../CvSelect/CvSelectOption.vue';
86
+ import { computed, onMounted, onUpdated, ref, useSlots } from 'vue';
87
+ import {
88
+ TIME_PICKER_SIZES,
89
+ TIME_PICKER_HOURS,
90
+ FIELD_MEDIUM,
91
+ TIME_PICKER_AM,
92
+ TIME_PICKER_PM,
93
+ TIME_PICKER_24,
94
+ } from './index';
95
+
96
+ defineOptions({
97
+ inheritAttrs: false,
98
+ });
99
+
100
+ const props = defineProps({
101
+ /**
102
+ * Initial value for the AM/PM `<cv-select>`. If set to `24` the `<cv-select>` is not included.
103
+ */
104
+ ampm: {
105
+ type: String,
106
+ default: TIME_PICKER_AM,
107
+ validator: value => TIME_PICKER_HOURS.includes(value),
108
+ },
109
+ /**
110
+ * Label for the AM/PM `<cv-select>`
111
+ */
112
+ ampmSelectLabel: { type: String, default: 'Select AM/PM' },
113
+ /**
114
+ * Specify whether the `<input>` should be disabled
115
+ */
116
+ disabled: { type: Boolean, default: false },
117
+ /**
118
+ * Provide the text that is displayed when the control is in an invalid state
119
+ */
120
+ invalidMessage: { type: String, default: undefined },
121
+ /**
122
+ * Label for the time `<input>`
123
+ */
124
+ label: { type: String, default: 'Select a time' },
125
+ /**
126
+ * Specify the regular expression working as the [pattern](https://www.w3schools.com/tags/att_input_pattern.asp) of the time string in `<input>`.
127
+ */
128
+ pattern: { type: String, default: '([01][0-9]:[0-6][0-9])' },
129
+ /**
130
+ * Specify the placeholder attribute for the <input>
131
+ */
132
+ placeholder: { type: String, default: 'hh:mm' },
133
+ /**
134
+ * Specify the initial value of the `<input>`
135
+ */
136
+ time: { type: String, default: undefined },
137
+ /**
138
+ * Specify the initial value of the `<cv-select>` for the timezone
139
+ */
140
+ timezone: { type: String, default: undefined },
141
+ /**
142
+ * List of timezones to display
143
+ * @type {Array<{value: string, label:string}>}
144
+ */
145
+ timezones: {
146
+ type: Array,
147
+ default: () => [],
148
+ },
149
+ /**
150
+ * Specify the label of the `<cv-select>` for the timezone. Label is hidden but text will be read by a screen reader when visiting this control.
151
+ */
152
+ timezonesSelectLabel: { type: String, default: 'Select time zone' },
153
+ /**
154
+ * Specify the size of the Time Picker.
155
+ */
156
+ fieldSize: {
157
+ type: String,
158
+ default: FIELD_MEDIUM,
159
+ validator: value => TIME_PICKER_SIZES.includes(value),
160
+ },
161
+ ...propsCvId,
162
+ ...propsTheme,
163
+ });
164
+
165
+ const uid = useCvId(props, true);
166
+ const isLight = useIsLight(props);
167
+
168
+ const isInvalid = ref(false);
169
+ const slots = useSlots();
170
+ function checkSlots() {
171
+ // NOTE: slots is not reactive so needs to be managed on updated
172
+ isInvalid.value = !!(
173
+ slots['invalid-message'] ||
174
+ (props.invalidMessage && props.invalidMessage.length)
175
+ );
176
+ }
177
+ onMounted(checkSlots);
178
+ onUpdated(checkSlots);
179
+
180
+ const emit = defineEmits([
181
+ 'change',
182
+ 'update:ampm',
183
+ 'update:timezone',
184
+ 'update:time',
185
+ ]);
186
+
187
+ const validTimezone = computed(() => {
188
+ // Validate timezone setting
189
+ let result = props.timezone;
190
+ if (props.timezones && props.timezones.length) {
191
+ if (!props.timezones.find(item => item.value === props.timezone)) {
192
+ if (props.timezone !== undefined)
193
+ console.error(
194
+ `CvTimePicker: invalid value '${props.timezone}' supplied for prop timezone. Default applied.`
195
+ );
196
+ // set to first valid value
197
+ result = props.timezones[0].value;
198
+ emit('update:timezone', result);
199
+ }
200
+ }
201
+ return result;
202
+ });
203
+ const isDisabled = computed(() => (props.disabled ? true : undefined));
204
+
205
+ function onInput(e) {
206
+ emit('change', { type: 'time', value: e?.target?.value });
207
+ emit('update:time', e?.target?.value);
208
+ }
209
+ function onChangeAMPM(value) {
210
+ emit('change', { type: 'ampm', value });
211
+ emit('update:ampm', value);
212
+ }
213
+ function onChangeTimeZone(value) {
214
+ emit('change', { type: 'timezone', value });
215
+ emit('update:timezone', value);
216
+ }
217
+ </script>
@@ -0,0 +1,21 @@
1
+ import CvTimePicker from './CvTimePicker.vue';
2
+ const FIELD_SMALL = 'sm';
3
+ const FIELD_MEDIUM = 'md';
4
+ const FIELD_LARGE = 'lg';
5
+ const TIME_PICKER_SIZES = [FIELD_SMALL, FIELD_MEDIUM, FIELD_LARGE];
6
+ const TIME_PICKER_AM = 'AM';
7
+ const TIME_PICKER_PM = 'PM';
8
+ const TIME_PICKER_24 = '24';
9
+ const TIME_PICKER_HOURS = [TIME_PICKER_AM, TIME_PICKER_PM, TIME_PICKER_24];
10
+
11
+ export {
12
+ CvTimePicker,
13
+ FIELD_SMALL,
14
+ FIELD_MEDIUM,
15
+ FIELD_LARGE,
16
+ TIME_PICKER_SIZES,
17
+ TIME_PICKER_AM,
18
+ TIME_PICKER_PM,
19
+ TIME_PICKER_24,
20
+ TIME_PICKER_HOURS,
21
+ };
@@ -1,14 +1,22 @@
1
1
  <template>
2
- <div :class="`cv-toggle ${carbonPrefix}--form-item`" :id="cvId">
3
- <label
4
- :class="`${carbonPrefix}--toggle__label ${carbonPrefix}--skeleton`"
5
- :for="cvId"
6
- :aria-label="label ? 'Toggle is loading' : label"
7
- >
8
- <span :class="`${carbonPrefix}--toggle__label-text`" />
9
- <span :class="`${carbonPrefix}--toggle__text--left`" />
10
- <span :class="`${carbonPrefix}--toggle__appearance`" />
11
- <span :class="`${carbonPrefix}--toggle__text--right`" />
2
+ <div :class="`cv-toggle ${carbonPrefix}--form-item`" :aria-label="label">
3
+ <input
4
+ :id="cvId"
5
+ type="checkbox"
6
+ :class="[
7
+ `${carbonPrefix}--toggle ${carbonPrefix}--skeleton`,
8
+ {
9
+ [`${carbonPrefix}--toggle-input--small`]: small,
10
+ },
11
+ ]"
12
+ />
13
+ <label :class="`${carbonPrefix}--toggle-input__label`" :for="cvId">
14
+ <div></div>
15
+ <span :class="`${carbonPrefix}--toggle__switch`">
16
+ <span :class="`${carbonPrefix}--toggle__text--left`" />
17
+ <span :class="`${carbonPrefix}--toggle__appearance`" />
18
+ <span :class="`${carbonPrefix}--toggle__text--right`" />
19
+ </span>
12
20
  </label>
13
21
  </div>
14
22
  </template>
@@ -18,12 +26,19 @@ import { carbonPrefix } from '../../global/settings';
18
26
  import { useCvId, props as propsCvId } from '../../use/cvId';
19
27
 
20
28
  const props = defineProps({
29
+ /**
30
+ * Label and aria-label for the toggle
31
+ */
21
32
  label: {
22
33
  type: String,
23
34
  default: 'Toggle is loading',
24
- ...propsCvId,
25
35
  },
36
+ /**
37
+ * Specify the size of the Toggle. Default is medium. Set to `true` for small.
38
+ */
39
+ small: { type: Boolean, default: false },
40
+ ...propsCvId,
26
41
  });
27
42
 
28
- const cvId = useCvId(props);
43
+ const cvId = useCvId(props, true);
29
44
  </script>
@@ -31,7 +31,6 @@ export default {
31
31
  },
32
32
  },
33
33
  argTypes: {
34
- label: { description: 'Toggle label' },
35
34
  checked: {
36
35
  type: 'boolean',
37
36
  table: {
@@ -63,6 +62,11 @@ const Template = args => {
63
62
 
64
63
  export const Default = Template.bind({});
65
64
  Default.args = initArgs;
65
+ Default.parameters = {
66
+ controls: {
67
+ exclude: ['change', 'update:modelValue', 'text-left', 'text-right'],
68
+ },
69
+ };
66
70
  Default.parameters = storyParametersObject(
67
71
  Default.parameters,
68
72
  template,
@@ -214,7 +218,7 @@ arrayVModel.parameters = storyParametersObject(
214
218
 
215
219
  const templateSkeleton = `
216
220
  <div>
217
- <cv-toggle-skeleton></cv-toggle-skeleton>
221
+ <cv-toggle-skeleton :small="small"></cv-toggle-skeleton>
218
222
  </div>
219
223
  `;
220
224
 
@@ -223,10 +227,23 @@ const TemplateSkeleton = args => {
223
227
  components: { CvToggle, CvToggleSkeleton },
224
228
  setup: () => ({
225
229
  args,
226
- onChange: action('change'),
230
+ small: args.small,
227
231
  }),
228
232
  template: templateSkeleton,
229
233
  };
230
234
  };
231
235
 
232
236
  export const Skeleton = TemplateSkeleton.bind({});
237
+ Skeleton.parameters = {
238
+ controls: {
239
+ exclude: [
240
+ 'change',
241
+ 'text-left',
242
+ 'text-right',
243
+ 'update:modelValue',
244
+ 'hideLabel',
245
+ 'formItem',
246
+ 'checked',
247
+ ],
248
+ },
249
+ };