@carbon/vue 3.0.9-alpha.0 → 3.0.9

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/vue",
3
3
  "license": "Apache-2.0",
4
- "version": "3.0.9-alpha.0",
4
+ "version": "3.0.9",
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",
@@ -206,5 +206,5 @@
206
206
  "url": "git+https://github.com/carbon-design-system/carbon-components-vue.git"
207
207
  },
208
208
  "sideEffects": true,
209
- "gitHead": "39dd5beb19a710758bd9c2b44a413f9cc296d31b"
209
+ "gitHead": "746ba85d1d2060314ea9bb7f8ae9c45783572efc"
210
210
  }
@@ -48,7 +48,7 @@ const skeletonTemplate = `
48
48
  </div>
49
49
  `;
50
50
 
51
- export const args = {
51
+ export const argTypes = {
52
52
  // attributes
53
53
  multiple: {
54
54
  type: 'boolean',
@@ -61,6 +61,7 @@ export const args = {
61
61
  // props
62
62
  accept: {
63
63
  type: 'string',
64
+ defaultValue: '.jpg,.png',
64
65
  table: {
65
66
  type: { summary: 'string' },
66
67
  category: 'props',
@@ -106,6 +107,14 @@ export const args = {
106
107
  },
107
108
  description: 'Reset file list when files are added',
108
109
  },
110
+ disabled: {
111
+ type: 'boolean',
112
+ table: {
113
+ type: { summary: 'boolean' },
114
+ category: 'props',
115
+ },
116
+ description: 'Disables input',
117
+ },
109
118
  dropTargetLabel: {
110
119
  type: 'string',
111
120
  table: {
@@ -122,6 +131,14 @@ export const args = {
122
131
  },
123
132
  description: 'Helper text positioned below label',
124
133
  },
134
+ initialStateUploading: {
135
+ type: 'boolean',
136
+ table: {
137
+ type: { summary: 'boolean' },
138
+ category: 'props',
139
+ },
140
+ description: 'Set "UPLOADING" state to new files',
141
+ },
125
142
  kind: {
126
143
  type: 'string',
127
144
  control: 'select',
@@ -235,7 +252,7 @@ Migration notes:
235
252
  helperText: 'Select the files you want to upload',
236
253
  removable: true,
237
254
  }}
238
- argTypes={args}
255
+ argTypes={argTypes}
239
256
  >
240
257
  {Template.bind({})}
241
258
  </Story>
@@ -263,11 +280,12 @@ Migration notes:
263
280
  helperText: 'Select the files you want to upload',
264
281
  kind: KINDS.BUTTON,
265
282
  removable: true,
283
+ dropTargetLabel: 'Add file',
266
284
  }}
267
285
  argTypes={{
268
- ...args,
286
+ ...argTypes,
269
287
  kind: {
270
- ...args.kind,
288
+ ...argTypes.kind,
271
289
  control: 'none',
272
290
  },
273
291
  }}
@@ -299,9 +317,9 @@ Migration notes:
299
317
  removable: true,
300
318
  }}
301
319
  argTypes={{
302
- ...args,
320
+ ...argTypes,
303
321
  kind: {
304
- ...args.kind,
322
+ ...argTypes.kind,
305
323
  control: 'none',
306
324
  },
307
325
  }}
@@ -1,11 +1,28 @@
1
1
  <template>
2
2
  <cv-form-item class="cv-file-uploader">
3
- <p :class="`${carbonPrefix}--file--label`">{{ label }}</p>
4
- <p :class="`${carbonPrefix}--label-description`">{{ helperText }}</p>
3
+ <p
4
+ :class="[
5
+ `${carbonPrefix}--file--label`,
6
+ { [`${carbonPrefix}--file--label--disabled`]: disabled },
7
+ ]"
8
+ >
9
+ {{ label }}
10
+ </p>
11
+ <p
12
+ :class="[
13
+ `${carbonPrefix}--label-description`,
14
+ { [`${carbonPrefix}--label-description--disabled`]: disabled },
15
+ ]"
16
+ >
17
+ {{ helperText }}
18
+ </p>
5
19
  <div v-if="kind === 'button'" :class="`${carbonPrefix}--file`" data-file>
