@gitlab/ui 115.11.0 → 117.0.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 (71) hide show
  1. package/dist/components/base/filtered_search/filtered_search_suggestion.js +11 -5
  2. package/dist/components/dashboards/dashboard_layout/grid_layout/grid_layout.js +2 -2
  3. package/dist/components/dashboards/dashboard_panel/dashboard_panel.js +45 -3
  4. package/dist/components/index.js +1 -4
  5. package/dist/index.css +1 -1
  6. package/dist/index.css.map +1 -1
  7. package/dist/tailwind.css +1 -1
  8. package/dist/tailwind.css.map +1 -1
  9. package/dist/tokens/common_story_options.js +1 -6
  10. package/dist/tokens/tokens_story.js +3 -16
  11. package/package.json +5 -5
  12. package/src/components/base/filtered_search/filtered_search_suggestion.vue +32 -14
  13. package/src/components/dashboards/dashboard_layout/grid_layout/grid_layout.vue +2 -2
  14. package/src/components/dashboards/dashboard_panel/dashboard_panel.md +61 -13
  15. package/src/components/dashboards/dashboard_panel/dashboard_panel.vue +46 -3
  16. package/src/components/index.js +1 -4
  17. package/src/scss/components.scss +0 -1
  18. package/src/tokens/common_story_options.js +1 -9
  19. package/src/tokens/tokens_story.vue +2 -22
  20. package/dist/components/base/form/form_checkbox_tree/checkbox_tree_node.js +0 -79
  21. package/dist/components/base/form/form_checkbox_tree/form_checkbox_tree.js +0 -138
  22. package/dist/components/base/form/form_checkbox_tree/models/constants.js +0 -12
  23. package/dist/components/base/form/form_checkbox_tree/models/node.js +0 -51
  24. package/dist/components/base/form/form_checkbox_tree/models/tree.js +0 -200
  25. package/dist/components/base/nav/nav.js +0 -132
  26. package/dist/components/base/nav/nav_item.js +0 -125
  27. package/src/components/base/form/form.md +0 -2
  28. package/src/components/base/form/form_character_count/form_character_count.md +0 -53
  29. package/src/components/base/form/form_checkbox_tree/checkbox_tree_node.vue +0 -58
  30. package/src/components/base/form/form_checkbox_tree/form_checkbox_tree.md +0 -73
  31. package/src/components/base/form/form_checkbox_tree/form_checkbox_tree.vue +0 -116
  32. package/src/components/base/form/form_checkbox_tree/models/constants.js +0 -12
  33. package/src/components/base/form/form_checkbox_tree/models/node.js +0 -48
  34. package/src/components/base/form/form_checkbox_tree/models/tree.js +0 -186
  35. package/src/components/base/form/form_combobox/form_combobox.md +0 -52
  36. package/src/components/base/form/form_date/form_date.md +0 -26
  37. package/src/components/base/form/form_fields/form_fields.md +0 -41
  38. package/src/components/base/form/form_group/form_group.md +0 -1
  39. package/src/components/base/form/form_input_group/form_input_group.md +0 -67
  40. package/src/components/base/form/input_group_text/input_group_text.md +0 -1
  41. package/src/components/base/nav/nav.md +0 -184
  42. package/src/components/base/nav/nav.scss +0 -7
  43. package/src/components/base/nav/nav.vue +0 -70
  44. package/src/components/base/nav/nav_item.vue +0 -109
  45. package/src/components/base/token_selector/token_selector.md +0 -78
  46. package/src/components/charts/bar/bar.md +0 -3
  47. package/src/components/charts/chart/chart.md +0 -19
  48. package/src/components/charts/gauge/gauge.md +0 -8
  49. package/src/components/charts/heatmap/heatmap.md +0 -7
  50. package/src/components/charts/legend/legend.md +0 -16
  51. package/src/components/charts/line/line.md +0 -7
  52. package/src/components/charts/series_label/series_label.md +0 -1
  53. package/src/components/charts/shared/tooltip/tooltip.md +0 -3
  54. package/src/components/charts/single_stat/single_stat.md +0 -8
  55. package/src/components/charts/sparkline/sparkline.md +0 -8
  56. package/src/components/charts/stacked_column/stacked_column.md +0 -10
  57. package/src/components/regions/empty_state/empty_state.md +0 -4
  58. package/src/components/utilities/animated_number/animated_number.md +0 -6
  59. package/src/components/utilities/friendly_wrap/friendly_wrap.md +0 -66
  60. package/src/components/utilities/intersection_observer/intersection_observer.md +0 -16
  61. package/src/components/utilities/intersperse/intersperse.md +0 -90
  62. package/src/components/utilities/sprintf/sprintf.md +0 -243
  63. package/src/components/utilities/truncate/truncate.md +0 -14
  64. package/src/components/utilities/truncate_text/truncate_text.md +0 -26
  65. package/src/directives/hover_load/hover_load.md +0 -22
  66. package/src/directives/outside/outside.md +0 -140
  67. package/src/directives/resize_observer/resize_observer.md +0 -54
  68. package/src/directives/safe_html/safe_html.md +0 -58
  69. package/src/directives/safe_link/safe_link.md +0 -37
  70. package/src/internal/color_contrast/color_contrast.md +0 -8
  71. package/src/internal/color_contrast/color_contrast.vue +0 -52
