@madgex/design-system 2.6.0 → 2.7.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 (65) hide show
  1. package/coverage/cobertura-coverage.xml +1 -1
  2. package/coverage/components/accordion/accordion.js.html +1 -1
  3. package/coverage/components/accordion/index.html +1 -1
  4. package/coverage/components/button/button.js.html +1 -1
  5. package/coverage/components/button/index.html +1 -1
  6. package/coverage/components/inputs/combobox/combobox.js.html +1 -1
  7. package/coverage/components/inputs/combobox/index.html +1 -1
  8. package/coverage/components/inputs/combobox/vue-components/Combobox.vue.html +1 -1
  9. package/coverage/components/inputs/combobox/vue-components/ListBoxOption.vue.html +1 -1
  10. package/coverage/components/inputs/combobox/vue-components/index.html +1 -1
  11. package/coverage/components/inputs/file-upload/file-upload.js.html +1 -1
  12. package/coverage/components/inputs/file-upload/index.html +1 -1
  13. package/coverage/components/inputs/textarea/character-count.js.html +1 -1
  14. package/coverage/components/inputs/textarea/index.html +1 -1
  15. package/coverage/components/modal/index.html +1 -1
  16. package/coverage/components/modal/modal.js.html +1 -1
  17. package/coverage/components/notification/index.html +1 -1
  18. package/coverage/components/notification/notification.js.html +1 -1
  19. package/coverage/components/popover/index.html +1 -1
  20. package/coverage/components/popover/popover.js.html +1 -1
  21. package/coverage/components/switch-state/index.html +1 -1
  22. package/coverage/components/switch-state/switch-state.js.html +1 -1
  23. package/coverage/components/tabs/index.html +1 -1
  24. package/coverage/components/tabs/tabs.js.html +1 -1
  25. package/coverage/index.html +1 -1
  26. package/coverage/js/common.js.html +1 -1
  27. package/coverage/js/fractal-scripts/combobox.js.html +1 -1
  28. package/coverage/js/fractal-scripts/index.html +1 -1
  29. package/coverage/js/fractal-scripts/notification.js.html +1 -1
  30. package/coverage/js/fractal-scripts/switch-state.js.html +1 -1
  31. package/coverage/js/index-fractal.js.html +1 -1
  32. package/coverage/js/index-polyfills.js.html +1 -1
  33. package/coverage/js/index-vue.js.html +1 -1
  34. package/coverage/js/index.html +1 -1
  35. package/coverage/js/index.js.html +1 -1
  36. package/coverage/js/polyfills/arrayPrototypeFind.js.html +1 -1
  37. package/coverage/js/polyfills/closest.js.html +1 -1
  38. package/coverage/js/polyfills/index.html +1 -1
  39. package/coverage/js/polyfills/objectAssign.js.html +1 -1
  40. package/coverage/js/polyfills/remove.js.html +1 -1
  41. package/coverage/tokens/_config.js.html +1 -1
  42. package/coverage/tokens/index.html +1 -1
  43. package/cypress/integration/components/checkbox-list.spec.js +15 -0
  44. package/cypress/integration/components/single-checkbox.spec.js +18 -0
  45. package/dist/_tokens/css/_tokens.css +1 -1
  46. package/dist/_tokens/js/_tokens-module.js +1 -1
  47. package/dist/_tokens/scss/_tokens.scss +1 -1
  48. package/dist/css/index.css +1 -1
  49. package/package.json +1 -1
  50. package/src/components/_macro-index.njk +3 -1
  51. package/src/components/inputs/_checkbox-elem/_macro.njk +3 -0
  52. package/src/components/inputs/_checkbox-elem/_template.njk +23 -0
  53. package/src/components/inputs/_form-elements.scss +17 -1
  54. package/src/components/inputs/checkbox-list/_macro.njk +3 -0
  55. package/src/components/inputs/{checkbox → checkbox-list}/_template.njk +13 -37
  56. package/src/components/inputs/{checkbox/checkbox.config.js → checkbox-list/checkbox-list.config.js} +6 -5
  57. package/src/components/inputs/{checkbox/checkbox.njk → checkbox-list/checkbox-list.njk} +2 -2
  58. package/src/components/inputs/single-checkbox/README.md +34 -0
  59. package/src/components/inputs/single-checkbox/_macro.njk +3 -0
  60. package/src/components/inputs/single-checkbox/_template.njk +49 -0
  61. package/src/components/inputs/single-checkbox/single-checkbox.config.js +46 -0
  62. package/src/components/inputs/single-checkbox/single-checkbox.njk +18 -0
  63. package/cypress/integration/components/checkbox.spec.js +0 -9
  64. package/src/components/inputs/checkbox/_macro.njk +0 -3
  65. /package/src/components/inputs/{checkbox → checkbox-list}/README.md +0 -0
