@carbon/vue 3.0.11 → 3.0.13

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 (31) hide show
  1. package/README.md +4 -4
  2. package/dist/carbon-vue-3.common.js +197 -99
  3. package/dist/carbon-vue-3.common.js.map +1 -1
  4. package/dist/carbon-vue-3.umd.js +197 -99
  5. package/dist/carbon-vue-3.umd.js.map +1 -1
  6. package/dist/carbon-vue-3.umd.min.js +2 -2
  7. package/dist/carbon-vue-3.umd.min.js.map +1 -1
  8. package/dist/web-types.json +5505 -0
  9. package/package.json +2 -2
  10. package/src/components/CvAccordion/CvAccordion.stories.mdx +153 -0
  11. package/src/components/CvAccordion/CvAccordion.vue +18 -5
  12. package/src/components/CvAccordion/CvAccordionItem.vue +18 -6
  13. package/src/components/CvAccordion/consts.js +8 -9
  14. package/src/components/CvCheckbox/CvCheckbox.vue +6 -2
  15. package/src/components/CvDataTable/CvDataTable.stories.mdx +39 -14
  16. package/src/components/CvDataTable/CvDataTableHeading.vue +3 -5
  17. package/src/components/CvDatePicker/CvDatePicker.stories.js +165 -14
  18. package/src/components/CvDatePicker/CvDatePicker.vue +31 -17
  19. package/src/components/CvModal/CvModal.vue +35 -13
  20. package/src/components/CvModal/index.js +29 -1
  21. package/src/components/CvMultiSelect/CvMultiSelect.vue +2 -2
  22. package/src/components/CvNotification/CvInlineNotification.stories.js +58 -1
  23. package/src/components/CvNotification/CvInlineNotification.vue +13 -3
  24. package/src/components/CvNotification/CvInlineNotificationTemplate.mdx +16 -0
  25. package/src/components/CvRadioButton/CvRadioButton.stories.js +20 -1
  26. package/src/components/CvRadioButton/CvRadioButton.vue +7 -5
  27. package/src/components/CvRadioButton/CvRadioGroup.vue +18 -2
  28. package/src/components/CvRadioButton/__tests__/__snapshots__/CvRadioButton.spec.js.snap +6 -4
  29. package/src/components/CvSearch/CvSearch.vue +1 -1
  30. package/src/components/CvTabs/CvTabs.vue +2 -2
  31. package/src/components/CvAccordion/CvAccordion.stories.js +0 -55
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/vue",
3
3
  "license": "Apache-2.0",
4
- "version": "3.0.11",
4
+ "version": "3.0.13",
5
5
  "description": "A collection of components for the Carbon Design System built using Vue.js",
6
6
  "packageManager": "yarn@3.2.0",
7
7
  "main": "dist/carbon-vue-3.umd.min.js",
@@ -174,5 +174,5 @@
174
174
  "url": "git+https://github.com/carbon-design-system/carbon-components-vue.git"
175
175
  },
176
176
  "sideEffects": true,
177
- "gitHead": "1a9b7dd369e0985937b5b1efcc1dea6ce9ce40a5"
177
+ "gitHead": "44c7e6ba63dee51b7f6426b46283b40deaed413c"
178
178
  }