@@ -1,125 +0,0 @@
1
- import GlLink from '../link/link';
2
- import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
3
-
4
- var script = {
5
- name: 'GlNavItem',
6
- components: {
7
- GlLink
8
- },
9
- props: {
10
- /**
11
- * When set to `true`, places the component in the active state with active styling
12
- */
13
- active: {
14
- type: Boolean,
15
- required: false,
16
- default: false
17
- },
18
- /**
19
- * When set to `true`, disables the component's functionality and places it in a disabled state.
20
- */
21
- disabled: {
22
- type: Boolean,
23
- required: false,
24
- default: false
25
- },
26
- /**
27
- * Denotes the target URL of the link for standard links.
28
- */
29
- href: {
30
- type: String,
31
- required: false,
32
- default: undefined
33
- },
34
- /**
35
- * <router-link> prop: Denotes the target route of the link.
36
- * When clicked, the value of the to prop will be passed to `router.push()` internally,
37
- * so the value can be either a string or a Location descriptor object.
38
- */
39
- to: {
40
- type: [Object, String],
41
- required: false,
42
- default: undefined
43
- },
44
- /**
45
- * <router-link> prop: Configure the active CSS class applied when the link is active.
46
- */
47
- activeClass: {
48
- type: String,
49
- required: false,
50
- default: undefined
51
- },
52
- /**
53
- * <router-link> prop: Configure the active CSS class applied when the link is active with exact match.
54
- */
55
- exactActiveClass: {
56
- type: String,
57
- required: false,
58
- default: undefined
59
- },
60
- /**
61
- * Attributes for the link element
62
- */
63
- linkAttrs: {
64
- type: Object,
65
- required: false,
66
- default: null
67
- },
68
- /**
69
- * Classes for the link element
70
- */
71
- linkClasses: {
72
- type: Array,
73
- required: false,
74
- default: () => []
75
- }
76
- },
77
- computed: {
78
- computedLinkClasses() {
79
- const classes = this.linkClasses;
80
-
81
- // the `unstyled` link variant does not do this by itself
82
- if (this.disabled) classes.push('disabled');
83
- if (this.active) classes.push('active');
84
- return classes;
85
- }
86
- }
87
- };
88
-
89
- /* script */
90
- const __vue_script__ = script;
91
-
92
- /* template */
93
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('li',{staticClass:"nav-item"},[_c('gl-link',_vm._g(_vm._b({staticClass:"nav-link",class:_vm.computedLinkClasses,attrs:{"variant":"unstyled","active":_vm.active,"disabled":_vm.disabled,"href":_vm.href,"to":_vm.to,"active-class":_vm.activeClass,"exact-active-class":_vm.exactActiveClass}},'gl-link',_vm.linkAttrs,false),_vm.$listeners),[_vm._t("default")],2)],1)};
94
- var __vue_staticRenderFns__ = [];
95
-
96
- /* style */
97
- const __vue_inject_styles__ = undefined;
98
- /* scoped */
99
- const __vue_scope_id__ = undefined;
100
- /* module identifier */
101
- const __vue_module_identifier__ = undefined;
102
- /* functional template */
103
- const __vue_is_functional_template__ = false;
104
- /* style inject */
105
-
106
- /* style inject SSR */
107
-
108
- /* style inject shadow dom */
109
-
110
-
111
-
112
- const __vue_component__ = /*#__PURE__*/__vue_normalize__(
113
- { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
114
- __vue_inject_styles__,
115
- __vue_script__,
116
- __vue_scope_id__,
117
- __vue_is_functional_template__,
118
- __vue_module_identifier__,
119
- false,
120
- undefined,
121
- undefined,
122
- undefined
123
- );
124
-
125
- export { __vue_component__ as default };
@@ -1,2 +0,0 @@
1
- A wrapper element for `gl-form-*` input elements. Supports `@submit` and `@reset` events.
2
- To disable native HTML validation pass the `novalidate` attribute.
@@ -1,53 +0,0 @@
1
- ## Usage
2
-
3
- `GlFormCharacterCount` can be used to add a character count to an input.
4
- If you are using `GlFormTextarea` on its own see [with character count example](https://design.gitlab.com/storybook?path=/story/base-form-form-textarea--with-character-count).
5
- If you are wrapping your input, such as in a markdown component, and need the character
6
- count separate from the input, use `GlFormCharacterCount`.
7
-
8
- ## Example
9
-
10
- ```html
11
- <script>
12
- import { GlFormCharacterCount, GlFormInput, GlFormGroup } from '@gitlab/ui'
13
-
14
- export default {
15
- inputId: 'form-input-with-character-count',
16
- countTextId: 'character-count-text',
17
- limit: 100,
18
- components: { GlFormCharacterCount, GlFormInput, GlFormGroup },
19
- data() {
20
- return {
21
- value: '',
22
- }
23
- },
24
- methods: {
25
- remainingCountText(count) {
26
- return n__('%d character remaining.', '%d characters remaining.', count)
27
- },
28
- overLimitText(count) {
29
- return n__('%d character over limit.', '%d characters over limit.', count);
30
- },
31
- },
32
- }
33
- <script>
34
-
35
- <template>
36
- <gl-form-group label="Form input with character count" :label-for="$options.inputId">
37
- <gl-form-input
38
- v-model="value"
39
- :id="$options.inputId"
40
- :value="value"
41
- :aria-describedby="$options.countTextId"
42
- />
43
- <gl-form-character-count
44
- :value="value"
45
- :limit="$options.limit"
46
- :count-text-id="$options.countTextId"
47
- >
48
- <template #remaining-count-text="{ count }">{{ remainingCountText(count) }}</template>
49
- <template #over-limit-text="{ count }">{{ overLimitText(count) }}</template>
50
- </gl-form-character-count>
51
- </gl-form-group>
52
- <template>
53
- ```
@@ -1,58 +0,0 @@
1
- <script>
2
- import GlFormCheckbox from '../form_checkbox/form_checkbox.vue';
3
- import { QA_PREFIX } from './models/constants';
4
-
5
- export default {
6
- name: 'GlFormCheckboxTreeNode',
7
- qaPrefix: QA_PREFIX,
8
- components: {
9
- GlFormCheckbox,
10
- },
11
- inject: ['tree'],
12
- props: {
13
- option: {
14
- type: Object,
15
- required: true,
16
- },
17
- isNested: {
18
- type: Boolean,
19
- required: false,
20
- default: false,
21
- },
22
- },
23
- computed: {
24
- node() {
25
- return this.tree.getNode(this.option.value);
26
- },
27
- label() {
28
- return this.node.label || this.node.value;
29
- },
30
- rootClass() {
31
- return this.isNested ? 'gl-ml-6' : null;
32
- },
33
- checkboxClass() {
34
- const { isChecked, isIndeterminate } = this.node;
35
- return [isChecked && 'js-is-checked', isIndeterminate && 'js-is-indeterminate'];
36
- },
37
- },
38
- };
39
- </script>
40
-
41
- <template>
42
- <div :class="rootClass" :data-testid="`${$options.qaPrefix}${option.value}`">
43
- <gl-form-checkbox
44
- :checked="node.isChecked"
45
- :indeterminate="node.isIndeterminate"
46
- :class="checkboxClass"
47
- @change="tree.toggleOption(option, $event)"
48
- >
49
- {{ label }}
50
- </gl-form-checkbox>
51
- <gl-form-checkbox-tree-node
52
- v-for="child in option.children"
53
- :key="child.value"
54
- :option="child"
55
- is-nested
56
- />
57
- </div>
58
- </template>
@@ -1,73 +0,0 @@
1
- `GlFormCheckboxTree` lets you display an options structure where any option can have n-level of
2
- children. It can be useful for creating a search filter that has nested facets.
3
-
4
- ## Usage
5
-
6
- `GlFormCheckboxTree` accepts an `options` prop representing the available options in the form of
7
- an n-level deep tree. Each option should have a `value` and can have optional
8
- `label` and `children`. If `label` is omitted, `value` is used as the checkbox's label.
9
- Here's a simple `options` tree for example:
10
-
11
- ```js
12
- [
13
- {
14
- label: 'Option #1',
15
- value: 1,
16
- children: [
17
- {
18
- label: 'Option #2',
19
- value: 2,
20
- },
21
- ],
22
- },
23
- {
24
- label: 'Option #3',
25
- value: 3,
26
- },
27
- ]
28
- ```
29
-
30
- `GlFormCheckboxTree` exposes the selected options via a `v-model` which is being kept in sync with
31
- the `change` event.
32
-
33
- ## Dos and don'ts
34
-
35
- ### Don't
36
-
37
- When rendering a `GlFormCheckboxTree` with pre-selected options, all the selected values should be
38
- passed to the component via the `v-model`/`value` property. For example, with the options tree
39
- above, if you wanted options `1` and `2` to be pre-selected, make sure that they are both included
40
- in the initial value, don't rely on the component to infer initially checked boxes by only passing
41
- `1` or `2`.
42
-
43
- ```html
44
- <!-- Good -->
45
- <gl-form-checkbox-tree
46
- :value="[1, 2]"
47
- :options="[
48
- {
49
- value: 1,
50
- children: [
51
- {
52
- value: 2,
53
- },
54
- ],
55
- },
56
- ]"
57
- />
58
-
59
- <!-- Bad -->
60
- <gl-form-checkbox-tree
61
- :value="[1]"
62
- :options="[
63
- {
64
- value: 1,
65
- children: [
66
- {
67
- value: 2,
68
- },
69
- ],
70
- },
71
- ]"
72
- />
73
- ```
@@ -1,116 +0,0 @@
1
- <script>
2
- import GlFormCheckbox from '../form_checkbox/form_checkbox.vue';
3
- import GlFormGroup from '../form_group/form_group.vue';
4
- import GlFormCheckboxTreeNode from './checkbox_tree_node.vue';
5
- import { V_MODEL } from './models/constants';
6
- import { Tree } from './models/tree';
7
-
8
- export default {
9
- name: 'GlFormCheckboxTree',
10
- components: {
11
- GlFormGroup,
12
- GlFormCheckbox,
13
- GlFormCheckboxTreeNode,
14
- },
15
- provide() {
16
- return {
17
- tree: this.tree,
18
- };
19
- },
20
- model: {
21
- prop: V_MODEL.PROP,
22
- event: V_MODEL.EVENT,
23
- },
24
- props: {
25
- /**
26
- * Options tree where each option is in the form:
27
- * {
28
- * value: String|Number,
29
- * label: String,
30
- * children: Array,
31
- * }
32
- */
33
- options: {
34
- type: Array,
35
- required: true,
36
- },
37
- /**
38
- * The selected options as an array of values
39
- */
40
- value: {
41
- type: Array,
42
- required: false,
43
- default: () => [],
44
- },
45
- /**
46
- * Set to true to hide the "Select/unselect all" checkbox
47
- */
48
- hideToggleAll: {
49
- type: Boolean,
50
- required: false,
51
- default: false,
52
- },
53
- /**
54
- * Label for the toggle all checkbox when some or all options are unchecked
55
- */
56
- selectAllLabel: {
57
- type: String,
58
- required: false,
59
- default: 'Select all',
60
- },
61
- /**
62
- * Label for the toggle all checkbox when all options are checked
63
- */
64
- unselectAllLabel: {
65
- type: String,
66
- required: false,
67
- default: 'Unselect all',
68
- },
69
- label: {
70
- type: String,
71
- required: false,
72
- default: 'Checkbox tree',
73
- },
74
- labelSrOnly: {
75
- type: Boolean,
76
- required: false,
77
- default: true,
78
- },
79
- },
80
- data() {
81
- return {
82
- tree: new Tree(this.options, this.value),
83
- };
84
- },
85
- computed: {
86
- toggleAllLabel() {
87
- return this.tree.allOptionsChecked ? this.unselectAllLabel : this.selectAllLabel;
88
- },
89
- },
90
- watch: {
91
- 'tree.selected': {
92
- handler(selected) {
93
- /**
94
- * Emitted when the selection changes.
95
- */
96
- this.$emit(V_MODEL.EVENT, selected);
97
- },
98
- },
99
- },
100
- };
101
- </script>
102
-
103
- <template>
104
- <gl-form-group :label="label" :label-sr-only="labelSrOnly">
105
- <gl-form-checkbox
106
- v-if="!hideToggleAll"
107
- class="gl-form-checkbox-tree-toggle-all"
108
- :checked="tree.allOptionsChecked"
109
- :indeterminate="tree.someOptionsChecked"
110
- @change="tree.toggleAllOptions($event)"
111
- >
112
- {{ toggleAllLabel }}
113
- </gl-form-checkbox>
114
- <gl-form-checkbox-tree-node v-for="option in options" :key="option.value" :option="option" />
115
- </gl-form-group>
116
- </template>
@@ -1,12 +0,0 @@
1
- export const CHECKED_STATE = {
2
- UNCHECKED: 0,
3
- INDETERMINATE: 1,
4
- CHECKED: 2,
5
- };
6
-
7
- export const V_MODEL = {
8
- PROP: 'value',
9
- EVENT: 'change',
10
- };
11
-
12
- export const QA_PREFIX = 'form_checkbox_tree_node_';
@@ -1,48 +0,0 @@
1
- import { CHECKED_STATE } from './constants';
2
-
3
- export class Node {
4
- constructor({ value, label, parent = null, children = [], depth, isChecked }) {
5
- this.value = value;
6
- this.label = label;
7
- this.parent = parent;
8
- this.children = children;
9
- this.depth = depth;
10
- this.checkedState = isChecked ? CHECKED_STATE.CHECKED : CHECKED_STATE.UNCHECKED;
11
- }
12
-
13
- /**
14
- * Sets the node's checked state
15
- * @param {number} checkedState
16
- */
17
- setCheckedState(checkedState) {
18
- this.checkedState = checkedState;
19
- }
20
-
21
- get isChild() {
22
- return this.parent !== null;
23
- }
24
-
25
- get isParent() {
26
- return this.children.length > 0;
27
- }
28
-
29
- get isLeaf() {
30
- return !this.isParent;
31
- }
32
-
33
- get isUnchecked() {
34
- return this.checkedState === CHECKED_STATE.UNCHECKED;
35
- }
36
-
37
- get isIndeterminate() {
38
- return this.checkedState === CHECKED_STATE.INDETERMINATE;
39
- }
40
-
41
- get isChecked() {
42
- return this.checkedState === CHECKED_STATE.CHECKED;
43
- }
44
-
45
- get isCheckedOrIndeterminate() {
46
- return this.isChecked || this.isIndeterminate;
47
- }
48
- }
@@ -1,186 +0,0 @@
1
- import { CHECKED_STATE } from './constants';
2
- import { Node } from './node';
3
-
4
- export class Tree {
5
- constructor(options, selected) {
6
- this.treeDepth = 0;
7
- this.nodes = {};
8
-
9
- this.initNodes(options, selected);
10
- this.initIndeterminateStates();
11
- }
12
-
13
- /**
14
- * @returns {[Node]} The tree as an array of Node instances
15
- */
16
- get nodesList() {
17
- return Object.values(this.nodes);
18
- }
19
-
20
- /**
21
- * @returns {array} The values currently selected
22
- */
23
- get selected() {
24
- return this.nodesList.filter((node) => node.isChecked).map((node) => node.value);
25
- }
26
-
27
- /**
28
- * @returns {boolean} Whether all options are checked
29
- */
30
- get allOptionsChecked() {
31
- return this.selected.length === this.nodesList.length;
32
- }
33
-
34
- /**
35
- * @returns {boolean} Whether some, but not all options are checked
36
- */
37
- get someOptionsChecked() {
38
- return this.selected.length > 0 && !this.allOptionsChecked;
39
- }
40
-
41
- /**
42
- * Creates a flat tree of Node instances.
43
- * @param {array} options The options list
44
- * @param {array} selected Pre-selected option values
45
- * @param {object} parent The options' parent
46
- * @param {number} depth The current depth-level in the tree
47
- */
48
- // eslint-disable-next-line max-params
49
- initNodes(options = [], selected = [], parent = null, depth = 0) {
50
- if (!options.length) {
51
- return;
52
- }
53
- this.treeDepth = depth > this.treeDepth ? depth : this.treeDepth;
54
-
55
- options.forEach((option) => {
56
- const isChecked = selected.includes(option.value);
57
- this.nodes[option.value] = new Node({ ...option, parent, isChecked, depth });
58
- this.initNodes(option.children, selected, option, depth + 1);
59
- });
60
- }
61
-
62
- /**
63
- * Looks for UNCHECKED nodes and sets their checked state to INDETERMINATE if needed. We start
64
- * with the deepest leaves and we go up level by level to propagate the correct INDETERMINATE
65
- * states to each parent node.
66
- */
67
- initIndeterminateStates() {
68
- const nodes = [...this.nodesList];
69
- for (let i = this.treeDepth; i >= 0; i -= 1) {
70
- const removeIndices = [];
71
- nodes.forEach((node, nodeIndex) => {
72
- if (node.depth === i && node.isUnchecked) {
73
- node.setCheckedState(
74
- this.optionHasSomeChildrenChecked(node)
75
- ? CHECKED_STATE.INDETERMINATE
76
- : node.checkedState,
77
- );
78
- removeIndices.push(nodeIndex);
79
- }
80
- });
81
- removeIndices.reverse().forEach((index) => {
82
- nodes.splice(index, 1);
83
- });
84
- }
85
- }
86
-
87
- /**
88
- * Returns true if all of the option's children are checked, false otherwise.
89
- * @param {object} option
90
- * @returns {boolean}
91
- */
92
- optionHasAllChildrenChecked(option) {
93
- return this.getOptionChildren(option).every((child) => child.isChecked);
94
- }
95
-
96
- /**
97
- * Returns true if at least one of the option's children is in a checked or indeterminate state,
98
- * returns false otherwise.
99
- * We consider the INDETERMINATE state as a checked state so we can propagate INDETERMINATE states
100
- * to the option's parents.
101
- * @param {object} option
102
- * @returns {boolean}
103
- */
104
- optionHasSomeChildrenChecked(option) {
105
- return this.getOptionChildren(option).some((child) => child.isCheckedOrIndeterminate);
106
- }
107
-
108
- /**
109
- * Returns the Node instance for a given option's value.
110
- * @param {number|string} value The option's value
111
- * @returns {Node}
112
- */
113
- getNode(value) {
114
- return this.nodes[value];
115
- }
116
-
117
- /**
118
- * Returns the option's children as Node instances.
119
- * @param {object} option
120
- * @returns {[Node]}
121
- */
122
- getOptionChildren(option) {
123
- return option.children.map(({ value }) => this.getNode(value));
124
- }
125
-
126
- /**
127
- * Sets a node's state based on whether it got checked or unchecked
128
- * @param {Node} node The node to be toggled
129
- * @param {boolean} checked Whether the node should be checked
130
- */
131
- static toggleNodeState(node, checked) {
132
- node.setCheckedState(checked ? CHECKED_STATE.CHECKED : CHECKED_STATE.UNCHECKED);
133
- }
134
-
135
- /**
136
- * Toggles all options.
137
- * @param {boolean} checked Whether the options should be checked or unchecked
138
- */
139
- toggleAllOptions(checked) {
140
- this.nodesList.forEach((node) => {
141
- Tree.toggleNodeState(node, checked);
142
- });
143
- }
144
-
145
- /**
146
- * Toggles an option's checked state and propagates the state change to the
147
- * option's parents and children.
148
- * @param {object} param0 The option to be toggled
149
- * @param {boolean} checked Whether the option is checked
150
- * @param {boolean} propagateToParent Whether the state should be propagated to the parents
151
- */
152
- toggleOption({ value }, checked, propagateToParent = true) {
153
- const node = this.getNode(value);
154
- Tree.toggleNodeState(node, checked);
155
-
156
- if (node.isChild && propagateToParent) {
157
- this.toggleParentOption(node.parent);
158
- }
159
-
160
- if (node.isParent) {
161
- node.children.forEach((child) => this.toggleOption(child, checked, false));
162
- }
163
- }
164
-
165
- /**
166
- * Toggles a parent option's checked state. This is called as a result of a child option being
167
- * toggled by the user and the change being propagated to that option's parents. This method
168
- * recursively propagates the state changes to all the ancestors chain until we have reached the
169
- * tree's trunk.
170
- * @param {object} param0 The option to be toggled
171
- */
172
- toggleParentOption({ value }) {
173
- const node = this.getNode(value);
174
- if (this.optionHasAllChildrenChecked(node)) {
175
- node.checkedState = CHECKED_STATE.CHECKED;
176
- } else if (this.optionHasSomeChildrenChecked(node)) {
177
- node.checkedState = CHECKED_STATE.INDETERMINATE;
178
- } else {
179
- node.checkedState = CHECKED_STATE.UNCHECKED;
180
- }
181
-
182
- if (node.isChild) {
183
- this.toggleParentOption(node.parent);
184
- }
185
- }
186
- }