@@ -2,7 +2,7 @@
2
2
  {% from "../_message/_macro.njk" import MdsInputMessages %}
3
3
  {% from "../../accordion/_macro.njk" import MdsAccordion %}
4
4
  {% from "../../icons/_macro.njk" import MdsIcon %}
5
-
5
+ {% from "../_checkbox-elem/_macro.njk" import MdsCheckboxElem %}
6
6
  {%- if params.name -%}
7
7
  {%- set name = params.name -%}
8
8
  {%- else -%}
@@ -23,11 +23,6 @@
23
23
  {%- set accordionIsExpanded = false -%}
24
24
  {% if checkboxParams.selectedOptions %}
25
25
  {% set selectedOptions = checkboxParams.selectedOptions %}
26
- {# check if `selectedOptions` is an array or not - if it isn't, change it into one #}
27
- {# didn't find any other way than to check the first character of the JSON.stringify version of the parameter #}
28
- {% if selectedOptions | dump | first != '[' %}
29
- {% set selectedOptions = [selectedOptions] %}
30
- {% endif %}
31
26
  {% for selectedOption in selectedOptions %}
32
27
  {% if selectedOption == option.value %}
33
28
  {%- set isSelected = true -%}
@@ -40,20 +35,14 @@
40
35
  {% endfor %}
41
36
  {% endif %}
42
37
  <div class="mds-form-check{% if option.classes %} {{option.classes}}{% endif %}">
43
- <input
44
- type="checkbox"
45
- class="mds-form-check__input"
46
- name="{{ checkboxParams.name }}"
47
- id="{{ optionId }}"
48
- {% if checkboxParams.disabled %}disabled="disabled"{% endif %}
49
- {% if checkboxParams.describedBy %}aria-describedby="{{checkboxParams.describedBy}}"{% endif %}
50
- {% if isSelected == true %}checked="checked"{% endif %}
51
- value="{{ option.value }}"
52
- />{#
53
- # Avoid extra space created by line breaks #
54
- #}<label class="mds-form-check__label" for="{{ optionId }}">{#
55
- #}{{ option.labelText | safe }}{#
56
- #}</label>
38
+ {{ MdsCheckboxElem({
39
+ disabled: checkboxParams.disabled,
40
+ isSelected: isSelected,
41
+ labelText: option.labelText,
42
+ name: checkboxParams.name,
43
+ id: optionId,
44
+ value: option.value
45
+ }) }}
57
46
  {% if option.options and option.options.length %}
58
47
  {%- set triggerLabel %}Select options under {{ option.labelText | safe }}{% endset -%}
59
48
  {%- set accordionContent %}
@@ -97,19 +86,10 @@
97
86
  {% set hasBorder = true %}
98
87
  {% endif %}
99
88
  {% endif %}
100
- {% if params.describedBy %}
101
- {% if params.options.length > 1 %}
102
- {% set describeByFieldset = params.describedBy %}
103
- {% else %}
104
- {% set describeByCheckbox = params.describedBy %}
105
- {% endif %}
106
- {% endif %}
107
89
 
108
90
  <div class="mds-form-element mds-form-element--checkbox{% if params.state %} mds-form-element--{{params.state}}{% endif %}{% if params.classes %} {{params.classes}}{% endif %}" id="{{params.id}}" data-test="checkbox{% if params.id %}-{{params.id}}{% endif %}">
109
- {# no need for fieldset and legend if there is only one checkbox #}
110
- {% if params.options.length > 1 %}
111
- <fieldset {%- if describeByFieldset %} aria-describedby="{{describeByFieldset}}"{% endif %}>
112
- {{ MdsInputLabel({
91
+ <fieldset {%- if params.describedBy %} aria-describedby="{{params.describedBy}}"{% endif %}>
92
+ {{ MdsInputLabel({
113
93
  element: 'legend',
114
94
  labelText: params.labelText,
115
95
  hideLabel: params.hideLabel,
@@ -117,7 +97,6 @@
117
97
  optional: params.optional,
118
98
  tooltipMessage: params.tooltipMessage
119
99
  }) }}
120
- {% endif %}
121
100
  {{ MdsInputMessages({
122
101
  id: params.id,
123
102
  helpText: params.helpText,
@@ -128,11 +107,8 @@
128
107
  options: params.options,
129
108
  selectedOptions: params.selectedOptions,
130
109
  name: name,
131
- disabled: params.disabled,
132
- describedBy: describeByCheckbox
110
+ disabled: params.disabled
133
111
  }) }}
134
112
  </div>
135
- {% if params.options.length > 1 %}
136
- </fieldset>
137
- {% endif %}
113
+ </fieldset>
138
114
  </div>
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- title: 'Checkbox',
2
+ title: 'Checkbox List',
3
3
  context: {
4
4
  id: 'checkbox-input',
5
5
  labelText: 'Standard checkbox group',
@@ -263,12 +263,13 @@ module.exports = {
263
263
  name: 'Single checkbox',
264
264
  context: {
265
265
  id: 'single-checkbox',
266
- describedBy: 'terms-description',
266
+ optional: true,
267
+ labelText: 'Job level',
267
268
  options: [
268
269
  {
269
- labelText: 'I agree to the terms and conditions',
270
- value: 'agree-terms',
271
- id: 'terms-and-conditions',
270
+ labelText: 'Graduate',
271
+ value: 'is-graduate',
272
+ id: 'graduate',
272
273
  },
273
274
  ],
274
275
  },
@@ -1,7 +1,7 @@
1
- {% from "./inputs/checkbox/_macro.njk" import MdsCheckbox %}
1
+ {% from "./inputs/checkbox-list/_macro.njk" import MdsCheckboxList %}
2
2
 
3
3
  <div class="mds-form-field">
4
- {{ MdsCheckbox({
4
+ {{ MdsCheckboxList({
5
5
  labelText: labelText,
6
6
  name: name,
7
7
  id: id,
@@ -0,0 +1,34 @@
1
+ ## Parameters
2
+
3
+ - `name`: The name of the input field, uses ID unless specified **optional**,
4
+ - `id`: The id attribute of the field, **required**
5
+ - `disabled`: Should the input be disabled **optional**,
6
+ - `helpText`: Helper text to display under the label **optional**,
7
+ - `validationError`: The error message provided by validation **optional**,
8
+ - `state`: The current state of the input, currently the only allowed value is `error` **optional**
9
+ - `classes`: add extra classes to the fieldgroup - **optional**
10
+ - `describedBy`: adding aria-describeby to the input field - **optional**
11
+ - `selectedOptions`: Preselected checkboxes - Array or comma-separed string
12
+ - `options`: array of options for a checkbox inside. **required**: `labelText`, `value`, `id`, `classes`
13
+
14
+ **Note:** `id` in `options` is optional. If you don't specify one, an id will be created for you using the name/id of the field and the value of the option.
15
+
16
+ See an example option below
17
+ ```
18
+ options: [
19
+ {
20
+ labelText: "Checkbox Input 1",
21
+ value: "2-1",
22
+ id: "checkbox-2-1",
23
+ },
24
+ ]
25
+ ```
26
+ which is the same as
27
+ ```
28
+ labelText: "Checkbox Input 1",
29
+ value: "2-1",
30
+ id: "checkbox-2-1",
31
+ ```
32
+
33
+ ## Accessibility
34
+ This input relies entirely on the browser standard checkbox input and applies the accessibility provided by that.
@@ -0,0 +1,3 @@
1
+ {% macro MdsSingleCheckbox(params) %}
2
+ {%- include "./_template.njk" -%}
3
+ {% endmacro %}
@@ -0,0 +1,49 @@
1
+ {% from "../_message/_macro.njk" import MdsInputMessages %}
2
+ {% from "../_checkbox-elem/_macro.njk" import MdsCheckboxElem %}
3
+ {%- if params.name -%}
4
+ {%- set name = params.name -%}
5
+ {%- else -%}
6
+ {%- set name = params.id -%}
7
+ {%- endif -%}
8
+
9
+ {%- set name -%}
10
+ {%- if params.name -%}
11
+ {{- params.name -}}
12
+ {%- else -%}
13
+ {{- params.id -}}
14
+ {%- endif -%}
15
+ {%- endset -%}
16
+
17
+ {%- set id -%}
18
+ {%- if params.options[0].id -%}
19
+ {{- params.options[0].id -}}
20
+ {% else %}
21
+ {{- name -}}-{{- params.options[0].value -}}
22
+ {% endif -%}
23
+ {%- endset -%}
24
+
25
+ {%- if params.selectedOptions === params.options[0].id -%}
26
+ {%- set isSelected = true -%}
27
+ {%- endif -%}
28
+
29
+ <div class="mds-form-element mds-form-element--checkbox{% if params.state %} mds-form-element--{{params.state}}{% endif %}{% if params.classes %} {{params.classes}}{% endif %}" data-test="checkbox{% if params.id %}-{{params.id}}{% endif %}">
30
+ {{ MdsInputMessages({
31
+ id: params.id,
32
+ helpText: params.helpText,
33
+ validationError: params.validationError
34
+ }) }}
35
+ <div class="mds-form-check-container">
36
+ <div class="mds-form-check{% if option.classes %} {{option.classes}}{% endif %}">
37
+ {{ MdsCheckboxElem({
38
+ disabled: params.disabled,
39
+ isSelected: isSelected,
40
+ labelText: params.options[0].labelText,
41
+ describedBy: params.describedBy,
42
+ optional: params.optional,
43
+ name: name,
44
+ id: id,
45
+ value: params.options[0].value
46
+ }) }}
47
+ </div>
48
+ </div>
49
+ </div>
@@ -0,0 +1,46 @@
1
+ module.exports = {
2
+ title: 'Single checkbox',
3
+ name: 'Single checkbox',
4
+ context: {
5
+ id: 'terms-and-conditions',
6
+ options: [
7
+ {
8
+ labelText: 'You need to agree to our terms of service',
9
+ value: 'tos',
10
+ id: 'tos-checkbox',
11
+ },
12
+ ],
13
+ },
14
+ variants: [
15
+ {
16
+ name: 'Preselected checkbox',
17
+ context: {
18
+ id: 'preselected',
19
+ optional: true,
20
+ options: [
21
+ {
22
+ labelText: 'I want to opt out of third party emails',
23
+ value: 'out-out',
24
+ id: 'out-out-checkbox',
25
+ },
26
+ ],
27
+ selectedOptions: 'out-out-checkbox',
28
+ },
29
+ },
30
+ {
31
+ name: 'Optional checkbox with help text',
32
+ context: {
33
+ id: 'data',
34
+ optional: true,
35
+ helpText: 'We will never sell your data.',
36
+ options: [
37
+ {
38
+ labelText: 'I agree to provide my data for analyzing purposes only.',
39
+ value: 'data-yes',
40
+ id: 'data-provide',
41
+ },
42
+ ],
43
+ },
44
+ },
45
+ ],
46
+ };
@@ -0,0 +1,18 @@
1
+ {% from "./inputs/single-checkbox/_macro.njk" import MdsSingleCheckbox %}
2
+
3
+ <div class="mds-form-field">
4
+ {{ MdsSingleCheckbox({
5
+ name: name,
6
+ id: id,
7
+ disabled: disabled,
8
+ selectedOptions: selectedOptions,
9
+ describedBy: describedBy,
10
+ classes: classes,
11
+ optional: optional,
12
+ state: state,
13
+ validationError: validationError,
14
+ helpText: helpText,
15
+ value: value,
16
+ options: options
17
+ }) }}
18
+ </div>
@@ -1,9 +0,0 @@
1
- context('checkbox', () => {
2
- beforeEach(() => {
3
- cy.visitComponent('checkbox');
4
- });
5
-
6
- it('has no detectable a11y violations on load', () => {
7
- cy.checkA11y('[data-test="checkbox"]');
8
- });
9
- });
@@ -1,3 +0,0 @@
1
- {% macro MdsCheckbox(params) %}
2
- {%- include "./_template.njk" -%}
3
- {% endmacro %}