@uh-design-system/component-library 0.5.2 → 0.6.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/dist/cjs/{utils-3412cbed.js → attributes-BMbXzbwU.js} +2 -28
- package/dist/cjs/component-library.cjs.js +7 -7
- package/dist/cjs/controlUtils-ofqiQxRF.js +42 -0
- package/dist/cjs/ds-accordion.cjs.entry.js +79 -0
- package/dist/cjs/ds-button.cjs.entry.js +107 -0
- package/dist/cjs/ds-card.cjs.entry.js +58 -0
- package/dist/cjs/ds-checkbox-group.cjs.entry.js +109 -49
- package/dist/cjs/ds-checkbox.cjs.entry.js +88 -79
- package/dist/cjs/ds-icon.cjs.entry.js +943 -0
- package/dist/cjs/ds-input-validity.cjs.entry.js +14 -15
- package/dist/cjs/ds-link-with-arrow.cjs.entry.js +21 -20
- package/dist/cjs/ds-link.cjs.entry.js +34 -31
- package/dist/cjs/ds-radio-button-group.cjs.entry.js +153 -0
- package/dist/cjs/ds-radio-button.cjs.entry.js +151 -0
- package/dist/cjs/ds-spinner.cjs.entry.js +62 -0
- package/dist/cjs/ds-text-input.cjs.entry.js +90 -77
- package/dist/cjs/ds-visually-hidden.cjs.entry.js +3 -6
- package/dist/cjs/index-Bp6Dd2i1.js +94 -0
- package/dist/cjs/{store-9bd20f3c.js → index-DwLFyR5p.js} +6 -2
- package/dist/cjs/{index-bf84b124.js → index-Mjp9Y-Sw.js} +701 -55
- package/dist/cjs/index.cjs.js +3 -5
- package/dist/cjs/{linkUtils-695da37c.js → linkUtils-onlbgKdI.js} +4 -2
- package/dist/cjs/loader.cjs.js +3 -5
- package/dist/cjs/utils-BjZTECpy.js +29 -0
- package/dist/collection/accessibility/stories/naming.stories.js +3 -3
- package/dist/collection/collection-manifest.json +78 -3
- package/dist/collection/components/01-base-components/ds-accordion/ds-accordion.css +18 -17
- package/dist/collection/components/01-base-components/ds-accordion/ds-accordion.js +91 -50
- package/dist/collection/components/01-base-components/ds-accordion/stories/ds-accordion.examples.stories.js +6 -6
- package/dist/collection/components/01-base-components/ds-accordion/stories/ds-accordion.features.stories.js +14 -14
- package/dist/collection/components/01-base-components/ds-accordion/stories/ds-accordion.stories.js +24 -66
- package/dist/collection/components/01-base-components/ds-button/ds-button.css +124 -145
- package/dist/collection/components/01-base-components/ds-button/ds-button.js +150 -65
- package/dist/collection/components/01-base-components/ds-button/stories/ds-button.examples.stories.js +121 -23
- package/dist/collection/components/01-base-components/ds-button/stories/ds-button.features.stories.js +49 -42
- package/dist/collection/components/01-base-components/ds-button/stories/ds-button.stories.js +16 -72
- package/dist/collection/components/01-base-components/ds-card/ds-card.css +127 -0
- package/dist/collection/components/01-base-components/ds-card/ds-card.js +303 -0
- package/dist/collection/components/01-base-components/ds-card/stories/ds-card.examples.stories.js +92 -0
- package/dist/collection/components/01-base-components/ds-card/stories/ds-card.features.stories.js +66 -0
- package/dist/collection/components/01-base-components/ds-card/stories/ds-card.stories.js +71 -0
- package/dist/collection/components/01-base-components/ds-checkbox/ds-checkbox.css +46 -46
- package/dist/collection/components/01-base-components/ds-checkbox/ds-checkbox.js +120 -111
- package/dist/collection/components/01-base-components/ds-checkbox/stories/ds-checkbox.features.stories.js +20 -20
- package/dist/collection/components/01-base-components/ds-checkbox/stories/ds-checkbox.stories.js +12 -25
- package/dist/collection/components/01-base-components/ds-checkbox-group/ds-checkbox-group.css +2 -3
- package/dist/collection/components/01-base-components/ds-checkbox-group/ds-checkbox-group.js +214 -63
- package/dist/collection/components/01-base-components/ds-checkbox-group/stories/ds-checkbox-group.features.stories.js +215 -50
- package/dist/collection/components/01-base-components/ds-checkbox-group/stories/ds-checkbox-group.stories.js +30 -28
- package/dist/collection/components/01-base-components/ds-icon/ds-icon.js +36 -31
- package/dist/collection/components/01-base-components/ds-icon/stories/ds-icon.stories.js +10 -37
- package/dist/collection/components/01-base-components/ds-input-validity/ds-input-validity.css +2 -2
- package/dist/collection/components/01-base-components/ds-input-validity/ds-input-validity.js +60 -30
- package/dist/collection/components/01-base-components/ds-input-validity/stories/ds-input-validity.features.stories.js +4 -4
- package/dist/collection/components/01-base-components/ds-input-validity/stories/ds-input-validity.stories.js +4 -9
- package/dist/collection/components/01-base-components/ds-link/ds-link.css +24 -14
- package/dist/collection/components/01-base-components/ds-link/ds-link.js +74 -75
- package/dist/collection/components/01-base-components/ds-link/stories/ds-link.examples.stories.js +27 -27
- package/dist/collection/components/01-base-components/ds-link/stories/ds-link.features.stories.js +38 -21
- package/dist/collection/components/01-base-components/ds-link/stories/ds-link.stories.js +8 -67
- package/dist/collection/components/01-base-components/ds-link-with-arrow/ds-link-with-arrow.css +10 -12
- package/dist/collection/components/01-base-components/ds-link-with-arrow/ds-link-with-arrow.js +30 -52
- package/dist/collection/components/01-base-components/ds-link-with-arrow/stories/ds-link-with-arrow.examples.stories.js +4 -4
- package/dist/collection/components/01-base-components/ds-link-with-arrow/stories/ds-link-with-arrow.features.stories.js +6 -6
- package/dist/collection/components/01-base-components/ds-link-with-arrow/stories/ds-link-with-arrow.stories.js +4 -28
- package/dist/collection/components/01-base-components/ds-radio-button/ds-radio-button.css +115 -0
- package/dist/collection/components/01-base-components/ds-radio-button/ds-radio-button.js +449 -0
- package/dist/collection/components/01-base-components/ds-radio-button/stories/ds-radio-button.features.stories.js +72 -0
- package/dist/collection/components/01-base-components/ds-radio-button/stories/ds-radio-button.stories.js +22 -0
- package/dist/collection/components/01-base-components/ds-radio-button-group/ds-radio-button-group.css +30 -0
- package/dist/collection/components/01-base-components/ds-radio-button-group/ds-radio-button-group.js +360 -0
- package/dist/collection/components/01-base-components/ds-radio-button-group/stories/ds-radio-button-group.examples.stories.js +42 -0
- package/dist/collection/components/01-base-components/ds-radio-button-group/stories/ds-radio-button-group.features.stories.js +71 -0
- package/dist/collection/components/01-base-components/ds-radio-button-group/stories/ds-radio-button-group.stories.js +60 -0
- package/dist/collection/components/01-base-components/ds-spinner/ds-spinner.css +279 -0
- package/dist/collection/components/01-base-components/ds-spinner/ds-spinner.js +221 -0
- package/dist/collection/components/01-base-components/ds-spinner/stories/ds-spinner.examples.stories.js +120 -0
- package/dist/collection/components/01-base-components/ds-spinner/stories/ds-spinner.features.stories.js +107 -0
- package/dist/collection/components/01-base-components/ds-spinner/stories/ds-spinner.stories.js +14 -0
- package/dist/collection/components/01-base-components/ds-text-input/ds-text-input.css +85 -118
- package/dist/collection/components/01-base-components/ds-text-input/ds-text-input.js +230 -155
- package/dist/collection/components/01-base-components/ds-text-input/stories/ds-text-input.examples.stories.js +26 -21
- package/dist/collection/components/01-base-components/ds-text-input/stories/ds-text-input.features.stories.js +40 -40
- package/dist/collection/components/01-base-components/ds-text-input/stories/ds-text-input.stories.js +30 -56
- package/dist/collection/components/01-base-components/ds-visually-hidden/ds-visually-hidden.js +1 -1
- package/dist/collection/store.js +7 -1
- package/dist/collection/utils/attributes/attributes.js +2 -2
- package/dist/collection/utils/button/buttonUtils.js +14 -0
- package/dist/collection/utils/colours/colourTypes.js +3 -3
- package/dist/collection/utils/colours/colourUtils.js +5 -3
- package/dist/collection/utils/controls/controlUtils.js +35 -1
- package/dist/collection/utils/link/linkUtils.js +3 -2
- package/dist/collection/utils/spinner/spinnerUtils.js +20 -0
- package/dist/collection/utils/tests/testUtils.js +1 -0
- package/dist/collection/utils/typography/typographyUtils.js +3 -3
- package/dist/collection/utils/utils.js +10 -9
- package/dist/component-library/{utils-cfc536bc.js → attributes-BD_lNRxn.js} +1 -1
- package/dist/component-library/component-library.css +1 -1
- package/dist/component-library/component-library.esm.js +1 -1
- package/dist/component-library/controlUtils-CNER0MvM.js +1 -0
- package/dist/component-library/ds-accordion.entry.js +1 -0
- package/dist/component-library/ds-button.entry.js +1 -0
- package/dist/component-library/ds-card.entry.js +1 -0
- package/dist/component-library/ds-checkbox-group.entry.js +1 -1
- package/dist/component-library/ds-checkbox.entry.js +1 -1
- package/dist/component-library/ds-icon.entry.js +1 -0
- package/dist/component-library/ds-input-validity.entry.js +1 -1
- package/dist/component-library/ds-link-with-arrow.entry.js +1 -1
- package/dist/component-library/ds-link.entry.js +1 -1
- package/dist/component-library/ds-radio-button-group.entry.js +1 -0
- package/dist/component-library/ds-radio-button.entry.js +1 -0
- package/dist/component-library/ds-spinner.entry.js +1 -0
- package/dist/component-library/ds-text-input.entry.js +1 -1
- package/dist/component-library/ds-visually-hidden.entry.js +1 -1
- package/dist/component-library/index-BfTCfPZ1.js +6 -0
- package/dist/component-library/index-Cm7V4EAn.js +2 -0
- package/dist/component-library/index-DuYjhvTn.js +1 -0
- package/dist/component-library/index.esm.js +1 -1
- package/dist/component-library/linkUtils-02nCfO0F.js +1 -0
- package/dist/component-library/utils-CqaqnfY4.js +1 -0
- package/dist/components/attributes.js +3 -3
- package/dist/components/controlUtils.js +35 -2
- package/dist/components/ds-accordion.js +58 -42
- package/dist/components/ds-button2.js +78 -39
- package/dist/components/ds-card.d.ts +11 -0
- package/dist/components/ds-card.js +91 -0
- package/dist/components/ds-checkbox-group.js +116 -56
- package/dist/components/ds-checkbox2.js +93 -80
- package/dist/components/ds-icon2.js +292 -292
- package/dist/components/ds-input-validity2.js +17 -14
- package/dist/components/ds-link-with-arrow.js +22 -22
- package/dist/components/ds-link.js +43 -40
- package/dist/components/ds-radio-button-group.d.ts +11 -0
- package/dist/components/ds-radio-button-group.js +185 -0
- package/dist/components/ds-radio-button.d.ts +11 -0
- package/dist/components/ds-radio-button.js +198 -0
- package/dist/components/ds-spinner.d.ts +11 -0
- package/dist/components/ds-spinner.js +6 -0
- package/dist/components/ds-spinner2.js +89 -0
- package/dist/components/ds-text-input.js +126 -104
- package/dist/components/ds-visually-hidden2.js +2 -3
- package/dist/components/index.js +208 -2
- package/dist/components/index2.js +713 -39
- package/dist/components/index3.js +69 -57
- package/dist/components/linkUtils.js +4 -2
- package/dist/docs.d.ts +443 -0
- package/dist/docs.json +4790 -0
- package/dist/esm/{utils-cfc536bc.js → attributes-BD_lNRxn.js} +3 -26
- package/dist/esm/component-library.js +6 -5
- package/dist/esm/controlUtils-CNER0MvM.js +37 -0
- package/dist/esm/ds-accordion.entry.js +77 -0
- package/dist/esm/ds-button.entry.js +105 -0
- package/dist/esm/ds-card.entry.js +56 -0
- package/dist/esm/ds-checkbox-group.entry.js +108 -46
- package/dist/esm/ds-checkbox.entry.js +78 -67
- package/dist/esm/ds-icon.entry.js +941 -0
- package/dist/esm/ds-input-validity.entry.js +14 -13
- package/dist/esm/ds-link-with-arrow.entry.js +21 -18
- package/dist/esm/ds-link.entry.js +34 -29
- package/dist/esm/ds-radio-button-group.entry.js +151 -0
- package/dist/esm/ds-radio-button.entry.js +149 -0
- package/dist/esm/ds-spinner.entry.js +60 -0
- package/dist/esm/ds-text-input.entry.js +88 -73
- package/dist/esm/ds-visually-hidden.entry.js +3 -4
- package/dist/esm/index-BfTCfPZ1.js +92 -0
- package/dist/esm/{index-434995e1.js → index-Cm7V4EAn.js} +699 -34
- package/dist/{components/store.js → esm/index-DuYjhvTn.js} +6 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/{linkUtils-3d1b28cf.js → linkUtils-02nCfO0F.js} +4 -2
- package/dist/esm/loader.js +4 -4
- package/dist/esm/utils-CqaqnfY4.js +25 -0
- package/dist/hydrate/index.d.ts +271 -0
- package/dist/hydrate/index.js +22280 -0
- package/dist/hydrate/index.mjs +22272 -0
- package/dist/hydrate/package.json +12 -0
- package/dist/styles/helpers.css +15 -0
- package/dist/styles/helpers.css.map +1 -0
- package/dist/styles/mixins/_breakpoints.scss +13 -0
- package/dist/styles/mixins/_focus.scss +26 -0
- package/dist/styles/mixins/_wrapper.scss +5 -0
- package/dist/styles/mixins/imports-default/_imports.scss +2 -0
- package/dist/styles/mixins/tokens/_breakpoints.scss +13 -0
- package/dist/styles/mixins/tokens/_semantic-colours.scss +75 -0
- package/dist/styles/mixins.scss +12 -0
- package/dist/styles/variables.css +176 -0
- package/dist/styles/variables.css.map +1 -0
- package/dist/types/components/01-base-components/ds-accordion/ds-accordion.d.ts +11 -8
- package/dist/types/components/01-base-components/ds-button/ds-button.d.ts +16 -11
- package/dist/types/components/01-base-components/ds-button/stories/ds-button.examples.stories.d.ts +1 -0
- package/dist/types/components/01-base-components/ds-button/stories/ds-button.features.stories.d.ts +1 -0
- package/dist/types/components/01-base-components/ds-card/ds-card.d.ts +20 -0
- package/dist/types/components/01-base-components/ds-card/stories/ds-card.examples.stories.d.ts +8 -0
- package/dist/types/components/01-base-components/ds-card/stories/ds-card.features.stories.d.ts +8 -0
- package/dist/types/components/01-base-components/ds-card/stories/ds-card.stories.d.ts +7 -0
- package/dist/types/components/01-base-components/ds-checkbox/ds-checkbox.d.ts +21 -22
- package/dist/types/components/01-base-components/ds-checkbox-group/ds-checkbox-group.d.ts +21 -11
- package/dist/types/components/01-base-components/ds-checkbox-group/stories/ds-checkbox-group.features.stories.d.ts +3 -0
- package/dist/types/components/01-base-components/ds-icon/ds-icon.d.ts +7 -5
- package/dist/types/components/01-base-components/ds-input-validity/ds-input-validity.d.ts +5 -6
- package/dist/types/components/01-base-components/ds-link/ds-link.d.ts +13 -14
- package/dist/types/components/01-base-components/ds-link/stories/ds-link.features.stories.d.ts +2 -0
- package/dist/types/components/01-base-components/ds-link-with-arrow/ds-link-with-arrow.d.ts +5 -7
- package/dist/types/components/01-base-components/ds-radio-button/ds-radio-button.d.ts +44 -0
- package/dist/types/components/01-base-components/ds-radio-button/stories/ds-radio-button.features.stories.d.ts +15 -0
- package/dist/types/components/01-base-components/ds-radio-button/stories/ds-radio-button.stories.d.ts +7 -0
- package/dist/types/components/01-base-components/ds-radio-button-group/ds-radio-button-group.d.ts +34 -0
- package/dist/types/components/01-base-components/ds-radio-button-group/stories/ds-radio-button-group.examples.stories.d.ts +6 -0
- package/dist/types/components/01-base-components/ds-radio-button-group/stories/ds-radio-button-group.features.stories.d.ts +11 -0
- package/dist/types/components/01-base-components/ds-radio-button-group/stories/ds-radio-button-group.stories.d.ts +7 -0
- package/dist/types/components/01-base-components/ds-spinner/ds-spinner.d.ts +17 -0
- package/dist/types/components/01-base-components/ds-spinner/stories/ds-spinner.examples.stories.d.ts +7 -0
- package/dist/types/components/01-base-components/ds-spinner/stories/ds-spinner.features.stories.d.ts +7 -0
- package/dist/types/components/01-base-components/ds-spinner/stories/ds-spinner.stories.d.ts +7 -0
- package/dist/types/components/01-base-components/ds-text-input/ds-text-input.d.ts +37 -32
- package/dist/types/components.d.ts +1287 -228
- package/dist/types/stencil-public-runtime.d.ts +22 -0
- package/dist/types/store.d.ts +6 -1
- package/dist/types/utils/attributes/attributes.d.ts +1 -1
- package/dist/types/utils/button/buttonUtils.d.ts +1 -0
- package/dist/types/utils/colours/colourTypes.d.ts +3 -3
- package/dist/types/utils/controls/controlUtils.d.ts +2 -0
- package/dist/types/utils/link/linkUtils.d.ts +1 -1
- package/dist/types/utils/spinner/spinnerUtils.d.ts +1 -0
- package/dist/types/utils/tests/testUtils.d.ts +1 -0
- package/dist/types/utils/utils.d.ts +2 -1
- package/package.json +40 -36
- package/dist/cjs/controlUtils-041de0fd.js +0 -7
- package/dist/cjs/ds-accordion_3.cjs.entry.js +0 -1095
- package/dist/cjs/index-5b0b9d4c.js +0 -82
- package/dist/component-library/controlUtils-9ca4087b.js +0 -1
- package/dist/component-library/ds-accordion_3.entry.js +0 -1
- package/dist/component-library/index-434995e1.js +0 -2
- package/dist/component-library/index-72ac5051.js +0 -6
- package/dist/component-library/linkUtils-3d1b28cf.js +0 -1
- package/dist/component-library/store-b8d17c10.js +0 -1
- package/dist/esm/controlUtils-9ca4087b.js +0 -4
- package/dist/esm/ds-accordion_3.entry.js +0 -1089
- package/dist/esm/index-72ac5051.js +0 -80
- package/dist/esm/store-b8d17c10.js +0 -204
- package/dist/loader/package.json +0 -11
- /package/dist/cjs/{app-globals-3a1e7e63.js → app-globals-V2Kpy_OQ.js} +0 -0
- /package/dist/component-library/{app-globals-0f993ce5.js → app-globals-DQuL1Twl.js} +0 -0
- /package/dist/esm/{app-globals-0f993ce5.js → app-globals-DQuL1Twl.js} +0 -0
package/dist/collection/components/01-base-components/ds-radio-button-group/ds-radio-button-group.js
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { h, Host } from "@stencil/core";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import { idGenerator } from "../../../utils/utils";
|
|
4
|
+
import { inheritAriaAttributes } from "../../../utils/attributes/attributes";
|
|
5
|
+
import { atLeastOneOption, getRequiredText } from "../../../utils/controls/controlUtils";
|
|
6
|
+
const radioButtonGroupIdGenerator = idGenerator('ds-radio-button-group');
|
|
7
|
+
export class DsRadioButtonGroup {
|
|
8
|
+
fieldsetId = radioButtonGroupIdGenerator.next().value;
|
|
9
|
+
errorTextId = `${this.fieldsetId}-error`;
|
|
10
|
+
assistiveTextId = `${this.fieldsetId}-assistive-text`;
|
|
11
|
+
inheritedAttributes = {};
|
|
12
|
+
el;
|
|
13
|
+
internals;
|
|
14
|
+
dsLegend;
|
|
15
|
+
dsAssistiveText;
|
|
16
|
+
dsValue;
|
|
17
|
+
dsDirection = 'vertical';
|
|
18
|
+
dsErrorText = '';
|
|
19
|
+
dsRequired = false;
|
|
20
|
+
showInternalsValidationMessage = false;
|
|
21
|
+
dsRadioGroupValueChange;
|
|
22
|
+
dsRadioGroupInvalidStateChange;
|
|
23
|
+
dsChange;
|
|
24
|
+
getLegendText = () => {
|
|
25
|
+
if (this.dsRequired) {
|
|
26
|
+
return getRequiredText(this.dsLegend);
|
|
27
|
+
}
|
|
28
|
+
return this.dsLegend;
|
|
29
|
+
};
|
|
30
|
+
getValidationMessage = () => this.dsErrorText || (this.showInternalsValidationMessage ? this.internals?.validationMessage : '');
|
|
31
|
+
getRadios = () => {
|
|
32
|
+
return Array.from(this.el.querySelectorAll('ds-radio-button'));
|
|
33
|
+
};
|
|
34
|
+
getEnabledRadios = () => {
|
|
35
|
+
return this.getRadios().filter(e => !e.dsDisabled);
|
|
36
|
+
};
|
|
37
|
+
updateRadios = (updateFn) => {
|
|
38
|
+
this.getRadios().forEach(updateFn);
|
|
39
|
+
};
|
|
40
|
+
updateFocusableRadioButton = () => {
|
|
41
|
+
const radios = this.getEnabledRadios();
|
|
42
|
+
if (!radios.length) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let focusableBtn = null;
|
|
46
|
+
for (const radio of radios) {
|
|
47
|
+
const isFocusable = radio.dsValue === this.dsValue;
|
|
48
|
+
radio.setFocusable(isFocusable);
|
|
49
|
+
if (isFocusable) {
|
|
50
|
+
focusableBtn = radio;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!focusableBtn) {
|
|
54
|
+
radios[0].setFocusable(true);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
formResetCallback() {
|
|
58
|
+
this.internals?.setValidity({});
|
|
59
|
+
}
|
|
60
|
+
componentWillLoad() {
|
|
61
|
+
this.inheritedAttributes = inheritAriaAttributes(this.el, ['aria-labelledby']);
|
|
62
|
+
this.updateFocusableRadioButton();
|
|
63
|
+
}
|
|
64
|
+
componentDidLoad() {
|
|
65
|
+
this.updateRadios(element => {
|
|
66
|
+
element.setAttribute('ds-errors-disabled', 'true');
|
|
67
|
+
});
|
|
68
|
+
if (this.dsRequired) {
|
|
69
|
+
this.internals?.setValidity({ valueMissing: true }, atLeastOneOption(), this.getRadios()?.[0].shadowRoot.querySelector('input'));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async getValue() {
|
|
73
|
+
return this.dsValue;
|
|
74
|
+
}
|
|
75
|
+
errorTextObserver(errorText) {
|
|
76
|
+
this.dsRadioGroupInvalidStateChange.emit(!!errorText);
|
|
77
|
+
}
|
|
78
|
+
dsValueObserver(value) {
|
|
79
|
+
this.dsChange.emit(value);
|
|
80
|
+
if (this.dsRequired) {
|
|
81
|
+
this.internals?.setValidity({ valueMissing: !value }, atLeastOneOption(), this.getRadios()?.[0].shadowRoot.querySelector('input'));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
onInputChange(e) {
|
|
85
|
+
e.stopPropagation();
|
|
86
|
+
const targetElem = e.target;
|
|
87
|
+
this.dsValue = targetElem.dsValue;
|
|
88
|
+
this.dsRadioGroupValueChange.emit(this.dsValue);
|
|
89
|
+
this.updateFocusableRadioButton();
|
|
90
|
+
}
|
|
91
|
+
onKeyDown(e) {
|
|
92
|
+
if (!['ArrowUp', 'ArrowLeft', 'ArrowDown', 'ArrowRight'].includes(e.key)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (e.target && !this.el.contains(e.target)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const radios = this.getEnabledRadios();
|
|
99
|
+
if (e.target && !radios.includes(e.target)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
const currentIndex = radios.findIndex(r => r === e.target);
|
|
104
|
+
let nextIndex;
|
|
105
|
+
if (['ArrowUp', 'ArrowLeft'].includes(e.key)) {
|
|
106
|
+
nextIndex = currentIndex === 0 ? radios.length - 1 : currentIndex - 1;
|
|
107
|
+
}
|
|
108
|
+
if (['ArrowDown', 'ArrowRight'].includes(e.key)) {
|
|
109
|
+
nextIndex = (currentIndex + 1) % radios.length;
|
|
110
|
+
}
|
|
111
|
+
const nextElem = radios[nextIndex];
|
|
112
|
+
nextElem.dsFocus();
|
|
113
|
+
nextElem.setChecked();
|
|
114
|
+
}
|
|
115
|
+
render() {
|
|
116
|
+
const classes = classNames('ds-radio-button-group');
|
|
117
|
+
const legendClasses = classNames('ds-radio-button-group__legend');
|
|
118
|
+
const assistiveTextClasses = classNames('ds-radio-button-group__assistive-text');
|
|
119
|
+
const radioButtonsSlotClasses = classNames('ds-radio-button-group__radio-buttons-slot', {
|
|
120
|
+
'ds-radio-button-group__radio-buttons-slot--horizontal': this.dsDirection === 'horizontal',
|
|
121
|
+
});
|
|
122
|
+
const errorClasses = classNames('ds-radio-button-group__error');
|
|
123
|
+
const ariaDescribedBy = [!!this.dsAssistiveText && this.assistiveTextId, !!this.dsErrorText && this.errorTextId].filter(Boolean).join(' ');
|
|
124
|
+
return (h(Host, { key: 'fd0fece58fea50d7ea0672b7f49608c2cdcb306e', "data-invalid": !!this.dsErrorText || undefined }, h("fieldset", { key: '809c66ac58f880345c231b2930ddd9c91c61cbc2', class: classes, "aria-describedby": ariaDescribedBy, ...this.inheritedAttributes }, h("legend", { key: '5194fa04e6645381ef83ad5b4f09c98ea6757da4', class: legendClasses }, h("slot", { key: '2944e5176ce596d6ab5ee6ee735f5b1e5a4e892b', name: "legend" }, this.getLegendText())), h("slot", { key: '3df729bf79cef8d07e88c3e52e337a54a3fb4ead', name: "assistiveText" }, this.dsAssistiveText && (h("small", { key: '36148c44fd5cc17ae506ab598ff79de41e23b71f', class: assistiveTextClasses, id: this.assistiveTextId }, this.dsAssistiveText))), h("div", { key: '54380add5970ee72c0357b9562815d39a95602f0', class: radioButtonsSlotClasses }, h("slot", { key: '3ec766be90173f61dbb76b762c7f6d3f9781570f', onSlotchange: this.updateFocusableRadioButton })), (!!this.dsErrorText || this.dsRequired) && (h("slot", { key: 'c8ae86acd96ecba84d7ab83dad731511629e3f4b', name: "validity" }, h("div", { key: 'da0ce15f076e2c76ca040a6ad6100d706e576862', class: errorClasses }, h("ds-input-validity", { key: 'd9beed52855b81a8125cb0c6498b023357383328', id: this.errorTextId, dsText: this.getValidationMessage(), dsType: "error", dsAriaLive: "polite", dsAriaAtomic: "true" })))))));
|
|
125
|
+
}
|
|
126
|
+
static get is() { return "ds-radio-button-group"; }
|
|
127
|
+
static get encapsulation() { return "shadow"; }
|
|
128
|
+
static get formAssociated() { return true; }
|
|
129
|
+
static get originalStyleUrls() {
|
|
130
|
+
return {
|
|
131
|
+
"$": ["ds-radio-button-group.scss"]
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
static get styleUrls() {
|
|
135
|
+
return {
|
|
136
|
+
"$": ["ds-radio-button-group.css"]
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
static get properties() {
|
|
140
|
+
return {
|
|
141
|
+
"dsLegend": {
|
|
142
|
+
"type": "string",
|
|
143
|
+
"attribute": "ds-legend",
|
|
144
|
+
"mutable": false,
|
|
145
|
+
"complexType": {
|
|
146
|
+
"original": "string",
|
|
147
|
+
"resolved": "string",
|
|
148
|
+
"references": {}
|
|
149
|
+
},
|
|
150
|
+
"required": false,
|
|
151
|
+
"optional": true,
|
|
152
|
+
"docs": {
|
|
153
|
+
"tags": [],
|
|
154
|
+
"text": "Label for the radio button group"
|
|
155
|
+
},
|
|
156
|
+
"getter": false,
|
|
157
|
+
"setter": false,
|
|
158
|
+
"reflect": false
|
|
159
|
+
},
|
|
160
|
+
"dsAssistiveText": {
|
|
161
|
+
"type": "string",
|
|
162
|
+
"attribute": "ds-assistive-text",
|
|
163
|
+
"mutable": false,
|
|
164
|
+
"complexType": {
|
|
165
|
+
"original": "string",
|
|
166
|
+
"resolved": "string",
|
|
167
|
+
"references": {}
|
|
168
|
+
},
|
|
169
|
+
"required": false,
|
|
170
|
+
"optional": true,
|
|
171
|
+
"docs": {
|
|
172
|
+
"tags": [],
|
|
173
|
+
"text": "Text for additional information shown below legend"
|
|
174
|
+
},
|
|
175
|
+
"getter": false,
|
|
176
|
+
"setter": false,
|
|
177
|
+
"reflect": false
|
|
178
|
+
},
|
|
179
|
+
"dsValue": {
|
|
180
|
+
"type": "string",
|
|
181
|
+
"attribute": "ds-value",
|
|
182
|
+
"mutable": true,
|
|
183
|
+
"complexType": {
|
|
184
|
+
"original": "string",
|
|
185
|
+
"resolved": "string",
|
|
186
|
+
"references": {}
|
|
187
|
+
},
|
|
188
|
+
"required": false,
|
|
189
|
+
"optional": true,
|
|
190
|
+
"docs": {
|
|
191
|
+
"tags": [],
|
|
192
|
+
"text": "Determines which radio button in the group is selected.\nThe radio button with the matching `value` will be selected."
|
|
193
|
+
},
|
|
194
|
+
"getter": false,
|
|
195
|
+
"setter": false,
|
|
196
|
+
"reflect": false
|
|
197
|
+
},
|
|
198
|
+
"dsDirection": {
|
|
199
|
+
"type": "string",
|
|
200
|
+
"attribute": "ds-direction",
|
|
201
|
+
"mutable": false,
|
|
202
|
+
"complexType": {
|
|
203
|
+
"original": "'horizontal' | 'vertical'",
|
|
204
|
+
"resolved": "\"horizontal\" | \"vertical\"",
|
|
205
|
+
"references": {}
|
|
206
|
+
},
|
|
207
|
+
"required": false,
|
|
208
|
+
"optional": false,
|
|
209
|
+
"docs": {
|
|
210
|
+
"tags": [],
|
|
211
|
+
"text": "`vertical` displays radio buttons stacked\n`horizontal` displays radio buttons side by side"
|
|
212
|
+
},
|
|
213
|
+
"getter": false,
|
|
214
|
+
"setter": false,
|
|
215
|
+
"reflect": false,
|
|
216
|
+
"defaultValue": "'vertical'"
|
|
217
|
+
},
|
|
218
|
+
"dsErrorText": {
|
|
219
|
+
"type": "string",
|
|
220
|
+
"attribute": "ds-error-text",
|
|
221
|
+
"mutable": false,
|
|
222
|
+
"complexType": {
|
|
223
|
+
"original": "string",
|
|
224
|
+
"resolved": "string",
|
|
225
|
+
"references": {}
|
|
226
|
+
},
|
|
227
|
+
"required": false,
|
|
228
|
+
"optional": false,
|
|
229
|
+
"docs": {
|
|
230
|
+
"tags": [],
|
|
231
|
+
"text": "Error message shown below the text input.\nIf set, the text input is shown in an invalid state."
|
|
232
|
+
},
|
|
233
|
+
"getter": false,
|
|
234
|
+
"setter": false,
|
|
235
|
+
"reflect": false,
|
|
236
|
+
"defaultValue": "''"
|
|
237
|
+
},
|
|
238
|
+
"dsRequired": {
|
|
239
|
+
"type": "boolean",
|
|
240
|
+
"attribute": "ds-required",
|
|
241
|
+
"mutable": false,
|
|
242
|
+
"complexType": {
|
|
243
|
+
"original": "boolean",
|
|
244
|
+
"resolved": "boolean",
|
|
245
|
+
"references": {}
|
|
246
|
+
},
|
|
247
|
+
"required": false,
|
|
248
|
+
"optional": false,
|
|
249
|
+
"docs": {
|
|
250
|
+
"tags": [],
|
|
251
|
+
"text": "One or more radio buttons must be checked."
|
|
252
|
+
},
|
|
253
|
+
"getter": false,
|
|
254
|
+
"setter": false,
|
|
255
|
+
"reflect": false,
|
|
256
|
+
"defaultValue": "false"
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
static get states() {
|
|
261
|
+
return {
|
|
262
|
+
"showInternalsValidationMessage": {}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
static get events() {
|
|
266
|
+
return [{
|
|
267
|
+
"method": "dsRadioGroupValueChange",
|
|
268
|
+
"name": "dsRadioGroupValueChange",
|
|
269
|
+
"bubbles": true,
|
|
270
|
+
"cancelable": true,
|
|
271
|
+
"composed": true,
|
|
272
|
+
"docs": {
|
|
273
|
+
"tags": [],
|
|
274
|
+
"text": "The `dsRadioGroupValueChange` event is emitted when a radio button\ninside the radio button group is selected.\nThis event is mainly used internally to synchronize the state of\nradio buttons."
|
|
275
|
+
},
|
|
276
|
+
"complexType": {
|
|
277
|
+
"original": "string | undefined",
|
|
278
|
+
"resolved": "string",
|
|
279
|
+
"references": {}
|
|
280
|
+
}
|
|
281
|
+
}, {
|
|
282
|
+
"method": "dsRadioGroupInvalidStateChange",
|
|
283
|
+
"name": "dsRadioGroupInvalidStateChange",
|
|
284
|
+
"bubbles": true,
|
|
285
|
+
"cancelable": true,
|
|
286
|
+
"composed": true,
|
|
287
|
+
"docs": {
|
|
288
|
+
"tags": [],
|
|
289
|
+
"text": "The `dsRadioGroupInvalidStateChange` event is emitted when the\n`dsErrorText` property changes. The event `detail` will be `false`\nif the `dsErrorText` is empty, otherwise `true`.\nThis event is mainly used internallty to synchronize the invalid\nstate of radio buttons."
|
|
290
|
+
},
|
|
291
|
+
"complexType": {
|
|
292
|
+
"original": "boolean",
|
|
293
|
+
"resolved": "boolean",
|
|
294
|
+
"references": {}
|
|
295
|
+
}
|
|
296
|
+
}, {
|
|
297
|
+
"method": "dsChange",
|
|
298
|
+
"name": "dsChange",
|
|
299
|
+
"bubbles": true,
|
|
300
|
+
"cancelable": true,
|
|
301
|
+
"composed": true,
|
|
302
|
+
"docs": {
|
|
303
|
+
"tags": [],
|
|
304
|
+
"text": "The `dsChange` event is emitted each time the `dsValue` of the\nradio button group is changed."
|
|
305
|
+
},
|
|
306
|
+
"complexType": {
|
|
307
|
+
"original": "string",
|
|
308
|
+
"resolved": "string",
|
|
309
|
+
"references": {}
|
|
310
|
+
}
|
|
311
|
+
}];
|
|
312
|
+
}
|
|
313
|
+
static get methods() {
|
|
314
|
+
return {
|
|
315
|
+
"getValue": {
|
|
316
|
+
"complexType": {
|
|
317
|
+
"signature": "() => Promise<string>",
|
|
318
|
+
"parameters": [],
|
|
319
|
+
"references": {
|
|
320
|
+
"Promise": {
|
|
321
|
+
"location": "global",
|
|
322
|
+
"id": "global::Promise"
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
"return": "Promise<string>"
|
|
326
|
+
},
|
|
327
|
+
"docs": {
|
|
328
|
+
"text": "",
|
|
329
|
+
"tags": []
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
static get elementRef() { return "el"; }
|
|
335
|
+
static get watchers() {
|
|
336
|
+
return [{
|
|
337
|
+
"propName": "dsErrorText",
|
|
338
|
+
"methodName": "errorTextObserver"
|
|
339
|
+
}, {
|
|
340
|
+
"propName": "dsValue",
|
|
341
|
+
"methodName": "dsValueObserver"
|
|
342
|
+
}];
|
|
343
|
+
}
|
|
344
|
+
static get listeners() {
|
|
345
|
+
return [{
|
|
346
|
+
"name": "dsRadioButtonChecked",
|
|
347
|
+
"method": "onInputChange",
|
|
348
|
+
"target": undefined,
|
|
349
|
+
"capture": false,
|
|
350
|
+
"passive": false
|
|
351
|
+
}, {
|
|
352
|
+
"name": "keydown",
|
|
353
|
+
"method": "onKeyDown",
|
|
354
|
+
"target": "document",
|
|
355
|
+
"capture": false,
|
|
356
|
+
"passive": false
|
|
357
|
+
}];
|
|
358
|
+
}
|
|
359
|
+
static get attachInternalsMemberName() { return "internals"; }
|
|
360
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { html } from "lit";
|
|
2
|
+
const renderRadio = (idx) => html `<ds-radio-button ds-value="${idx + 1}" ds-text="Value text ${idx + 1}"></ds-radio-button>`;
|
|
3
|
+
const renderGroup = (args) => html `
|
|
4
|
+
<ds-radio-button-group
|
|
5
|
+
ds-legend="${args.dsLegend}"
|
|
6
|
+
ds-assistive-text="${args.dsAssistiveText}"
|
|
7
|
+
ds-direction="${args.dsDirection}"
|
|
8
|
+
>
|
|
9
|
+
${Array.from(new Array(args.count)).map((_, i) => renderRadio(i))}
|
|
10
|
+
</ds-radio-button-group>
|
|
11
|
+
`;
|
|
12
|
+
const meta = {
|
|
13
|
+
title: 'Base Components/RadioButtonGroup/Examples',
|
|
14
|
+
component: 'ds-radio-button-group',
|
|
15
|
+
render: (args) => renderGroup(args),
|
|
16
|
+
};
|
|
17
|
+
export default meta;
|
|
18
|
+
export const WithVariableRadioButtonsCount = {
|
|
19
|
+
args: {
|
|
20
|
+
dsLegend: "Group label",
|
|
21
|
+
dsAssistiveText: "Use storybook controls to change the count of radio buttons shown",
|
|
22
|
+
dsDirection: 'vertical',
|
|
23
|
+
count: 1,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export const SomeRadioButtonsDisabled = {
|
|
27
|
+
args: {
|
|
28
|
+
dsLegend: "Group label",
|
|
29
|
+
dsDirection: 'vertical',
|
|
30
|
+
},
|
|
31
|
+
render: (args) => html `
|
|
32
|
+
<ds-radio-button-group
|
|
33
|
+
ds-legend="${args.dsLegend}"
|
|
34
|
+
ds-assistive-text="${args.dsAssistiveText}"
|
|
35
|
+
ds-direction="${args.dsDirection}"
|
|
36
|
+
>
|
|
37
|
+
<ds-radio-button ds-value="1" ds-text="Value text 1"></ds-radio-button>
|
|
38
|
+
<ds-radio-button ds-value="2" ds-text="Value text 2"></ds-radio-button>
|
|
39
|
+
<ds-radio-button ds-disabled="true" ds-value="3" ds-text="Value text 3"></ds-radio-button>
|
|
40
|
+
<ds-radio-button ds-value="4" ds-text="Value text 4"></ds-radio-button>
|
|
41
|
+
</ds-radio-button-group>`
|
|
42
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { html } from "lit";
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Base Components/RadioButtonGroup/Features',
|
|
4
|
+
component: 'ds-radio-button-group',
|
|
5
|
+
render: (args) => html `
|
|
6
|
+
<ds-radio-button-group
|
|
7
|
+
ds-legend=${args.dsLegend}
|
|
8
|
+
ds-assistive-text=${args.dsAssistiveText}
|
|
9
|
+
ds-direction=${args.dsDirection}
|
|
10
|
+
ds-error-text=${args.dsErrorText}
|
|
11
|
+
ds-value=${args.dsValue}
|
|
12
|
+
ds-required=${args.dsRequired}
|
|
13
|
+
>
|
|
14
|
+
<ds-radio-button ds-value="1" ds-text="Value text 1"></ds-radio-button>
|
|
15
|
+
<ds-radio-button ds-value="2" ds-text="Value text 2"></ds-radio-button>
|
|
16
|
+
<ds-radio-button ds-value="3" ds-text="Value text 3"></ds-radio-button>
|
|
17
|
+
<ds-radio-button ds-value="4" ds-text="Value text 4"></ds-radio-button>
|
|
18
|
+
</ds-radio-button-group>
|
|
19
|
+
`,
|
|
20
|
+
};
|
|
21
|
+
export default meta;
|
|
22
|
+
export const Vertical = {
|
|
23
|
+
args: {
|
|
24
|
+
dsLegend: "Group label",
|
|
25
|
+
dsAssistiveText: "Assistive text",
|
|
26
|
+
dsDirection: 'vertical',
|
|
27
|
+
dsRequired: false,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
export const Horizontal = {
|
|
31
|
+
args: {
|
|
32
|
+
dsLegend: "Group label",
|
|
33
|
+
dsAssistiveText: "Assistive text",
|
|
34
|
+
dsDirection: 'horizontal',
|
|
35
|
+
dsRequired: false,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
export const Invalid = {
|
|
39
|
+
args: {
|
|
40
|
+
dsLegend: "Group label",
|
|
41
|
+
dsAssistiveText: "Assistive text",
|
|
42
|
+
dsDirection: 'vertical',
|
|
43
|
+
dsErrorText: 'Error text',
|
|
44
|
+
dsRequired: false,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
export const HorizontalInvalid = {
|
|
48
|
+
args: {
|
|
49
|
+
dsLegend: "Group label",
|
|
50
|
+
dsAssistiveText: "Assistive text",
|
|
51
|
+
dsDirection: 'horizontal',
|
|
52
|
+
dsErrorText: 'Error text',
|
|
53
|
+
dsRequired: false,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
export const Required = {
|
|
57
|
+
args: {
|
|
58
|
+
dsLegend: "Group label",
|
|
59
|
+
dsAssistiveText: "Assistive text",
|
|
60
|
+
dsRequired: true
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
export const WithDefaultValue = {
|
|
64
|
+
args: {
|
|
65
|
+
dsLegend: "Group label",
|
|
66
|
+
dsAssistiveText: "Assistive text",
|
|
67
|
+
dsDirection: 'horizontal',
|
|
68
|
+
dsValue: '2',
|
|
69
|
+
dsRequired: false,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { html } from "lit";
|
|
2
|
+
import { getDsElem } from "../../../../utils/tests/testUtils";
|
|
3
|
+
import { expect, userEvent, waitFor } from "@storybook/test";
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Base Components/RadioButtonGroup',
|
|
6
|
+
component: 'ds-radio-button-group',
|
|
7
|
+
render: args => html `
|
|
8
|
+
<ds-radio-button-group
|
|
9
|
+
ds-legend=${args.dsLegend}
|
|
10
|
+
ds-assistive-text=${args.dsAssistiveText}
|
|
11
|
+
ds-direction=${args.dsDirection}
|
|
12
|
+
ds-value=${args.dsValue}
|
|
13
|
+
ds-error-text=${args.dsErrorText}
|
|
14
|
+
ds-required=${args.dsRequired}>
|
|
15
|
+
<ds-radio-button ds-text="Value text 1"></ds-radio-button>
|
|
16
|
+
<ds-radio-button ds-text="Value text 2"></ds-radio-button>
|
|
17
|
+
<ds-radio-button ds-text="Value text 3"></ds-radio-button>
|
|
18
|
+
<ds-radio-button ds-text="Value text 4"></ds-radio-button>
|
|
19
|
+
</ds-radio-button-group>
|
|
20
|
+
`,
|
|
21
|
+
};
|
|
22
|
+
export default meta;
|
|
23
|
+
export const Default = {
|
|
24
|
+
args: {
|
|
25
|
+
dsLegend: 'Group label',
|
|
26
|
+
dsAssistiveText: 'Assistive text',
|
|
27
|
+
dsRequired: false,
|
|
28
|
+
},
|
|
29
|
+
play: async ({ canvasElement, step }) => {
|
|
30
|
+
const dsElem = (await getDsElem(canvasElement, 'ds-radio-button-group'));
|
|
31
|
+
let radioButtons = [];
|
|
32
|
+
await waitFor(() => {
|
|
33
|
+
radioButtons = Array.from(dsElem.querySelectorAll('ds-radio-button'));
|
|
34
|
+
expect(radioButtons[0].shadowRoot.querySelector('input')).not.toBeNull();
|
|
35
|
+
});
|
|
36
|
+
await step('Clicking radio button should select it', async () => {
|
|
37
|
+
userEvent.click(radioButtons[1].shadowRoot.querySelector('input'));
|
|
38
|
+
await waitFor(() => {
|
|
39
|
+
expect(radioButtons[1].dsChecked).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
await step('Clicking another button should select it and unselect previous selected item', async () => {
|
|
43
|
+
userEvent.click(radioButtons[0].shadowRoot.querySelector('input'));
|
|
44
|
+
await waitFor(() => {
|
|
45
|
+
expect(radioButtons[1].dsChecked).toBe(false);
|
|
46
|
+
expect(radioButtons[0].dsChecked).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
export const Playground = {
|
|
52
|
+
args: {
|
|
53
|
+
dsLegend: 'Group label',
|
|
54
|
+
dsAssistiveText: '',
|
|
55
|
+
dsDirection: 'vertical',
|
|
56
|
+
dsErrorText: '',
|
|
57
|
+
dsValue: '',
|
|
58
|
+
dsRequired: false,
|
|
59
|
+
},
|
|
60
|
+
};
|