@hashicorp/design-system-components 0.12.6 → 0.12.9

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 (79) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/addon/components/hds/alert/index.hbs +8 -1
  3. package/addon/components/hds/alert/index.js +31 -0
  4. package/addon/components/hds/card/container.js +65 -5
  5. package/addon/components/hds/form/checkbox/base.hbs +1 -0
  6. package/addon/components/hds/form/checkbox/base.js +19 -0
  7. package/addon/components/hds/form/checkbox/field.hbs +19 -0
  8. package/addon/components/hds/form/checkbox/group.hbs +9 -0
  9. package/addon/components/hds/form/error/index.hbs +6 -0
  10. package/addon/components/hds/form/error/index.js +56 -0
  11. package/addon/components/hds/form/error/message.hbs +3 -0
  12. package/addon/components/hds/form/field/index.hbs +21 -0
  13. package/addon/components/hds/form/field/index.js +66 -0
  14. package/addon/components/hds/form/fieldset/index.hbs +23 -0
  15. package/addon/components/hds/form/fieldset/index.js +49 -0
  16. package/addon/components/hds/form/helper-text/index.hbs +3 -0
  17. package/addon/components/hds/form/helper-text/index.js +56 -0
  18. package/addon/components/hds/form/label/index.hbs +3 -0
  19. package/addon/components/hds/form/label/index.js +24 -0
  20. package/addon/components/hds/form/legend/index.hbs +3 -0
  21. package/addon/components/hds/form/legend/index.js +24 -0
  22. package/addon/components/hds/form/radio/base.hbs +1 -0
  23. package/addon/components/hds/form/radio/base.js +19 -0
  24. package/addon/components/hds/form/radio/field.hbs +19 -0
  25. package/addon/components/hds/form/radio/group.hbs +7 -0
  26. package/addon/components/hds/form/select/base.hbs +3 -0
  27. package/addon/components/hds/form/select/base.js +22 -0
  28. package/addon/components/hds/form/select/field.hbs +18 -0
  29. package/addon/components/hds/form/text-input/base.hbs +1 -0
  30. package/addon/components/hds/form/text-input/base.js +56 -0
  31. package/addon/components/hds/form/text-input/field.hbs +16 -0
  32. package/addon/components/hds/form/textarea/base.hbs +2 -0
  33. package/addon/components/hds/form/textarea/base.js +22 -0
  34. package/addon/components/hds/form/textarea/field.hbs +15 -0
  35. package/addon/components/hds/form/toggle/base.hbs +4 -0
  36. package/addon/components/hds/form/toggle/base.js +27 -0
  37. package/addon/components/hds/form/toggle/field.hbs +20 -0
  38. package/addon/components/hds/form/utils/getAriaDescribedBy.js +21 -0
  39. package/addon/components/hds/form/utils/getElementId.js +14 -0
  40. package/app/components/hds/form/checkbox/base.js +1 -0
  41. package/app/components/hds/form/checkbox/field.js +1 -0
  42. package/app/components/hds/form/checkbox/group.js +1 -0
  43. package/app/components/hds/form/error/index.js +1 -0
  44. package/app/components/hds/form/error/message.js +1 -0
  45. package/app/components/hds/form/field/index.js +1 -0
  46. package/app/components/hds/form/fieldset/index.js +1 -0
  47. package/app/components/hds/form/helper-text/index.js +1 -0
  48. package/app/components/hds/form/label/index.js +1 -0
  49. package/app/components/hds/form/legend/index.js +1 -0
  50. package/app/components/hds/form/radio/base.js +1 -0
  51. package/app/components/hds/form/radio/field.js +1 -0
  52. package/app/components/hds/form/radio/group.js +1 -0
  53. package/app/components/hds/form/select/base.js +1 -0
  54. package/app/components/hds/form/select/field.js +1 -0
  55. package/app/components/hds/form/text-input/base.js +1 -0
  56. package/app/components/hds/form/text-input/field.js +1 -0
  57. package/app/components/hds/form/textarea/base.js +1 -0
  58. package/app/components/hds/form/textarea/field.js +1 -0
  59. package/app/components/hds/form/toggle/base.js +1 -0
  60. package/app/components/hds/form/toggle/field.js +1 -0
  61. package/app/styles/@hashicorp/design-system-components.scss +1 -0
  62. package/app/styles/components/badge.scss +1 -0
  63. package/app/styles/components/button.scss +0 -6
  64. package/app/styles/components/card/container.scss +25 -0
  65. package/app/styles/components/form/checkbox.scss +96 -0
  66. package/app/styles/components/form/error.scss +26 -0
  67. package/app/styles/components/form/field.scss +90 -0
  68. package/app/styles/components/form/group.scss +52 -0
  69. package/app/styles/components/form/helper-text.scss +10 -0
  70. package/app/styles/components/form/index.scss +18 -0
  71. package/app/styles/components/form/label.scss +12 -0
  72. package/app/styles/components/form/legend.scss +10 -0
  73. package/app/styles/components/form/radio.scss +100 -0
  74. package/app/styles/components/form/select.scss +58 -0
  75. package/app/styles/components/form/text-input.scss +144 -0
  76. package/app/styles/components/form/textarea.scss +80 -0
  77. package/app/styles/components/form/toggle.scss +171 -0
  78. package/blueprints/hds-component-test/files/tests/dummy/app/templates/components/__name__.hbs +3 -3
  79. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @hashicorp/design-system-components