@@ -0,0 +1,153 @@
1
+ import { Canvas, Meta, Story } from '@storybook/addon-docs';
2
+ import { action } from '@storybook/addon-actions';
3
+ import { CvAccordion, CvAccordionItem } from '.';
4
+ import { alignConsts, sizeConsts } from './consts';
5
+ import {
6
+ sbCompPrefix,
7
+ storyParametersObject,
8
+ } from '../../global/storybook-utils';
9
+ import { ref } from 'vue';
10
+ const open = ref({
11
+ accItem1: false,
12
+ accItem2: false,
13
+ accItem3: false,
14
+ accItem4: false,
15
+ });
16
+
17
+ <Meta title={`${sbCompPrefix}/CvAccordion`} component={CvAccordion} />
18
+
19
+ export const Template = args => ({
20
+ components: { CvAccordion, CvAccordionItem },
21
+ setup() {
22
+ return {
23
+ ...args,
24
+ align: alignConsts[alignConsts.$labels[args.align]],
25
+ size: sizeConsts[sizeConsts.$labels[args.size]],
26
+ onChange: action('change'),
27
+ open,
28
+ };
29
+ },
30
+ template: args.template,
31
+ });
32
+ const template = `<cv-accordion @change="onChange" :align="align" :size="size">
33
+ <cv-accordion-item v-for="n in 4" :key="\`acc-item-\${n}\`" :id="n % 2 ? \`acc-item-\${n}\` : ''">
34
+ <template v-slot:title>Episode {{n}} </template>
35
+ <template v-slot:content>
36
+ <p>Did you hear that? They've shut down the main reactor. We'll be destroyed for sure. This is madness! We're doomed! There'll be no escape for the Princess this time. What's that? R2! R2-D2, where are you? At last! Where have you been? They're heading in this direction.</p>
37
+ </template>
38
+ </cv-accordion-item>
39
+ </cv-accordion>`;
40
+ const Default = Template.bind({});
41
+ Default.args = {};
42
+ Default.parameters = storyParametersObject(
43
+ Default.parameters,
44
+ template,
45
+ Default.args
46
+ );
47
+ const templateVModel = `
48
+ <div>
49
+ <cv-accordion @change="onChange" :align="align" :size="size">
50
+ <cv-accordion-item v-for="n in 4" :key="\`acc-item-\${n}\`" :id="\`accItem\${n}\`" v-model:open="open[\`accItem\${n}\`]">
51
+ <template #title>Episode {{n}} </template>
52
+ <template #content>
53
+ <p>Give us a few minutes to lock it down. Large leak...very dangerous. Who is this? What's your operating number? Boring conversation anyway. Luke! We're going to have company! Aren't you a little short to be a stormtrooper? What? Oh...the uniform.</p>
54
+ </template>
55
+ </cv-accordion-item>
56
+ </cv-accordion>
57
+ <div style="margin-top:1rem; background-color: #888888; padding:1rem"><div style="font-size: 150%">Sample interaction</div>
58
+ <label for="checkbox">V-model: Check 1:</label>
59
+ <input id="checkbox" type="checkbox" v-model="open.accItem1"/>
60
+ <span>Checked: <span style="font-weight: bold;">{{open.accItem1}}</span></span><br/>
61
+ <label for="checkbox">V-model: Check 2:</label>
62
+ <input id="checkbox" type="checkbox" v-model="open.accItem2"/>
63
+ <span>Checked: <span style="font-weight: bold;">{{open.accItem2}}</span></span><br/>
64
+ <label for="checkbox">V-model: Check 3:</label>
65
+ <input id="checkbox" type="checkbox" v-model="open.accItem3"/>
66
+ <span>Checked: <span style="font-weight: bold;">{{open.accItem3}}</span></span><br/>
67
+ <label for="checkbox">V-model: Check 4:</label>
68
+ <input id="checkbox" type="checkbox" v-model="open.accItem4"/>
69
+ <span>Checked: <span style="font-weight: bold;">{{open.accItem4}}</span></span>
70
+ </div>
71
+ </div>
72
+ `;
73
+
74
+ # CvAccordion
75
+
76
+ <Canvas>
77
+ <Story
78
+ name="Default"
79
+ parameters={{
80
+ docs: { source: { code: template } },
81
+ controls: {
82
+ include: ['align', 'size'],
83
+ },
84
+ }}
85
+ args={{
86
+ template: template,
87
+ }}
88
+ argTypes={{
89
+ align: {
90
+ control: 'select',
91
+ options: Object.keys(alignConsts.$labels),
92
+ },
93
+ size: {
94
+ control: 'select',
95
+ options: Object.keys(sizeConsts.$labels),
96
+ },
97
+ }}
98
+ >
99
+ {Template.bind({})}
100
+ </Story>
101
+ </Canvas>
102
+
103
+ # Control open state with v-model
104
+
105
+ - Notes: The Vue 2 component does not support v-model. One interesting implementation using this would be to create an
106
+ "auto close" component such that opening one section closes other sections.
107
+
108
+ ```javascript
109
+ // example auto close
110
+ // <cv-accordion @change="onAutoClose">
111
+ const open = ref({
112
+ accItem1: false,
113
+ accItem2: false,
114
+ accItem3: false,
115
+ accItem4: false,
116
+ });
117
+ function autoClose(ev) {
118
+ if (ev.change.open) {
119
+ for (let state in open.value) {
120
+ if (state !== ev.change.id) open.value[state] = false;
121
+ }
122
+ }
123
+ }
124
+ ```
125
+
126
+ <Canvas>
127
+ <Story
128
+ name="v-model"
129
+ parameters={{
130
+ docs: { source: { code: templateVModel } },
131
+ controls: {
132
+ include: ['align', 'size'],
133
+ },
134
+ }}
135
+ args={{
136
+ template: templateVModel,
137
+ }}
138
+ argTypes={{
139
+ align: {
140
+ control: 'select',
141
+ default: 'end',
142
+ options: Object.keys(alignConsts.$labels),
143
+ },
144
+ size: {
145
+ control: 'select',
146
+ default: 'md',
147
+ options: Object.keys(sizeConsts.$labels),
148
+ },
149
+ }}
150
+ >
151
+ {Template.bind({})}
152
+ </Story>
153
+ </Canvas>
@@ -26,26 +26,26 @@ import { alignConsts, sizeConsts } from './consts';
26
26
 
