@gitlab/ui 55.2.1 → 55.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "55.2.1",
3
+ "version": "55.3.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -44,7 +44,7 @@
44
44
  }
45
45
 
46
46
  .gl-toggle-label,
47
- .gl-help-label {
47
+ .gl-description-label {
48
48
  @include gl-text-gray-500;
49
49
  }
50
50
  }
@@ -73,7 +73,6 @@
73
73
  }
74
74
 
75
75
  .gl-toggle-label {
76
- @include gl-mb-3;
77
76
  @include gl-font-weight-bold;
78
77
  }
79
78
 
@@ -8,6 +8,7 @@ describe('toggle', () => {
8
8
  let wrapper;
9
9
 
10
10
  const label = 'toggle label';
11
+ const descriptionText = 'description text';
11
12
  const helpText = 'help text';
12
13
 
13
14
  const createWrapper = (props = {}, options = {}) => {
@@ -21,6 +22,7 @@ describe('toggle', () => {
21
22
  };
22
23
 
23
24
  const findButton = () => wrapper.find('button');
25
+ const findDescriptionElement = () => wrapper.find('[data-testid="toggle-description"]');
24
26
  const findHelpElement = () => wrapper.find('[data-testid="toggle-help"]');
25
27
 
26
28
  it('has role=switch', () => {
@@ -85,6 +87,28 @@ describe('toggle', () => {
85
87
  });
86
88
  });
87
89
 
90
+ describe.each`
91
+ state | description | props | options
92
+ ${'with description'} | ${descriptionText} | ${{ description: descriptionText }} | ${undefined}
93
+ ${'with description in slot'} | ${descriptionText} | ${undefined} | ${{ slots: { description: descriptionText } }}
94
+ ${'without description'} | ${undefined} | ${undefined} | ${undefined}
95
+ ${'with description and labelPosition left'} | ${undefined} | ${{ desciption: descriptionText, labelPosition: toggleLabelPosition.left }} | ${undefined}
96
+ `('$state', ({ description, props, options }) => {
97
+ beforeEach(() => {
98
+ createWrapper(props, options);
99
+ });
100
+
101
+ if (description) {
102
+ it('shows description', () => {
103
+ expect(findDescriptionElement().text()).toBe(description);
104
+ });
105
+ } else {
106
+ it('does not show description', () => {
107
+ expect(findDescriptionElement().exists()).toBe(false);
108
+ });
109
+ }
110
+ });
111
+
88
112
  describe.each`
89
113
  state | help | props | options | getAriaDescribedBy
90
114
  ${'with help'} | ${helpText} | ${{ help: helpText }} | ${undefined} | ${() => findHelpElement().attributes('id')}
@@ -5,7 +5,9 @@ import readme from './toggle.md';
5
5
 
6
6
  const defaultValue = (prop) => GlToggle.props[prop].default;
7
7
 
8
- const longHelp = `This is a toggle component with a long help message.
8
+ const withDescription = 'A dark color theme that is easier on the eyes.';
9
+
10
+ const longHelp = `This is a toggle component with a long help message.
9
11
  You can notice how the text wraps when the width of the container
10
12
  is not enough to fix the entire text.`;
11
13
 
@@ -15,7 +17,8 @@ const generateProps = ({
15
17
  isLoading = defaultValue('isLoading'),
16
18
  label = 'Dark mode',
17
19
  labelId = 'dark-mode-toggle',
18
- help = 'Toggle dark mode for the website',
20
+ description = '',
21
+ help = 'Toggle dark mode for the website.',
19
22
  labelPosition = defaultValue('labelPosition'),
20
23
  } = {}) => ({
21
24
  value,
@@ -23,6 +26,7 @@ const generateProps = ({
23
26
  isLoading,
24
27
  label,
25
28
  labelId,
29
+ description,
26
30
  help,
27
31
  labelPosition,
28
32
  });
@@ -35,6 +39,7 @@ const Template = (args, { argTypes }) => ({
35
39
  <gl-toggle
36
40
  v-model="value"
37
41
  :disabled="disabled"
42
+ :description="description"
38
43
  :help="help"
39
44
  :label-id="labelId"
40
45
  :is-loading="isLoading"
@@ -47,11 +52,21 @@ const Template = (args, { argTypes }) => ({
47
52
  export const Default = Template.bind({});
48
53
  Default.args = generateProps();
49
54
 
55
+ export const WithDescription = Template.bind({});
56
+ WithDescription.args = generateProps({
57
+ description: withDescription,
58
+ });
59
+
50
60
  export const WithLongHelp = Template.bind({});
51
61
  WithLongHelp.args = generateProps({
52
62
  help: longHelp,
53
63
  });
54
64
 
65
+ export const LabelPositionLeft = Template.bind({});
66
+ LabelPositionLeft.args = generateProps({
67
+ labelPosition: 'left',
68
+ });
69
+
55
70
  export default {
56
71
  title: 'base/toggle',
57
72
  component: GlToggle,
@@ -71,6 +86,9 @@ export default {
71
86
  label: {
72
87
  control: 'text',
73
88
  },
89
+ description: {
90
+ control: 'text',
91
+ },
74
92
  help: {
75
93
  control: 'text',
76
94
  },
@@ -55,6 +55,14 @@ export default {
55
55
  type: String,
56
56
  required: true,
57
57
  },
58
+ /**
59
+ * The toggle's description.
60
+ */
61
+ description: {
62
+ type: String,
63
+ required: false,
64
+ default: undefined,
65
+ },
58
66
  /**
59
67
  * A help text to be shown below the toggle.
60
68
  */
@@ -81,10 +89,20 @@ export default {
81
89
  };
82
90
  },
83
91
  computed: {
92
+ shouldRenderDescription() {
93
+ // eslint-disable-next-line @gitlab/vue-prefer-dollar-scopedslots
94
+ return Boolean(this.$scopedSlots.description || this.description) && this.isVerticalLayout;
95
+ },
84
96
  shouldRenderHelp() {
85
97
  // eslint-disable-next-line @gitlab/vue-prefer-dollar-scopedslots
86
98
  return Boolean(this.$slots.help || this.help) && this.isVerticalLayout;
87
99
  },
100
+ toggleClasses() {
101
+ return [
102
+ { 'gl-sr-only': this.labelPosition === 'hidden' },
103
+ this.shouldRenderDescription ? 'gl-mb-2' : 'gl-mb-3',
104
+ ];
105
+ },
88
106
  icon() {
89
107
  return this.value ? 'mobile-issue-close' : 'close';
90
108
  },
@@ -132,13 +150,21 @@ export default {
132
150
  >
133
151
  <span
134
152
  :id="labelId"
135
- :class="{ 'gl-sr-only': labelPosition === 'hidden' }"
153
+ :class="toggleClasses"
136
154
  class="gl-toggle-label gl-flex-shrink-0"
137
155
  data-testid="toggle-label"
138
156
  >
139
157
  <!-- @slot The toggle's label. -->
140
158
  <slot name="label">{{ label }}</slot>
141
159
  </span>
160
+ <span
161
+ v-if="shouldRenderDescription"
162
+ class="gl-description-label gl-mb-3"
163
+ data-testid="toggle-description"
164
+ >
165
+ <!-- @slot A description text to be shown below the label. -->
166
+ <slot name="description">{{ description }}</slot>
167
+ </span>
142
168
  <input v-if="name" :name="name" :value="value" type="hidden" />
143
169
  <button
144
170
  role="switch"