@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/CHANGELOG.md +8 -0
- package/dist/components/base/toggle/toggle.js +18 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/package.json +1 -1
- package/src/components/base/toggle/toggle.scss +1 -2
- package/src/components/base/toggle/toggle.spec.js +24 -0
- package/src/components/base/toggle/toggle.stories.js +20 -2
- package/src/components/base/toggle/toggle.vue +27 -1
package/package.json
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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="
|
|
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"
|