@gitlab/ui 77.2.0 → 77.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/components/base/new_dropdowns/base_dropdown/base_dropdown.js +10 -3
  3. package/dist/components/base/sorting/sorting.js +1 -4
  4. package/dist/index.css +2 -2
  5. package/dist/index.css.map +1 -1
  6. package/dist/tokens/common_story_options.js +28 -68
  7. package/dist/tokens/css/tokens.css +1 -1
  8. package/dist/tokens/css/tokens.dark.css +1 -1
  9. package/dist/tokens/js/tokens.dark.js +1 -1
  10. package/dist/tokens/js/tokens.js +1 -1
  11. package/dist/tokens/scss/_tokens.dark.scss +1 -1
  12. package/dist/tokens/scss/_tokens.scss +1 -1
  13. package/dist/tokens/tokens_story.js +83 -0
  14. package/package.json +1 -1
  15. package/src/components/base/button/button.stories.js +0 -30
  16. package/src/components/base/button_group/button_group.md +22 -0
  17. package/src/components/base/button_group/button_group.stories.js +92 -12
  18. package/src/components/base/new_dropdowns/base_dropdown/base_dropdown.spec.js +1 -1
  19. package/src/components/base/new_dropdowns/base_dropdown/base_dropdown.vue +8 -1
  20. package/src/components/base/new_dropdowns/disclosure/disclosure_dropdown.md +13 -9
  21. package/src/components/base/new_dropdowns/disclosure/disclosure_dropdown.scss +0 -32
  22. package/src/components/base/new_dropdowns/dropdown.scss +58 -2
  23. package/src/components/base/new_dropdowns/listbox/listbox.md +19 -15
  24. package/src/components/base/sorting/sorting.vue +1 -9
  25. package/src/tokens/color.dark.tokens.stories.js +8 -38
  26. package/src/tokens/color.data_viz.dark.tokens.stories.js +7 -27
  27. package/src/tokens/color.data_viz.tokens.stories.js +7 -27
  28. package/src/tokens/color.theme.dark.tokens.stories.js +8 -32
  29. package/src/tokens/color.theme.tokens.stories.js +8 -32
  30. package/src/tokens/color.tokens.stories.js +8 -38
  31. package/src/tokens/color.transparency.tokens.stories.js +5 -14
  32. package/src/tokens/common_story_options.js +21 -67
  33. package/src/tokens/text.tokens.stories.js +4 -7
  34. package/src/tokens/tokens_story.vue +73 -0
@@ -64,7 +64,6 @@
64
64
  &.gl-new-dropdown-toggle-no-caret .gl-new-dropdown-chevron {
65
65
  @include gl-display-none;
66
66
  }
67
-
68
67
  }
69
68
 
70
69
  .gl-new-dropdown-toggle {
@@ -110,7 +109,15 @@
110
109
  &.btn-sm .gl-new-dropdown-chevron {
111
110
  @include gl-mx-0;
112
111
  }
113
-
112
+ }
113
+
114
+ .gl-new-dropdown-caret-only {
115
+ // optically center the caret
116
+ @include gl-pl-2;
117
+
118
+ &.btn-sm {
119
+ @include gl-pl-0;
120
+ }
114
121
  }
115
122
 
116
123
  $dropdown-content-padding: 0.25rem;
@@ -178,3 +185,52 @@
178
185
  }
179
186
  }
180
187
  }