6
20
  <label
7
21
  :for="cvId"
8
- :class="buttonClasses"
22
+ :class="[
23
+ buttonClasses,
24
+ { [`${carbonPrefix}--btn--disabled`]: disabled },
25
+ ]"
9
26
  tabindex="0"
10
27
  @keydown.enter.prevent="onKeyHit"
11
28
  @keydown.space.prevent="onKeyHit"
@@ -17,6 +34,7 @@
17
34
  ref="fileInput"
18
35
  :class="`${carbonPrefix}--file-input`"
19
36
  :accept="accept"
37
+ :disabled="disabled"
20
38
  type="file"
21
39
  v-bind="$attrs"
22
40
  data-file-uploader
@@ -34,8 +52,10 @@
34
52
  `${carbonPrefix}--file-browse-btn`,
35
53
  `${carbonPrefix}--file__drop-container`,
36
54
  {
37
- [`${carbonPrefix}--file__drop-container--drag-over`]: allowDrop,
55
+ [`${carbonPrefix}--file__drop-container--drag-over`]:
56
+ allowDrop && !disabled,
38
57
  },
58
+ { [`${carbonPrefix}--file-browse-btn--disabled`]: disabled },
39
59
  ]"
40
60
  @dragover="onDragEvent"
41
61
  @dragleave="onDragEvent"
@@ -50,6 +70,7 @@
50
70
  ref="fileInput"
51
71
  :class="`${carbonPrefix}--file-input`"
52
72
  :accept="accept"
73
+ :disabled="disabled"
53
74
  type="file"
54
75
  v-bind="$attrs"
55
76
  tabindex="-1"