27
27
  defineProps({
28
28
  /**
29
- * optional align, defaults to 'end'
29
+ * Specify the alignment of the accordion heading title and chevron.
30
30
  */
31
31
  align: {
32
32
  type: String,
33
- default: null,
33
+ default: '',
34
34
  validator: val => alignConsts.includes(val),
35
35
  },
36
36
  /**
37
- * optional size setting
37
+ * Specify the size of the Accordion
38
38
  */
39
39
  size: {
40
40
  type: String,
41
- default: null,
41
+ default: '',
42
42
  validator: val => sizeConsts.includes(val),
43
43
  },
44
44
  });
45
45
 
46
46
  const emit = defineEmits({
47
47
  /**
48
- * Triggers when the clear button is pressed on a filter CvTag
48
+ * Triggers when state of an accordion item changes
49
49
  */
50
50
  change: payload => {
51
51
  return (
@@ -83,6 +83,19 @@ provide('registerItem', (itemCvId, item) => {
83
83
  provide('deregisterItem', itemCvId => {
84
84
  items.delete(itemCvId);
85
85
  });
86
+
87
+ /**
88
+ * @typedef {Object} AccordionChangeElement
89
+ * @property {string} id
90
+ * @property {boolean} open
91
+ */
92
+
93
+ /**
94
+ * @typedef {Object} AccordionChangeEvent
95
+ * @property {AccordionChangeElement} change
96
+ * @property {Array<AccordionChangeElement>} state
97
+ * @param ev
98
+ */
86
99
  provide('onAccItemChange', (clickedItemCvId, open) => {
87
100
  items.get(clickedItemCvId).open = open;
88
101
  emit('change', {
@@ -46,18 +46,18 @@ export default {
46
46
  </script>
47
47
 
48
48
  <script setup>
49
- import { onMounted, onBeforeUnmount, inject, ref } from 'vue';
49
+ import { onMounted, onBeforeUnmount, inject, ref, watch } from 'vue';
50
50
  import { carbonPrefix } from '../../global/settings';
51
51
  import { useCvId, props as propsCvId } from '../../use/cvId';
52
52
  import { ChevronRight16 } from '@carbon/icons-vue/';
53
53
 
54
54
  const props = defineProps({
55
55
  /**
56
- * disables this accodion item
56
+ * disables this accordion item
57
57
  */
58
58
  disabled: Boolean,
59
59
  /**
60
- * initial open state of the accordion item
60
+ * open state of the accordion item. available as a v-model
61
61
  */
62
62
  open: Boolean,
63
63
  ...propsCvId,
@@ -66,10 +66,21 @@ const props = defineProps({
66
66
  // Accordion methods
67
67
  const registerItem = inject('registerItem', () => {});
68
68
  const deregisterItem = inject('deregisterItem', () => {});
69
- const onAccItemChagne = inject('onAccItemChange', () => {});
69
+ const onAccItemChange = inject(
70
+ 'onAccItemChange',
71
+ (clickedItemCvId, open) => {}
72
+ );
73
+
74
+ const emit = defineEmits(['update:open']);
75
+ watch(
76
+ () => props.open,
77
+ () => {
78
+ if (props.open !== isOpen.value) toggleOpen(props.open);
79
+ }
80
+ );
70
81
 
71
82
  // Accordion item methods
72
- const cvId = useCvId(props);
83
+ const cvId = useCvId(props, true);
73
84
  const isOpen = ref(props.open);
74
85
  const animation = ref('');
75
86
 
@@ -77,8 +88,9 @@ const toggleOpen = force => {
77
88
  const newValue = typeof force !== 'undefined' ? force : !isOpen.value;
78
89
 
79
90
  animation.value = newValue ? 'expanding' : 'collapsing';
91
+ if (newValue !== props.open) emit('update:open', newValue);
92
+ if (isOpen.value !== newValue) onAccItemChange(cvId.value, newValue);
80
93
  isOpen.value = newValue;
81
- onAccItemChagne(cvId.value, newValue);
82
94
  };
83
95
 
84
96
  const onClick = () => {
@@ -1,16 +1,15 @@
1
- export const alignConsts = [null, 'start', 'end', ''];
1
+ export const alignConsts = ['', 'start', 'end'];
2
2
  alignConsts.$labels = {
3
- 'Not supplied': 0,
4
- Start: 1,
5
- End: 2,
6
- 'Empty string': 3,
3
+ 'Default (end)': 0,
4
+ 'Start (start)': 1,
5
+ 'End (end)': 2,
7
6
  };
8
- export const sizeConsts = [null, 'sm', 'xl', ''];
7
+ export const sizeConsts = ['', 'sm', 'md', 'xl'];
9
8
  sizeConsts.$labels = {
10
- 'Not supplied': 0,
9
+ 'Default (md)': 0,
11
10
  'Small (sm)': 1,
12
- 'Large (xl)': 2,
13
- 'Empty string': 3,
11
+ 'Medium (md)': 2,
12
+ 'Extra large (xl)': 3,
14
13
  };
15
14
 
16
15
  const CvAccordionConsts = { alignConsts, sizeConsts };
@@ -13,7 +13,6 @@
13
13
  type="checkbox"
14
14
  :class="`${carbonPrefix}--checkbox`"
15
15
  :checked="isChecked === true"
16
- :aria-checked="`${isChecked}`"
17
16
  :value="value"
18
17
  :disabled="disabled || null"
19
18
  @focus="onFocus"
@@ -55,7 +54,12 @@ const props = defineProps({
55
54
  /**
56
55
  * Provide a label to provide a description of the Checkbox input that you are exposing to the user
57
56
  */
58
- label: { type: String, default: null },
57
+ label: {
58
+ type: String,
59
+ default: null,
60
+ required: true,
61
+ validator: label => !!label.length,
62
+ },
59
63
  /**
60
64
  * Specify whether the "bx--form-item" style should be applied
61
65
  */
@@ -10,16 +10,28 @@ import { sbCompPrefix } from '../../global/storybook-utils';
10
10
  import { action } from '@storybook/addon-actions';
11
11
  import { Terminal16 as CompileIcon, Debug16 as DebugIcon, Chip16 as EmbedIcon,
12
12
  TrashCan16 as TrashCanIcon} from '@carbon/icons-vue'
13
- const testData = [
14
- { name:"Java", year:1995, oo:"Yes", purpose:"Applications", standard:"Java Language Specification", desc: "As of September 2022, Java 19 is the latest version, while Java 17, 11 and 8 are the current long-term support (LTS) versions."},
15
- { name:"COBOL", year:1959, oo:"Yes", purpose:"Business applications", standard:"COBOL 2014", desc: "COBOL statements have an English-like syntax, which was designed to be self-documenting and highly readable."},
16
- { name:"Pascal", year:1970, oo:"No", purpose:"Applications", standard:"None", desc: "Pascal was developed on the pattern of the ALGOL 60 language."},
17
- { name:"Ada", year:1980, oo:"Yes", purpose:"US DoD projects", standard:"Ada 2012 TC1", desc: "Ada was named after Ada Lovelace (1815–1852), who has been credited as the first computer programmer."},
18
- { name:"BASIC", year:1964, oo:"No", purpose:"Education", standard:"ANSI", desc: "BASIC declined in popularity in the 1990s"},
19
- { name:"C++", year:1985, oo:"Yes", purpose:"Systems programming", standard:"ISO/IEC 2017", desc: "C++ is standardized by the International Organization for Standardization (ISO), with the latest standard version ratified and published by ISO in December 2020 as ISO/IEC 14882:2020 (informally known as C++20)."},
20
- { name:"Fortran", year:1957, oo:"No", purpose:"Engineering applications", standard:"ANSI", desc: "Fortran was originally developed by IBM in the 1950s for scientific and engineering applications, and subsequently came to dominate scientific computing."},
21
- { name:"Go", year:2009, oo:"Maybe", purpose:"Networked applications", standard:"Go Spec", desc: "Go's designers were primarily motivated by their shared dislike of C++."},
22
- ];
13
+ import { ref } from 'vue';
14
+ const testData = ref([
15
+ { index:"0", name:"Java", year:1995, oo:"Yes", purpose:"Applications", standard:"Java Language Specification", desc: "As of September 2022, Java 19 is the latest version, while Java 17, 11 and 8 are the current long-term support (LTS) versions."},
16
+ { index:"1", name:"COBOL", year:1959, oo:"Yes", purpose:"Business applications", standard:"COBOL 2014", desc: "COBOL statements have an English-like syntax, which was designed to be self-documenting and highly readable."},
17
+ { index:"2", name:"Pascal", year:1970, oo:"No", purpose:"Applications", standard:"None", desc: "Pascal was developed on the pattern of the ALGOL 60 language."},
18
+ { index:"3", name:"Ada", year:1980, oo:"Yes", purpose:"US DoD projects", standard:"Ada 2012 TC1", desc: "Ada was named after Ada Lovelace (1815–1852), who has been credited as the first computer programmer."},
19
+ { index:"4", name:"BASIC", year:1964, oo:"No", purpose:"Education", standard:"ANSI", desc: "BASIC declined in popularity in the 1990s"},
20
+ { index:"5", name:"C++", year:1985, oo:"Yes", purpose:"Systems programming", standard:"ISO/IEC 2017", desc: "C++ is standardized by the International Organization for Standardization (ISO), with the latest standard version ratified and published by ISO in December 2020 as ISO/IEC 14882:2020 (informally known as C++20)."},
21
+ { index:"6", name:"Fortran", year:1957, oo:"No", purpose:"Engineering applications", standard:"ANSI", desc: "Fortran was originally developed by IBM in the 1950s for scientific and engineering applications, and subsequently came to dominate scientific computing."},
22
+ { index:"7", name:"Go", year:2009, oo:"Maybe", purpose:"Networked applications", standard:"Go Spec", desc: "Go's designers were primarily motivated by their shared dislike of C++."},
23
+ ]);
24
+ function sortTestData(opts) {
25
+ action('sort')(opts)
26
+ if (opts.order === 'none')
27
+ return testData.value.sort((a, b) => a.index.localeCompare(b.index, 'en', { sensitivity: 'base' }));
28
+ let direction = 1
29
+ if (opts.order === 'descending') direction = -1
30
+ if (opts.name === 'name')
31
+ return testData.value.sort((a, b) => direction * a.name.localeCompare(b.name, 'en', { sensitivity: 'base' }));
32
+ else if (opts.name === 'year')
33
+ return testData.value.sort((a, b) => direction * (a.year - b.year));
34
+ }
23
35
 
24
36
  <Meta title={`${sbCompPrefix}/CvDataTable`} component={CvDataTable} />
25
37
 
@@ -46,7 +58,7 @@ setup() {
46
58
  useHelperTextSlot: undefined,
47
59
  template: undefined},
48
60
  trashIcon: TrashCanIcon,
49
- onSort: action('sort'),
61
+ onSort: sortTestData,
50
62
  onSearch: action('search'),
51
63
  onRowSelectChange: action('row-select-change'),
52
64
  onRowSelectChanges: action('row-select-changes'),
@@ -101,14 +113,14 @@ const defaultTemplate = `
101
113
  </embed-icon>
102
114
  </cv-data-table-action>
103
115
  </template>
104
- <template v-slot:headings>
116
+ <template #headings>
105
117
  <cv-data-table-heading heading="Name" name="name" sortable/>
106
118
  <cv-data-table-heading heading="Year" name="year" sortable/>
107
119
  <cv-data-table-heading heading="Object Oriented"/>
108
120
  <cv-data-table-heading heading="Purpose" />
109
121
  <cv-data-table-heading heading="Standard" />
110
122
  </template>
111
- <template v-slot:data>
123
+ <template #data>
112
124
  <cv-data-table-row v-for="row in testData" :key="row.name" :value="row.name">
113
125
  <cv-data-table-cell>{{row.name}}</cv-data-table-cell>
114
126
  <cv-data-table-cell>{{row.year}}</cv-data-table-cell>
@@ -122,7 +134,7 @@ const defaultTemplate = `
122
134
  `;
123
135
  const expandingRowsTemplate = defaultTemplate.replace(
124
136
  "<!-- Add optional expanding data here -->",
125
- `<template v-slot:expandedContent>{{row.desc}}</template>`)
137
+ `<template #expandedContent>{{row.desc}}</template>`)
126
138
  .replace('@search="onSearch"', '')
127
139
  const skeletonTemplate = `
128
140
  <cv-data-table-skeleton
@@ -137,6 +149,19 @@ const skeletonTemplate = `
137
149
 
138
150
  **Usage:**
139
151
  - Sorting, filtering and pagination are the responsibility of the component user. This component raises events to facilitate this.
152
+ For example the test data is sorted like this but this is very specific to this data. Users will need to provide their own sort and filtering.
153
+ ```javascript
154
+ function sortTestData(opts) {
155
+ if (opts.order === 'none')
156
+ return testData.value.sort((a, b) => a.index.localeCompare(b.index, 'en', { sensitivity: 'base' }));
157
+ let direction = 1
158
+ if (opts.order === 'descending') direction = -1
159
+ if (opts.name === 'name')
160
+ return testData.value.sort((a, b) => direction * a.name.localeCompare(b.name, 'en', { sensitivity: 'base' }));
161
+ else if (opts.name === 'year')
162
+ return testData.value.sort((a, b) => direction * (a.year - b.year));
163
+ }
164
+ ```
140
165
  - The search bar appears only if the search event is listened for.
141
166
 
142
167
  **Row attributes:**
@@ -127,11 +127,9 @@ const internalOrder = computed(() => {
127
127
  return undefined;
128
128
  }
129
129
  const heading = store.findHeading(parent, cvId);
130
- if (heading?.order !== 'ascending' && heading?.order !== 'descending') {
131
- return 'none';
132
- } else {
133
- return heading?.order;
134
- }
130
+ if (['ascending', 'descending', 'none'].includes(heading?.order))
131
+ return heading.order;
132
+ else return 'none';
135
133
  });
136
134
 
137
135
  const headingLabelTag = computed(() => {