188
+
189
+ .btn-group {
190
+ .gl-new-dropdown:not(:last-child) {
191
+ .gl-new-dropdown-toggle {
192
+ @include gl-rounded-top-right-none;
193
+ @include gl-rounded-bottom-right-none;
194
+ }
195
+ }
196
+
197
+ .gl-new-dropdown:not(:first-child) {
198
+ .gl-new-dropdown-toggle {
199
+ @include gl-rounded-top-left-none;
200
+ @include gl-rounded-bottom-left-none;
201
+
202
+ // Prevent double borders when buttons are next to each other
203
+ margin-left: -1px;
204
+ }
205
+ }
206
+
207
+ // The dropdown toggle of a "split" is by design supposed to be the last
208
+ // child of a button group, so only apply styles for that.
209
+ .gl-new-dropdown:last-child {
210
+ .gl-new-dropdown-caret-only {
211
+ &.btn-confirm,
212
+ &.btn-danger {
213
+ margin-left: 1px;
214
+ }
215
+
216
+ &:disabled,
217
+ &.disabled,
218
+ &[class*='-secondary'] {
219
+ margin-left: -1px;
220
+ }
221
+ }
222
+ }
223
+
224
+ .gl-new-dropdown:hover {
225
+ .gl-new-dropdown-toggle {
226
+ @include gl-z-index-1;
227
+ }
228
+ }
229
+
230
+ .gl-new-dropdown {
231
+ .gl-new-dropdown-toggle:focus,
232
+ .gl-new-dropdown-toggle:active {
233
+ @include gl-z-index-1;
234
+ }
235
+ }
236
+ }
@@ -8,7 +8,7 @@ When option is selected, the dropdown will be closed and focus set on the toggle
8
8
  **Multi-select:** Selecting an option will not update the toggle, but it can be customized
9
9
  providing `toggleText` property. Also, selecting or deselecting an item won't close the dropdown.
10
10
 
11
- ### Icon-only listbox
11
+ ## Icon-only listbox
12
12
 
13
13
  Icon-only listboxes must have an accessible name.
14
14
  You can provide this with the combination of `toggleText` and `textSrOnly` props.
@@ -27,12 +27,12 @@ Optionally, you can use `no-caret` to remove the caret and `category="tertiary"`
27
27
  >
28
28
  ```
29
29
 
30
- ### Opening the listbox
30
+ ## Opening the listbox
31
31
 
32
32
  Listbox will open on toggle button click (if it was previously closed).
33
33
  On open, `GlCollapsibleListbox` will emit the `shown` event.
34
34
 
35
- ### Closing the listbox
35
+ ## Closing the listbox
36
36
 
37
37
  The listbox is closed by any of the following:
38
38
 
@@ -42,21 +42,21 @@ The listbox is closed by any of the following:
42
42
 
43
43
  After closing, `GlCollapsibleListbox` emits a `hidden` event.
44
44
 
45
- ### Selecting items
45
+ ## Selecting items
46
46
 
47
47
  Set the `v-model` on the listbox to have 2-way data binding for the selected items in the listbox.
48
48
  Alternatively, you can set `selected` property to the array of selected items
49
49
  `value` properties (for multi-select) or to the selected item `value` property for a single-select.
50
50
  On selection the listbox will emit the `select` event with the selected values.
51
51
 
52
- ### Resetting the selection
52
+ ## Resetting the selection
53
53
 
54
54
  `GlCollapsibleListbox` can render a reset button if the `headerText` and
55
55
  `resetButtonLabel` props are provided.
56
56
  When clicking on the reset button, a `reset` event is emitted. It is the consumer's responsibility
57
57
  to listen to that event and to update the model as needed.
58
58
 
59
- ### Setting listbox options
59
+ ## Setting listbox options
60
60
 
61
61
  Use the `items` prop to provide options to the listbox. Each item can be
62
62
  either an option or a group. Below are the expected shapes of these
@@ -77,7 +77,7 @@ type Group = {
77
77
  type ItemsProp = Array<Option> | Array<Group>
78
78
  ```
79
79
 
80
- #### Options
80
+ ### Options
81
81
 
82
82
  The `value` property of options must be unique across all options
83
83
  provided to the listbox, as it's used as a primary key.
@@ -100,7 +100,7 @@ template. If you want to render a custom template for items, use the
100
100
  </gl-collapsible-listbox>
101
101
  ```
102
102
 
103
- #### Groups
103
+ ### Groups
104
104
 
105
105
  Options can be contained within groups. A group has a required `text`
106
106
  property, which must be unique across all groups within the listbox, as
@@ -123,7 +123,15 @@ To render custom group labels, use the `group-label` scoped slot:
123
123
  </gl-collapsible-listbox>
124
124
  ```
125
125
 
126
- #### Search
126
+ ### Dealing with long option texts
127
+
128
+ - Some options might have long non-wrapping text that would overflow the dropdown maximum width. In
129
+ such cases, it's recommended to override the `#list-item` slot and to truncate the option text using
130
+ `GlTruncate`.
131
+ - If the toggle text reflects the selected option text, it might be necessary to truncate
132
+ it too by overriding the `#toggle` slot.
133
+
134
+ ## Search
127
135
 