@@ -107,8 +128,10 @@ const props = defineProps({
107
128
  },
108
129
  buttonSize: commonCvButtonProps.size,
109
130
  clearOnReselect: Boolean,
131
+ disabled: Boolean,
110
132
  dropTargetLabel: String,
111
133
  helperText: String,
134
+ initialStateUploading: Boolean,
112
135
  kind: {
113
136
  type: String,
114
137
  default: KINDS.DRAG_TARGET,
@@ -178,7 +201,7 @@ function addFiles(files) {
178
201
  const newFile = createInternalFile(internalFile?.file || file);
179
202
 
180
203
  if (internalFile) {
181
- internalFile.state = newFile.initialState;
204
+ internalFile.state = newFile.state;
182
205
  internalFile.invalidMessageTitle = newFile.invalidMessageTitle;
183
206
  internalFile.invalidMessage = newFile.invalidMessage;
184
207
  } else {
@@ -216,6 +239,11 @@ function onChange(ev) {
216
239
  }
217
240
 
218
241
  function onDragEvent(evt) {
242
+ if (props.disabled) {
243
+ evt.preventDefault();
244
+ return;
245
+ }
246
+
219
247
  if (Array.prototype.indexOf.call(evt.dataTransfer.types, 'Files') === -1) {
220
248
  return;
221
249
  }
@@ -249,7 +277,7 @@ function onDragEvent(evt) {
249
277
 
250
278
  function onItemRemove(index) {
251
279
  internalFiles.value.splice(index, 1);
252
- emit('update:modelValue', this.internalFiles);
280
+ emit('update:modelValue', internalFiles.value);
253
281
  }
254
282
 
255
283
  function onKeyHit() {
@@ -262,20 +290,31 @@ onMounted(() => {
262
290
  });
263
291
 
264
292
  // exposed methods
293
+ function clear() {
294
+ internalFiles.value = [];
295
+ emit('update:modelValue', internalFiles.value);
296
+ }
297
+
298
+ function remove(index) {
299
+ onItemRemove(index);
300
+ }
301
+
302
+ function setInvalidMessage(index, message) {
303
+ internalFiles.value[index].invalidMessage = message;
304
+ }
305
+
306
+ function setState(index, state) {
307
+ if ([STATES.COMPLETE, STATES.UPLOADING, STATES.NONE].includes(state)) {
308
+ internalFiles.value[index].state = state;
309
+ }
310
+ }
311
+
312
+ // exposing methods
265
313
  defineExpose({
266
- setState(index, state) {
267
- if ([STATES.COMPLETE, STATES.UPLOADING, STATES.NONE].includes(state)) {
268
- internalFiles.value[index].state = state;
269
- }
270
- },
271
- clear() {
272
- internalFiles.value = [];
273
- emit('update:modelValue', internalFiles);
274
- },
275
- setInvalidMessage(index, message) {
276
- internalFiles.value[index].invalidMessage = message;
277
- },
278
- remove: onItemRemove,
314
+ clear,
315
+ remove,
316
+ setInvalidMessage,
317
+ setState,
279
318
  });
280
319
  </script>
281
320
 
@@ -5,6 +5,7 @@ import CvTab from './CvTab.vue';
5
5
  import CvTabsSkeleton from './CvTabsSkeleton.vue';
6
6
  import SbContainer from './_SbContainer.vue';
7
7
  import { action } from '@storybook/addon-actions';
8
+ import { IbmSecurity20 as SampleIcon } from '@carbon/icons-vue';
8
9
 
9
10
  <Meta
10
11
  title={`${sbCompPrefix}/CvTabs`}
@@ -23,6 +24,7 @@ export const Template = args => ({
23
24
  CvTabs,
24
25
  CvTab,
25
26
  CvTabsSkeleton,
27
+ SampleIcon,
26
28
  },
27
29
  // The story's `args` need to be mapped into the template through the `setup()` method
28
30
  setup() {
@@ -31,6 +33,7 @@ export const Template = args => ({
31
33
  noDefaultToFirst: args.noDefaultToFirst,
32
34
  selectedId: args.selectedId,
33
35
  disabledIds: args.disabledIds,
36
+ slottedTabs: args.slottedTabs,
34
37
  onTabSelected: action('tab-selected'),
35
38
  onTabSelectedId: action('tab-selected-id'),
36
39
  };
@@ -46,20 +49,47 @@ const defaultTemplate = `
46
49
  @tab-selected-id="onTabSelectedId"
47
50
  aria-label="navigation tab label">
48
51
  <cv-tab id="tab-1" label="House" :selected="selectedId === 'tab-1'" :disabled="disabledIds.includes('tab-1')">
49
- <p>
52
+ <p v-if="slottedTabs">
53
+ To customise tab look, in CvTabs component use scoped slot named with tab's id.
54
+ Example: current tab has id "<strong>tab-1</strong>", so the code for customising tab looks like:
55
+ <div style="background-color: lightgrey; padding: 0.5rem;">
56
+ &lt;template #tab-1="tab"&gt;
57
+ {&nbsp;{ tab.label }&nbsp;} &lt;IbmSecurity20 /&gt;
58
+ &lt;template&gt;
59
+ </div>
60
+ </p>
61
+ <p v-else>
50
62
  29 Arlington Avenue is a house in Islington, London. Douglas Adams shared the house for a time
51
63
  with Jonny Brock and Clare Gorst. It is mentioned in the dedication of The Hitchhiker's Guide to
52
64
  the Galaxy, which is dedicated to the "Arlingtonians for tea, sympathy, and a sofa."
53
65
  </p>
54
66
  </cv-tab>
55
67
  <cv-tab id="tab-2" label="Bar" :selected="selectedId === 'tab-2'" :disabled="disabledIds.includes('tab-2')">
56
- <p>
68
+ <p v-if="slottedTabs">
69
+ To customise tab look, in CvTabs component use scoped slot named with tab's id.
70
+ Example: current tab has id "<strong>tab-2</strong>", so the code for customising tab looks like:
71
+ <div style="background-color: lightgrey; padding: 0.5rem;">
72
+ &lt;template #tab-2="tab"&gt;
73
+ {&nbsp;{ tab.label }&nbsp;} &lt;strong style="color: red;"&gt;(*)&lt;/strong&gt;
74
+ &lt;template&gt;
75
+ </div>
76
+ </p>
77
+ <p v-else>
57
78
  The Old Pink Dog Bar was the bar in Han Dold City that Ford Prefect was in when he discovered
58
79
  that his Guide had his full entry on Earth on it.
59
80
  </p>
60
81
  </cv-tab>
61
82
  <cv-tab id="tab-3" label="Reach" :selected="selectedId === 'tab-3'" :disabled="disabledIds.includes('tab-3')">
62
- <p>
83
+ <p v-if="slottedTabs">
84
+ To customise tab look, in CvTabs component use scoped slot named with tab's id.
85
+ Example: current tab has id "<strong>tab-3</strong>", so the code for customising tab looks like:
86
+ <div style="background-color: lightgrey; padding: 0.5rem;">
87
+ &lt;template #tab-3="tab"&gt;
88
+ {&nbsp;{ tab.label }&nbsp;} &lt;strong style="color: orange;"&gt;(!)&lt;/strong&gt;
89
+ &lt;template&gt;
90
+ </div>
91
+ </p>
92
+ <p v-else>
63
93
  The Third Reach of the Unknown is what might be loosely described as a "place" which exists only
64
94
  under high improbability conditions and was created on the starship Heart of Gold due to the
65
95
  Infinite Improbability Drive. During Arthur Dent and Ford Prefect's first trip on board the Heart
@@ -81,6 +111,15 @@ const defaultTemplate = `
81
111
  <a target='_blank' href='https://hitchhikers.fandom.com/wiki/Main_Page'>credits</a>
82
112
  </p>
83
113
  </cv-tab>
114
+ <template v-if="slottedTabs" #tab-1="tab">
115
+ House <SampleIcon/>
116
+ </template>
117
+ <template v-if="slottedTabs" #tab-2="tab">
118
+ {{tab.label}} <strong style="color: red;">(*)</strong>
119
+ </template>
120
+ <template v-if="slottedTabs" #tab-3="tab">
121
+ {{tab.label}} <strong style="color: orange;">(!)</strong>
122
+ </template>
84
123
  </cv-tabs>
85
124
  `;
86
125
  const skeletonTemplate = `<cv-tabs-skeleton></cv-tabs-skeleton>`;
@@ -173,3 +212,45 @@ screens, and so I suggest using a different component for mobile cases.
173
212
  {Template.bind({})}
174
213
  </Story>
175
214
  </Canvas>
215
+
216
+ # Tabs slotted
217
+
218
+ <Canvas>
219
+ <Story
220
+ name="tabsSlot"
221
+ parameters={{
222
+ controls: {
223
+ exclude: [
224
+ 'default',
225
+ 'template',
226
+ 'leftOverflowIconButtonProps',
227
+ 'rightOverflowIconButtonProps',
228
+ 'scrollIntoView',
229
+ 'tab-selected',
230
+ 'tab-selected-id',
231
+ 'slottedTabs',
232
+ ],
233
+ },
234
+ docs: { source: { code: defaultTemplate } },
235
+ }}
236
+ args={{
237
+ template: defaultTemplate,
238
+ selectedId: '',
239
+ disabledIds: [],
240
+ slottedTabs: true
241
+ }}
242
+ argTypes={{
243
+ selectedId: {
244
+ control: 'select',
245
+ default: '',
246
+ options: ['', 'tab-1', 'tab-2', 'tab-3', 'tab-4', 'tab-5'],
247
+ },
248
+ disabledIds: {
249
+ control: 'multi-select',
250
+ options: ['tab-1', 'tab-2', 'tab-3', 'tab-4', 'tab-5'],
251
+ },
252
+ }}
253
+ >
254
+ {Template.bind({})}
255
+ </Story>
256
+ </Canvas>
@@ -76,7 +76,9 @@
76
76
  :tabindex="selectedId === tab.uid ? 0 : -1"
77
77
  type="button"
78
78
  >
79
- {{ tab.label }}
79
+ <slot :name="tab.uid" v-bind="tab">
80
+ {{ tab.label }}
81
+ </slot>
80
82
  </button>
81
83
  </li>
82
84
  </ul>
@@ -0,0 +1,24 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`CvTabs CvTabs - test slotted tab buttons to match snapshot 1`] = `
4
+ <div class="cv-tabs ABC-class-123" style="width: 100%;" aria-label="ABC-aria-label-123">
5
+ <div data-tabs="" class="cv-tab bx--tabs--scrollable ABC-class-123" role="navigation" aria-label="ABC-aria-label-123"><button aria-hidden="true" aria-label="scroll left" class="bx--tab--overflow-nav-button--hidden" tabindex="-1" type="button"><svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
6
+ <path d="M5 8L10 3 10.7 3.7 6.4 8 10.7 12.3 10 13z"></path>
7
+ </svg></button>
8
+ <!--v-if-->
9
+ <ul class="bx--tabs--scrollable__nav" role="tablist">
10
+ <li class="cv-tabs-button bx--tabs--scrollable__nav-item bx--tabs__nav-item--selected bx--tabs--scrollable__nav-item--selected" role="presentation"><button class="bx--tabs--scrollable__nav-link" role="tab" aria-controls="tab-1" aria-disabled="false" aria-selected="true" id="tab-1-link" tabindex="0" type="button">Hello <strong style="color: red;">(*)</strong></button></li>
11
+ <li class="cv-tabs-button bx--tabs--scrollable__nav-item" role="presentation"><button class="bx--tabs--scrollable__nav-link" role="tab" aria-controls="tab-2" aria-disabled="false" aria-selected="false" id="tab-2-link" tabindex="-1" type="button">Origin<strong style="color: orange;">(!)</strong></button></li>
12
+ <li class="cv-tabs-button bx--tabs--scrollable__nav-item" role="presentation"><button class="bx--tabs--scrollable__nav-link" role="tab" aria-controls="tab-3" aria-disabled="false" aria-selected="false" id="tab-3-link" tabindex="-1" type="button">Tab 3 label</button></li>
13
+ </ul>
14
+ <!--v-if--><button aria-hidden="true" aria-label="scroll right" class="bx--tab--overflow-nav-button--hidden" tabindex="-1" type="button"><svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
15
+ <path d="M11 8L6 13 5.3 12.3 9.6 8 5.3 3.7 6 3z"></path>
16
+ </svg></button>
17
+ </div>
18
+ <div class="cv-tabs__panels">
19
+ <div class="cv-tab bx--tab-content" id="tab-1" role="tabpanel" aria-labelledby="tab-1-link" aria-hidden="false">Tab 1 content</div>
20
+ <div class="cv-tab bx--tab-content" id="tab-2" role="tabpanel" aria-labelledby="tab-2-link" aria-hidden="true" hidden="">Tab 2 content</div>
21
+ <div class="cv-tab bx--tab-content" id="tab-3" role="tabpanel" aria-labelledby="tab-3-link" aria-hidden="true" hidden="">Tab 3 content</div>
22
+ </div>
23
+ </div>
24
+ `;
@@ -14,7 +14,7 @@ export default {
14
14
  },
15
15
  };
16
16
 
17
- const template = `<CvTag @remove="onRemove" v-bind="args" />`;
17
+ const template = `<cv-tag @remove="onRemove" v-bind="args" />`;
18
18
  const Template = (args, { argTypes }) => {
19
19
  return {
20
20
  props: Object.keys(argTypes),
@@ -56,6 +56,7 @@ Filter.parameters = storyParametersObject(
56
56
  export const Skeleton = Template.bind({});
57
57
  Skeleton.args = {
58
58
  skeleton: true,
59
+ label: '',
59
60
  };
60
61
  Skeleton.parameters = storyParametersObject(
61
62
  Skeleton.parameters,
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div v-if="skeleton" :class="tagClasses" />
2
+ <div v-if="skeleton" :class="tagClasses"></div>
3
3
  <div v-else :class="tagClasses" role="listitem" :title="title">
4
4
  <span :class="`${carbonPrefix}--tag__label`">
5
5
  {{ label }}
@@ -56,6 +56,10 @@ export default {
56
56
  * skeleton used when loading
57
57
  */
58
58
  skeleton: Boolean,
59
+ /**
60
+ * tag size small
61
+ */
62
+ small: Boolean,
59
63
  },
60
64
  emits: [
61
65
  /**
@@ -69,14 +73,15 @@ export default {
69
73
  });
70
74
 
71
75
  const tagClasses = computed(() => {
72
- const classes = [
73
- `${carbonPrefix}--tag`,
74
- `${carbonPrefix}--tag--${props.kind}`,
75
- ];
76
+ const classes = [`${carbonPrefix}--tag`];
77
+
78
+ if (props.small) classes.push(`${carbonPrefix}--tag--sm`);
76
79
 
77
80
  if (props.skeleton) {
78
81
  classes.push(`${carbonPrefix}--skeleton`);
79
82
  } else {
83
+ classes.push(`${carbonPrefix}--tag--${props.kind}`);
84
+
80
85
  if (props.filter) {
81
86
  classes.push(`${carbonPrefix}--tag--filter`);
82
87
  }
@@ -0,0 +1,39 @@
1
+ import {
2
+ sbCompPrefix,
3
+ storyParametersObject,
4
+ } from '../../global/storybook-utils';
5
+ import CvTagSkeleton from './CvTagSkeleton.vue';
6
+
7
+ export default {
8
+ title: `${sbCompPrefix}/CvTagSkeleton`,
9
+ component: CvTagSkeleton,
10
+ };
11
+
12
+ const template = `<cv-tag-skeleton v-bind="args"></cv-tag-skeleton>`;
13
+ const Template = (args, { argTypes }) => {
14
+ return {
15
+ props: Object.keys(argTypes),
16
+ components: { CvTagSkeleton },
17
+ template,
18
+ setup() {
19
+ return { args };
20
+ },
21
+ };
22
+ };
23
+
24
+ export const Default = Template.bind({});
25
+ Default.parameters = storyParametersObject(
26
+ Default.parameters,
27
+ template,
28
+ Default.args
29
+ );
30
+
31
+ export const Small = Template.bind({});
32
+ Small.args = {
33
+ small: true,
34
+ };
35
+ Small.parameters = storyParametersObject(
36
+ Small.parameters,
37
+ template,
38
+ Small.args
39
+ );
@@ -0,0 +1,20 @@
1
+ <template>
2
+ <CvTag skeleton :small="small" :label="''" />
3
+ </template>
4
+
5
+ <script>
6
+ import CvTag from './CvTag.vue';
7
+
8
+ export default {
9
+ name: 'CvTagSkeleton',
10
+ components: { CvTag },
11
+ props: {
12
+ /**
13
+ * tag size small
14
+ */
15
+ small: {
16
+ type: Boolean,
17
+ },
18
+ },
19
+ };
20
+ </script>
@@ -1,5 +1,6 @@
1
1
  import CvTag from './CvTag.vue';
2
2
  import CvTagConsts from './consts';
3
+ import CvTagSkeleton from './CvTagSkeleton.vue';
3
4
 
4
- export { CvTag, CvTagConsts };
5
+ export { CvTag, CvTagConsts, CvTagSkeleton };
5
6
  export default CvTag;