2
2
 
3
+ ## 0.12.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#418](https://github.com/hashicorp/design-system/pull/418) [`981e2bd9`](https://github.com/hashicorp/design-system/commit/981e2bd99d29398a40274d390d1885ebfcd85133) Thanks [@alex-ju](https://github.com/alex-ju)! - Determine an accessible name for `alertdialog` alerts #418
8
+
9
+ * [#416](https://github.com/hashicorp/design-system/pull/416) [`824e53d1`](https://github.com/hashicorp/design-system/commit/824e53d11678a5bb2544add3d9d1b2a93f9c42c1) Thanks [@alex-ju](https://github.com/alex-ju)! - Remove stray aria-describedby in alert component
10
+
11
+ - [#415](https://github.com/hashicorp/design-system/pull/415) [`c6842109`](https://github.com/hashicorp/design-system/commit/c68421094991b2d62832cb346b4cf23eca1049e4) Thanks [@didoo](https://github.com/didoo)! - Added `@levelHover` and `@levelActive` arguments to `Card::Container` component
12
+
13
+ ## 0.12.8
14
+
15
+ ### Patch Changes
16
+
17
+ - [#400](https://github.com/hashicorp/design-system/pull/400) [`d87d622b`](https://github.com/hashicorp/design-system/commit/d87d622b0f1f8829a0d5e6a48cfcd8ad8ff6f425) Thanks [@alex-ju](https://github.com/alex-ju)! - Determine alert component's role based on the presence of interactive elements
18
+
19
+ ## 0.12.7
20
+
21
+ ### Patch Changes
22
+
23
+ - [#406](https://github.com/hashicorp/design-system/pull/406) [`3c3f49b9`](https://github.com/hashicorp/design-system/commit/3c3f49b950fe7c0c9fa9732d9a8534d3b73e69fd) Thanks [@alex-ju](https://github.com/alex-ju)! - Fix badge vertical alignment
24
+
3
25
  ## 0.12.6
4
26
 
5
27
  ### Patch Changes
@@ -1,4 +1,11 @@
1
- <div class={{this.classNames}} role="alert" aria-live="polite" ...attributes>
1
+ <div
2
+ class={{this.classNames}}
3
+ role={{this.role}}
4
+ aria-live="polite"
5
+ aria-labelledby={{this.ariaLabelledBy}}
6
+ {{did-insert this.didInsert}}
7
+ ...attributes
8
+ >
2
9
  {{#if this.icon}}
3
10
  <div class="hds-alert__icon">
4
11
  <FlightIcon @name={{this.icon}} @size={{this.iconSize}} @stretched={{true}} @isInlineBlock={{false}} />
@@ -1,5 +1,8 @@
1
1
  import Component from '@glimmer/component';
2
+ import { action } from '@ember/object';
2
3
  import { assert } from '@ember/debug';
4
+ import { guidFor } from '@ember/object/internals';
5
+ import { tracked } from '@glimmer/tracking';
3
6
 
4
7
  export const TYPES = ['page', 'inline', 'compact'];
5
8
  export const DEFAULT_COLOR = 'neutral';
@@ -18,7 +21,14 @@ export const MAPPING_COLORS_TO_ICONS = {
18
21
  critical: 'alert-diamond',
19
22
  };
20
23
 
24
+ const CONTENT_ELEMENT_SELECTOR = '.hds-alert__content';
25
+ const TITLE_ELEMENT_SELECTOR = '.hds-alert__title';
26
+ const DESCRIPTION_ELEMENT_SELECTOR = '.hds-alert__description';
27
+
21
28
  export default class HdsAlertIndexComponent extends Component {
29
+ @tracked role = 'alert';
30
+ @tracked ariaLabelledBy;
31
+
22
32
  constructor() {
23
33
  super(...arguments);
24
34
 
@@ -125,4 +135,25 @@ export default class HdsAlertIndexComponent extends Component {
125
135
 
126
136
  return classes.join(' ');
127
137
  }
138
+
139
+ @action
140
+ didInsert(element) {
141
+ let actions = element.querySelectorAll(
142
+ `${CONTENT_ELEMENT_SELECTOR} button, ${CONTENT_ELEMENT_SELECTOR} a`
143
+ );
144
+ if (actions.length) {
145
+ this.role = 'alertdialog';
146
+ }
147
+
148
+ // `alertdialog` must have an accessible name so we use either the
149
+ // title or the description as label for the alert
150
+ let label =
151
+ element.querySelector(TITLE_ELEMENT_SELECTOR) ||
152
+ element.querySelector(DESCRIPTION_ELEMENT_SELECTOR);
153
+ if (label) {
154
+ let labelId = label.getAttribute('id') || guidFor(element);
155
+ label.setAttribute('id', labelId);
156
+ this.ariaLabelledBy = labelId;
157
+ }
158
+ }
128
159
  }
@@ -21,7 +21,7 @@ export default class HdsCardContainerComponent extends Component {
21
21
  let { level = DEFAULT_LEVEL } = this.args;
22
22
 
23
23
  assert(
24
- `@level for "Hds::CardContainer" must be one of the following: ${LEVELS.join(
24
+ `@level for "Hds::Card::Container" must be one of the following: ${LEVELS.join(
25
25
  ', '
26
26
  )}, received: ${level}`,
27
27
  LEVELS.includes(level)
@@ -30,6 +30,50 @@ export default class HdsCardContainerComponent extends Component {
30
30
  return level;
31
31
  }
32
32
 
33
+ /**
34
+ * Sets the "elevation" level for the component on ":hover" state
35
+ * Accepted values: base, mid, high
36
+ *
37
+ * @param levelHover
38
+ * @type {string}
39
+ */
40
+ get levelHover() {
41
+ let { levelHover } = this.args;
42
+
43
+ if (levelHover) {
44
+ assert(
45
+ `@levelHover for "Hds::Card::Container" must be one of the following: ${LEVELS.join(
46
+ ', '
47
+ )}, received: ${levelHover}`,
48
+ LEVELS.includes(levelHover)
49
+ );
50
+ }
51
+
52
+ return levelHover;
53
+ }
54
+
55
+ /**
56
+ * Sets the "elevation" level for the component on ":active" state
57
+ * Accepted values: base, mid, high
58
+ *
59
+ * @param levelActive
60
+ * @type {string}
61
+ */
62
+ get levelActive() {
63
+ let { levelActive } = this.args;
64
+
65
+ if (levelActive) {
66
+ assert(
67
+ `@levelActive for "Hds::Card::Container" must be one of the following: ${LEVELS.join(
68
+ ', '
69
+ )}, received: ${levelActive}`,
70
+ LEVELS.includes(levelActive)
71
+ );
72
+ }
73
+
74
+ return levelActive;
75
+ }
76
+
33
77
  /**
34
78
  * Sets the background for the component
35
79
  * Accepted values: neutral-primary, neutral-secondary
@@ -42,7 +86,7 @@ export default class HdsCardContainerComponent extends Component {
42
86
  let { background = DEFAULT_BACKGROUND } = this.args;
43
87
 
44
88
  assert(
45
- `@background for "Hds::CardContainer" must be one of the following: ${BACKGROUNDS.join(
89
+ `@background for "Hds::Card::Container" must be one of the following: ${BACKGROUNDS.join(
46
90
  ', '
47
91
  )}, received: ${background}`,
48
92
  BACKGROUNDS.includes(background)
@@ -63,7 +107,7 @@ export default class HdsCardContainerComponent extends Component {
63
107
  let { overflow = DEFAULT_OVERFLOW } = this.args;
64
108
 
65
109
  assert(
66
- `@overflow for "Hds::CardContainer" must be one of the following: ${OVERFLOWS.join(
110
+ `@overflow for "Hds::Card::Container" must be one of the following: ${OVERFLOWS.join(
67
111
  ', '
68
112
  )}, received: ${overflow}`,
69
113
  OVERFLOWS.includes(overflow)
@@ -80,10 +124,26 @@ export default class HdsCardContainerComponent extends Component {
80
124
  get classNames() {
81
125
  let classes = ['hds-card__container'];
82
126
 
83
- // add an "elevation" class helper based on the @level and @hasBorder arguments
127
+ // add "elevation" classes based on the @level and @hasBorder arguments
84
128
  classes.push(
85
- `hds-${this.args.hasBorder ? 'surface' : 'elevation'}-${this.level}`
129
+ `hds-card__container--level-${
130
+ this.args.hasBorder ? 'surface' : 'elevation'
131
+ }-${this.level}`
86
132
  );
133
+ if (this.levelHover) {
134
+ classes.push(
135
+ `hds-card__container--hover-level-${
136
+ this.args.hasBorder ? 'surface' : 'elevation'
137
+ }-${this.levelHover}`
138
+ );
139
+ }
140
+ if (this.levelActive) {
141
+ classes.push(
142
+ `hds-card__container--active-level-${
143
+ this.args.hasBorder ? 'surface' : 'elevation'
144
+ }-${this.levelActive}`
145
+ );
146
+ }
87
147
 
88
148
  // add a class based on the @background argument
89
149
  classes.push(`hds-card__container--background-${this.background}`);
@@ -0,0 +1 @@
1
+ <input type="checkbox" class={{this.classNames}} ...attributes value={{@value}} />
@@ -0,0 +1,19 @@
1
+ import Component from '@glimmer/component';
2
+
3
+ export default class HdsFormCheckboxBaseComponent extends Component {
4
+ /**
5
+ * Get the class names to apply to the component.
6
+ * @method classNames
7
+ * @return {string} The "class" attribute to apply to the component.
8
+ */
9
+ get classNames() {
10
+ let classes = ['hds-form-checkbox'];
11
+
12
+ // add a class based on the @isInvalid argument
13
+ if (this.args.isInvalid) {
14
+ classes.push(`hds-form-checkbox--is-invalid`);
15
+ }
16
+
17
+ return classes.join(' ');
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ <Hds::Form::Field
2
+ @layout="flag"
3
+ @contextualClass={{@contextualClass}}
4
+ @extraAriaDescribedBy={{@extraAriaDescribedBy}}
5
+ as |F|
6
+ >
7
+ {{! Notice: the order of the elements is not relevant here, because it's controlled at "Hds::Form::Field" component level }}
8
+ {{yield (hash Label=F.Label HelperText=F.HelperText Error=F.Error)}}
9
+ <F.Control>
10
+ <Hds::Form::Checkbox::Base
11
+ class="hds-form-field__control"
12
+ @value={{@value}}
13
+ @isInvalid={{@isInvalid}}
14
+ ...attributes
15
+ id={{F.id}}
16
+ aria-describedby={{F.ariaDescribedBy}}
17
+ />
18
+ </F.Control>
19
+ </Hds::Form::Field>
@@ -0,0 +1,9 @@
1
+ <Hds::Form::Fieldset @layout={{@layout}} ...attributes as |F|>
2
+ {{! Notice: the order of the elements is not relevant here, because it's controlled at "Hds::Form::Fieldset" component level }}
3
+ {{yield (hash Legend=F.Legend HelperText=F.HelperText Error=F.Error)}}
4
+ <F.Control>
5
+ {{yield
6
+ (hash Checkbox::Field=(component "hds/form/checkbox/field" contextualClass="hds-form-group__control-field"))
7
+ }}
8
+ </F.Control>
9
+ </Hds::Form::Fieldset>
@@ -0,0 +1,6 @@
1
+ <div class={{this.classNames}} id={{this.id}} {{did-insert this.onInsert}} ...attributes>
2
+ <FlightIcon class="hds-form-error__icon" @name="alert-diamond-fill" />
3
+ <div class="hds-form-error__content">
4
+ {{yield (hash Message=(component "hds/form/error/message"))}}
5
+ </div>
6
+ </div>
@@ -0,0 +1,56 @@
1
+ import Component from '@glimmer/component';
2
+ export const ID_PREFIX = 'error-';
3
+
4
+ const NOOP = () => {};
5
+
6
+ export default class HdsFormErrorIndexComponent extends Component {
7
+ /**
8
+ * Determines the unique ID to assign to the element
9
+ * @method id
10
+ * @return {(string|null)} The "id" attribute to apply to the element or null, if no controlId is provided
11
+ */
12
+ get id() {
13
+ let { controlId } = this.args;
14
+ if (controlId) {
15
+ return `${ID_PREFIX}${controlId}`;
16
+ }
17
+ return null;
18
+ }
19
+
20
+ /**
21
+ * @param onInsert
22
+ * @type {function}
23
+ * @default () => {}
24
+ */
25
+ get onInsert() {
26
+ let { onInsert } = this.args;
27
+
28
+ // notice: this is a guard used to prevent triggering an error when the component is used as standalone element
29
+ if (typeof onInsert === 'function') {
30
+ return onInsert;
31
+ } else {
32
+ return NOOP;
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Get the class names to apply to the component.
38
+ * @method classNames
39
+ * @return {string} The "class" attribute to apply to the component.
40
+ */
41
+ get classNames() {
42
+ let classes = ['hds-form-error'];
43
+
44
+ // add typographic classes
45
+ classes.push('hds-typography-body-100', 'hds-font-weight-medium');
46
+
47
+ // add a class based on the @contextualClass argument
48
+ // notice: this will *not* be documented for public use
49
+ // the reason for this is that the contextual component declarations don't pass attributes to the component
50
+ if (this.args.contextualClass) {
51
+ classes.push(this.args.contextualClass);
52
+ }
53
+
54
+ return classes.join(' ');
55
+ }
56
+ }
@@ -0,0 +1,3 @@
1
+ <p class="hds-form-error__message" ...attributes>
2
+ {{yield}}
3
+ </p>
@@ -0,0 +1,21 @@
1
+ <div class={{this.classNames}} ...attributes>
2
+ {{yield (hash Label=(component "hds/form/label" controlId=this.id contextualClass="hds-form-field__label"))}}
3
+ {{yield
4
+ (hash
5
+ HelperText=(component
6
+ "hds/form/helper-text"
7
+ controlId=this.id
8
+ onInsert=this.appendDescriptor
9
+ contextualClass="hds-form-field__helper-text"
10
+ )
11
+ )
12
+ }}
13
+ {{yield (hash Control=(component "hds/yield") id=this.id ariaDescribedBy=this.ariaDescribedBy)}}
14
+ {{yield
15
+ (hash
16
+ Error=(component
17
+ "hds/form/error" controlId=this.id onInsert=this.appendDescriptor contextualClass="hds-form-field__error"
18
+ )
19
+ )
20
+ }}
21
+ </div>
@@ -0,0 +1,66 @@
1
+ import Component from '@glimmer/component';
2
+ import { tracked } from '@glimmer/tracking';
3
+ import { assert } from '@ember/debug';
4
+ import { action } from '@ember/object';
5
+ import { getElementId } from '../utils/getElementId';
6
+ import { getAriaDescribedBy } from '../utils/getAriaDescribedBy';
7
+
8
+ export const LAYOUT_TYPES = ['vertical', 'flag'];
9
+
10
+ export default class HdsFormFieldIndexComponent extends Component {
11
+ @tracked ariaDescribedBy = getAriaDescribedBy(this);
12
+ @tracked descriptors = [];
13
+
14
+ @action
15
+ appendDescriptor(element) {
16
+ this.descriptors.push(element.id);
17
+ this.ariaDescribedBy = getAriaDescribedBy(this);
18
+ }
19
+
20
+ /**
21
+ * Sets the layout of the field
22
+ *
23
+ * @param layout
24
+ * @type {string}
25
+ */
26
+ get layout() {
27
+ let { layout } = this.args;
28
+
29
+ assert(
30
+ `@type for "Hds::Form::Field" must be one of the following: ${LAYOUT_TYPES.join(
31
+ ', '
32
+ )}, received: ${layout}`,
33
+ LAYOUT_TYPES.includes(layout)
34
+ );
35
+
36
+ return layout;
37
+ }
38
+
39
+ /**
40
+ * Calculates the unique ID to assign to the form control
41
+ */
42
+ get id() {
43
+ return getElementId(this);
44
+ }
45
+
46
+ /**
47
+ * Get the class names to apply to the component.
48
+ * @method classNames
49
+ * @return {string} The "class" attribute to apply to the component.
50
+ */
51
+ get classNames() {
52
+ let classes = [];
53
+
54
+ if (this.args.layout) {
55
+ classes.push(`hds-form-field--layout-${this.layout}`);
56
+ }
57
+
58
+ // add a class based on the @contextualClass argument
59
+ // notice: this will *not* be documented for public use
60
+ if (this.args.contextualClass) {
61
+ classes.push(this.args.contextualClass);
62
+ }
63
+
64
+ return classes.join(' ');
65
+ }
66
+ }
@@ -0,0 +1,23 @@
1
+ <fieldset class={{this.classNames}} id={{this.id}} ...attributes aria-describedby={{this.ariaDescribedBy}}>
2
+ {{yield (hash Legend=(component "hds/form/legend" contextualClass="hds-form-group__legend"))}}
3
+ {{yield
4
+ (hash
5
+ HelperText=(component
6
+ "hds/form/helper-text"
7
+ controlId=this.id
8
+ onInsert=this.appendDescriptor
9
+ contextualClass="hds-form-group__helper-text"
10
+ )
11
+ )
12
+ }}
13
+ <div class="hds-form-group__control-fields-wrapper">
14
+ {{yield (hash Control=(component "hds/yield"))}}
15
+ </div>
16
+ {{yield
17
+ (hash
18
+ Error=(component
19
+ "hds/form/error" controlId=this.id onInsert=this.appendDescriptor contextualClass="hds-form-group__error"
20
+ )
21
+ )
22
+ }}
23
+ </fieldset>
@@ -0,0 +1,49 @@
1
+ import Component from '@glimmer/component';
2
+ import { tracked } from '@glimmer/tracking';
3
+ import { action } from '@ember/object';
4
+ import { getElementId } from '../utils/getElementId';
5
+ import { getAriaDescribedBy } from '../utils/getAriaDescribedBy';
6
+
7
+ export default class HdsFormFieldsetIndexComponent extends Component {
8
+ @tracked ariaDescribedBy = getAriaDescribedBy(this);
9
+ @tracked descriptors = [];
10
+
11
+ @action
12
+ appendDescriptor(element) {
13
+ this.descriptors.push(element.id);
14
+ this.ariaDescribedBy = getAriaDescribedBy(this);
15
+ }
16
+
17
+ /**
18
+ * Sets the layout of the group
19
+ *
20
+ * @param layout
21
+ * @type {enum}
22
+ * @default 'vertical'
23
+ */
24
+ get layout() {
25
+ return this.args.layout ?? 'vertical';
26
+ }
27
+
28
+ /**
29
+ * Calculates the unique ID to assign to the fieldset
30
+ */
31
+ get id() {
32
+ return getElementId(this);
33
+ }
34
+
35
+ /**
36
+ * Get the class names to apply to the component.
37
+ * @method classNames
38
+ * @return {string} The "class" attribute to apply to the component.
39
+ */
40
+ get classNames() {
41
+ // we just need a class for the layout
42
+ let classes = ['hds-form-group'];
43
+
44
+ // add a class based on the @layout argument
45
+ classes.push(`hds-form-group--layout-${this.layout}`);
46
+
47
+ return classes.join(' ');
48
+ }
49
+ }
@@ -0,0 +1,3 @@
1
+ <div class={{this.classNames}} id={{this.id}} {{did-insert this.onInsert}} ...attributes>
2
+ {{yield}}
3
+ </div>
@@ -0,0 +1,56 @@
1
+ import Component from '@glimmer/component';
2
+ export const ID_PREFIX = 'helper-text-';
3
+
4
+ const NOOP = () => {};
5
+
6
+ export default class HdsFormHelperTextIndexComponent extends Component {
7
+ /**
8
+ * Determines the unique ID to assign to the element
9
+ * @method id
10
+ * @return {(string|null)} The "id" attribute to apply to the element or null, if no controlId is provided
11
+ */
12
+ get id() {
13
+ let { controlId } = this.args;
14
+ if (controlId) {
15
+ return `${ID_PREFIX}${controlId}`;
16
+ }
17
+ return null;
18
+ }
19
+
20
+ /**
21
+ * @param onInsert
22
+ * @type {function}
23
+ * @default () => {}
24
+ */
25
+ get onInsert() {
26
+ let { onInsert } = this.args;
27
+
28
+ // notice: this is a guard used to prevent triggering an error when the component is used as standalone element
29
+ if (typeof onInsert === 'function') {
30
+ return onInsert;
31
+ } else {
32
+ return NOOP;
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Get the class names to apply to the component.
38
+ * @method classNames
39
+ * @return {string} The "class" attribute to apply to the component.
40
+ */
41
+ get classNames() {
42
+ let classes = ['hds-form-helper-text'];
43
+
44
+ // add typographic classes
45
+ classes.push('hds-typography-body-100', 'hds-font-weight-regular');
46
+
47
+ // add a class based on the @contextualClass argument
48
+ // notice: this will *not* be documented for public use
49
+ // the reason for this is that the contextual component declarations don't pass attributes to the component
50
+ if (this.args.contextualClass) {
51
+ classes.push(this.args.contextualClass);
52
+ }
53
+
54
+ return classes.join(' ');
55
+ }
56
+ }
@@ -0,0 +1,3 @@
1
+ <label class={{this.classNames}} for={{@controlId}} ...attributes>
2
+ {{yield}}
3
+ </label>
@@ -0,0 +1,24 @@
1
+ import Component from '@glimmer/component';
2
+
3
+ export default class HdsFormLabelIndexComponent extends Component {
4
+ /**
5
+ * Get the class names to apply to the component.
6
+ * @method classNames
7
+ * @return {string} The "class" attribute to apply to the component.
8
+ */
9
+ get classNames() {
10
+ let classes = ['hds-form-label'];
11
+
12
+ // add typographic classes
13
+ classes.push('hds-typography-body-200', 'hds-font-weight-semibold');
14
+
15
+ // add a class based on the @contextualClass argument
16
+ // notice: this will *not* be documented for public use
17
+ // the reason for this is that the contextual component declarations don't pass attributes to the component
18
+ if (this.args.contextualClass) {
19
+ classes.push(this.args.contextualClass);
20
+ }
21
+
22
+ return classes.join(' ');
23
+ }
24
+ }
@@ -0,0 +1,3 @@
1
+ <legend class={{this.classNames}} ...attributes>
2
+ {{yield}}
3
+ </legend>
@@ -0,0 +1,24 @@
1
+ import Component from '@glimmer/component';
2
+
3
+ export default class HdsFormLegendIndexComponent extends Component {
4
+ /**
5
+ * Get the class names to apply to the component.
6
+ * @method classNames
7
+ * @return {string} The "class" attribute to apply to the component.
8
+ */
9
+ get classNames() {
10
+ let classes = ['hds-form-legend'];
11
+
12
+ // add typographic classes
13
+ classes.push('hds-typography-body-200', 'hds-font-weight-semibold');
14
+
15
+ // add a class based on the @contextualClass argument
16
+ // notice: this will *not* be documented for public use
17
+ // the reason for this is that the contextual component declarations don't pass attributes to the component
18
+ if (this.args.contextualClass) {
19
+ classes.push(this.args.contextualClass);
20
+ }
21
+
22
+ return classes.join(' ');
23
+ }
24
+ }
@@ -0,0 +1 @@
1
+ <input type="radio" class={{this.classNames}} ...attributes value={{@value}} />
@@ -0,0 +1,19 @@
1
+ import Component from '@glimmer/component';
2
+
3
+ export default class HdsFormRadioBaseComponent extends Component {
4
+ /**
5
+ * Get the class names to apply to the component.
6
+ * @method classNames
7
+ * @return {string} The "class" attribute to apply to the component.
8
+ */
9
+ get classNames() {
10
+ let classes = ['hds-form-radio'];
11
+
12
+ // add a class based on the @isInvalid argument
13
+ if (this.args.isInvalid) {
14
+ classes.push(`hds-form-radio--is-invalid`);
15
+ }
16
+
17
+ return classes.join(' ');
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ <Hds::Form::Field
2
+ @layout="flag"
3
+ @contextualClass={{@contextualClass}}
4
+ @extraAriaDescribedBy={{@extraAriaDescribedBy}}
5
+ as |F|
6
+ >
7
+ {{! Notice: the order of the elements is not relevant here, because it's controlled at "Hds::Form::Field" component level }}
8
+ {{yield (hash Label=F.Label HelperText=F.HelperText Error=F.Error)}}
9
+ <F.Control>
10
+ <Hds::Form::Radio::Base
11
+ class="hds-form-field__control"
12
+ @value={{@value}}
13
+ @isInvalid={{@isInvalid}}
14
+ ...attributes
15
+ id={{F.id}}
16
+ aria-describedby={{F.ariaDescribedBy}}
17
+ />
18
+ </F.Control>
19
+ </Hds::Form::Field>
@@ -0,0 +1,7 @@
1
+ <Hds::Form::Fieldset @layout={{@layout}} ...attributes as |F|>
2
+ {{! Notice: the order of the elements is not relevant here, because it's controlled at "Hds::Form::Fieldset" component level }}
3
+ {{yield (hash Legend=F.Legend HelperText=F.HelperText Error=F.Error)}}
4
+ <F.Control>
5
+ {{yield (hash Radio::Field=(component "hds/form/radio/field" contextualClass="hds-form-group__control-field"))}}
6
+ </F.Control>
7
+ </Hds::Form::Fieldset>
@@ -0,0 +1,3 @@
1
+ <select class={{this.classNames}} {{style width=@width}} ...attributes>
2
+ {{yield (hash Options=(component "hds/yield"))}}
3
+ </select>