128
136
  To filter out items by search query set `searchable` property to `true`.
129
137
  Listbox will render the search field and will emit `search` event with the `searchQuery` value.
@@ -146,10 +154,6 @@ Screen reader will announce this text when the list is updated.
146
154
  </gl-collapsible-listbox>
147
155
  ```
148
156
 
149
- #### Dealing with long option texts
157
+ ## Split dropdown
150
158
 
151
- - Some options might have long non-wrapping text that would overflow the dropdown maximum width. In
152
- such cases, it's recommended to override the `#list-item` slot and to truncate the option text using
153
- `GlTruncate`.
154
- - If the toggle text reflects the selected option text, it might be necessary to truncate
155
- it too by overriding the `#toggle` slot.
159
+ See [button group documentation](/docs/base-button-group--docs#split-dropdowns).
@@ -105,14 +105,6 @@ export default {
105
105
  ? translate('GlSorting.sortAscending', 'Sort direction: ascending')
106
106
  : translate('GlSorting.sortDescending', 'Sort direction: descending');
107
107
  },
108
- listboxToggleClass() {
109
- return [
110
- this.dropdownToggleClass,
111
- 'gl-rounded-top-right-none!',
112
- 'gl-rounded-bottom-right-none!',
113
- 'gl-focus-z-index-1',
114
- ];
115
- },
116
108
  },
117
109
  methods: {
118
110
  toggleSortDirection() {
@@ -150,7 +142,7 @@ export default {
150
142
  :toggle-text="text"
151
143
  :items="sortOptions"
152
144
  :selected="sortBy"
153
- :toggle-class="listboxToggleClass"
145
+ :toggle-class="dropdownToggleClass"
154
146
  :class="dropdownClass"
155
147
  placement="right"
156
148
  :block="block"
@@ -1,54 +1,24 @@
1
1
  import COMPILED_TOKENS from '../../dist/tokens/json/tokens.dark.json';
2
- import { colorTokenStoryOptions } from './common_story_options';
2
+ import { createDesignTokenStory } from './common_story_options';
3
3
 
4
- const generateProps = ({ tokens = {} } = {}) => ({ tokens });
5
-
6
- export const Default = (args, { argTypes }) => ({
7
- props: Object.keys(argTypes),
8
- ...colorTokenStoryOptions,
9
- });
10
- Default.args = generateProps({
4
+ export const Default = createDesignTokenStory({
11
5
  tokens: {
12
6
  white: COMPILED_TOKENS.white,
13
7
  black: COMPILED_TOKENS.black,
14
8
  },
15
9
  });
16
10
 
17
- export const Gray = (args, { argTypes }) => ({
18
- props: Object.keys(argTypes),
19
- ...colorTokenStoryOptions,
20
- });
21
- Gray.args = generateProps({ tokens: COMPILED_TOKENS.gray });
11
+ export const Gray = createDesignTokenStory({ tokens: COMPILED_TOKENS.gray });
22
12
 
23
- export const Blue = (args, { argTypes }) => ({
24
- props: Object.keys(argTypes),
25
- ...colorTokenStoryOptions,
26
- });
27
- Blue.args = generateProps({ tokens: COMPILED_TOKENS.blue });
13
+ export const Blue = createDesignTokenStory({ tokens: COMPILED_TOKENS.blue });
28
14
 
29
- export const Green = (args, { argTypes }) => ({
30
- props: Object.keys(argTypes),
31
- ...colorTokenStoryOptions,
32
- });
33
- Green.args = generateProps({ tokens: COMPILED_TOKENS.green });
15
+ export const Green = createDesignTokenStory({ tokens: COMPILED_TOKENS.green });
34
16
 
35
- export const Orange = (args, { argTypes }) => ({
36
- props: Object.keys(argTypes),
37
- ...colorTokenStoryOptions,
38
- });
39
- Orange.args = generateProps({ tokens: COMPILED_TOKENS.orange });
17
+ export const Orange = createDesignTokenStory({ tokens: COMPILED_TOKENS.orange });
40
18
 
41
- export const Red = (args, { argTypes }) => ({
42
- props: Object.keys(argTypes),
43
- ...colorTokenStoryOptions,
44
- });
45
- Red.args = generateProps({ tokens: COMPILED_TOKENS.red });
19
+ export const Red = createDesignTokenStory({ tokens: COMPILED_TOKENS.red });
46
20
 
47
- export const Purple = (args, { argTypes }) => ({
48
- props: Object.keys(argTypes),
49
- ...colorTokenStoryOptions,
50
- });
51
- Purple.args = generateProps({ tokens: COMPILED_TOKENS.purple });
21
+ export const Purple = createDesignTokenStory({ tokens: COMPILED_TOKENS.purple });
52
22
 
53
23
  // eslint-disable-next-line storybook/csf-component
54
24
  export default {
@@ -1,37 +1,17 @@
1
1
  import COMPILED_TOKENS from '../../dist/tokens/json/tokens.dark.json';
2
- import { colorTokenStoryOptions } from './common_story_options';
2
+ import { createDesignTokenStory } from './common_story_options';
3
3
 
4
- const generateProps = ({ tokens = {} } = {}) => ({ tokens });
4
+ export const DataVizGreen = createDesignTokenStory({ tokens: COMPILED_TOKENS['data-viz'].green });
5
5
 
6
- export const DataVizGreen = (args, { argTypes }) => ({
7
- props: Object.keys(argTypes),
8
- ...colorTokenStoryOptions,
9
- });
10
- DataVizGreen.args = generateProps({ tokens: COMPILED_TOKENS['data-viz'].green });
6
+ export const DataVizAqua = createDesignTokenStory({ tokens: COMPILED_TOKENS['data-viz'].aqua });
11
7
 
12
- export const DataVizAqua = (args, { argTypes }) => ({
13
- props: Object.keys(argTypes),
14
- ...colorTokenStoryOptions,
15
- });
16
- DataVizAqua.args = generateProps({ tokens: COMPILED_TOKENS['data-viz'].aqua });
8
+ export const DataVizBlue = createDesignTokenStory({ tokens: COMPILED_TOKENS['data-viz'].blue });
17
9
 
18
- export const DataVizBlue = (args, { argTypes }) => ({
19
- props: Object.keys(argTypes),
20
- ...colorTokenStoryOptions,
10
+ export const DataVizMagenta = createDesignTokenStory({
11
+ tokens: COMPILED_TOKENS['data-viz'].magenta,
21
12
  });
22
- DataVizBlue.args = generateProps({ tokens: COMPILED_TOKENS['data-viz'].blue });
23
13
 
24
- export const DataVizMagenta = (args, { argTypes }) => ({
25
- props: Object.keys(argTypes),
26
- ...colorTokenStoryOptions,
27
- });
28
- DataVizMagenta.args = generateProps({ tokens: COMPILED_TOKENS['data-viz'].magenta });
29
-
30
- export const DataVizOrange = (args, { argTypes }) => ({
31
- props: Object.keys(argTypes),
32
- ...colorTokenStoryOptions,
33
- });
34
- DataVizOrange.args = generateProps({ tokens: COMPILED_TOKENS['data-viz'].orange });
14
+ export const DataVizOrange = createDesignTokenStory({ tokens: COMPILED_TOKENS['data-viz'].orange });
35
15
 
36
16
  // eslint-disable-next-line storybook/csf-component
37
17
  export default {
@@ -1,37 +1,17 @@
1
1
  import COMPILED_TOKENS from '../../dist/tokens/json/tokens.json';
2
- import { colorTokenStoryOptions } from './common_story_options';
2
+ import { createDesignTokenStory } from './common_story_options';
3
3
 
4
- const generateProps = ({ tokens = {} } = {}) => ({ tokens });
4
+ export const DataVizGreen = createDesignTokenStory({ tokens: COMPILED_TOKENS['data-viz'].green });
5
5
 
6
- export const DataVizGreen = (args, { argTypes }) => ({
7
- props: Object.keys(argTypes),
8
- ...colorTokenStoryOptions,
9
- });
10
- DataVizGreen.args = generateProps({ tokens: COMPILED_TOKENS['data-viz'].green });
6
+ export const DataVizAqua = createDesignTokenStory({ tokens: COMPILED_TOKENS['data-viz'].aqua });
11
7
 
12
- export const DataVizAqua = (args, { argTypes }) => ({
13
- props: Object.keys(argTypes),
14
- ...colorTokenStoryOptions,
15
- });
16
- DataVizAqua.args = generateProps({ tokens: COMPILED_TOKENS['data-viz'].aqua });
8
+ export const DataVizBlue = createDesignTokenStory({ tokens: COMPILED_TOKENS['data-viz'].blue });
17
9
 
18
- export const DataVizBlue = (args, { argTypes }) => ({
19
- props: Object.keys(argTypes),
20
- ...colorTokenStoryOptions,
10
+ export const DataVizMagenta = createDesignTokenStory({
11
+ tokens: COMPILED_TOKENS['data-viz'].magenta,
21
12
  });
22
- DataVizBlue.args = generateProps({ tokens: COMPILED_TOKENS['data-viz'].blue });
23
13
 
24
- export const DataVizMagenta = (args, { argTypes }) => ({
25
- props: Object.keys(argTypes),
26
- ...colorTokenStoryOptions,
27
- });
28
- DataVizMagenta.args = generateProps({ tokens: COMPILED_TOKENS['data-viz'].magenta });
29
-
30
- export const DataVizOrange = (args, { argTypes }) => ({
31
- props: Object.keys(argTypes),
32
- ...colorTokenStoryOptions,
33
- });
34
- DataVizOrange.args = generateProps({ tokens: COMPILED_TOKENS['data-viz'].orange });
14
+ export const DataVizOrange = createDesignTokenStory({ tokens: COMPILED_TOKENS['data-viz'].orange });
35
15
 
36
16
  // eslint-disable-next-line storybook/csf-component
37
17
  export default {
@@ -1,43 +1,19 @@
1
1
  import COMPILED_TOKENS from '../../dist/tokens/json/tokens.dark.json';
2
- import { colorTokenStoryOptions } from './common_story_options';
2
+ import { createDesignTokenStory } from './common_story_options';
3
3
 
4
- const generateProps = ({ tokens = {} } = {}) => ({ tokens });
4
+ export const ThemeIndigo = createDesignTokenStory({ tokens: COMPILED_TOKENS.theme.indigo });
5
5
 
6
- export const ThemeIndigo = (args, { argTypes }) => ({
7
- props: Object.keys(argTypes),
8
- ...colorTokenStoryOptions,
9
- });
10
- ThemeIndigo.args = generateProps({ tokens: COMPILED_TOKENS.theme.indigo });
11
-
12
- export const ThemeBlue = (args, { argTypes }) => ({
13
- props: Object.keys(argTypes),
14
- ...colorTokenStoryOptions,
15
- });
16
- ThemeBlue.args = generateProps({ tokens: COMPILED_TOKENS.theme.blue });
6
+ export const ThemeBlue = createDesignTokenStory({ tokens: COMPILED_TOKENS.theme.blue });
17
7
 
18
- export const ThemeLightBlue = (args, { argTypes }) => ({
19
- props: Object.keys(argTypes),
20
- ...colorTokenStoryOptions,
8
+ export const ThemeLightBlue = createDesignTokenStory({
9
+ tokens: COMPILED_TOKENS.theme['light-blue'],
21
10
  });
22
- ThemeLightBlue.args = generateProps({ tokens: COMPILED_TOKENS.theme['light-blue'] });
23
11
 
24
- export const ThemeGreen = (args, { argTypes }) => ({
25
- props: Object.keys(argTypes),
26
- ...colorTokenStoryOptions,
27
- });
28
- ThemeGreen.args = generateProps({ tokens: COMPILED_TOKENS.theme.green });
12
+ export const ThemeGreen = createDesignTokenStory({ tokens: COMPILED_TOKENS.theme.green });
29
13
 
30
- export const ThemeRed = (args, { argTypes }) => ({
31
- props: Object.keys(argTypes),
32
- ...colorTokenStoryOptions,
33
- });
34
- ThemeRed.args = generateProps({ tokens: COMPILED_TOKENS.theme.red });
14
+ export const ThemeRed = createDesignTokenStory({ tokens: COMPILED_TOKENS.theme.red });
35
15
 
36
- export const ThemeLightRed = (args, { argTypes }) => ({
37
- props: Object.keys(argTypes),
38
- ...colorTokenStoryOptions,
39
- });
40
- ThemeLightRed.args = generateProps({ tokens: COMPILED_TOKENS.theme['light-red'] });
16
+ export const ThemeLightRed = createDesignTokenStory({ tokens: COMPILED_TOKENS.theme['light-red'] });
41
17
 
42
18
  // eslint-disable-next-line storybook/csf-component
43
19
  export default {
@@ -1,43 +1,19 @@
1
1
  import COMPILED_TOKENS from '../../dist/tokens/json/tokens.json';
2
- import { colorTokenStoryOptions } from './common_story_options';
2
+ import { createDesignTokenStory } from './common_story_options';
3
3
 
4
- const generateProps = ({ tokens = {} } = {}) => ({ tokens });
4
+ export const ThemeIndigo = createDesignTokenStory({ tokens: COMPILED_TOKENS.theme.indigo });
5
5
 
6
- export const ThemeIndigo = (args, { argTypes }) => ({
7
- props: Object.keys(argTypes),
8
- ...colorTokenStoryOptions,
9
- });
10
- ThemeIndigo.args = generateProps({ tokens: COMPILED_TOKENS.theme.indigo });
11
-
12
- export const ThemeBlue = (args, { argTypes }) => ({
13
- props: Object.keys(argTypes),
14
- ...colorTokenStoryOptions,
15
- });
16
- ThemeBlue.args = generateProps({ tokens: COMPILED_TOKENS.theme.blue });
6
+ export const ThemeBlue = createDesignTokenStory({ tokens: COMPILED_TOKENS.theme.blue });
17
7
 
18
- export const ThemeLightBlue = (args, { argTypes }) => ({
19
- props: Object.keys(argTypes),
20
- ...colorTokenStoryOptions,
8
+ export const ThemeLightBlue = createDesignTokenStory({
9
+ tokens: COMPILED_TOKENS.theme['light-blue'],
21
10
  });
22
- ThemeLightBlue.args = generateProps({ tokens: COMPILED_TOKENS.theme['light-blue'] });
23
11
 
24
- export const ThemeGreen = (args, { argTypes }) => ({
25
- props: Object.keys(argTypes),
26
- ...colorTokenStoryOptions,
27
- });
28
- ThemeGreen.args = generateProps({ tokens: COMPILED_TOKENS.theme.green });
12
+ export const ThemeGreen = createDesignTokenStory({ tokens: COMPILED_TOKENS.theme.green });
29
13
 
30
- export const ThemeRed = (args, { argTypes }) => ({
31
- props: Object.keys(argTypes),
32
- ...colorTokenStoryOptions,
33
- });
34
- ThemeRed.args = generateProps({ tokens: COMPILED_TOKENS.theme.red });
14
+ export const ThemeRed = createDesignTokenStory({ tokens: COMPILED_TOKENS.theme.red });
35
15
 
36
- export const ThemeLightRed = (args, { argTypes }) => ({
37
- props: Object.keys(argTypes),
38
- ...colorTokenStoryOptions,
39
- });
40
- ThemeLightRed.args = generateProps({ tokens: COMPILED_TOKENS.theme['light-red'] });
16
+ export const ThemeLightRed = createDesignTokenStory({ tokens: COMPILED_TOKENS.theme['light-red'] });
41
17
 
42
18
  // eslint-disable-next-line storybook/csf-component
43
19
  export default {
@@ -1,54 +1,24 @@
1
1
  import COMPILED_TOKENS from '../../dist/tokens/json/tokens.json';
2
- import { colorTokenStoryOptions } from './common_story_options';
2
+ import { createDesignTokenStory } from './common_story_options';
3
3
 
4
- const generateProps = ({ tokens = {} } = {}) => ({ tokens });
5
-
6
- export const Default = (args, { argTypes }) => ({
7
- props: Object.keys(argTypes),
8
- ...colorTokenStoryOptions,
9
- });
10
- Default.args = generateProps({
4
+ export const Default = createDesignTokenStory({
11
5
  tokens: {
12
6
  white: COMPILED_TOKENS.white,
13
7
  black: COMPILED_TOKENS.black,
14
8
  },
15
9
  });
16
10
 
17
- export const Gray = (args, { argTypes }) => ({
18
- props: Object.keys(argTypes),
19
- ...colorTokenStoryOptions,
20
- });
21
- Gray.args = generateProps({ tokens: COMPILED_TOKENS.gray });
11
+ export const Gray = createDesignTokenStory({ tokens: COMPILED_TOKENS.gray });
22
12
 
23
- export const Blue = (args, { argTypes }) => ({
24
- props: Object.keys(argTypes),
25
- ...colorTokenStoryOptions,
26
- });
27
- Blue.args = generateProps({ tokens: COMPILED_TOKENS.blue });
13
+ export const Blue = createDesignTokenStory({ tokens: COMPILED_TOKENS.blue });
28
14
 
29
- export const Green = (args, { argTypes }) => ({
30
- props: Object.keys(argTypes),
31
- ...colorTokenStoryOptions,
32
- });
33
- Green.args = generateProps({ tokens: COMPILED_TOKENS.green });
15
+ export const Green = createDesignTokenStory({ tokens: COMPILED_TOKENS.green });
34
16
 
35
- export const Orange = (args, { argTypes }) => ({
36
- props: Object.keys(argTypes),
37
- ...colorTokenStoryOptions,
38
- });
39
- Orange.args = generateProps({ tokens: COMPILED_TOKENS.orange });
17
+ export const Orange = createDesignTokenStory({ tokens: COMPILED_TOKENS.orange });
40
18
 
41
- export const Red = (args, { argTypes }) => ({
42
- props: Object.keys(argTypes),
43
- ...colorTokenStoryOptions,
44
- });
45
- Red.args = generateProps({ tokens: COMPILED_TOKENS.red });
19
+ export const Red = createDesignTokenStory({ tokens: COMPILED_TOKENS.red });
46
20
 
47
- export const Purple = (args, { argTypes }) => ({
48
- props: Object.keys(argTypes),
49
- ...colorTokenStoryOptions,
50
- });
51
- Purple.args = generateProps({ tokens: COMPILED_TOKENS.purple });
21
+ export const Purple = createDesignTokenStory({ tokens: COMPILED_TOKENS.purple });
52
22
 
53
23
  // eslint-disable-next-line storybook/csf-component
54
24
  export default {
@@ -1,21 +1,12 @@
1
1
  import COMPILED_TOKENS from '../../dist/tokens/json/tokens.json';
2
- import { colorTokenStoryOptions } from './common_story_options';
2
+ import { createDesignTokenStory } from './common_story_options';
3
3
 
4
- const generateProps = ({ tokens = {} } = {}) => ({ tokens });
4
+ export const Gray = createDesignTokenStory({ tokens: COMPILED_TOKENS['t-gray-a'] });
5
5
 
6
- export const Gray = (args, { argTypes }) => ({
7
- props: Object.keys(argTypes),
8
- ...colorTokenStoryOptions,
6
+ export const White = createDesignTokenStory({
7
+ tokens: COMPILED_TOKENS['t-white-a'],
8
+ containerClass: 'gl-bg-gray-900 gl-text-white',
9
9
  });
10
- Gray.args = generateProps({ tokens: COMPILED_TOKENS['t-gray-a'] });
11
-
12
- export const White = (args, { argTypes }) => ({
13
- props: Object.keys(argTypes),
14
- components: colorTokenStoryOptions.components,
15
- methods: colorTokenStoryOptions.methods,
16
- template: `<div class="gl-bg-gray-900 gl-text-white">${colorTokenStoryOptions.template}</div>`,
17
- });
18
- White.args = generateProps({ tokens: COMPILED_TOKENS['t-white-a'] });
19
10
 
20
11
  // eslint-disable-next-line storybook/csf-component
21
12
  export default {
@@ -1,71 +1,25 @@
1
1
  import { WHITE, GRAY_950 } from '../../dist/tokens/js/tokens';
2
- import { colorFromBackground } from '../utils/utils';
3
- import GlColorContrast from '../internal/color_contrast/color_contrast.vue';
2
+ import TokensStory from './tokens_story.vue';
4
3
 
5
- export const components = {
6
- GlColorContrast,
7
- };
8
-
9
- export const methods = {
10
- isAlpha(value) {
11
- return value.startsWith('rgba(');
12
- },
13
- isBackgroundColor(property) {
14
- return property === 'backgroundColor';
15
- },
16
- getTokenName(token) {
17
- return token.path.filter(Boolean).join('.');
18
- },
19
- getClasses(property, value) {
20
- if (this.isAlpha(value)) return '';
21
- if (!this.isBackgroundColor(property)) return '';
22
- const textColorVariant = colorFromBackground(value, 4.5);
23
- return {
24
- 'gl-text-gray-950': textColorVariant === 'dark',
25
- 'gl-text-white': textColorVariant === 'light',
26
- };
27
- },
28
- getStyle(property, value) {
29
- if (this.isBackgroundColor(property)) {
30
- return { backgroundColor: value };
31
- }
32
- return { color: value };
33
- },
34
- };
35
-
36
- const colorTemplate = (
37
- property = 'backgroundColor',
38
- lightBackground = WHITE,
39
- darkBackground = GRAY_950
40
- ) => `
41
- <ul
42
- class="gl-list-style-none gl-m-0 gl-p-0"
43
- >
44
- <li
45
- v-for="token in tokens"
46
- :key="token.name"
47
- class="gl-display-flex gl-flex-wrap gl-align-items-center gl-justify-content-space-between gl-gap-3 gl-p-3"
48
- :class="getClasses('${property}', token.value)"
49
- :style="getStyle('${property}', token.value)"
50
- >
51
- <code class="gl-reset-color">{{ getTokenName(token) }}</code>
52
- <div class="gl-display-flex gl-align-items-center gl-gap-3">
53
- <code class="gl-reset-color">{{ token.value }}</code>
54
- <gl-color-contrast v-if="!isAlpha(token.value)" :foreground="token.value" background="${darkBackground}" />
55
- <gl-color-contrast v-if="!isAlpha(token.value)" :foreground="token.value" background="${lightBackground}" />
56
- </div>
57
- </li>
58
- </ul>
59
- `;
60
-
61
- export const colorTokenStoryOptions = {
62
- components,
63
- methods,
64
- template: colorTemplate('backgroundColor'),
65
- };
4
+ export const createDesignTokenStory = ({
5
+ tokens = {},
6
+ isBackgroundColorStory = true,
7
+ containerClass = '',
8
+ } = {}) => {
9
+ const Story = (args, { argTypes }) => ({
10
+ props: Object.keys(argTypes),
11
+ components: {
12
+ TokensStory,
13
+ },
14
+ provide: {
15
+ containerClass,
16
+ isBackgroundColorStory,
17
+ lightBackground: WHITE,
18
+ darkBackground: GRAY_950,
19
+ },
20
+ template: `<tokens-story v-bind="$props" />`,
21
+ });
22
+ Story.args = { tokens };
66
23
 
67
- export const colorTextTokenStoryOptions = {
68
- components,
69
- methods,
70
- template: colorTemplate('color'),
24
+ return Story;
71
25
  };
@@ -1,13 +1,10 @@
1
1
  import COMPILED_TOKENS from '../../dist/tokens/json/tokens.json';
2
- import { colorTextTokenStoryOptions } from './common_story_options';
2
+ import { createDesignTokenStory } from './common_story_options';
3
3
 
4
- const generateProps = ({ tokens = {} } = {}) => ({ tokens });
5
-
6
- export const Default = (args, { argTypes }) => ({
7
- props: Object.keys(argTypes),
8
- ...colorTextTokenStoryOptions,
4
+ export const Default = createDesignTokenStory({
5
+ tokens: COMPILED_TOKENS.text,
6
+ isBackgroundColorStory: false,
9
7
  });
10
- Default.args = generateProps({ name: 'text', tokens: COMPILED_TOKENS.text });
11
8
 
12
9
  // eslint-disable-next-line storybook/csf-component
13
10
  export default {